2013-06-20 59 views

回答

0

确保您已将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 = /路径/要/ OUTPUT_DIR xdebug.profiler_output_name = cachegrind.out%R.%T

编辑: 哎呀,你是对的,我想用cachegrind的。要添加的行将在下面,但我的主要观点是相同的。确保你看看cli php.ini。

[xhprof] 
extension=xhprof.so 
xhprof.output_dir="/var/tmp/xhprof" 
+1

问题是关于XHProf的,这是Xdebug的 –

10

要找出测试运行速度慢,你可以使用

通过作曲家安装监听器,然后在phpunit.xml,例如启用

<phpunit bootstrap="vendor/autoload.php"> 
... 
    <listeners> 
     <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /> 
    </listeners> 
</phpunit> 

要找出为什么测试运行速度慢,你可以使用

可以在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> 
+0

你在哪里得到XHProf.php文件?那么xhprof_lib目录中的文件呢? –

+0

[XHProf.php](https://github.com/phpunit/phpunit-testlistener-xhprof)。 [xhprof_lib.php和朋友](https://github.com/phacility/xhprof)。 – bishop

3

补充@ Gordon对xhprof的回答。

有两个部分:

  1. PECL extension
  2. user-space viewer

PECL扩展添加方法为指标收集的PHP引擎。您必须安装此扩展。

用户空间查看器提供用于了解度量标准集合输出的Web界面。你不需要这个这个,但是你真的想要吧。除非您喜欢查看原始指标数据。要安装和配置的用户空间的观众,这样的PHPUnit可以分析你的测试:

(1)这些软件包添加到您的composer.json

composer require "facebook/xhprof:[email protected]" --dev 
composer require "phpunit/test-listener-xhprof:1.0.*@dev" --dev 

(2)配置Web服务器来服务供应商/ facebook/xhprof/xhprof_html /目录。记住URL。 (3)将您现有的PHPUnit配置调整为与此类似的phpunit-xhprof.xml。请确保您更改“appNamespace”你的代码,并改变“xhprofWeb”从第2步匹配的网址:

<phpunit> 
    <testsuites> 
    <testsuite name="All Tests"> 
     <directory suffix="Test.php">tests/</directory> 
    </testsuite> 
    </testsuites> 
    <listeners> 
    <listener class="PHPUnit\XHProfTestListener\XHProfTestListener" file="vendor/phpunit/test-listener-xhprof/src/XHProfTestListener.php"> 
    <arguments> 
     <array> 
     <element key="appNamespace"> 
     <string>App</string> 
     </element> 
     <element key="xhprofWeb"> 
     <string>http://localhost/vendor/facebook/xhprof/xhprof_html/index.php</string> 
     </element> 
     <element key="xhprofLibFile"> 
     <string>./vendor/facebook/xhprof/xhprof_lib/utils/xhprof_lib.php</string> 
     </element> 
     <element key="xhprofRunsFile"> 
     <string>./vendor/facebook/xhprof/xhprof_lib/utils/xhprof_runs.php</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> 
</phpunit> 

(4)运行PHP和收集统计信息:phpunit -c ./phpunit-xhprof.xml

你会看到输出类似于以下内容:

* BishopB\Pattern\Exception\InvalidArgumentTest::test_hierarchy 
    http://localhost/vendor/facebook/xhprof/xhprof_html/index.php?run=556e05cec844c&source=BishopB\Pattern 

这就是您配置为查看运行结果的URL。如果你想查看原始指标数据,发现运行键(“556e05cec844c”,在这个例子中)在临时目录:

$ ls -l /tmp/556e05cec844c.BishopB\\Pattern.xhprof 
-rw-rw-r-- 1 bishop staff 16963 Jun 2 15:36 /tmp/556e05cec844c.BishopB\Pattern.xhprof