Skip to content

msonnabaum/xhprof-flamegraphs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

XHProf FlameGraphs

A script to convert a directory of xhprof or uprofiler sampling files to a format that can be read by Brendan Gregg's FlameGraph script.

Note: This works with files generated by xhprof_sample_enable/xhprof_sample_disable. It will not work with the more common hierarchical xhprof/uprofiler format.

Usage

First, generate the sampling data, writing the files with a sample_xhprof (resp. sample_uprofiler) file extension. Then run the script passing the directory containing those files as an argument like so:

Generating the sample data

One way to generate the sample data is prepend the following fragment to the entry point of the application, often index.php:

if (extension_loaded('uprofiler')) {
  $profiler = 'uprofiler';
}
elseif (extension_loaded('xhprof')) {
  $profiler = 'xhprof';
}
else {
  $profiler = NULL;
}
if ($profiler) {
  $enable = "{$profiler}_sample_enable";
  $disable = "{$profiler}_sample_disable";
  $uri = substr($_SERVER['REQUEST_URI'], 1);
  $uri = preg_replace('/[?\/]/', '-', $uri);
  $enable();
  register_shutdown_function(function () use($disable, $profiler, $uri) {
    $filename = "/tmp/xhprof/{$uri}." . uniqid() . ".{$profiler}";
    file_put_contents($filename, serialize($disable()));
    chmod($filename, 0777);
  });
}

Building the flamegraph from the data

./xhprof-sample-to-flamegraph-stacks /directory/with/sample/xhprof/files | flamegraph.pl > xhprof-flamegraph.svg

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages