PHP 脚本的计时部分,包括对象的各个方法的运行时间?

发布于 2024-08-26 21:51:06 字数 613 浏览 1 评论 0原文

我一直在寻找一种可靠、简洁的方法来为 PHP 脚本的特定部分生成高级运行时报告。我想做的是动态计时并跟踪脚本执行期间每个对象的每个方法调用,记录此信息,并在脚本末尾创建一个表/报告以进行输出。

我考虑过用伪代码做一些事情:

class MagicTimingClass redefines *ALL_CLASSES* {
    public function __call($name, $args) {
        log_start_time();
        $return = run_the_method();
        log_end_time();
        return $return; // return original method results
    }
}

我知道我不能这样做,并且我已经研究过 PHP 的 runkit/classkit 但是我不确定这是否能帮助我准确地完成我正在寻找的事情。

我希望得到一份报告,这样我就可以确定哪些方法导致我的脚本出现瓶颈,而无需暂时修改我的类以进行此级别的调试,然后在我需要代码投入生产时再次取消修改。

如果有人有任何想法或线索,那就太好了!提前致谢

I was looking for a reliable, clean way to do advanced runtime reports for specific portions of a PHP script. What I'd love to do is dynamically time and track every method call of every object during script execution, log this information, and create a table/report at the end of the script for output.

I've thought about doing something along the lines of, in pseudocode:

class MagicTimingClass redefines *ALL_CLASSES* {
    public function __call($name, $args) {
        log_start_time();
        $return = run_the_method();
        log_end_time();
        return $return; // return original method results
    }
}

I know I can't do this, and I've looked into runkit/classkit for PHP but I'm not sure this will help me do exactly what I'm looking for.

I'm hoping to get out a report so I can determine what methods are causing my script to bottleneck without temporarily modifying my classes for this level of debugging and then un-modifying again when I need the code to go to production.

If anyone has any thoughts or leads that would be great! Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2024-09-02 21:51:06

您可以使用像 Xdebug 这样的分析器,这意味着您根本不必修改代码。

You could use a profiler like Xdebug which would mean you wouldn't have to modify your code at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文