查看xdebug profile文件的几个程序2010-10-05在优化php代码执行效率过程中,有个好办法是利用xdebug生成profile文件,然后查看整个程序的瓶颈在哪里。现在xdebug profile的查看程序有好几个,在这里罗列一下.WincachegrindWincachegrind是windows下的profile查看程序,使用起来感觉还不错,profile文件太大的话偶尔会崩溃。今天在高春辉的博客上看到这些:最近又开始拿 Xdebug 和 wincachegrind 对项目的 PHP 代码进行分析和优化,但是发现和自己输出的执行时间总是相差十倍,差的不是零头,而是十倍。上网搜索了一下,原来在 Xdebug 2.0.0RC4 版本开始,对 profiler 日志中的时间单位进行了修改。(“Use µ seconds instead of a tenths of µ seconds to avoid confusion in profile information. ”)而 wincachegrind 又不再升级维护了,所以凡是用 2.0.0RC4 以及之后版本的 Xdebug 输出的 profiler 日志用 wincachegrind 来分析的话,都会有十倍的时间差距。他已经提供了hack后的版本,可以解决时间差距的问题,有兴趣的同学可以试试。CachegrindVisualizerCachegrindVisualizer是一个xdebug的profile文件查看客户端,采用Adobe的AIR制作。更详细的介绍可以看以前写的关于CachegrindVisualizer的介绍。KcachegrindKcachegrind是linux下的一个图形化profile查看工具,功能很强劲。Callgrind uses runtime instrumentation via the Valgrind framework for its cache simulation and call-graph generation. This way, even shared libraries and dynamically opened plugins can be profiled. The data files generated by Callgrind can be loaded into KCachegrind for browsing the performance results.webgrindwebgrind和wincachegrind的功能差不多,但是webgrind是基于web的,采用php写的查看工具。看了一下代码,跑在linux的服务器比较好。Webgrind is an Xdebug profiling web frontend in PHP5. It implements only a minimal subset of the features of kcachegrind, but installs in seconds and works on all platforms. For quick’n"dirty optimizations it does the job.下面是用webgrind查看phpmyadmin的profile抓图: