FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/dev/performance/LICENSE.txt
Normal file
339
sites/all/modules/contrib/dev/performance/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
132
sites/all/modules/contrib/dev/performance/README.txt
Normal file
132
sites/all/modules/contrib/dev/performance/README.txt
Normal file
@@ -0,0 +1,132 @@
|
||||
By Khalid Baheyeldin
|
||||
|
||||
Copyright 2008 http://2bits.com
|
||||
|
||||
Description
|
||||
-----------
|
||||
This module provides performance statistics logging for a site, such as page
|
||||
generation times, and memory usage, for each page load.
|
||||
|
||||
This module is useful for developers and site administrators alike to identify
|
||||
pages that are slow to generate or use excessive memory.
|
||||
|
||||
Features include:
|
||||
* Settings to enable detailed logging or summary logging. The module defaults to
|
||||
no logging at all.
|
||||
|
||||
* Detailed logging causes one database row to be written for each page load of
|
||||
the site. The data includes page generation time in milliseconds, and the
|
||||
number of bytes allocated to PHP, time stamp, etc.
|
||||
|
||||
* Summary logging logs the average and maximum page generation time, average and
|
||||
maximum memory usage, last access time, and number of accesses for each path.
|
||||
|
||||
* Summary can be logged to any cache for which a Drupal caching module is
|
||||
available that transparently integrates with the drupal cache layer. Some
|
||||
examples:
|
||||
http://drupal.org/project/apc
|
||||
http://drupal.org/project/memcache
|
||||
http://drupal.org/project/filecache
|
||||
|
||||
* A settings option is available when using summary mode, to exclude
|
||||
pages with less than a certain number of accesses. Useful for large sites.
|
||||
|
||||
* Support for normal page cache.
|
||||
|
||||
Note that detailed logging is only suitable for a site that is in development or
|
||||
testing. Do NOT enable detailed logging on a live site.
|
||||
|
||||
The memory measurement feature of this module depends on the
|
||||
memory_get_peak_usage() function, available only in PHP 5.2.x or later.
|
||||
|
||||
Only summary logging with Memcache, APC or similar mechanisms are the
|
||||
recommended mode for live sites, with a threshold of 2 or more.
|
||||
|
||||
Note on Completeness:
|
||||
---------------------
|
||||
Please note that when summary logging to APC or Memcache, the data captured in
|
||||
the summary will not be comprehensive reflecting every single page view for
|
||||
every URL.
|
||||
|
||||
The reason for this is that there is no atomic locking when updating the data
|
||||
structures that store per-URL statistics in this module.
|
||||
|
||||
This means that the values you get when using these storage caches are only
|
||||
samples, and would miss some page views, depending on how busy the site is.
|
||||
|
||||
For memcache, there is way to implement locking using the $mc->increment and/or
|
||||
$mc->add as well. However, there is a risk if these are implemented, that there
|
||||
will be less concurrency and we can cause a site to slow down.
|
||||
|
||||
Configuration:
|
||||
--------------
|
||||
To configure the Performance Logging and Monitoring module, navigate to
|
||||
/admin/config/development/performance-logging. By default, this module creates a
|
||||
key for each entry based off of the hostname of the site being accessed. If you
|
||||
have a site with multiple domains, it is recommended to specify a shared key
|
||||
between all sites in your settings.php file:
|
||||
|
||||
$conf['performance_key'] = 'example_key';
|
||||
|
||||
If you are using memcache, then you need to configure an extra bin for
|
||||
performance. If you have multiple web server boxes, then it is best to
|
||||
centralize this bin for all the boxes, so you get combined statistics.
|
||||
|
||||
Your settings.php looks like this:
|
||||
|
||||
$conf['cache_backends'][] = './sites/all/modules/memcache/memcache.inc';
|
||||
$conf['cache_default_class'] = 'MemCacheDrupal';
|
||||
// Prevent special cache_form bin from being assigned to a volatile cache
|
||||
// storage implementation
|
||||
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
|
||||
|
||||
$conf['memcache_servers'] = array(
|
||||
'127.0.0.1:11211' => 'default',
|
||||
// More bins here ....
|
||||
'127.0.0.1:11311' => 'performance',
|
||||
);
|
||||
$conf['memcache_bins'] = array(
|
||||
'cache_performance' => 'performance',
|
||||
);
|
||||
|
||||
Note that since version 2.x, you can use any Drupal caching module available
|
||||
that transparently integrates with the drupal cache layer (like the apc or
|
||||
filecache modules).
|
||||
|
||||
Statistics:
|
||||
-----------
|
||||
You can view the recorded performance statistics (summary and details) at
|
||||
/admin/reports/performance-logging
|
||||
|
||||
Drush support
|
||||
-------------
|
||||
Drush support has been integrated as well. You can check the summary and detail
|
||||
logs using the performance-summary (aliased as perf-sm) and performance-detail
|
||||
(aliased as perf-dt) commands. Some examples:
|
||||
|
||||
Retrieve last 15 entries from the detail log:
|
||||
drush performance-detail 15
|
||||
|
||||
Retrieve last 20 summary log entries sorted by the number of queries,
|
||||
descending:
|
||||
drush performance-summary 20 query_count
|
||||
|
||||
Retrieve last 35 entries from the detail log sorted by size, ascending:
|
||||
drush performance-detail 35 bytes asc
|
||||
|
||||
Use drush perf-sm --help or drush perf-dt --help to see a full explanation.
|
||||
|
||||
Bugs/Features/Patches:
|
||||
----------------------
|
||||
If you want to report bugs, feature requests, or submit a patch, please do so at
|
||||
the project page on the Drupal web site at http://drupal.org/project/performance
|
||||
|
||||
Author
|
||||
------
|
||||
Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
|
||||
|
||||
If you use this module, find it useful, and want to send the author a thank you
|
||||
note, then use the Feedback/Contact page at the URL above.
|
||||
|
||||
The author can also be contacted for paid customizations of this and other
|
||||
modules.
|
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views integration for the Performance module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function performance_views_data() {
|
||||
// The 'group' index will be used as a prefix in the UI for any of this
|
||||
// table's fields, sort criteria, etc. so it's easy to tell where they came
|
||||
// from.
|
||||
// Find it a bit silly in the performance logging context but it's mandatory.
|
||||
$data['performance_detail']['table']['group'] = t('Performance logging details');
|
||||
|
||||
$data['performance_detail']['table']['base'] = array(
|
||||
'field' => 'pid',
|
||||
'title' => t('Performance logging details'),
|
||||
'weight' => -10,
|
||||
);
|
||||
|
||||
// Path ID field.
|
||||
$data['performance_detail']['pid'] = array(
|
||||
'title' => t('Path ID'),
|
||||
'help' => t('Serialised ID field.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Last access field.
|
||||
$data['performance_detail']['timestamp'] = array(
|
||||
'title' => t('Timestamp'),
|
||||
'help' => t('Time when this data was recorded.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_date',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort_date',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_date',
|
||||
),
|
||||
);
|
||||
|
||||
// Bytes field.
|
||||
$data['performance_detail']['bytes'] = array(
|
||||
'title' => t('Bytes'),
|
||||
'help' => t('Amount of memory consumed in bytes when rendering the page.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Bytes field.
|
||||
$data['performance_detail']['ms'] = array(
|
||||
'title' => t('Milliseconds'),
|
||||
'help' => t('Amount of milliseconds needed to render this page.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Query count field.
|
||||
$data['performance_detail']['query_count'] = array(
|
||||
'title' => t('Query count'),
|
||||
'help' => t('Amount of queries executed when rendering this page.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Query timer field.
|
||||
$data['performance_detail']['query_timer'] = array(
|
||||
'title' => t('Query timer'),
|
||||
'help' => t('Amount of milliseconds spent on queries for this page.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Anonymous user field.
|
||||
$data['performance_detail']['anon'] = array(
|
||||
'title' => t('Anonymous user?'),
|
||||
'help' => t('Whether the access was by an anonymous user or not.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_boolean',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_boolean_operator',
|
||||
'label' => t('Anonymous?'),
|
||||
'type' => 'yes-no',
|
||||
// use boolean_field = 1 instead of boolean_field <> 0 in WHERE statment
|
||||
'use equal' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// Path field.
|
||||
$data['performance_detail']['path'] = array(
|
||||
'title' => t('Path'),
|
||||
'help' => t('The path of the page for which detailed performance logging was stored.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
340
sites/all/modules/contrib/dev/performance/performance.drush.inc
Normal file
340
sites/all/modules/contrib/dev/performance/performance.drush.inc
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Drush integration for the Performance module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function performance_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$limit = "Limit the number of records. Defaults to 25.";
|
||||
$direction = "Sort direction, defaults to descending: asc or desc.";
|
||||
|
||||
$items['performance-summary'] = array(
|
||||
'callback' => 'drush_performance_summary',
|
||||
'description' => "Display the Performance Logging and Monitoring summary entries.",
|
||||
'aliases' => array('perf-sm'),
|
||||
'arguments' => array(
|
||||
'limit' => $limit,
|
||||
'orderby' => "The column name to sort on, defaults to last_access: path, last_access, bytes_max, bytes_avg, ms_max, ms_avg, [query_count_max, query_count_avg, query_timer_max, query_timer_avg] or num_accesses.",
|
||||
'direction' => $direction,
|
||||
),
|
||||
'examples' => array(
|
||||
'performance-summary 25' => 'Retrieve last 25 entries.',
|
||||
'performance-summary 10 path' => 'Retrieve last 10 entries sorted by path, descending.',
|
||||
'performance-summary 40 bytes_avg asc' => 'Retrieve last 40 entries sorted by average size, ascending.',
|
||||
),
|
||||
);
|
||||
|
||||
$items['performance-detail'] = array(
|
||||
'callback' => 'drush_performance_details',
|
||||
'description' => "Display the Performance Logging and Monitoring detail entries.",
|
||||
'aliases' => array('perf-dt'),
|
||||
'arguments' => array(
|
||||
'limit' => $limit,
|
||||
'orderby' => "The column name to sort on, defaults to timestamp: pid, timestamp, bytes, ms, [query_count, query_timer], anon or path.",
|
||||
'direction' => $direction,
|
||||
),
|
||||
'examples' => array(
|
||||
'performance-detail 15' => 'Retrieve last 15 entries.',
|
||||
'performance-detail 20 query_count' => 'Retrieve last 20 entries sorted by the number of queries, descending.',
|
||||
'performance-detail 35 bytes asc' => 'Retrieve last 35 entries sorted by size, ascending.',
|
||||
),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary page callback.
|
||||
* Differs a little from the version in the module because drush_print_table()
|
||||
* works differently.
|
||||
*/
|
||||
function drush_performance_summary() {
|
||||
$args = func_get_args();
|
||||
|
||||
// Collect arguments.
|
||||
$orderby = 'last_access';
|
||||
$columns = array('path', 'last_access', 'bytes_max', 'bytes_avg', 'ms_max', 'ms_avg', 'num_accesses');
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$columns[] = 'query_count_max';
|
||||
$columns[] = 'query_count_avg';
|
||||
$columns[] = 'query_timer_max';
|
||||
$columns[] = 'query_timer_avg';
|
||||
}
|
||||
$arguments = drush_performance_parse_args($args, $orderby, $columns);
|
||||
// Error thrown, abort.
|
||||
if (!is_array($arguments)) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
// Go back no more than 1 hour.
|
||||
$arguments['timestamp'] = REQUEST_TIME - 60 * 60;
|
||||
|
||||
// Get actual data.
|
||||
$data_list = performance_traverse_cache('drush_performance_get_summary', $arguments);
|
||||
$data_list = performance_sort_summary($data_list, $arguments['direction'], $arguments['orderby']);
|
||||
|
||||
if (empty($data_list) && !variable_get('performance_summary', 0)) {
|
||||
return drush_set_error(dt('Summary performance log is not enabled. Go to the settings page to enable it.'));
|
||||
}
|
||||
elseif (empty($data_list)) {
|
||||
drush_print("\033[1m" . dt('No log messages available.') . "\033[0m\n", 1);
|
||||
drush_print(dt('Possible causes:'), 1);
|
||||
drush_print('- ' . dt('no data stored yet'), 2);
|
||||
drush_print('- ' . dt('all data stored is older than one hour'), 2);
|
||||
return drush_print('- $base_url ' . dt('not properly set: run drush with the --uri parameter'), 2);
|
||||
}
|
||||
elseif (!variable_get('performance_summary', 0)) {
|
||||
drush_print("\033[1;33m" . dt('Summary performance log is not enabled! Showing stored logs.') . "\033[0m\n", 1);
|
||||
}
|
||||
|
||||
// Build table header.
|
||||
$header = array(
|
||||
dt('Path'),
|
||||
dt('Last access'),
|
||||
dt('# accesses'),
|
||||
dt('MB Memory (Max)'),
|
||||
dt('MB Memory (Avg)'),
|
||||
dt('ms (Max)'),
|
||||
dt('ms (Avg)'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = dt('Query ms (Max)');
|
||||
$header[] = dt('Query ms (Avg)');
|
||||
$header[] = dt('Query Count (Max)');
|
||||
$header[] = dt('Query Count (Avg)');
|
||||
}
|
||||
$rows[] = $header;
|
||||
|
||||
// Format data into table.
|
||||
$threshold = variable_get('performance_threshold_accesses', 0);
|
||||
$total_rows = $shown = $last_max = $total_bytes = $total_ms = $total_accesses = 0;
|
||||
$last_min = REQUEST_TIME;
|
||||
|
||||
foreach ($data_list as $data) {
|
||||
$total_rows++;
|
||||
$last_max = max($last_max, $data['last_access']);
|
||||
$last_min = min($last_min, $data['last_access']);
|
||||
|
||||
// Calculate running averages.
|
||||
$total_bytes += $data['bytes_sum'] / $data['num_accesses'];
|
||||
$total_ms += $data['ms_sum'] / $data['num_accesses'];
|
||||
$total_accesses += $data['num_accesses'];
|
||||
|
||||
$row_data = array();
|
||||
if ($data['num_accesses'] > $threshold) {
|
||||
$shown++;
|
||||
$row_data[] = check_plain($data['path']);
|
||||
$row_data[] = format_date($data['last_access'], 'small');
|
||||
$row_data[] = $data['num_accesses'];
|
||||
$row_data[] = number_format($data['bytes_max'] / 1024 / 1024, 2);
|
||||
$row_data[] = number_format($data['bytes_avg'] / 1024 / 1024, 2);
|
||||
$row_data[] = number_format($data['ms_max'], 1);
|
||||
$row_data[] = number_format($data['ms_avg'], 1);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = number_format($data['query_timer_max'], 1);
|
||||
$row_data[] = number_format($data['query_timer_avg'], 1);
|
||||
$row_data[] = $data['query_count_max'];
|
||||
$row_data[] = $data['query_count_avg'];
|
||||
}
|
||||
}
|
||||
$rows[] = $row_data;
|
||||
}
|
||||
|
||||
if (!$rows) {
|
||||
$rows[] = dt('No statistics available yet.');
|
||||
}
|
||||
|
||||
if ($threshold) {
|
||||
drush_print("\n" . dt('Showing !shown paths with more than !threshold accesses, out of !total total paths.',
|
||||
array('!threshold' => $threshold, '!shown' => $shown, '!total' => $total_rows)));
|
||||
}
|
||||
else {
|
||||
drush_print("\n" . dt('Showing all !total paths.', array('!total' => $total_rows)));
|
||||
}
|
||||
|
||||
// Protect against divide by zero.
|
||||
if ($total_rows > 0) {
|
||||
$mb_avg = number_format($total_bytes / $total_rows / 1024 / 1024, 1);
|
||||
$ms_avg = number_format($total_ms / $total_rows, 2);
|
||||
}
|
||||
else {
|
||||
$mb_avg = 'n/a';
|
||||
$ms_avg = 'n/a';
|
||||
}
|
||||
|
||||
drush_print(dt('Average memory per page: !mb_avg MB', array('!mb_avg' => $mb_avg)));
|
||||
drush_print(dt('Average duration per page: !ms_avg ms', array('!ms_avg' => $ms_avg)));
|
||||
drush_print(dt('Total number of page accesses: !accesses', array('!accesses' => $total_accesses)));
|
||||
drush_print(dt('First access: !access.', array('!access' => format_date($last_min, 'small'))));
|
||||
drush_print(dt('Last access: !access.', array('!access' => format_date($last_max, 'small'))) . "\n");
|
||||
|
||||
drush_print("\033[1m" . dt('Performance log summary: !rows entries ordered by !column, !direction', array('!rows' => count($rows) - 1, '!column' => $arguments['orderby'], '!direction' => $arguments['direction'])) . "\033[0m", 1);
|
||||
|
||||
// TODO: add 'running averages' here, like in the Drupal backend.
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
|
||||
function drush_performance_details() {
|
||||
$header = array(
|
||||
dt('#'),
|
||||
dt('Date'),
|
||||
dt('Path'),
|
||||
dt('Memory (MB)'),
|
||||
dt('ms (Total)'),
|
||||
dt('Anonymous?'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = dt('# Queries');
|
||||
$header[] = dt('Query ms');
|
||||
}
|
||||
$rows[] = $header;
|
||||
|
||||
// Collect arguments.
|
||||
$args = func_get_args();
|
||||
$orderby = 'timestamp';
|
||||
$columns = array('pid', 'timestamp', 'bytes', 'ms', 'anon', 'path');
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$columns[] = 'query_count';
|
||||
$columns[] = 'query_timer';
|
||||
}
|
||||
$arguments = drush_performance_parse_args($args, $orderby, $columns);
|
||||
|
||||
// Error thrown, abort.
|
||||
if (!is_array($arguments)) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$data_list = drush_performance_get_detail($arguments);
|
||||
|
||||
if (empty($data_list) && !variable_get('performance_detail', 0)) {
|
||||
return drush_set_error(dt('Detail performance log is not enabled! Go to the settings page to enable it.'));
|
||||
}
|
||||
elseif (empty($data_list)) {
|
||||
return drush_print("\033[1m" . dt('No log messages available.') . "\033[0m", 1);
|
||||
}
|
||||
elseif (!variable_get('performance_detail', 0)) {
|
||||
drush_print("\033[1;33m" . dt('Detail performance log is not enabled! Showing stored logs.') . "\033[0m\n", 1);
|
||||
}
|
||||
|
||||
foreach ($data_list as $data) {
|
||||
// Cast to object because of the DB API now returning row objects by default.
|
||||
$data = is_array($data) ? (object)$data : $data;
|
||||
$row_data = array();
|
||||
$row_data[] = $data->pid;
|
||||
$row_data[] = format_date($data->timestamp, 'small');
|
||||
$row_data[] = check_plain($data->path);
|
||||
$row_data[] = number_format($data->bytes/1024/1024, 2);
|
||||
$row_data[] = $data->ms;
|
||||
$row_data[] = ($data->anon) ? t('Yes') : t('No');
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = $data->query_count;
|
||||
$row_data[] = $data->query_timer;
|
||||
}
|
||||
|
||||
$rows[] = $row_data;
|
||||
}
|
||||
|
||||
drush_print("\033[1m" . dt('Performance log details: !rows entries ordered by !column, !direction', array('!rows' => count($rows) - 1, '!column' => $arguments['orderby'], '!direction' => $arguments['direction'])) . "\033[0m", 1);
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to parse the arguments which are the same for both commands.
|
||||
* Only columns differ.
|
||||
*/
|
||||
function drush_performance_parse_args($args, $orderby, $columns) {
|
||||
$arguments = array();
|
||||
$default = TRUE;
|
||||
|
||||
// Set limit from arguments or fall back to default.
|
||||
$arguments['limit'] = 25;
|
||||
if ((count($args) > 2 || count($args) == 1) && isset($args[0])) {
|
||||
if (is_numeric($args[0])) {
|
||||
$arguments['limit'] = $args[0];
|
||||
}
|
||||
else {
|
||||
return drush_set_error(dt('First argument must be numeric!'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 1st parameter was most likely omitted, so we prepend the default to the
|
||||
// arguments to make the following checks check the right argument :-)
|
||||
array_unshift($args, $arguments['limit']);
|
||||
}
|
||||
|
||||
// Order by column name.
|
||||
$arguments['orderby'] = $orderby;
|
||||
if (isset($args[1])) {
|
||||
if (in_array($args[1], $columns)) {
|
||||
$arguments['orderby'] = $args[1];
|
||||
}
|
||||
// Let the user know what the options are.
|
||||
else {
|
||||
return drush_set_error(dt('Unknown column name. Possible values are: !columns', array('!columns' => implode(', ', $columns))));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort direction.
|
||||
$arguments['direction'] = 'desc';
|
||||
$options = array('asc', 'desc');
|
||||
if (isset($args[2])) {
|
||||
if (in_array($args[2], $options)) {
|
||||
$arguments['direction'] = $args[2];
|
||||
}
|
||||
// Let the user know what the options are.
|
||||
else {
|
||||
return drush_set_error(dt('Unknown sort direction. Possible values are: !options', array('!options' => implode(', ', $options))));
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used by performance_traverse_cache() for fetching summary data.
|
||||
*
|
||||
* @param $cache cache object
|
||||
* @param $arguments associative array containing limit and timestamp
|
||||
* @return the processed data or NULL
|
||||
*
|
||||
* @see performance_traverse_cache()
|
||||
*/
|
||||
function drush_performance_get_summary($cache, $arguments) {
|
||||
static $count = 0;
|
||||
|
||||
if ($cache->data['last_access'] >= $arguments['timestamp'] && $count < $arguments['limit']) {
|
||||
$count++;
|
||||
return $cache->data;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drupal version independant variation of performance_db_get_data() for easy
|
||||
* maintenance of the drush commands.
|
||||
*/
|
||||
function drush_performance_get_detail($arguments) {
|
||||
$data_list = array();
|
||||
|
||||
$result = drush_db_select('performance_detail', '*', NULL, NULL, 0, $arguments['limit'], $arguments['orderby'], $arguments['direction']);
|
||||
if (drush_drupal_major_version() >= 7) {
|
||||
foreach ($result as $row) {
|
||||
$data_list[] = $row;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while ($row = db_fetch_object($result)) {
|
||||
$data_list[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $data_list;
|
||||
}
|
14
sites/all/modules/contrib/dev/performance/performance.info
Normal file
14
sites/all/modules/contrib/dev/performance/performance.info
Normal file
@@ -0,0 +1,14 @@
|
||||
name = Performance Logging
|
||||
description = Logs detailed and/or summary page generation time and memory consumption for page requests.
|
||||
package = Development
|
||||
core = 7.x
|
||||
configure = admin/config/development/performance-logging
|
||||
tags[] = developer
|
||||
tags[] = monitoring
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-12
|
||||
version = "7.x-2.0-beta1"
|
||||
core = "7.x"
|
||||
project = "performance"
|
||||
datestamp = "1358019516"
|
||||
|
389
sites/all/modules/contrib/dev/performance/performance.install
Normal file
389
sites/all/modules/contrib/dev/performance/performance.install
Normal file
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install and update for Performance Logging
|
||||
*
|
||||
* Copyright Khalid Baheyeldin 2008 of http://2bits.com
|
||||
*/
|
||||
|
||||
// Minimum APC shm memory size to require
|
||||
define('PERFORMANCE_MIN_MEMORY', 48);
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function performance_schema() {
|
||||
$schema = array();
|
||||
|
||||
$schema['cache_performance'] = array(
|
||||
'description' => 'Table that holds summary performance data.',
|
||||
'fields' => array(
|
||||
'cid' => array(
|
||||
'description' => 'Primary Key: Unique cache ID.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'A collection of data to cache.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
),
|
||||
'expire' => array(
|
||||
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'created' => array(
|
||||
'description' => 'A Unix timestamp indicating when the cache entry was created.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'serialized' => array(
|
||||
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
|
||||
'type' => 'int',
|
||||
'size' => 'small',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'expire' => array('expire'),
|
||||
),
|
||||
'primary key' => array('cid'),
|
||||
);
|
||||
|
||||
$schema['performance_detail'] = array(
|
||||
'fields' => array(
|
||||
'pid' => array(
|
||||
'description' => 'Primary Key: Unique path ID.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'timestamp' => array(
|
||||
'description' => 'A Unix timestamp indicating when the entry was created.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'bytes' => array(
|
||||
'description' => 'Memory consumed in bytes.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'ms' => array(
|
||||
'description' => 'Time consumed in milliseconds.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'query_count' => array(
|
||||
'description' => 'Number of queries executed.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'query_timer' => array(
|
||||
'description' => 'Time taken to execute queries.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'anon' => array(
|
||||
'description' => 'Whether the page was accessed by an anonymous user.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'default' => 1,
|
||||
),
|
||||
'path' => array(
|
||||
'description' => 'The path the data belongs to.',
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'language' => array(
|
||||
'description' => 'The {languages}.language used when calling this path.',
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'Additional (debug) info for future expansion.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
),
|
||||
),
|
||||
'primary key' => array('pid'),
|
||||
'indexes' => array(
|
||||
'timestamp' => array('timestamp'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function performance_install() {
|
||||
// Set the weight so this module runs last
|
||||
// SQL: UPDATE {system} SET weight = 3000 WHERE name = 'performance'
|
||||
db_update('system')
|
||||
->fields(array('weight' => 3000))
|
||||
->condition('name', 'performance')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function performance_uninstall() {
|
||||
// SQL: DELETE FROM {variable} WHERE name LIKE 'performance\_%'
|
||||
db_delete('variable')
|
||||
->condition('name', 'performance\_%', 'LIKE')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function performance_requirements($phase) {
|
||||
$requirements = array();
|
||||
|
||||
if ($phase != 'runtime') {
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
if (variable_get('performance_detail', 0)) {
|
||||
$requirements['performance_detail'] = array(
|
||||
'title' => t('Performance logging details'),
|
||||
'value' => 'Enabled',
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('Performance detailed logging is !link. This can cause severe issues on live sites.', array('!link' => l(t('enabled'), PERFORMANCE_SETTINGS))),
|
||||
);
|
||||
}
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
if (variable_get('performance_detail', 0) || variable_get('performance_summary', 0)) {
|
||||
$requirements['performance_query'] = array(
|
||||
'title' => t('Performance logging query'),
|
||||
'value' => 'Enabled',
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('Query timing and count logging is !link. This can cause memory size per page to be larger than normal.', array('!link' => l(t('enabled'), PERFORMANCE_SETTINGS))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$default = 'DrupalDatabaseCache';
|
||||
$cache = variable_get(PERFORMANCE_CACHE, $default);
|
||||
if ($cache == $default) {
|
||||
$requirements['performance_cache'] = array(
|
||||
'title' => t('Performance logging summary'),
|
||||
'value' => 'Disabled',
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('Performance logging on live web sites works best if an alternative caching mechanism, like APC or Memcache, is enabled.'),
|
||||
);
|
||||
}
|
||||
|
||||
$shm_size = ini_get('apc.shm_size');
|
||||
if (function_exists('apc_fetch') && $shm_size < PERFORMANCE_MIN_MEMORY) {
|
||||
$requirements['performance_apc_mem'] = array(
|
||||
'title' => t('Performance logging APC memory size'),
|
||||
'value' => $shm_size,
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('APC has been configured for !size, which is less than the recommended !min_memory MB of memory. If you encounter errors when viewing the summary report, then try to increase that limit for APC.', array('!size' => 1 * $shm_size, '!min_memory' => PERFORMANCE_MIN_MEMORY)),
|
||||
);
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Harmonize notations for milliseconds to "ms".
|
||||
*/
|
||||
function performance_update_7001() {
|
||||
$int_field = array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'disp-width' => '11',
|
||||
);
|
||||
|
||||
db_change_field('performance_summary', 'millisecs_max', 'ms_max', $int_field);
|
||||
db_change_field('performance_summary', 'millisecs_avg', 'ms_avg', $int_field);
|
||||
db_change_field('performance_detail', 'millisecs', 'ms', $int_field);
|
||||
|
||||
// We don't have a cache update method, so it's better to clear it
|
||||
if (function_exists('apc_fetch')) {
|
||||
apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move summary data from old performance_summary table to new cache bin.
|
||||
* Note that we now cache per language and separate anonymous users from logged
|
||||
* in users! During this migration, we do BASIC separation between anonymous and
|
||||
* logged in users based on admin paths. Back up your data if you want to keep
|
||||
* the original logs!
|
||||
* DRUSH NOTE: make sure to set a proper $base_url using the --uri parameter or
|
||||
* by means of a drushrc.php config file! Alternatively you can setup a
|
||||
* $conf['performance_key'] = 'my_unique_key'; in settings.php when using
|
||||
* multiple domains for one site.
|
||||
*/
|
||||
function performance_update_7200() {
|
||||
global $language;
|
||||
|
||||
// Abort when improperly invoked when using drush. See DRUSH NOTE above.
|
||||
if(drupal_is_cli() && variable_get('performance_key', FALSE) === FALSE && $GLOBALS['base_url'] == 'http://default') {
|
||||
// Throw an exception to make this update fail. Found no other way. Better
|
||||
// suggestion anyone? Tried various drush functions, such as
|
||||
// drush_set_error(), to no avail. Update was always marked as 'completed'
|
||||
// and was not re-executed when re-running drush updb.
|
||||
throw new Exception(dt("Please run drush with the --uri parameter or setup a drushrc.php file to successfully migrate the summary data! The site's domain name will be used in the cache key! Use \$conf['performance_key'] = 'my_unique_key'; in settings.php when using multiple domains on one site."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new cache bin, see http://drupal.org/node/150220.
|
||||
$table = array(
|
||||
'description' => 'Table that holds summary performance data.',
|
||||
'fields' => array(
|
||||
'cid' => array(
|
||||
'description' => 'Primary Key: Unique cache ID.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'A collection of data to cache.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
),
|
||||
'expire' => array(
|
||||
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'created' => array(
|
||||
'description' => 'A Unix timestamp indicating when the cache entry was created.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'serialized' => array(
|
||||
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
|
||||
'type' => 'int',
|
||||
'size' => 'small',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'expire' => array('expire'),
|
||||
),
|
||||
'primary key' => array('cid'),
|
||||
);
|
||||
|
||||
$keys_cache = array();
|
||||
// Keep records for 1 day.
|
||||
$expire = REQUEST_TIME + (24 * 60 * 60);
|
||||
|
||||
// Extra check to prevent errors when running this update multiple times.
|
||||
if (db_table_exists('performance_summary') && !db_table_exists('cache_performance')) {
|
||||
db_create_table('cache_performance', $table);
|
||||
|
||||
$result = db_select('performance_summary', 'ps')
|
||||
->fields('ps')
|
||||
->execute();
|
||||
foreach ($result as $row) {
|
||||
// Make some BASIC separation between anonymous users and logged in users.
|
||||
$anonymous = 1;
|
||||
if (preg_match('/^(admin|admin\/.*|node\/add.*)$/i', $row->path) || preg_match('/^(node|user)\/\d+\/(edit|translate|delete|revisions.*)$/i', $row->path)) {
|
||||
$anonymous = 0;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'path' => $row->path,
|
||||
'bytes_max' => $row->bytes_max,
|
||||
'bytes_sum' => $row->bytes_avg * $row->num_accesses,
|
||||
'ms_max' => $row->ms_max,
|
||||
'ms_sum' => $row->ms_avg * $row->num_accesses,
|
||||
'query_timer_max' => $row->query_timer_max,
|
||||
'query_timer_sum' => $row->query_timer_avg * $row->num_accesses,
|
||||
'query_count_max' => $row->query_count_max,
|
||||
'query_count_sum' => $row->query_count_avg * $row->num_accesses,
|
||||
'num_accesses' => $row->num_accesses,
|
||||
'last_access' => $row->last_access,
|
||||
'anon' => $anonymous,
|
||||
'language' => $language->language,
|
||||
);
|
||||
// We now cache per language and distinguish between anonymous users and
|
||||
// logged in users. As usual, we keep logs for one day!
|
||||
$key = PERFORMANCE_KEY . $row->path . ':' . $language->language . ':' . $anonymous;
|
||||
cache_set($key, $data, 'cache_performance', $expire);
|
||||
// Keep the key for the key cache store. We do it this way so that keys
|
||||
// will replace eachother which would not happen when using
|
||||
// $keys_cache[] = $key;
|
||||
$keys_cache[$key] = 1;
|
||||
}
|
||||
// This will allow easy retrieval of data as we cannot use SQL queries since
|
||||
// the cache store can by anything!
|
||||
cache_set(PERFORMANCE_KEY, $keys_cache, 'cache_performance');
|
||||
|
||||
// No longer needed!
|
||||
db_drop_table('performance_summary');
|
||||
|
||||
// Preserve summary logging setting if enabled.
|
||||
// There can, in theory, be unlimited variables named performance_summary_%
|
||||
// where we do not know what % is, hence this approach.
|
||||
$result = db_select('variable', 'v')
|
||||
->fields('v', array('value'))
|
||||
->condition('name', 'performance_summary\_%', 'LIKE')
|
||||
->execute();
|
||||
foreach ($result as $row) {
|
||||
if (unserialize($row->value)) {
|
||||
variable_set('performance_summary', 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete old performance summary variables!
|
||||
db_delete('variable')
|
||||
->condition('name', 'performance_summary\_%', 'LIKE')
|
||||
->execute();
|
||||
|
||||
return t('Migrated all data from old performance_summary table to new cache bin.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new language field to performance_detail table.
|
||||
*/
|
||||
function performance_update_7201() {
|
||||
$field = 'language';
|
||||
$table = 'performance_detail';
|
||||
|
||||
// See http://drupal.org/node/150220.
|
||||
$language = array(
|
||||
'description' => 'The {languages}.language used when calling this path.',
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
);
|
||||
|
||||
if (!db_field_exists($table, $field)) {
|
||||
db_add_field($table, $field, $language);
|
||||
return t('Created language field in performance_detail table.');
|
||||
}
|
||||
}
|
955
sites/all/modules/contrib/dev/performance/performance.module
Normal file
955
sites/all/modules/contrib/dev/performance/performance.module
Normal file
@@ -0,0 +1,955 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Logs detailed and/or summary page generation time and memory consumption for
|
||||
* page requests.
|
||||
* Copyright Khalid Baheyeldin 2008 of http://2bits.com
|
||||
*/
|
||||
|
||||
// Check for a variable for the performance key. This allows you to set a
|
||||
// unique key in the case that you have multiple domains accessing the same
|
||||
// site. If this is not set, fall back to the hostname which we get from the
|
||||
// base_url global variable for drush compatibility (you will need to pass the
|
||||
// --url parameter to drush).
|
||||
define('PERFORMANCE_KEY', 'dru-perf:' . variable_get('performance_key', parse_url($GLOBALS['base_url'], PHP_URL_HOST)) . ':');
|
||||
|
||||
define('PERFORMANCE_BIN', 'cache_performance');
|
||||
|
||||
define('PERFORMANCE_QUERY_VAR', 'performance_query');
|
||||
|
||||
define('PERFORMANCE_CACHE', 'cache_default_class');
|
||||
|
||||
define('PERFORMANCE_SETTINGS', 'admin/config/development/performance-logging');
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function performance_menu() {
|
||||
$items = array();
|
||||
|
||||
$items[PERFORMANCE_SETTINGS] = array(
|
||||
'title' => 'Performance logging',
|
||||
'description' => 'Logs performance data: page generation times and memory usage.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('performance_settings_form'),
|
||||
'access arguments' => array('administer performance logging'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/reports/performance-logging'] = array(
|
||||
'title' => 'Performance logs',
|
||||
'description' => 'View summary performance logs: page generation times and memory usage.',
|
||||
'page callback' => 'performance_view_summary',
|
||||
'access arguments' => array('administer performance logging'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/reports/performance-logging/summary'] = array(
|
||||
'title' => 'Summary',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => 0,
|
||||
);
|
||||
|
||||
$items['admin/reports/performance-logging/details'] = array(
|
||||
'title' => 'Details',
|
||||
'description' => 'View detailed, per page, performance logs: page generation times and memory usage.',
|
||||
'page callback' => 'performance_view_details',
|
||||
'access arguments' => array('administer performance logging'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 1,
|
||||
);
|
||||
|
||||
// We use no % after clear here (clear/%) to catch the arguments because we do
|
||||
// not want the clear page to fall back on its parent when no argument is
|
||||
// passed. See the callback of the page for more info.
|
||||
$items['admin/reports/performance-logging/clear'] = array(
|
||||
'title' => 'Clear logs',
|
||||
'description' => 'Clears all collected performance statistics.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('performance_clear_form'),
|
||||
'access arguments' => array('administer performance logging'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'weight' => 1,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function performance_permission() {
|
||||
return array(
|
||||
'administer performance logging' => array(
|
||||
'title' => t('Administer performance logging'),
|
||||
'description' => t('Allows both configuring the performance module and accessing its reports.'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_cron().
|
||||
*/
|
||||
function performance_cron() {
|
||||
// Remove all entries that have expired.
|
||||
// TODO: make this work as expected, seems to throw away everything now :-s
|
||||
cache_clear_all(NULL, PERFORMANCE_BIN);
|
||||
|
||||
// Remove entries that have less than so many accesses
|
||||
performance_traverse_cache('performance_cron_prune');
|
||||
|
||||
// Remove performance_detail rows on a daily basis.
|
||||
db_delete('performance_detail')
|
||||
->condition('timestamp', REQUEST_TIME - (24 * 60 * 60), '<=')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used by performance_traverse_cache() for pruning data on cron based
|
||||
* on a preset threshold.
|
||||
*
|
||||
* @param $cache cache object
|
||||
*
|
||||
* @see performance_traverse_cache()
|
||||
*/
|
||||
function performance_cron_prune($cache) {
|
||||
static $threshold;
|
||||
// Prevent a variable_get() each time this callback is triggered.
|
||||
if(!isset($threshold)) {
|
||||
$threshold = variable_get('performance_threshold_accesses', 0);
|
||||
}
|
||||
|
||||
if ($threshold && $cache->data['num_accesses'] <= $threshold) {
|
||||
cache_clear_all($cache->cid, PERFORMANCE_BIN);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function performance_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
'path' => drupal_get_path('module', 'performance') . '/includes',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* System settings form.
|
||||
*/
|
||||
function performance_settings_form() {
|
||||
$status = performance_caching_message();
|
||||
|
||||
// Setup settings form.
|
||||
$form['mode'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Logging mode'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
|
||||
$form['mode']['performance_detail'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Detailed logging'),
|
||||
'#default_value' => variable_get('performance_detail', 0),
|
||||
'#description' => t('Log memory usage and page generation times for every page. This logging mode is <strong>not</strong> suitable for large sites, as it can degrade performance severly. It is intended for use by developers, or on a test copy of the site.'),
|
||||
);
|
||||
|
||||
$form['mode']['performance_summary'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Summary logging'),
|
||||
'#default_value' => variable_get('performance_summary', 0),
|
||||
'#description' => t('Log summary data, such as average and maximum page generation times and memory usage.'),
|
||||
);
|
||||
|
||||
if ($status != 'error') {
|
||||
$form['mode']['performance_summary']['#description'] .= ' ' . t('The summary will be stored in an alternative cache, and hence there is no load on the database. This logging is suitable for most live sites, unless the number of unique page accesses is excessively high.');
|
||||
}
|
||||
else {
|
||||
$form['mode']['performance_summary']['#description'] .= ' ' . t('This logging mode is <strong>not</strong> suitable for most live sites.');
|
||||
}
|
||||
|
||||
$form['other'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Other'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
|
||||
$form['other'][PERFORMANCE_QUERY_VAR] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Database Query timing and count'),
|
||||
'#default_value' => variable_get(PERFORMANCE_QUERY_VAR, 0),
|
||||
'#description' => t('Log database query timing and query count for each page. This is useful to know if the bottleneck is in excessive database query counts, or the time required to execute those queries is high. Enabling this will incurr some memory overhead as query times and the actual query strings are cached in memory as arrays for each page, hence skewing the overall page memory reported.'),
|
||||
);
|
||||
|
||||
$form['other']['performance_threshold_accesses'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Accesses threshold'),
|
||||
'#default_value' => variable_get('performance_threshold_accesses', 0),
|
||||
'#options' => array(0, 1, 2, 5, 10),
|
||||
'#description' => t("When displaying the summary report, only pages with the number of accesses larger than the specified threshold will be shown. Also, when cron runs and summary is <strong>not</strong> logged to DB, pages with that number of accesses or less will be removed, so as not to overflow the cache's memory. This is useful on a live site with a high volume of hits. On a development site, you probably want this set to 0, so you can see all pages."),
|
||||
);
|
||||
|
||||
$form['other']['performance_nodrush'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Do not log drush access'),
|
||||
'#default_value' => variable_get('performance_nodrush', 1),
|
||||
'#description' => t('Prevent !link access to the site from being logged.', array('!link' => l(t('drush'), 'http://www.drupal.org/project/drush', array('attributes' => array('target' => '_blank'))))),
|
||||
);
|
||||
|
||||
$form['other']['performance_skip_paths'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Paths to exclude'),
|
||||
'#default_value' => variable_get('performance_skip_paths', ''),
|
||||
'#description' => t("Enter one path per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display message on settings form.
|
||||
*/
|
||||
function performance_caching_message() {
|
||||
$default = 'DrupalDatabaseCache';
|
||||
$type = 'error';
|
||||
|
||||
$cache = variable_get(PERFORMANCE_CACHE, $default);
|
||||
if ($cache != $default) {
|
||||
$message = t('Alternative caching (%class) is enabled. It is reasonably safe to enable summary logging on live sites.', array('%class' => $cache));
|
||||
$type = 'status';
|
||||
}
|
||||
else {
|
||||
$message = t('Only the default database caching mechanism is enabled. It is <strong>not</strong> safe to enable summary logging to the database on live sites!');
|
||||
}
|
||||
|
||||
drupal_set_message($message, $type, FALSE);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_boot().
|
||||
*/
|
||||
function performance_boot() {
|
||||
register_shutdown_function('performance_shutdown');
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
@include_once DRUPAL_ROOT . '/includes/database/log.inc';
|
||||
Database::startLog('performance', 'default');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown function that collects all performance data.
|
||||
*/
|
||||
function performance_shutdown() {
|
||||
global $user, $language;
|
||||
|
||||
// Don't log drush access.
|
||||
if (drupal_is_cli() && variable_get('performance_nodrush', 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($_GET['q']) && $_GET['q']) {
|
||||
// q= has a value, use that for the path
|
||||
$path = $_GET['q'];
|
||||
}
|
||||
elseif (drupal_is_cli()) {
|
||||
$path = 'drush';
|
||||
}
|
||||
else {
|
||||
// q= is empty, use whatever the site_frontpage is set to
|
||||
$path = variable_get('site_frontpage', 'node');
|
||||
}
|
||||
|
||||
// Skip certain paths defined by the user.
|
||||
if (drupal_match_path($path, variable_get('performance_skip_paths', ''))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'timer' => timer_read('page'),
|
||||
'path' => $path,
|
||||
);
|
||||
|
||||
// Memory.
|
||||
// No need to check if this function exists in D7, as it has a minimal
|
||||
// requirement of PHP 5.2.5.
|
||||
$params['mem'] = memory_get_peak_usage(TRUE);
|
||||
|
||||
// Query time and count
|
||||
$query_count = $query_timer = $sum = 0;
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
// See http://drupal.org/node/1022204
|
||||
$queries = Database::getLog('performance', 'default');
|
||||
foreach ($queries as $query) {
|
||||
$sum += $query['time'];
|
||||
$query_count++;
|
||||
}
|
||||
$query_timer = round($sum * 1000, 2);
|
||||
}
|
||||
|
||||
$params['query_count'] = $query_count;
|
||||
$params['query_timer'] = $query_timer;
|
||||
|
||||
// Anonymous access?
|
||||
$params['anon'] = ($user->uid) ? 0 : 1;
|
||||
|
||||
// Language
|
||||
$params['language'] = $language->language;
|
||||
|
||||
// There used to be a module_invoke_all('performance', 'header', $header) call
|
||||
// here but it has been removed. $header was an associative array containing
|
||||
// path, timer (ms) and anon ('Yes' or 'No').
|
||||
|
||||
if (variable_get('performance_detail', 0)) {
|
||||
// There used to be a module_invoke_all('performance', 'data') call here. As
|
||||
// it was undocumented and therefore unknown, it has been removed. The data
|
||||
// column has been kept so that we can re-implement if needed.
|
||||
$params['data'] = NULL;
|
||||
performance_log_details($params);
|
||||
}
|
||||
// There used to be a module_invoke_all('performance', 'disable') call here in
|
||||
// an else statement.
|
||||
|
||||
if (variable_get('performance_summary', 0)) {
|
||||
performance_log_summary($params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the summary data.
|
||||
*/
|
||||
function performance_log_summary($params) {
|
||||
$key = PERFORMANCE_KEY . $params['path'] . ':' . $params['language'] . ':' . $params['anon'];
|
||||
$data = cache_get($key, PERFORMANCE_BIN);
|
||||
if (is_object($data)) {
|
||||
$data = $data->data;
|
||||
}
|
||||
$result = performance_build_summary_data($data, $params);
|
||||
|
||||
if ($result['type'] == 'new') {
|
||||
// $keys_cache is used to easily retrieve our data later on.
|
||||
if ($keys_cache = cache_get(PERFORMANCE_KEY, PERFORMANCE_BIN)) {
|
||||
$keys_values = $keys_cache->data;
|
||||
}
|
||||
// Keep the key for the key cache store. We do it this way so that keys
|
||||
// will replace eachother which would not happen when using
|
||||
// $keys_values[] = $key;
|
||||
$keys_values[$key] = 1;
|
||||
cache_set(PERFORMANCE_KEY, $keys_values, PERFORMANCE_BIN);
|
||||
}
|
||||
|
||||
// Keep records for 1 day.
|
||||
$expire = $result['last_access'] + (24 * 60 * 60);
|
||||
cache_set($key, $result['data'], PERFORMANCE_BIN, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to build summary data array.
|
||||
*
|
||||
* @param data array of previous data
|
||||
* @param params array of current data
|
||||
* @return array holding summary data
|
||||
*/
|
||||
function performance_build_summary_data($data, $params) {
|
||||
if ($data) {
|
||||
$type = 'existing';
|
||||
$data = array(
|
||||
'path' => $data['path'],
|
||||
'bytes_max' => max($params['mem'], $data['bytes_max']),
|
||||
'bytes_sum' => $data['bytes_sum'] + $params['mem'],
|
||||
'ms_max' => max($params['timer'], $data['ms_max']),
|
||||
'ms_sum' => $data['ms_sum'] + $params['timer'],
|
||||
'query_timer_max' => max($params['query_timer'], $data['query_timer_max']),
|
||||
'query_timer_sum' => $data['query_timer_sum'] + $params['query_timer'],
|
||||
'query_count_max' => max($params['query_count'], $data['query_count_max']),
|
||||
'query_count_sum' => $data['query_count_sum'] + $params['query_count'],
|
||||
'num_accesses' => $data['num_accesses'] + 1,
|
||||
'last_access' => REQUEST_TIME,
|
||||
'anon' => $params['anon'],
|
||||
'language' => $params['language'],
|
||||
);
|
||||
}
|
||||
else {
|
||||
$type = 'new';
|
||||
$data = array(
|
||||
'path' => $params['path'],
|
||||
'bytes_max' => $params['mem'],
|
||||
'bytes_sum' => $params['mem'],
|
||||
'ms_max' => (int)$params['timer'],
|
||||
'ms_sum' => (int)$params['timer'],
|
||||
'query_timer_max' => $params['query_timer'],
|
||||
'query_timer_sum' => $params['query_timer'],
|
||||
'query_count_max' => (int)$params['query_count'],
|
||||
'query_count_sum' => (int)$params['query_count'],
|
||||
'num_accesses' => 1,
|
||||
'last_access' => REQUEST_TIME,
|
||||
'anon' => $params['anon'],
|
||||
'language' => $params['language'],
|
||||
);
|
||||
}
|
||||
|
||||
return array('data' => $data, 'type' => $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to traverse the cache_bin data for retrieving and/or
|
||||
* pruning data.
|
||||
*
|
||||
* @param $callback string function to execute on the data fetched
|
||||
* @param $args optional additional argument(s) to pass to the callback (use an
|
||||
* array or object to pass multiple arguments)
|
||||
* @return array of data where the contents depends on the callback
|
||||
*/
|
||||
function performance_traverse_cache($callback, $args = NULL) {
|
||||
$data_list = array();
|
||||
$pruned = FALSE;
|
||||
|
||||
if ($keys_cache = cache_get(PERFORMANCE_KEY, PERFORMANCE_BIN)) {
|
||||
// is_array() check to prevent anything from ever going wrong here.
|
||||
if (is_array($keys_cache->data)) {
|
||||
foreach ($keys_cache->data as $key => $value) {
|
||||
$cache = cache_get($key, PERFORMANCE_BIN);
|
||||
if (!$cache) {
|
||||
// Cache entry for this key has expired, remove the key.
|
||||
unset($keys_cache->data[$key]);
|
||||
// Mark as pruned: we have to rewrite the keys cache!
|
||||
$pruned = TRUE;
|
||||
}
|
||||
else {
|
||||
// call_user_func() does not support passing by reference. See
|
||||
// http://php.net/manual/en/function.call-user-func-array.php and the
|
||||
// note about PHP 5.4 concerning the possibility of passing by
|
||||
// reference there. Hence this approach to prevent future
|
||||
// compatibility issues
|
||||
if ($data = call_user_func($callback, $cache, $args)) {
|
||||
$data_list[] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write the pruned key cache if needed.
|
||||
if ($pruned) {
|
||||
cache_set(PERFORMANCE_KEY, $keys_cache->data, PERFORMANCE_BIN);
|
||||
}
|
||||
|
||||
return $data_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used by performance_traverse_cache() for fetching summary data.
|
||||
*
|
||||
* @param $cache cache object
|
||||
* @param $timestamp unix timestamp to start fetching data from
|
||||
* @return the processed data or NULL
|
||||
*
|
||||
* @see performance_traverse_cache()
|
||||
*/
|
||||
function performance_get_summary($cache, $timestamp) {
|
||||
static $count = 0;
|
||||
|
||||
// Don't combine these IF statemens here, otherwise else might get executed
|
||||
// while $timestamp IS set!
|
||||
if ($timestamp !== NULL) {
|
||||
if($cache->created >= $timestamp) {
|
||||
// return based on timestamp
|
||||
return $cache->data;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// return paged
|
||||
global
|
||||
$pager_page_array, // array of element-keyed current page - 1
|
||||
$pager_total_items, // array of element-keyed total number of data rows
|
||||
$pager_limits, // array of element-keyed number of rows per page
|
||||
$pager_total; // array of element-keyed total number of pages
|
||||
|
||||
$pager_total_items[0]++;
|
||||
if (($pager_page_array[0] * $pager_limits[0]) < $pager_total_items[0] && $count < $pager_limits[0]) {
|
||||
$count++;
|
||||
return $cache->data;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to store detailed data in database.
|
||||
*/
|
||||
function performance_log_details($params = array()) {
|
||||
$fields = array(
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'bytes' => $params['mem'],
|
||||
'ms' => (int)$params['timer'],
|
||||
'query_count' => $params['query_count'],
|
||||
'query_timer' => (int)$params['query_timer'],
|
||||
'anon' => $params['anon'],
|
||||
'path' => $params['path'],
|
||||
'language' => $params['language'],
|
||||
'data' => $params['data'],
|
||||
);
|
||||
|
||||
try {
|
||||
db_insert('performance_detail')
|
||||
->fields($fields)
|
||||
->execute();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('performance', $e, NULL, array(), WATCHDOG_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary page callback.
|
||||
*/
|
||||
function performance_view_summary() {
|
||||
drupal_set_title(t('Performance logs: Summary'));
|
||||
|
||||
global
|
||||
$pager_page_array, // array of element-keyed current page - 1
|
||||
$pager_total_items, // array of element-keyed total number of data rows
|
||||
$pager_limits, // array of element-keyed number of rows per page
|
||||
$pager_total; // array of element-keyed total number of pages
|
||||
|
||||
$rows = $data_list = array();
|
||||
|
||||
// Build table header.
|
||||
$header = array(
|
||||
array('data' => t('Path'), 'field' => 'path'),
|
||||
array('data' => t('Last access'), 'field' => 'last_access'),
|
||||
array('data' => t('# accesses'), 'field' => 'num_accesses'),
|
||||
array('data' => t('MB Memory (Max)'), 'field' => 'bytes_max'),
|
||||
array('data' => t('MB Memory (Avg)'), 'field' => 'bytes_sum'),
|
||||
array('data' => t('ms (Max)'), 'field' => 'ms_max'),
|
||||
array('data' => t('ms (Avg)'), 'field' => 'ms_sum'),
|
||||
array('data' => t('Language'), 'field' => 'language'),
|
||||
array('data' => t('Anonymous?'), 'field' => 'anon'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = array('data' => t('Query ms (Max)'), 'field' => 'query_timer_max');
|
||||
$header[] = array('data' => t('Query ms (Avg)'), 'field' => 'query_timer_sum');
|
||||
$header[] = array('data' => t('Query Count (Max)'), 'field' => 'query_count_max');
|
||||
$header[] = array('data' => t('Query Count (Avg)'), 'field' => 'query_count_sum');
|
||||
}
|
||||
|
||||
// Set up pager since this is not done automatically when using caching bins.
|
||||
// Note that there can be data in these variables already hence the 'keyed'
|
||||
// setup of the arrays.
|
||||
$pager_height = 50;
|
||||
$pager_total_items = array(0 => 0);
|
||||
$pager_limits = array(0 => $pager_height);
|
||||
$page = isset($_GET['page']) ? sprintf('%d', $_GET['page']) : 0;
|
||||
$pager_page_array = array(0 => $page);
|
||||
|
||||
$data_list = performance_traverse_cache('performance_get_summary');
|
||||
|
||||
if (empty($data_list) && !variable_get('performance_summary', 0)) {
|
||||
return t('Summary performance log is not enabled. Go to the !link to enable it.', array('!link' => l(t('settings page'), PERFORMANCE_SETTINGS, array('query' => drupal_get_destination())))
|
||||
);
|
||||
}
|
||||
elseif (!variable_get('performance_summary', 0)) {
|
||||
drupal_set_message(t('Summary performance log is not enabled! Showing stored logs.'), 'warning');
|
||||
}
|
||||
|
||||
$pager_total = array(0 => ceil($pager_total_items[0] / $pager_limits[0]));
|
||||
|
||||
// Setup sorting since this is not done automatically when using caching bins.
|
||||
$sort_direction = tablesort_get_sort($header);
|
||||
$sort_field = tablesort_get_order($header);
|
||||
// TODO: find a solution for the avg columns! These need to be calculated
|
||||
// first, prolly...
|
||||
$data_list = performance_sort_summary($data_list, $sort_direction, $sort_field['sql']);
|
||||
|
||||
// Format data into table.
|
||||
$threshold = variable_get('performance_threshold_accesses', 0);
|
||||
$total_rows = $shown = $last_max = $total_bytes = $total_ms = $total_accesses = 0;
|
||||
$last_min = REQUEST_TIME;
|
||||
|
||||
foreach ($data_list as $data) {
|
||||
$total_rows++;
|
||||
$last_max = max($last_max, $data['last_access']);
|
||||
$last_min = min($last_min, $data['last_access']);
|
||||
|
||||
// Calculate running averages.
|
||||
$total_bytes += $data['bytes_sum'] / $data['num_accesses'];
|
||||
$total_ms += $data['ms_sum'] / $data['num_accesses'];
|
||||
$total_accesses += $data['num_accesses'];
|
||||
|
||||
$row_data = array();
|
||||
if ($data['num_accesses'] > $threshold) {
|
||||
$shown++;
|
||||
$row_data[] = l($data['path'], $data['path']);
|
||||
$row_data[] = format_date($data['last_access'], 'small');
|
||||
$row_data[] = $data['num_accesses'];
|
||||
$row_data[] = number_format($data['bytes_max'] / 1024 / 1024, 2);
|
||||
$row_data[] = number_format($data['bytes_sum'] / $data['num_accesses'] / 1024 / 1024, 2);
|
||||
$row_data[] = number_format($data['ms_max'], 1);
|
||||
$row_data[] = number_format($data['ms_sum'] / $data['num_accesses'], 1);
|
||||
$row_data[] = $data['language'];
|
||||
$row_data[] = ($data['anon']) ? t('Yes') : t('No');
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = number_format($data['query_timer_max'], 1);
|
||||
$row_data[] = number_format($data['query_timer_sum'] / $data['num_accesses'], 1);
|
||||
$row_data[] = $data['query_count_max'];
|
||||
$row_data[] = $data['query_count_sum'] / $data['num_accesses'];
|
||||
}
|
||||
}
|
||||
$rows[] = array('data' => $row_data);
|
||||
}
|
||||
|
||||
$output = '';
|
||||
if ($threshold) {
|
||||
$output .= t('Showing !shown paths with more than !threshold accesses, out of !total total paths.',
|
||||
array('!threshold' => $threshold, '!shown' => $shown, '!total' => $total_rows)) . '<br/>';
|
||||
}
|
||||
else {
|
||||
$output .= t('Showing all !total paths.', array('!total' => $total_rows)) . '<br/>';
|
||||
}
|
||||
|
||||
// Protect against divide by zero.
|
||||
if ($total_rows > 0) {
|
||||
$mb_avg = number_format($total_bytes / $total_rows / 1024 / 1024, 1);
|
||||
$ms_avg = number_format($total_ms / $total_rows, 2);
|
||||
}
|
||||
else {
|
||||
$mb_avg = 'n/a';
|
||||
$ms_avg = 'n/a';
|
||||
}
|
||||
|
||||
$output .= t('Average memory per page: !mb_avg MB', array('!mb_avg' => $mb_avg)) . '<br/>';
|
||||
$output .= t('Average duration per page: !ms_avg ms', array('!ms_avg' => $ms_avg)) . '<br/>';
|
||||
$output .= t('Total number of page accesses: !accesses', array('!accesses' => $total_accesses)) . '<br/>';
|
||||
$output .= t('First access: !access.', array('!access' => format_date($last_min, 'small'))) . '<br/>';
|
||||
$output .= t('Last access: !access.', array('!access' => format_date($last_max, 'small')));
|
||||
|
||||
// Return a renderable array.
|
||||
return array(
|
||||
'general_info' => array(
|
||||
'#prefix' => '<p>',
|
||||
'#markup' => $output,
|
||||
'#suffix' => '</p><p> </p>',
|
||||
),
|
||||
'query_data_summary' => array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#sticky' => TRUE,
|
||||
'#empty' => t('No statistics available yet.'),
|
||||
),
|
||||
'pager' => array(
|
||||
'#theme' => 'pager',
|
||||
'#quantity' => $pager_height,
|
||||
),
|
||||
'clear' => array(
|
||||
'#markup' => l(t('Clear logs'), 'admin/reports/performance-logging/clear/summary'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to sort data from the cache bin.
|
||||
*
|
||||
* @param $data array of data to sort
|
||||
* @param $direction string asc or desc
|
||||
* @param $field string name of field to sort
|
||||
* @return sorted $data array
|
||||
*
|
||||
* @see array_multisort()
|
||||
*/
|
||||
function performance_sort_summary($data, $direction, $field) {
|
||||
if(empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
switch($direction) {
|
||||
case 'asc':
|
||||
$direction = SORT_ASC;
|
||||
break;
|
||||
case 'desc':
|
||||
$direction = SORT_DESC;
|
||||
break;
|
||||
}
|
||||
|
||||
// Extract the column of data to be sorted.
|
||||
$column = array();
|
||||
foreach ($data as $key => $row) {
|
||||
$column[$key] = $row[$field];
|
||||
}
|
||||
array_multisort($column, $direction, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail page callback.
|
||||
*/
|
||||
function performance_view_details() {
|
||||
drupal_set_title(t('Performance logs: Details'));
|
||||
|
||||
$header = array(
|
||||
array('data' => t('#'), 'field' => 'pid', 'sort' => 'desc'),
|
||||
array('data' => t('Path'), 'field' => 'path'),
|
||||
array('data' => t('Date'), 'field' => 'timestamp'),
|
||||
array('data' => t('Memory (MB)'), 'field' => 'bytes'),
|
||||
array('data' => t('ms (Total)'), 'field' => 'ms'),
|
||||
array('data' => t('Language'), 'field' => 'language'),
|
||||
array('data' => t('Anonymous?'), 'field' => 'anon'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = array('data' => t('# Queries'), 'field' => 'query_count');
|
||||
$header[] = array('data' => t('Query ms'), 'field' => 'query_timer');
|
||||
}
|
||||
|
||||
$pager_height = 50;
|
||||
$result = db_select('performance_detail', 'p')
|
||||
->fields('p')
|
||||
->extend('PagerDefault')
|
||||
->limit($pager_height)
|
||||
->extend('TableSort')
|
||||
->orderByHeader($header)
|
||||
->execute();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($result as $data) {
|
||||
$row_data = array();
|
||||
$row_data[] = $data->pid;
|
||||
$row_data[] = l($data->path, $data->path);
|
||||
$row_data[] = format_date($data->timestamp, 'small');
|
||||
$row_data[] = number_format($data->bytes / 1024 / 1024, 2);
|
||||
$row_data[] = $data->ms;
|
||||
$row_data[] = $data->language;
|
||||
$row_data[] = ($data->anon) ? t('Yes') : t('No');
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = $data->query_count;
|
||||
$row_data[] = $data->query_timer;
|
||||
}
|
||||
|
||||
$rows[] = array('data' => $row_data);
|
||||
}
|
||||
|
||||
if (empty($rows) && !variable_get('performance_detail', 0)) {
|
||||
return array(
|
||||
'content' => array(
|
||||
'#markup' => t('Detail performance log is not enabled. Go to the !link to enable it.', array('!link' => l(t('settings page'), PERFORMANCE_SETTINGS, array('query' => drupal_get_destination()))))
|
||||
),
|
||||
);
|
||||
}
|
||||
elseif (!variable_get('performance_detail', 0)) {
|
||||
drupal_set_message(t('Detail performance log is not enabled! Showing stored logs.'), 'warning');
|
||||
}
|
||||
|
||||
// Return a renderable array.
|
||||
return array(
|
||||
'query_data_detail' => array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#sticky' => TRUE,
|
||||
'#empty' => t('No log messages available.'),
|
||||
),
|
||||
'clear' => array(
|
||||
'#markup' => l(t('Clear logs'), 'admin/reports/performance-logging/clear/details'),
|
||||
),
|
||||
'pager' => array(
|
||||
'#theme' => 'pager',
|
||||
'#quantity' => $pager_height,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear logs form.
|
||||
*/
|
||||
function performance_clear_form($form, &$form_state, $store = NULL) {
|
||||
$base = 'admin/reports/performance-logging/';
|
||||
|
||||
// Seemed the best solution, instead of doing something like
|
||||
// t('Are you sure you want to clear all @store data?', array ('@store' => $store));
|
||||
switch ($store) {
|
||||
case 'summary':
|
||||
$question = t('Are you sure you want to clear all summary data?');
|
||||
$path = $base . 'summary';
|
||||
break;
|
||||
case 'details':
|
||||
$question = t('Are you sure you want to clear all detail data?');
|
||||
$path = $base . 'details';
|
||||
break;
|
||||
default:
|
||||
// None or unrecognised store => 404.
|
||||
drupal_not_found();
|
||||
return 2;
|
||||
}
|
||||
|
||||
$form['store'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $store,
|
||||
);
|
||||
|
||||
$form['redirect'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $path,
|
||||
);
|
||||
|
||||
return confirm_form($form, $question, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear logs form submit handler.
|
||||
*/
|
||||
function performance_clear_form_submit($form, &$form_state) {
|
||||
switch ($form_state['values']['store']) {
|
||||
case 'summary':
|
||||
cache_clear_all('*', PERFORMANCE_BIN, TRUE);
|
||||
break;
|
||||
case 'details':
|
||||
db_truncate('performance_detail')->execute();
|
||||
break;
|
||||
}
|
||||
|
||||
$form_state['redirect'] = array($form_state['values']['redirect']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather performance data for external modules.
|
||||
*/
|
||||
function performance_gather_summary_data() {
|
||||
// Data from last 15 minutes.
|
||||
$timestamp = REQUEST_TIME - 15 * 60;
|
||||
$data_list = performance_traverse_cache('performance_get_summary', $timestamp);
|
||||
|
||||
// Initialize variables.
|
||||
$total_rows = $total_bytes = $total_ms = $total_accesses = $total_query_time = $total_query_count = 0;
|
||||
|
||||
foreach ($data_list as $data) {
|
||||
$total_rows++;
|
||||
|
||||
// Calculate running averages.
|
||||
$total_bytes += $data['bytes_sum'] / $data['num_accesses'];
|
||||
$total_ms += $data['ms_sum'] / $data['num_accesses'];
|
||||
$total_accesses += $data['num_accesses'];
|
||||
$total_query_time += $data['query_timer_sum'] / $data['num_accesses'];
|
||||
$total_query_count += $data['query_count_sum'] / $data['num_accesses'];
|
||||
}
|
||||
|
||||
$results = array();
|
||||
$results['total_accesses'] = $total_accesses;
|
||||
// Protect against divide by zero.
|
||||
if ($total_rows > 0) {
|
||||
$results['ms_avg'] = number_format($total_ms / $total_rows, 1, '.', '');
|
||||
$results['ms_query'] = number_format($total_query_time / $total_rows, 1, '.', '');
|
||||
$results['query_count'] = number_format($total_query_count / $total_rows, 2, '.', '');
|
||||
$results['mb_avg'] = number_format($total_bytes / $total_rows / 1024 / 1024, 1);
|
||||
}
|
||||
else {
|
||||
$results['ms_avg'] = '';
|
||||
$results['ms_query'] = '';
|
||||
$results['mb_avg'] = '';
|
||||
$results['query_count'] = '';
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_nagios_info().
|
||||
*/
|
||||
function performance_nagios_info() {
|
||||
return array(
|
||||
'name' => 'Performance logging',
|
||||
'id' => 'PERF',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_nagios().
|
||||
*/
|
||||
function performance_nagios() {
|
||||
$data = performance_gather_summary_data();
|
||||
|
||||
if (!$data) {
|
||||
$info = performance_nagios_info();
|
||||
return array(
|
||||
$info['id'] => array(
|
||||
'status' => NAGIOS_STATUS_UNKNOWN,
|
||||
'type' => 'perf',
|
||||
'text' => t('Performance logging is not enabled'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$status = NAGIOS_STATUS_OK;
|
||||
|
||||
return array(
|
||||
'ACC' => array(
|
||||
'status' => $status,
|
||||
'type' => 'perf',
|
||||
'text' => $data['total_accesses'],
|
||||
),
|
||||
'MS' => array(
|
||||
'status' => $status,
|
||||
'type' => 'perf',
|
||||
'text' => $data['ms_avg'],
|
||||
),
|
||||
'MMB' => array(
|
||||
'status' => $status,
|
||||
'type' => 'perf',
|
||||
'text' => $data['mb_avg'],
|
||||
),
|
||||
'QRC' => array(
|
||||
'status' => $status,
|
||||
'type' => 'perf',
|
||||
'text' => $data['query_count'],
|
||||
),
|
||||
'QRT' => array(
|
||||
'status' => $status,
|
||||
'type' => 'perf',
|
||||
'text' => $data['ms_query'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_prod_check_alter().
|
||||
*/
|
||||
function performance_prod_check_alter(&$checks) {
|
||||
$checks['perf_data']['functions']['performance_prod_check_return_data'] = 'Performance logging';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return performance data to Production Monitor.
|
||||
*/
|
||||
function performance_prod_check_return_data() {
|
||||
$data = performance_gather_summary_data();
|
||||
|
||||
if (!$data) {
|
||||
return array(
|
||||
'performance' => array(
|
||||
'title' => 'Performance logging',
|
||||
'data' => 'No performance data found.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'performance' => array(
|
||||
'title' => 'Performance logging',
|
||||
'data' => array(
|
||||
'Total number of page accesses' => array($data['total_accesses']),
|
||||
'Average duration per page' => array($data['ms_avg'], 'ms'),
|
||||
'Average memory per page' => array($data['mb_avg'], 'MB'),
|
||||
'Average querycount' => array($data['query_count']),
|
||||
'Average duration per query' => array($data['ms_query'], 'ms'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user