Viewing detailed code execution path with Blackfire

By Christophe Dujarric, on Sep 18, 2019

When debugging some code, it is often very useful to understand its execution path: which function/method is calling, or is being called, by which one.

Before Blackfire

Traditional ways to do that during development cycles would for instance be to:

  • instrument code with echo, error_log(), debug_print_backtrace() and others in order to track when a specific bit of code is executed;
  • use XDebug and optionally its integration with IDEs, such as in PHPStorm.

Both options are suitable only in development, and require some configuration work and/or modification of the code base.

With Blackfire, via the Debug Add-on

Blackfire is a profiler which can be used in development, test/staging and production (with no impact for end users). Its core principle is to show developers how each function/method is related to callers and callees.

As Blackfire’s initial focus is performance, standard Blackfire profiles are pruned from calls responsible for less than 1% of the overall resources consumption. These calls are not available in the call-graph. The rationale is that when looking for performance, those calls are not significant enough; developers should focus on the method calls that consume the highest quantity of resources. Not showing them makes call-graphs easier to read – and also significantly decreases Blackfire’s payload size.

When using the Debug Add-on for a profile, pruning is disabled. Either check the box in the browser extension, or use the --debugoption if creating profiles with blackfire curl or blackfire run.

All function calls will then be available and visible in the call-graph.

Notes:

  • in order to avoid collecting heavy profiles that would take too long to load, using this feature automatically disables aggregation. The profile will be executed only once instead of getting the average of 10 samples.
  • this feature does not affect the data shown on the timeline
  • this add-on is an option for Profiler, Premium and Enterprise subscriptions.

Happy debugging,

Christophe Dujarric

Christophe is the Chief Product Officer at Blackfire. He's an engineer, but probably one of the least "tech" people in the company. He's wearing many hats, from product management to marketing and sales. He loves the beauty of simple solutions that solve actual problems.