I'm trying to get additional timing information into the Symfony Profiler Timeline, but I can't get anything to appear. According to the documentation I've read, it should be as simple as the following example, but this doesn't cause any additional info to appear on the timeline.
Do I need to somehow make the profiler aware of the events I'm starting and stopping?
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;
}
}
Symfony's profiler can't scan to code for all stopwatch instances and put that into the timeline. You have to use the preconfigured stopwatch provided by the profiler instead:
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...
You should inject the stopwacth as a service in your constructor or a specific function, becasue after Symfony 3.4: Services are private by default.
testAction(\Symfony\Component\Stopwatch\Stopwatch $stopwatch) {
$stopwatch->start('testController');
// ...
$event = $stopwatch->stop('testController');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With