ob-ivan/sd-profiler

There is no license information available for the latest version (v1.3) of this package.

Tag your code with profiler frames and calculate durations for each tag.

v1.3 2018-02-15 09:34 UTC

This package is auto-updated.

Last update: 2024-04-10 15:46:35 UTC


README

Allows you to tag your code with profiler frames. It will calculate inclusive and exclusive durations for each tag and output with selected strategies.

Installation

composer require ob-ivan/sd-profiler

Init

To start profiling and select output strategies:

profiler()->init([
    'append' => true,
    // or:
    'firephp' => true,
);
register_shutdown_function(function () {
    profiler()->dispatch();
});

Example from WordPress functions.php:

if (isset($_COOKIE['secretcookie']) && $_COOKIE['secretcookie'] === 'secretvalue') {
    profiler()->init([
        'firephp' => true,
    ]);
    // Dispatch profiling result before WP forcefully closes all output buffers.
    add_action(
        'shutdown',
        function () {
            profiler()->dispatch();
        },
        0
    );
}

Usage

To put profiler frame tags:

profiler()->in('my_function', $vars);
my_function($vars);
profiler()->out('my_function');

You can add arbitrary debug info with log method:

function my_function($vars) {
    profiler()->log('my_function', $vars);
    // useful stuff here...
}