A suite of tools to store, analyze and compare output of tideways xhprof extension.
This could help you find bottlenecks and follow the performance evolution continuously.
- Install and activate the
tidewawys_xhprof.so
extension - Generate some profiling data in your application
- Pass it to
bin/import-xhprof
's stdin (will bejson_decode
d!)
Example:
php example/bench1.php | bin/import-xhprof "profile1"
# improve stuff...
php example/bench1.php | bin/import-xhprof "profile2"
php example/bench1.php | bin/import-xhprof "profile3" wt 1000000 # only import calls that take more than 1s
bin/compare profile1 profile2 wt 100000 | xdot -
bin/profile profile1 wt,ct,mu 100000 | xdot -
bin/profile-table asset1 ct,wt | sort -rn -k3 -k4 | column -t |less
You can provide a comma-separated list of metrics to the scripts.
Example:
bin/profile profile1 wt,ct,cpu,mu 100000 | xdot -
For xhprof:
wt
The summary wall time of all calls of this parent ==> child function pair.ct
The number of calls between this parent ==> child function pair.cpu
The cpu cycle time of all calls of this parent ==> child function pair.mu
The sum of increase inmemory_get_usage
for this parent ==> child function pair.pmu
The sum of increase inmemory_get_peak_usage
for this parent ==> child function pair.
NEO4J_URL
: a validbolt
URL pointing to a neo4j instance
Configure php.ini's auto_prepend_file
directive to point to a file containing the following,
and send signals (using pkill -SIGINT
for example), or wait for register_shutdown_function
to do it.
By sending regular SIGINT
signals, you will end up with different dumps relating the evolution of your program in time.
You'll then be able to use bin/compare
to analyze the differences.
<?php declare(strict_types=1);
pcntl_async_signals(true);
$signal = getenv('XHPROF_SIGNAL') ?: SIGINT;
error_log('xhprof dump at signal: '.strval($signal));
function dump_xhprof($signo) {
$path = strval(microtime(true)).(getenv('XHPROF_PATH') ?: '-xhprof.json');
error_log('dumping xhprof profile at path: '.$path);
file_put_contents($path, json_encode(tideways_xhprof_disable()));
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU);
}
register_shutdown_function('dump_xhprof', 0);
pcntl_signal($signal, 'dump_xhprof');
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU);
Once you generated many profiles, you can import the results into influxdb and see how results evolve over time, like how the wall time of 'array_map' evolves:
php bin/into-influxdb array_map | curl -sSL -XPOST 'http://localhost:8086/write?db=mydb&precision=s' --data-binary '@-'
Then use the TICK stack to make dashboards of some metrics.