Skip to content
Paul Bunyan Message Logger. The best damn logger there ever was. WordPress, PHP, MySQL.

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.

Updated · By Diamond Sierra

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

ArgumentWhat it isDefault
$nameWhat the block doesRequired
$componentThe part of your code it belongs toapp
$dataAn optional array of values stored with itEmpty

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_