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.

Maintainers

Package info

github.com/ob-ivan/sd-profiler

pkg:composer/ob-ivan/sd-profiler

Statistics

Installs: 1 027

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

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

This package is auto-updated.

Last update: 2026-03-10 19:57:16 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...
}