Getting More Precision with Arguments Capturing

By Jérôme Vieilledent, on Nov 18, 2019

In the Call Graph view of a Blackfire profile, function calls are aggregated into nodes. These nodes hold information about the resources consumed by their related functions, regardless of their callers or their arguments. This representation makes the understanding of the application flow easier, answering a common question for a developer: “How my application is behaving for a given task?”.

The counterpart of this approach is that you get little information on how each function is called as you’re missing the arguments. This can be problematic in some cases where you need to differentiate similar function calls.

A classic example is the Symfony Event Dispatcher. The EventDispatcher::dispatch() function can be called with many different values as the first argument, which represents the name of the dispatched event. Another example is PDOStatement::execute() which receives the SQL query to run. In such cases, it is critical to discriminate function calls with their arguments in order to have the best insight of your application behavior. This is where Arguments Capturing comes in.

Arguments Capturing: A Primer

Arguments Capturing enables you to discriminate function calls depending on their arguments. Blackfire will display as many nodes as variations exist, based on the captured arguments.

Let’s illustrate with an example. Consider you have a Greetings class with a phrase() method where the first argument is the greeting type (e.g. Hello, Bonsoir, …) and the second argument the actual phrase.

We can discriminate these calls in order to get 2 nodes, by adding the following configuration in .blackfire.yaml file

The “*” character is a “catch-all” selector, which means that Blackfire will create as many nodes as different values are passed during the application flow. Other selectors exist, such as “Starts-with” or “RegExp” selectors.

The result will be:

Icing on the cake, you will be able to search function calls by captured argument in the Functions list on the left of the call graph.

Multiple arguments capturing

Now, what if we wanted to discriminate on the 2 arguments of Greetings::phrase()? Add a new line in the .blackfire.yaml file:

One more thing…

Yes, there is always one more thing 🤓.

Arguments to be captured can also be associative arrays (aka hashes)!

Happy profiling!

Jérôme Vieilledent

As a Developer Advocate, Jérôme is all about spreading the love! His technical/development background enable him to talk as a peer to peers with our developer users. You’ll read his tips and advices on performance management with Blackfire. And he’ll support you as a day-to-day user.