Skip to content

Instantly share code, notes, and snippets.

@attitude
Created February 29, 2012 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attitude/1939511 to your computer and use it in GitHub Desktop.
Save attitude/1939511 to your computer and use it in GitHub Desktop.
Display Timestamps when Debugging WordPress for Speed
<?php
//----------------------------------------------------------------------------------------------
// Display Timestamps when Debugging WordPress for Speed
//----------------------------------------------------------------------------------------------
//
// A GIST by Martin Adamko, martin(at)attitude.sk
//
// It happens from time to time you need to know where the crack is. I assume you are willing
// to kick in the WP source and put some 'echos' in there. But WP has 2 functions to help you
// with that already: timer_start() and timer_stop(). Why not to use it?
//
//----------------------------------------------------------------------------------------------
//
// Some original core rewriting is needed, but you can do it again even after upgrading very
// easily. This piece is provided as is, without any waranty. Use at your own risk.
//
// HOW TO USE IT:
//
// 1/ Find file {WP Instalation Root}/wp-includes/plugin.php
// 2/ Locate functions do_action() and do_action_ref_array() in the source
// line +-360: function do_action($tag, $args = '') {...
// line +-450: function do_action_ref_array($tag, $args) {...
// 3/ Paste the code below just after the opening curly bracket and before the globals:
//
//----------------------------------------------------------------------------------------------
// Start copy here:
if( WP_DEBUG) { // Make sure we are debugging
global $last_time, $last_time_micro; // See the last values
// First time we set 0
$last_time = (!isset( $last_time) ) ? 0 : $last_time;
// Get time since start, see the WP Codex for details.
$new_time = timer_stop();
// I care only for major delays and the shutdown time
if($new_time-$last_time_micro > 0.1 || $tag == 'shutdown') {
// It fires as a HTML comment so should not mess the site
echo "<!--delta: ".($new_time-$last_time)."; tag: $tag; time: ".$new_time."-->\n";
// Rememter this major delay time as the new big point
$last_time=$new_time;
}
// Just remember this time
$last_time_micro = $new_time;
}
// Done.
//----------------------------------------------------------------------------------------------
// Leave a comment if you have any questions.
//----------------------------------------------------------------------------------------------
// ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment