composer require csa/xhprof-profiler:dev-master
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());
- Improve context support (for both Cli or request contexts).
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.