Symfony StopWatch Events Not Displayed on the Profiler Timeline

I am trying to get more information about timing in Timeline Profiler Timeline, but I can not get anything to appear. According to the documentation I read, it should be as simple as in the following example, but this does not lead to additional information appearing on the timeline.

Do I need to somehow make the profiler aware of the events that I start and stop?

use Symfony\Component\Stopwatch\Stopwatch; class DefaultController extends Controller { public function testAction() { $stopwatch = new Stopwatch(); $stopwatch->start('testController'); usleep(1000000); $response = new Response( '<body>Hi</body>', Response::HTTP_OK, array('content-type' => 'text/html') ); $event = $stopwatch->stop('testController'); return $response; } } 
+5
source share
2 answers

Symfony Profiler cannot scan code for all instances of the stopwatch and put it in the timeline. Instead, you should use the pre-configured stopwatch provided by the profiler:

 public function testAction() { $stopwatch = $this->get('debug.stopwatch'); $stopwatch->start('testController'); // ... $event = $stopwatch->stop('testController'); return $response; } 

However, your controller is already on the timeline ...

+19
source

You must embed the stopwatch as a service in your constructor or in a specific function, because after Symfony 3.4: Services are private by default.

 testAction(\Symfony\Component\Stopwatch\Stopwatch $stopwatch) { $stopwatch->start('testController'); // ... $event = $stopwatch->stop('testController'); } 
0
source

Source: https://habr.com/ru/post/1204966/


All Articles