Skip to content

Instantly share code, notes, and snippets.

@Steveorevo
Created May 3, 2015 16:44
Show Gist options
  • Save Steveorevo/69795c774c6b89911c30 to your computer and use it in GitHub Desktop.
Save Steveorevo/69795c774c6b89911c30 to your computer and use it in GitHub Desktop.
CPU Tick Hack
<?php
/**
* Place next to wp-blog-header.php. Visit this file to find the time suck.
*/
declare(ticks=1);
register_tick_function('ds_do_profile');
$ds_profile = array();
$ds_last_time = microtime(true);
function ds_do_profile() {
global $ds_profile, $ds_last_time;
$bt = debug_backtrace();
if (count($bt) <= 1) {
return ;
}
$frame = $bt[1];
unset($bt);
if ( $frame['file'] == '' ){
$frame['file'] = 'muliple locations';
}else{
$frame['file'] = substr( $frame['file'], strlen( $_SERVER['DOCUMENT_ROOT']) );
}
$function = $frame['function'] . ' in ' . $frame['file'];
if (!isset($ds_profile[$function])) {
$ds_profile[$function] = 0;
}
$ds_profile[$function] += (microtime(true) - $ds_last_time);
$ds_last_time = microtime(true);
}
function ds_show_profile() {
global $ds_profile;
arsort($ds_profile);
trace($ds_profile); // DesktopServer's trace window
}
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
ds_show_profile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment