- Add to index.php
<?php
xhprof_sample_enable();
register_shutdown_function(function () {
$namespace = "somename";
$filename = '/tmp/' . uniqid() . '.' . $namespace . '.sample_xhprof';
file_put_contents($filename, serialize(xhprof_sample_disable()));
chmod($filename, 0777);
});
- Make a bunch of requests
- Move sample files into a directory
mkdir some-dir
mv /tmp/*.sample_xhprof some-dir/
- Get flamegraph scripts
git clone https://github.com/brendangregg/FlameGraph.git
git clone https://github.com/msonnabaum/xhprof-flamegraphs.git
- Create flamegraph from sample files
xhprof-flamegraphs/xhprof-sample-to-flamegraph-stacks test-samples | FlameGraph/flamegraph.pl > result.svg
open result.svg