New in Symfony 2.7: Twig Profiler

Contributed by
Fabien Potencier
in #13428.

In Symfony project we believe that all the information relevant to developers should be one click away. That's why in Symfony 2.7 we've added a new panel with Twig information in the web debug toolbar.

Currently, the information about the resources used to render each template is displayed in the Timeline panel of the Symfony profiler:

Twig Basic Profiler

Sadly, this panel doesn't provide much detail for templates. Moreover, some templates aren't registered, so their information is missing in that panel.

Symfony 2.7 solves these problems thanks to the new profiler introduced by Twig in its 1.18.0 version. First, you'll see a new Twig debug panel in the web debug toolbar that gives you a quick overview of the main Twig stats:

Twig Debug Panel

If you click on that panel, you'll see the full information collected by the Twig profiler. First, you'll get the main Twig stats for the page, which is the first thing to check when things go wrong:

Twig Profiler Stats

Second, you'll see the full list of templates used to render the page, including the templates of third-party bundles and the template fragments:

Twig Profiler Templates

Lastly, you'll get the full call graph executed by Twig to render the page. This information is mostly useful when things go wrong or your templates render slowly. Thanks to the detailed information, you'll discover the performance bottlenecks instantly:

Twig Profiler Call Graph

Symfony 2.7 enables the Twig profiler automatically when the application uses the debug mode. If you are using Twig outside of Symfony, you must register the new profiler extension before rendering the templates:

1
2
3
4
5
6
7
$profile = new Twig_Profiler_Profile();
$twig->addExtension(new Twig_Extension_Profiler($profile));

// render templates ...

$dumper = new Twig_Profiler_Dumper_Text();
echo $dumper->dump($profile);

In addition to the basic text dumper (which is the one used by Symfony), Twig also includes an advanced dumper to output the call graph information in a format compatible with the Blackfire Profiler.

Comments

Great job ! :D
Nice idea! I like that :)
Awesome. Great job guys!!!!
A while ago I was facing this problem (profiling views) in RoR and haven't found anything good (New relic kinda helped). Glad to hear I won't have this problem with Sf2 :) Thanks!
Awesome!
Nice Tool ! Thx
Thanx !
Nice, thanks for this great improvement !
There's a lot of useful information! I've been waiting for this look, thanks!
Beschde!
Nice tool :)
Very usefull tool, specially the tree command !
Great job! Thanks!
Very good idea. Thank!
Nice tool !

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.