Created
May 3, 2015 16:44
-
-
Save Steveorevo/69795c774c6b89911c30 to your computer and use it in GitHub Desktop.
CPU Tick Hack
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
<?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