-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a Twig profiler #13428
Added a Twig profiler #13428
Conversation
Very much looking forward to having this in Drupal 8! (Via https://www.drupal.org/project/webprofiler .) |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this use lateCollect
to take into account templates rendered later (in a streamed response for instance) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth on this one, but the current version is probably fine with the late data collector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
<argument type="service" id="debug.stopwatch" on-invalid="ignore" /> | ||
</service> | ||
|
||
<service id="twig.profile" class="Twig_Profiler_Profile" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this service is only meant to be accessed by twig.extension.profiler
and data_collector.twig
. It does not need to be retrieved dynamically. Right ? If yes, it could be marked private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made public because you might want to get the profile from a CLI tool or something else. It is available through the data collector, but exposing it directly seems like a better idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine with me (making it private would not allow inlining it anyway, as it is referenced twice)
the composer.json of the TwigBridge needs to be updated to Twig |
@@ -63,13 +63,12 @@ public function process(ContainerBuilder $container) | |||
$container->getDefinition('twig.extension.code')->replaceArgument(0, $container->getParameter('templating.helper.code.file_link_format')); | |||
} | |||
|
|||
if ($container->getParameter('kernel.debug') && $container->has('debug.stopwatch')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it really be tied to the presence of debug.stopwatch
(which is optional in the service definition already) ? this would prevent getting the Twig profiling data when you don't have the Stopwatch
15a1815
to
9c621b6
Compare
Oh yeah! This feature is very welcomed! Really nice to have. |
{ | ||
$this->getProfile(); | ||
|
||
return $this->computed['templates']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it's weird to call a getter before reading a property wich seem to not be related to the previous call
What's about
public function getComputedData($key)
{
if (null === $this->computed ) {
$this->computed = $this->computeData($this->getProfile());
}
return $this->computed[$key];
}
👍 ! Really great ! |
quick idea: would be nice to dump template context vars also. allows me to provide ide completion. |
👍 |
This PR was merged into the 1.17-dev branch. Discussion ---------- added a profiler This profiler allows to better understand what's going on when rendering templates. It should be used when debug is true only as it adds some overhead. Here is a sample output in the text format: ``` main 567.04ms/100% └ index 463.28ms/82% └ base 463.24ms/82% └ base::block(header) └ index::block(content) 306.29ms/54% │ └ included 50.18ms/9% │ └ included 45.42ms/8% │ └ included 35.42ms/6% │ └ base::block(content) 104.97ms/19% │ │ └ included 34.90ms/6% │ └ included 35.84ms/6% └ base::block(footer) 156.84ms/28% └ included 38.96ms/7% └ base::macro(foo) ``` You can also dump a profile in a Blackfire compatible format to [visualise the data as a graph](http://goo.gl/RwNGFH). A profile is also a great way to be able to list all templates/blocks/macros that were used when rendering a template. A PR on Symfony (symfony/symfony#13428) integrates this profiler in the Symfony web profiler to replace the current TimedTwigEngine and to add a new Twig panel. ![symfony-web-profiler](https://cloud.githubusercontent.com/assets/47313/5755461/019cd6a4-9ca5-11e4-8762-68e2a709c336.png) Commits ------- 4408caa added a profiler
This PR was merged into the 2.7 branch. Discussion ---------- Added a Twig profiler | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #6914 | License | MIT | Doc PR | n/a This PR integrates the new Twig 1.18 Profiler (see twigphp/Twig#1597) into Symfony (replace the current TimedTwigEngine) and adds a new Twig panel. The timers are now available for all rendered templates (TimedTwigEngine was only able to get information from a few of them -- mainly the first template only). The Twig panel gives you a lot of information about the execution of the templates, including a call graph. ![image](https://cloud.githubusercontent.com/assets/47313/5773885/fdf6756e-9d67-11e4-8dce-5ec20b07eca9.png) ![image](https://cloud.githubusercontent.com/assets/47313/5773892/0ae24d5c-9d68-11e4-9cbe-767bc31c9152.png) ![image](https://cloud.githubusercontent.com/assets/47313/5773897/13c0b6b6-9d68-11e4-95a1-b9188aca9651.png) ![image](https://cloud.githubusercontent.com/assets/47313/5773902/1c5498d8-9d68-11e4-975e-9822385fb836.png) ![image](https://cloud.githubusercontent.com/assets/47313/5773917/4eba00ba-9d68-11e4-8114-0a2d05eae5ea.png) Commits ------- daad64f added a Twig panel to the WebProfiler ef0c967 integrated the Twig profiler
very nice! |
…derusse) This PR was merged into the 2.7 branch. Discussion ---------- [twig] Fix getComputedData in new twig profiler | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | should be | Fixed tickets | NA | License | MIT | Doc PR | NA Add a small fix to #13428 Commits ------- e8ca06a Fix getComputedData
great one! but how to enable it in the silex web profiler? |
$this->computed = $this->computeData($this->getProfile()); | ||
} | ||
|
||
return $this->computed['index']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be $this->computed[$index];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR integrates the new Twig 1.18 Profiler (see twigphp/Twig#1597) into Symfony (replace the current TimedTwigEngine) and adds a new Twig panel.
The timers are now available for all rendered templates (TimedTwigEngine was only able to get information from a few of them -- mainly the first template only).
The Twig panel gives you a lot of information about the execution of the templates, including a call graph.