Skip to content

Commit 0c1bf57

Browse files
committed
feature #45265 [HttpKernel] Add Profiler::isEnabled() method (Bilge)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [HttpKernel] Add Profiler::isEnabled() method | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> 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. Commits ------- b305386 [HttpKernel] Add Profiler::isEnabled() method
2 parents f341ce5 + b305386 commit 0c1bf57

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add `BackedEnumValueResolver` to resolve backed enum cases from request attributes in controller arguments
88
* Deprecate StreamedResponseListener, it's not needed anymore
9+
* Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves.
910

1011
6.0
1112
---

src/Symfony/Component/HttpKernel/Profiler/Profiler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function enable()
6060
$this->enabled = true;
6161
}
6262

63+
public function isEnabled(): bool
64+
{
65+
return $this->enabled;
66+
}
67+
6368
/**
6469
* Loads the Profile for the given Response.
6570
*/

src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ public function testFindWorksWithStatusCode()
8383
$this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
8484
}
8585

86+
public function testIsInitiallyEnabled()
87+
{
88+
self::assertTrue((new Profiler($this->storage))->isEnabled());
89+
}
90+
91+
public function testDisable()
92+
{
93+
$profiler = new Profiler($this->storage);
94+
$profiler->disable();
95+
96+
self::assertFalse($profiler->isEnabled());
97+
}
98+
99+
public function testEnable()
100+
{
101+
$profiler = new Profiler($this->storage);
102+
$profiler->disable();
103+
$profiler->enable();
104+
105+
self::assertTrue($profiler->isEnabled());
106+
}
107+
86108
protected function setUp(): void
87109
{
88110
$this->tmp = tempnam(sys_get_temp_dir(), 'sf_profiler');

0 commit comments

Comments
 (0)