Get Time Taken By Each Action Hook in WordPress

I am developing a Plugin, and want to record Time taken by each Action Hook, I am able to get all the Hooks Triggered on a Page with the Action and Priority, but i am unable to get the Time taken by each of them for their Full Execution. The Code to list all the Triggered Action Hooks is given as :

`
class MyTracker {

static $hooks;

static function track_hooks( ) {

$filter = current_filter();
if ( ! empty($GLOBALS[‘wp_filter’][$filter]) ) {
foreach ( $GLOBALS[‘wp_filter’][$filter] as $priority => $tag_hooks ) {
foreach ( $tag_hooks as $hook ) {
if ( is_array($hook[‘function’]) ) {
if ( is_object($hook[‘function’][0]) ) {
$func = get_class($hook[‘function’][0]) . ‘->’ . $hook[‘function’][1];
} elseif ( is_string($hook[‘function’][0]) ) {
$func = $hook[‘function’][0] . ‘::’ . $hook[‘function’][1];
}
} elseif( $hook[‘function’] instanceof Closure ) {
$func = ‘a closure’;
} elseif( is_string($hook[‘function’]) ) {
$func = $hook[‘function’];
}
self::$hooks[] = ‘On hook <b>”‘ . $filter . ‘”</b> run <b>’. $func . ‘</b> at priority ‘ . $priority;
}
}
}

}

}

add_action( ‘all’, array(‘MyTracker’, ‘track_hooks’) );

add_action( ‘shutdown’, function() {
echo implode( ‘
‘, MyTracker::$hooks );
}, 9999);
`
Thanks in advance.

Read more here:: Get Time Taken By Each Action Hook in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *