如何使用Blackfire对PHP shell脚本应用或worker进行分析性能?

3
我注意到当我有一个无限的worker时,我无法对PHP shell脚本进行性能分析。因为当它被杀死时,它不会发送探针。
我应该做哪些改变?
2个回答

3
当您尝试分析运行无限循环的工作程序时,您需要手动编辑代码以删除无限循环或在代码中进行手动调用探针的close()方法(https://blackfire.io/doc/manual-instrumentation)。这是因为仅在调用close()方法时才会将数据发送到代理服务器(除非您终止了程序,在程序结束时会自动调用close()方法)。
您可以使用Blackfire探针捆绑的BlackfireProbe类手动对某些代码进行检测。
// Get the probe main instance
$probe = BlackfireProbe::getMainInstance();
// start profiling the code
$probe->enable();

// Calling close() instead of disable() stops the profiling and forces the  collected data to be sent to Blackfire:

// stop the profiling
// send the result to Blackfire
$probe->close();

与自动仪器化一样,分析只有在通过 Companion 或 blackfire CLI 实用程序运行代码时才处于活动状态。否则,所有调用均转换为 noop。


2
希望那个页面永远存在,否则你应该包含那个页面上的代码/文本,除非你是该网站的“所有者”;-) 你知道Stack对于仅链接的看法。 - Funk Forty Niner

0

我不知道,也许在2015年这个页面不存在,但现在你可以通过以下方式进行分析:https://blackfire.io/docs/24-days/17-php-sdk

$blackfire = new LoopClient(new Client(), 10);
$blackfire->setSignal(SIGUSR1);
$blackfire->attachReference(7);
$blackfire->promoteReferenceSignal(SIGUSR2);

for (;;) {
    $blackfire->startLoop($profileConfig);

    consume();

    $blackfire->endLoop();

    usleep(400000);
}

现在你可以向这个工作进程发送信号SIGUSR1,LoopClient 将开始分析。它会监听方法consume的10次迭代并发送最后一个探测值。之后它将停止分析。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接