Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

A small library on top of XhProf, with support for profiling and tracing

License

Notifications You must be signed in to change notification settings

quadrilatere/xhprof-profiler

Repository files navigation

XhProf profiler

Latest Stable Version Latest Unstable Version SensioLabs Insight Scrutinizer Quality Score Code Coverage Build Status

Installation

composer require csa/xhprof-profiler:dev-master

Usage

Create any type of PHP web or console application, then use the following in your code:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use XhProf\Profiler;

$profiler = new Profiler();

$profiler->start();

// Your code

// You may either use $profiler->stop() at the end of the code you wish to do something with the trace,
// or let xhprof-profiler manage it, as it registers a shutdown function automatically.
$trace = $profiler->stop();

You can easily store a trace using any storage class implementing StorageInterface:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use XhProf\Profiler;
use XhProf\Storage\MemoryStorage;

$profiler = new Profiler();
$profiler->start();
$trace = $profiler->stop();
$storage = new MemoryStorage();
$storage->store($trace);

You may also override the profiler's shutdown function:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use XhProf\Storage\FileStorage;
use XhProf\Profiler;
use XhProf\Trace;

$profiler = new Profiler();

$callback = function (Trace $trace) {
    $storage = new FileStorage();
    $storage->store($trace);

    // Do whatever you want with the trace
};

$profiler->setShutdownFunction($callback);
$profiler->start();

If you are using the file storage implementation, you may fetch a trace simply by using the fetch method. You may also fetch the list of available tokens:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use XhProf\Storage\FileStorage;

$storage = new FileStorage();
echo implode(PHP_EOL, $storage->getTokens());

Todo

  • Improve context support (for both Cli or request contexts).

License

This library is under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Bitdeli Badge

About

A small library on top of XhProf, with support for profiling and tracing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages