Skip to content

Commit

Permalink
Initial alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
soulseekah committed Aug 8, 2014
0 parents commit 487eb02
Show file tree
Hide file tree
Showing 5 changed files with 1,491 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.swp
33 changes: 33 additions & 0 deletions README.md
@@ -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.
26 changes: 26 additions & 0 deletions wptop/enable.php
@@ -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 ) );
}

0 comments on commit 487eb02

Please sign in to comment.