gpt4 book ai didi

Symfony StopWatch 事件未出现在探查器时间线中

转载 作者:行者123 更新时间:2023-12-02 02:07:55 26 4
gpt4 key购买 nike

我正在尝试将其他计时信息添加到 Symfony Profiler 时间轴中,但我无法显示任何内容。根据我读过的文档,它应该像下面的示例一样简单,但这不会导致时间轴上出现任何附加信息。

我是否需要以某种方式让探查器了解我正在启动和停止的事件?

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 的分析器无法扫描所有秒表实例的代码并将其放入时间线中。您必须使用探查器提供的预配置秒表:

public function testAction()
{
$stopwatch = $this->get('debug.stopwatch');
$stopwatch->start('testController');

// ...

$event = $stopwatch->stop('testController');

return $response;
}

但是,您的 Controller 已经在时间轴上...

关于Symfony StopWatch 事件未出现在探查器时间线中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26436987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com