Skip to content

A suite of tools to store, analyze and compare output of tideways xhprof extension

Notifications You must be signed in to change notification settings

docteurklein/xhprof-analyze

Repository files navigation

xhprof-analyze

What ?

A suite of tools to store, analyze and compare output of tideways xhprof extension.

Why ?

This could help you find bottlenecks and follow the performance evolution continuously.

How ?

Import a profile dump in neo4j

  • Install and activate the tidewawys_xhprof.so extension
  • Generate some profiling data in your application
  • Pass it to bin/import-xhprof's stdin (will be json_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

Compare 2 profiles by wall time for calls that take more than 100ms

bin/compare profile1 profile2 wt 100000 | xdot -

Display one profile graph with wall time, count and memory usage

bin/profile profile1 wt,ct,mu 100000 | xdot -

display tabular data:

bin/profile-table asset1 ct,wt | sort -rn -k3 -k4 | column -t |less

Metrics:

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 in memory_get_usage for this parent ==> child function pair.
  • pmu The sum of increase in memory_get_peak_usage for this parent ==> child function pair.

Environment variables

  • NEO4J_URL: a valid bolt URL pointing to a neo4j instance

Example of automatic dump with auto_prepend_file

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);

analyze evolution over time series with influxdb

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.

About

A suite of tools to store, analyze and compare output of tideways xhprof extension

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published