Symfony 秒表事件未出现在分析器时间线中 [英] Symfony StopWatch events not appearing in profiler timeline

查看:19
本文介绍了Symfony 秒表事件未出现在分析器时间线中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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...

这篇关于Symfony 秒表事件未出现在分析器时间线中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆