jaxwilko/profiler

v0.0.6 2022-04-14 02:32 UTC

This package is auto-updated.

Last update: 2024-10-14 07:30:44 UTC


README

This package aids development by allowing you to profile sections of your codebase.

Installation

composer require "jaxwilko/profiler" --dev

Usage

Firstly, you need to install ext-xdebug.

Then add the following to your php.ini:

[xdebug]
xdebug.mode = develop,gcstats,profile,trace
xdebug.collect_return = 1
xdebug.collect_assignments = 1
xdebug.use_compression = false

Once this has been done, you can add the following to your codebase:

use JaxWilko\Profiler\Watcher;

Watcher::start();
// execute application logic
Watcher::end(__DIR__ . '/output.html');

The filename passed will be used to store the resulting parsed profile. Alternatively you can call end() without any params to get the profile as a variable.

$profile = Watcher::end();

The watcher also supports returning the profile as an array, this can be done as follows:

Watcher::setMode(Watcher::OUTPUT_ARR);
$profile = Watcher::end();

There are helpers provided to achieve the same functionality:

jax_watcher_start();
// execute application logic
jax_watcher_end($outputFile);