Home » Php » How to generate flame graphs with PHP?

How to generate flame graphs with PHP?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I learned about flame graphs and find them fascinating – however, I could find no useful reference on how to generate them for my PHP script(s). How can I gather the data and generate the graphs using PHP?

How to&Answers:

You can use Xdebug to create cachegrind profiles of your php code. You can take a look to this project that handles xdebug’s cachegrind output using php.

Answer:

I found this article from platform.sh where they use xhprof to output the data set from the execution calls, then a perl script called flamegraph.pl process the data set to be displayed as a SVG. A bit more digging and I was able to find the official flame graph repo on GitHub that contains the flamegraph.pl logic. The three resources combined I was able to generate a flame graph as desired though YMMV.