ob-ivan / sd-profiler
Tag your code with profiler frames and calculate durations for each tag.
Installs: 1 023
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- firephp/firephp-core: ^0.4.0
Requires (Dev)
- phpunit/phpunit: ^7.0
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... }