On this page
Paul Bunyan sees functions attached to WordPress hooks, database queries, outside calls and email. To time anything else, such as a function your code calls directly or one step of a long job, wrap it in a scope.
$scope = paul_bunyan_scope( 'draw winners', 'raffle' );
// ... the work you want timed ...
$scope->end();The scope appears in the request timeline with its duration, alongside everything else that request did.
The arguments
| Argument | What it is | Default |
|---|---|---|
$name | What the block does | Required |
$component | The part of your code it belongs to | app |
$data | An optional array of values stored with it | Empty |
Timing a function that is not on a hook
function my_build_report( $rows ) {
$scope = paul_bunyan_scope( 'build report', 'reports', array( 'rows' => count( $rows ) ) );
$report = my_render_rows( $rows );
$scope->end();
return $report;
}In the custom WooCommerce case study, Paul Bunyan showed a 453 ms block of CPU time inside a page shortcode; a two-line timing check like this one found the 300 ms loop inside it.
Watching a hook from code
To time every function on a hook, function by function, add it to the watch list in Settings, or from code:
paul_bunyan_watch( 'woocommerce_email_order_details' );
paul_bunyan_watch( 'my_plugin_*' ); // every hook that starts with my_plugin_
