Skip to content

[HttpKernel] Add Profiler::isEnabled() method #45265

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

Merged
merged 0 commits into from
Feb 21, 2022

Conversation

Bilge
Copy link
Contributor

@Bilge Bilge commented Feb 1, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR symfony/symfony-docs#...

When disabling the profiler programmatically, collectors will not be called, but any collaborating services that collect profiling data on behalf of those collectors will still do unnecessary work. By being able to inquire about whether the profiler is enabled, such services may elect to omit data collection thus reducing memory and CPU footprint.

Relates to #45241.

@carsonbot carsonbot added this to the 6.1 milestone Feb 1, 2022
@Bilge Bilge force-pushed the profiler-enabled branch 2 times, most recently from 2063db8 to c3b08e8 Compare February 1, 2022 10:08
@carsonbot
Copy link

Hey!

I think @mtarld has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@GromNaN
Copy link
Member

GromNaN commented Feb 2, 2022

If I get it right, the "collaborating services" will depend on the profiler service, which is not needed currently. Don't you get a circular depencency (profiler -> collector -> collaborating service -> profiler) ?

Alternative proposition : propagate status to the collectors when Profiler::disable() is called.

@Bilge
Copy link
Contributor Author

Bilge commented Feb 2, 2022 via email

@GromNaN
Copy link
Member

GromNaN commented Feb 2, 2022

This has nothing to do with collectors.

Well, could you describe your use-case a little more. What is a "collaborating service that collect profiling data on behalf of those collectors" ?

@Bilge
Copy link
Contributor Author

Bilge commented Feb 2, 2022

Sure. I wrote a database profiler similar to the one you know in Doctrine, but for the Amp drivers instead (see also: doctrine/DoctrineBundle#1464). The regular connection pool is decorated with a profiled pool; this is the collaborating service. This service is injected into the collector. When the profiler is disabled the collector will not be called, but the pool is still decorated and still collects data anyway, since it is unaware of the status of the profiler.

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Thanks for the details.
I have almost the same use-case and used %kernel.debug% to enable/disable collection of queries in the client decorator. Your solution is smarter.

Regarding circular dependency, the container builder is able to handle it.

@carsonbot carsonbot changed the title Add Profiler::isEnabled() method [HttpKernel] Add Profiler::isEnabled() method Feb 2, 2022
@SHTIKOV

This comment was marked as off-topic.

@Bilge
Copy link
Contributor Author

Bilge commented Feb 21, 2022

Can this be included in 5.4 somehow?

@fabpot
Copy link
Member

fabpot commented Feb 21, 2022

No, new features are always merged on the upcoming branch.

@fabpot
Copy link
Member

fabpot commented Feb 21, 2022

Thank you @Bilge.

@fabpot fabpot closed this Feb 21, 2022
@fabpot fabpot merged commit 0c1bf57 into symfony:6.1 Feb 21, 2022
@fabpot fabpot mentioned this pull request Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants