aeatech/snapshot-profiler-xhprof
The package contains implementation of aeatech/snapshot-profiler-contracts to profile applications with xhprof. It can be used for production profiling.
System requirements:
Installation (Composer):
composer require aeatech/snapshot-profiler-xhprof
<?php
declare(strict_types=1);
use AEATech\SnapshotProfiler\Profiler;
use AEATech\SnapshotProfilerXhprof\Adapter;
use AEATech\SnapshotProfilerXhprof\Saver;
use Xhgui\Profiler\Profiler as BackendProfiler;
use Xhgui\Profiler\ProfilingFlags;
require_once 'vendor/autoload.php';
/**
* Start initialization
*/
$profilerConfig = [
'profiler' => BackendProfiler::PROFILER_XHPROF,
'profiler.flags' => [
ProfilingFlags::MEMORY,
],
'save.handler' => BackendProfiler::SAVER_UPLOAD,
'save.handler.upload' => [
'uri' => 'http://xhgui:80/run/import',
'timeout' => 1,
],
];
$backendProfiler = new BackendProfiler($profilerConfig);
$saver = new Saver($backendProfiler);
$adapterIniSettings = [
'xhprof.collect_additional_info' => '1',
];
$adapter = new Adapter($backendProfiler, $adapterIniSettings);
$profiler = new Profiler($adapter);
$profilingOptions = [];
/**
* End initialization
*/
/**
* Start profiling
*/
$profiler->enable();
/**
* It's doing nothing and added for backward compatibility with newrelic
*/
$profiler->setProfilingOptions($profilingOptions);
for ($i = 0; $i < 10; $i++) {
random_int(1, 10);
}
$data = $profiler->disable();
/**
* End profiling
*/
/**
* Start customization (not necessarily)
*/
/**
* If you use fpm it will take current URL as snapshot name
* If you use cli it will take script.php as snapshot name
* Example of custom snapshot name
*/
$data[Adapter::KEY_META][Adapter::KEY_META_URL] = '1.0.0|serviceName|env|snapshotName';
/**
* Set snapshot timestamps (usable for cli processes)
*/
$dateTime = new DateTime();
$timestamp = $dateTime->getTimestamp();
$data[Adapter::KEY_META][Adapter::KEY_META_REQUEST_TS_MICRO] = [
Adapter::KEY_META_REQUEST_TS_MICRO_SEC => $timestamp,
Adapter::KEY_META_REQUEST_TS_MICRO_USEC => $dateTime->format('u'),
];
$data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME]
= $timestamp;
$data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME_FLOAT]
= $dateTime->format('U.u');
/**
* End customization
*/
/**
* Save profiling result
*/
$saver->save($data);
/**
* http://127.0.0.1:8142 - profile results here
*/
MIT License. See LICENSE for details.
How can I help you explore Laravel packages today?