Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

wouterj
Copy link
Member

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PRsymfony/symfony-docs#2630

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:

{%stopwatchfoo%}... some things that gets timed{%endstopwatch%}

This feature is based on the idea of@lsmith77 (see also our twitter conversation:https://twitter.com/lsmith/status/330772561413672962 )

@lsmith77
Copy link
Contributor

thank you for this .. works perfectly.
note we discussed at length if this should go into the TwigBundle or into WebProfilerBundle. in the end we agreed on putting it into TwigBundle since this way one can even put template using this tag into production where the profiler is usually disabled.

{
$name = $this->getAttribute('name');

$compiler
Copy link
Contributor

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 theStopwatchTokenParser and from there intoStopwatchNode if the stopwatch service is even available. If so we would then not even write the startEvent/stopEvent code into the cached PHP.

Copy link
MemberAuthor

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

@fabpot
Copy link
Member

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.

@lsmith77
Copy link
Contributor

ah doh .. makes sense.

* Some stuff which will be recorded on the timeline
* {% endstopwatch %}
*/
new StopwatchTokenParser(),
Copy link
Contributor

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@wouterj
Copy link
MemberAuthor

@fabpot I've moved the code to the twig bridge

* file that was distributed with this source code.
*/

namespace Symfony\Bundle\TwigBridge\Extension;
Copy link
Contributor

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.

@mpdude
Copy link
Contributor

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());
Copy link
Contributor

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?

Copy link
MemberAuthor

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.

Copy link
MemberAuthor

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

@fabpot
Copy link
Member

You should add a note in the CHANGELOG of the Twig bridge about this addition.

@Tobion
Copy link
Contributor

What happens when u have multiple stopwatch blocks with the same name? Does it get aggregated or overwritten?

{% stopwatch foo %}... some things that gets timed{% endstopwatch %}uninteresting stuff{% stopwatch foo %}... some things that gets timed{% endstopwatch %}

@stof
Copy link
Member

stof commentedMay 9, 2013

Tests are missing

@stof
Copy link
Member

stof commentedMay 9, 2013

btw, usingNAME_TYPE forbids having dots in the event name. Shouldn't we allow using a string too ?

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.

@wouterj
Copy link
MemberAuthor

@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

  • Add test
  • Allow strings
  • Throw error when name already exists
  • Make it dynamic (?)

@fabpot
Copy link
Member

We should usestart,stop instead to allow what@Tobion describe. Adn we should also support categories.

@wouterj
Copy link
MemberAuthor

@fabpot I can understand it wrong, but I already use start and stop?

@stof
Copy link
Member

stof commentedMay 9, 2013

@wouterj here is what I mean:

{%stopwatch'foo'%}{# equivalent of current stopwatch foo #}{%endstopwatch%}{%setbar ='foo'%}{%stopwatchbar%}{# uses the variable #}{%endstopwatch%}{%stopwatch (bar ~'test')|upper%}{# uses a complex expression #}{%endstopwatch%}

@stof
Copy link
Member

stof commentedMay 9, 2013

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

@wouterj
Copy link
MemberAuthor

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.

@stof
Copy link
Member

stof commentedMay 9, 2013

@wouterj block names have to be known at compile time. So it is a bad comparison

@matthiasnoback
Copy link

I think it would be good to support{% endstopwatch 'name' %} to make sure the right stopwatch is stopped. As far as I can see, it is also not possible to nest these tags, am I right?

@stof
Copy link
Member

@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

@wouterj
Copy link
MemberAuthor

I've implemented everything that is said here, except for 2 things:

  • Dynamic names. I fail to see when this is used.
  • Fabien's last comment (I can't follow that one). It throws an exception now if 2 names are equal

@wouterj
Copy link
MemberAuthor

ping@fabpot

@@ -4,6 +4,7 @@ CHANGELOG
2.3.0
-----

* added stopwatch tag to time templates with the WebProfilerBundle
Copy link
Contributor

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.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@fabpot
Copy link
Member

Closing in favor of#8719

@fabpotfabpot closed thisAug 11, 2013
fabpot added a commit that referenced this pull requestAug 13, 2013
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#2630This PR is the continuation of#7953This 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 expression4590974 removed code that prevents the stopwatch to work properly2f67776 removed unneeded safeguard as it's already done during compilationbbad387 fixed CSf39ed57 Created stopwatch tag
@wouterjwouterj deleted the twig_stopwatch_helper branchMay 1, 2014 07:55
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

11 participants
@wouterj@lsmith77@fabpot@mpdude@Tobion@stof@matthiasnoback@stloyd@pborreli@linniksa@bendavies

[8]ページ先頭

©2009-2025 Movatter.jp