Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created October 30, 2014 14:30
Show Gist options
  • Save msonnabaum/c8902d5000d892ba121b to your computer and use it in GitHub Desktop.
Save msonnabaum/c8902d5000d892ba121b to your computer and use it in GitHub Desktop.
  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