Visualizing existing XHProf and Callgrind Profiles
The new Blackfire upload CLI command allows anyone to use the Blackfire Web visualization tool on existing XHProf and Callgrind profiles.
This feature is deprecated as of March 2021.
When profiling some code, Blackfire stores a bunch of data in a specific format that encompasses a lot of information about time, memory, and some metadata as well. The Blackfire format is interesting in itself (and inspired by XHProf) but I will blog about it in a future post.
Blackfire is not the only profiler in the PHP world, and you’ve probably already heard of existing Open-Source ones like XHProf, UProfiler, which is really just an up-to-date fork of XHProf, and Xdebug. XHProf uses a simple but very PHP-oriented format: data are stored in a PHP array and serialized via the PHP
serialize() function. Xdebug uses the more common and standard Callgrind format; the Callgrind format is used by many profilers and one of the best visualization tools is KCachegrind (with ports for non-Linux platforms).
For the past few months, you’ve been able to use Blackfire.io as an alternative frontend for XHprof and Xdebug profiles by uploading them via our web interface. But it was impractical and of limited-use as such profiles can be really huge even for a few lines of code (several Gigabytes).
The web uploading feature has just been disabled and replaced with a much better alternative: a
blackfire upload CLI command (you need to upgrade Blackfire to version 0.20.0 to benefit from this new feature).
Using the new
upload command is as easy as it can get: pass it a profile file name (containing a profile in the Blackfire, XHProf, or Callgrind format) and it will take care of everything:
$ blackfire upload profile.pprof
Like for any other Blackfire commands (like
curl), you can also pass a slot number to make the command non-interactive (note that options must be placed before
$ blackfire --slot=upload profile.pprof
Before uploading the file to our platform, Blackfire first optimizes the data into a much smaller representation (on average, it compresses the profile by a factor of 1000 for Callgrind profiles); so feel free to feed it with your biggest profiles.
You can even ask Blackfire to aggregate several files into one:
$ blackfire upload profile1.pprof profile2.pprof profile3.pprof ...
There is one more thing: if you are still on PHP 5.2, you can still use Blackfire via XHProf and Xdebug… but of course, try to migrate to modern PHP versions as soon as possible.
If you are using XHprof, Xdebug, or any other tools that is able to generate a Callgind output, you can use Blackfire as a frontend thanks to the new Blackfire upload command. And as you might have realized now, this is the first step towards supporting more than PHP in Blackfire.
Stay tuned and happy profiling!