Performance Probe

Sat, 12th August 2006

As seen on the Weblog Tools Collection, Investigating WordPress 2.0.4 Performance and Memory Usage in WordPress 2.0.2.

With a one-line change to the WordPress core code, this plugin gathers readings of WordPress use of memory, time and database queries which it dumps to a compressed file for later analysis. The core code change enables a reading to be taken each time WP calls do_action(), and looks like this:

function do_action($tag, $arg = '') {
  if( $tag != 'do_action' ) do_action( 'do_action', $tag );

You don’t need to make this core change for the plugin to work, but without the change the plugin can only take a single reading at the end of the WP run. This can still be useful.

performance-probe.php. Use at your own risk.

Further Reading

As I find interesting and/or useful stuff on the net about WP performance, I’ll link here.

WP Queries: a short review
Some performance analysis and tuning against WP SQL queries.
measuring WordPress performance
By _ck_ on #wordpress. Links to some useful performance and diagnostic tools. Also links back here :)
WP Performance Graph
A developing Python script using rrdtool to produce a running graph from the output of my plugin. Neat.

8 Responses

  1. Hey take a look at this too: http://blog.rompe.org/node/85
    I wasn’t aware of the getrusage function, might give more useful info than just memory_get_usage.

    Reply
  2. I wasn’t aware of that function either. Thanks for the link. I’ll investigate…

    Reply
  3. Rather than hacking a core file can you not use the special (and probably undocumented) “all” action which gets called for all do_action (and apply_filters) calls. It needs careful use because it runs on all the filter calls (which include the options) but that should make the plugin self contained then.

    Reply
    1. Hi Westi,

      I found and tried the “all” hook during development of the probe. As you point out, it hooks filters also, which made the probe too intrusive for my purposes, so I didn’t explore that route.

      I would love to make the probe self-contained. If a “do_action” hook isn’t destined for the core, perhaps I’ll examine the “all” hook again.

      Or maybe the Open Source muse will smile and someone else will fix it for me. :)

      Reply
  4. Hi,

    This seems a good plugin. I haven’t yet installed it. I just wanted to know is how exactly do you read the output file.

    Ajay

    Reply
    1. Hi Ajay,

      The plugin (with the core do_action() mod) builds an array during the course of the WP run. Each entry in the array is created when WP calls “do_action”. At that point, the current time, memory usage, database query count and do_action() tag are appended to the array. At shutdown, the array is written out serialized and (unnecessarily!) gzipped to a timestamped file.

      My accompanying dump program reads the serialized array from a file and writes out each entry in CSV format as follows:

      Field 1 is the sequence number
      Field 2 is the tag passed to do_action()
      Field 3 is the value of memory_get_usage() when the hook was called
      Field 4 is the change in memory usage from the previous reading
      Field 5 is the run time so far, returned from timer_stop()
      Field 6 is the number of database queries (from $wpdb->num_queries)

      The final record is special, in that it is generated during shutdown. Field 2 on the final record contains the REQUEST_URI passed to WP, so you know which page generated the probe file.

      Reply
  5. hii

    i get this error

    Cannot modify header information - headers already sent by (output started at C:\netserve\www\wblog\wp-content\plugins\performance-probe.php:92) in C:\netserve\www\wblog\wp-includes\pluggable-functions.php on line 272

    Fatal error: Call to undefined function: memory_get_usage() in C:\netserve\www\wblog\wp-content\plugins\performance-probe.php on line 53

    Reply
    1. Hi Mustaq,

      I’ve experienced this problem before, and I know of no way to overcome it. The performance probe primarily tracks the amount of memory used. The PHP you are using was compiled without memory limits, so the built-in function to get the amount of memory used is not available.

      The PHP manual entry for memory_get_usage() has more details, including various workarounds, none of which are acceptable because they run external programs and would disturb the performance statistics being measured.

      Reply

Leave a Reply

You may also log in to post a comment.

XHTML:

If you want to <q>tag</q>, please balance these; a, i, em, b, strong, u, blockquote, q, ul, li, ol, abbr, code, pre, sub and sup.