-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TwigBundle] Created stopwatch tag for profiling templates #7953
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
Conversation
thank you for this .. works perfectly. |
{ | ||
$name = $this->getAttribute('name'); | ||
|
||
$compiler |
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.
we might want to pass a parameter into the StopwatchTokenParser
and from there into StopwatchNode
if the stopwatch service is even available. If so we would then not even write the startEvent/stopEvent code into the cached PHP.
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 thought about that too. I'll implement something like this
I would have put the code into the Twig bridge instead as this is where the integration of Twig and components happens. That would make the tag easily available for Drupal and Silex for instance. |
ah doh .. makes sense. |
* Some stuff which will be recorded on the timeline | ||
* {% endstopwatch %} | ||
*/ | ||
new StopwatchTokenParser(), |
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.
you are missing the $stopwatchIsAvailable
parameter here
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.
fixed
@fabpot I've moved the code to the twig bridge |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\TwigBridge\Extension; |
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.
Namespace is not correct, should be: Symfony\Bridge\Twig\Extension
.
Great! That deserves a "living on the edge" blog entry :-) |
$body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true); | ||
$stream->expect(\Twig_Token::BLOCK_END_TYPE); | ||
|
||
return new StopwatchNode($name, $body, $this->stopwatchIsAvailable, $lineno, $this->getTag()); |
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.
we can not simply return the $body if not stopwatchIsAvailable?
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 need to test that. If it works, it's definitelly better than what we now have.
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.
tested and it works, it's implemented now
You should add a note in the CHANGELOG of the Twig bridge about this addition. |
What happens when u have multiple stopwatch blocks with the same name? Does it get aggregated or overwritten?
|
Tests are missing |
btw, using And would it make sense to allow passing any Twig expression instead of only compile-time values ? Nothing in the current code requires to be able to use the event name at compile-time so we could make it dynamic. |
@stof should I add a StopwatchTokenParserTest? And what exactly do you mean with your last paragraph? Allowing string is a great idea, I'll add it. @Tobion due to the way the stopwatch works, only the first one is recorded. I'll throw an error if the name already exists. Todo
|
We should use |
@fabpot I can understand it wrong, but I already use start and stop? |
@wouterj here is what I mean: {% stopwatch 'foo' %}
{# equivalent of current stopwatch foo #}
{% endstopwatch %}
{% set bar = 'foo' %}
{% stopwatch bar %}
{# uses the variable #}
{% endstopwatch %}
{% stopwatch (bar ~ 'test')|upper %}
{# uses a complex expression #}
{% endstopwatch %} |
hmm, it could cause an issue to stop as we would need to stop the one we started, not to re-evaluate the expression as variables could have changed inside the body |
Thanks for the explaination! But do you really think it's worth it? The core block tag doesn't support it and I don't think people will use such a things for debugging. |
@wouterj block names have to be known at compile time. So it is a bad comparison |
I think it would be good to support |
@matthiasnoback The end tag should stop the corresponding opening tag. So passing the name explicitly is only a way to allow mistakes as it must be the same value. And nothing forbids you to nest them if you use different names |
I've implemented everything that is said here, except for 2 things:
|
ping @fabpot |
@@ -4,6 +4,7 @@ CHANGELOG | |||
2.3.0 | |||
----- | |||
|
|||
* added stopwatch tag to time templates with the WebProfilerBundle |
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 is not correct, 2.3
is already released.
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.
fixed
Closing in favor of #8719 |
This PR was merged into the master branch. Discussion ---------- [TwigBundle] Created stopwatch tag for profiling templates | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7953 | License | MIT | Doc PR | symfony/symfony-docs#2630 This PR is the continuation of #7953 This PR adds a new tag to Twig which you can use to time parts of a template and see it in the timing tab of the profiler. Usage: ````jinja {% stopwatch foo %} ... some things that gets timed {% endstopwatch %} ```` Commits ------- 29a58e7 change the stopwatch argument to be any valid expression 4590974 removed code that prevents the stopwatch to work properly 2f67776 removed unneeded safeguard as it's already done during compilation bbad387 fixed CS f39ed57 Created stopwatch tag
This PR adds a new tag to Twig which you can use to time parts of a template and see it in the timing tab of the profiler.
Usage:
This feature is based on the idea of @lsmith77 (see also our twitter conversation: https://twitter.com/lsmith/status/330772561413672962 )