Skip to content

Commit 5e22436

Browse files
authored
[Profiler] document how to disable data collector internal tracing logic
1 parent 06fe160 commit 5e22436

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

profiler.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,38 @@ data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-
368368
with ``autoconfigure``, then Symfony will start using your data collector after the
369369
next page refresh. Otherwise, :ref:`enable the data collector by hand <data_collector_tag>`.
370370

371+
.. warning::
372+
373+
It arrives that some data collector leverage some decorated underlying service (traceable service).
374+
And as the profiler mechanism can be disabled, you may adapt your collector to handle such case
375+
to avoid unwanted useless memory leak.
376+
You can do so by injecting the ``profiler.is_disabled_state_checker`` service::
377+
378+
// src/DataCollector/ServiceCollector.php
379+
namespace App\DataCollector;
380+
381+
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
382+
use Symfony\Component\HttpFoundation\Request;
383+
use Symfony\Component\HttpFoundation\Response;
384+
385+
class ServiceCollector extends AbstractDataCollector
386+
{
387+
public function __construct(
388+
private ServiceInterface $decoratedService,
389+
protected readonly ?\Closure $disabled = null, // profiler.is_disabled_state_checker
390+
) {}
391+
392+
public function action(): void
393+
{
394+
if ($this->disabled?->__invoke()) {
395+
return $this->decoratedService->action();
396+
}
397+
398+
// do the trace job to have some data to be collected by your data collector.
399+
}
400+
}
401+
402+
371403
Adding Web Profiler Templates
372404
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373405

0 commit comments

Comments
 (0)