window wamp下xhprof的安装使用,Graphviz配置
在新的工作安排下来前赶紧把手上工作优化下,本来是靠xdebug+grindview来的,不过还是麻烦,就换上这个轻量级的性能测试了。网上搜的大多都是lamp环境下的,wamp下的倒是不多,而且不好用,于是整理了这篇教程。1.下载在这里 http://dev.freshsite.pl/php-extensions/xhprof.html 如果你下载不下来,可以给16090288@qq.com发邮件,说明版本。
我使用的是wamp 2.2d 32位的 ,这里罗嗦一句,既然用windows的wamp了,就不要装64位了,毕竟都是开发环境,正式环境肯定是32位的
这里下载两个文件 XHProf 0.10.3 for PHP 5.3 vc9.zip xhprof_html.zip
2.安装。 这步骤很简单,把XHProf 0.10.3 for PHP 5.3 vc9.zip里面的dll文件重命名为 php_xhprof.dll 放在php的ext目录下,然后在php.ini配置里面加入配置(不要忘记创建对应的文件夹)
extension=php_xhprof.dll
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
xhprof.output_dir=”d:/wamp/logs/xhprof_log”
重启你的wamp即可,看看phpinfo()里面有没有对应的文件
3.使用:
xhprof_html.zip 这个文件解压到你想测试的网站根目录就好了
现在网站一般使用的是框架,唯一入口这点最好了,直接在index.php里面写就好了,我用的是yaf框架
1
<?php
2
xhprof_enable();//开始
3
require 'init.php';
4
require 'conf/db.inc.php';
5
$app = new Yaf_Application(BASE_PATH . "/conf/itxiangqin.ini");
6
Yaf_Registry::set('config', Yaf_Application::app()->getConfig());
7
$app->bootstrap()->run();
8
$xhprof_data = xhprof_disable();//结束,然后写入文件,注意目录
9
$XHPROF_ROOT = realpath(dirname(__FILE__).'/xhprof');
10
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
11
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
12
13
// save raw data for this profiler run using default
14
// implementation of iXHProfRuns.
15
$xhprof_runs = new XHProfRuns_Default();
16
17
// save the run under a namespace "xhprof_foo"
18
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
19
echo "<a href='http://www.pztai.com/xhprof/xhprof_html/?run=$run_id&source=xhprof_foo'>分析</a>";//这里的pztai换成你自己的域名就好了,本地就localhost
还在学习使用中,写上几个缩写的
Inclusive Time 包括子函数所有执行时间。
Exclusive Time/Self Time 函数执行本身花费的时间,不包括子树执行时间。
Wall Time 花去了的时间或挂钟时间。
CPU Time 用户耗的时间+内核耗的时间
Inclusive CPU 包括子函数一起所占用的CPU
Exclusive CPU 函数自身所占用的CPU
以上内容大部分来自于google,我整理的而已,嘿嘿。
如果想要进一步研究,可以参考这篇文章。
============================================
但是我按照上面的最完后点击,
总是报错:
( ! ) Warning: file_get_contents(e:/wamp/tmp/xhprof/tmp//d1dede98ac80af3210574c7f7145cfa2.png) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in E:\wamp\www\xhprof\xhprof_lib\utils\callgraph_utils.php on line 192
( ! ) Warning: unlink(e:/wamp/tmp/xhprof/tmp//d1dede98ac80af3210574c7f7145cfa2.png) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in E:\wamp\www\xhprof\xhprof_lib\utils\callgraph_utils.php on line 202
找了半天原来是Graphviz的路径不对:
config.php:
<?php
/*
* Set the absolute paths on your system
*/
define('ERROR_FILE', 'e:/wamp/logs/xhprof_dot_errfile.log');
define('TMP_DIRECTORY', 'e:/wamp/tmp/xhprof/tmp/');
define('DOT_BINARY', 'd:/Program Files/Grafika/Graphviz/bin/dot.exe');
?>
==》改成:
<?php
/*
* Set the absolute paths on your system
*/
define('ERROR_FILE', 'e:/wamp/logs/xhprof_dot_errfile.log');
define('TMP_DIRECTORY', 'e:/wamp/tmp/xhprof/tmp/');
define('DOT_BINARY', 'd:/Program Files/Grafika/Graphviz/bin/dot');
?>
多了个“.exe”,太误导人了!
http://blog.iyunv.com/lanbingkafei/article/details/7707382
页:
[1]