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

Eir*_*sen 5 symfony

我正在尝试将更多的计时信息输入到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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Wou*_*r J 20

Symfony的探查器无法扫描所有秒表实例的代码并将其放入时间轴.您必须使用分析器提供的预配置秒表:

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

    // ...

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

    return $response;
}
Run Code Online (Sandbox Code Playgroud)

但是,您的控制器已经在时间轴上......

  • 他们应该在官方文档中添加这个,在秒表页面上没有提到它. (6认同)