Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 487eb02
Showing
5 changed files
with
1,491 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
`top` for WordPress | ||
=================== | ||
|
||
An XHProf-based WordPress code profiler. Gives you real-time overview of your WordPress application's performance and can be used in production due to very low overhead. Find out your slow pages and functions, optimize and profit from faster WordPress websites. | ||
|
||
Requires xhprof. | ||
|
||
Installation | ||
------------ | ||
|
||
Since we need the profiler to kick in as early as possible, the following should be added to your wp-config.php soon after `ABSPATH` is available but before `wp-settings.php` is required. | ||
It is safe to call `wptop_enable` in any practical place. Using it in `index.php` is, however, discouraged, since updates will erase your change. | ||
|
||
``` | ||
/** Turn on real-time profiling using wptop */ | ||
require ABSPATH . 'wp-content/plugins/wptop/enable.php'; | ||
wptop_enable(); | ||
``` | ||
|
||
Configuration | ||
------------- | ||
|
||
`wptop_enable` accepts the following array parameters: | ||
- `memory` (`bool`) tells the profiler to gather memory information, `true` by default | ||
- `cpu` (`bool`) tells the profiler to gather CPU time data, `false` by default, not recommended in production | ||
- `builtins` (`bool`) tells the profiler whether to profile built-in PHP functions or not, `false` by default | ||
|
||
So for example, `wptop_enable( array( 'memory' => false, 'cpu' => false, 'builtins' => false ) )` will have the profiler not generate any memory data, CPU time data or profile built-in PHP functions. Sane defaults are recommended. | ||
|
||
Notes | ||
----- | ||
|
||
A profiled request will store at least 200kb of data in the database in raw format. A cronjob will clean these up freeing most of it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** Enable the XHProf code profiler */ | ||
|
||
/** | ||
* The main profiler enable function. | ||
* | ||
* Needs to be called early on from pretty much any context as it does | ||
* not depend on WordPress to be available. | ||
*/ | ||
function wptop_enable( $attrs = array() ) { | ||
if ( !isset( $attrs['memory'] ) ) $attrs['memory'] = true; | ||
if ( !isset( $attrs['cpu'] ) ) $attrs['cpu'] = true; | ||
if ( !isset( $attrs['builtins'] ) ) $attrs['builtins'] = true; | ||
|
||
$flags = $attrs['memory'] ? XHPROF_FLAGS_MEMORY : 0; | ||
$flags |= $attrs['cpu'] ? XHPROF_FLAGS_CPU : 0; | ||
$flags |= $attrs['builtins'] ? XHPROF_FLAGS_NO_BUILTINS : 0; | ||
|
||
/** Ooh, no xhprof? Too bad... */ | ||
if ( !function_exists( 'xhprof_enable' ) ) return; | ||
|
||
xhprof_enable( $flags ); | ||
|
||
/** Global state of the profiler */ | ||
define( 'WPTOP_ENABLED', serialize( $attrs ) ); | ||
} |
Oops, something went wrong.