The Timeline Threshold
In Blackfire Timeline view, the “threshold” metric is a powerful, but underrated tool… Let’s have a closer look.
The Blackfire Timeline View is a very good complement to the call-graph as it allows to visualize a profile on a time base. It is a good starting point when starting profiling, because it shows how your application behaves over time, which is usually close to the representation we have in mind (e.g. “First the request comes here, then application reacts doing this, etc…“).
In the Timeline View, function calls are represented by blocks called events; these events are piled-down so that you can visualize how deep your application goes, from your top controller to the low-level functions. The result is similar to a reverse Flame Graph. Note that unlike regular flame graphs which goes from bottom to top, we chose to go from top to bottom in order to represent the deepness of your application.
Some events are noticeable with their colors; it means that Blackfire “recognized” these function calls as part of metrics. Those metrics are either part of the ones provided by Blackfire (which include various frameworks and libraries), or custom ones defined in the
Among all the metrics, which are grouped in the panel at the left of the timeline, one has a special meaning and worths our attention: threshold.
The Timeline Threshold “Metric” Explained
The Timeline documentation states the following:
thresholdtimeline metric highlights one or several event blocks in the Timeline view. It is designed to draw your attention on something that Blackfire considers significant.
In short, the emphasized events are considered as potentially improvable. Like when analyzing hot paths in a callgraph, such events are usually a consequence of some intensive and/or malfunctioning code. As such, it is quite common to get vendor code highlighted this way. As a developer, your task is then to identifiy which part of the code you control is responsible of this “hot point”.
In this example, two Doctrine events are tagged as significant. Moving our gaze a few blocks upper, we can observe that
PostRepository::findLatest(), which is part of our application code, is responsible for calling Doctrine upstream. We can then assume that the bottleneck is coming from our code in the first place, and start looking for a fix.
The Timeline Threshold is not an absolute value. It is relative to the way your application performs. The threshold value is calculated by Blackfire as 1% of the duration of the profiled page/script. Given this value, which is accessible from the profile information panel, an event is usually considered significant when its exclusive wall-time exceeds it. This is why you may still get emphasized blocks on an optimized page.
Like callgraphs emphasize a hot path for you, the Timeline provides you hints on potential bottlenecks. As such, the “threshold metric” is a tool worth using to understand how your application behaves over time, and to find bottlenecks.
However it is important to keep in mind that these hints only remain directions for improvement. There is no “Thy shall fix green blocks” commandment, so Keep Calm and Carry On Profiling 😉.