Mat*_*son 9 php phpunit xhprof
我有一些非常慢的PHPUnit测试(43次测试需要8分钟),我需要使用XHProf来找出问题所在.
我怎么能从命令行执行此操作?我在项目的/ vendor目录中有PHPUnit,通过composer加载.
Gor*_*don 10
要找出哪个测试运行缓慢,您可以使用
通过Composer安装Listener,然后在phpunit.xml中启用它,例如
<phpunit bootstrap="vendor/autoload.php">
...
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
要找出为什么测试运行速度慢,你可以使用
您可以在phpunit.xml中配置它,例如
<listeners>
<listener class="PHPUnit_Util_Log_XHProf" file="PHPUnit/Util/Log/XHProf.php">
<arguments>
<array>
<element key="xhprofLibFile">
<string>/var/www/xhprof_lib/utils/xhprof_lib.php</string>
</element>
<element key="xhprofRunsFile">
<string>/var/www/xhprof_lib/utils/xhprof_runs.php</string>
</element>
<element key="xhprofWeb">
<string>http://localhost/xhprof_html/index.php</string>
</element>
<element key="appNamespace">
<string>Doctrine2</string>
</element>
<element key="xhprofFlags">
<string>XHPROF_FLAGS_CPU,XHPROF_FLAGS_MEMORY</string>
</element>
<element key="xhprofIgnore">
<string>call_user_func,call_user_func_array</string>
</element>
</array>
</arguments>
</listener>
</listeners>
Run Code Online (Sandbox Code Playgroud)
确保您已将 xdebug 行添加到 cli php.ini,而不仅仅是 apache php.ini。在 Ubuntu 上,它位于 /etc/php5/cli/php.ini。您应该将这些行添加到文件中:
zend_extension=/usr/lib/php5/20100525+lfs/xdebug.so xdebug.profiler_enable=1 xdebug.profiler_output_dir=/path/to/output_dir xdebug.profiler_output_name=cachegrind.out.%R .%t
编辑: 哎呀,你是对的,我正在考虑使用cachegrind。要添加的行将在下面,但我的要点是相同的。请务必查看 cli php.ini。
[xhprof]
extension=xhprof.so
xhprof.output_dir="/var/tmp/xhprof"
Run Code Online (Sandbox Code Playgroud)