Instantly share code, notes, and snippets.

Embed
What would you like to do?
  1. 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);
});
  1. Make a bunch of requests
  2. Move sample files into a directory
mkdir some-dir
mv /tmp/*.sample_xhprof some-dir/
  1. Get flamegraph scripts
git clone https://github.com/brendangregg/FlameGraph.git
git clone https://github.com/msonnabaum/xhprof-flamegraphs.git
  1. Create flamegraph from sample files
xhprof-flamegraphs/xhprof-sample-to-flamegraph-stacks test-samples | FlameGraph/flamegraph.pl > result.svg
open result.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment