Time your own code with pb_scope
Paul Bunyan times functions attached to hooks on its own. Wrap any other block of code in pb_scope() to time it too.
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 = pb_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 = pb_scope( 'build report', 'reports', array( 'rows' => count( $rows ) ) );
$report = my_render_rows( $rows );
$scope->end();
return $report;
}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:
pb_watch( 'woocommerce_email_order_details' );
pb_watch( 'my_plugin_*' ); // every hook that starts with my_plugin_