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.soextension - Generate some profiling data in your application
- Pass it to
bin/import-xhprof's stdin (will bejson_decoded!)
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:
wtThe summary wall time of all calls of this parent ==> child function pair.ctThe number of calls between this parent ==> child function pair.cpuThe cpu cycle time of all calls of this parent ==> child function pair.muThe sum of increase inmemory_get_usagefor this parent ==> child function pair.pmuThe sum of increase inmemory_get_peak_usagefor this parent ==> child function pair.
NEO4J_URL: a validboltURL 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.