首页 > 代码库 > centOS下 php xprof 性能测试
centOS下 php xprof 性能测试
首先,第一步,安装
1.安装 xhprof扩展
wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar zxvf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib <directory_for_htdocs> # 应用程序所在目录
cd extension
/usr/local/webserver/php/bin/phpize(路径如果不对一般都在/usr/local/下有php文件夹)
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
2.配置php.ini(php.ini目录一般存在于usr/local/php/etc)
3.为了更直观的跟踪查看哪里影响了性能,需要图形展示的话 需要安装dot
#如果要图形话,需要安装dot
wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz
tar zxvf graphviz-2.24.0.tar.gz
cd graphviz-2.24.0
./configure
make
make install
4.调用方式
在方法的开头写上
xhprof_enable();
在方法的结尾写上
$xhprof_data = http://www.mamicode.com/xhprof_disable();
$XHPROF_ROOT = realpath(dirname(__FILE__) .‘/..‘);
include_once ($XHPROF_ROOT . "/../xhprof/xhprof_lib/utils/xhprof_lib.php");//路径为解压之后xhprof_html存放的地址
include_once ($XHPROF_ROOT . "/../xhprof/xhprof_lib/utils/xhprof_runs.php");//路径为解压之后xhprof_runs存放地址
$xhprof_runs = new \XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
echo ‘<a href="http://xhprof.wst3.meici.com?run=‘ . $run_id . ‘&source=xhprof_foo" target="_blank">性能分析</a>‘;//输出地址,可以通过这个地址查看,也可自行配置
执行需要监控的方法后,可以通过配置之后的地址进入xhprof.index查看方法执行情况
选择一个点进去
点击进入图形界面后,会以图片的形式展示
黄色的代表的是执行时间较长的地方,可以进行优化
附一份解释
对于xhprof的名词解释:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 附录 Function Name 函数名 Calls 调用次数 Calls% 调用百分比 Incl. Wall Time (microsec) 调用的包括子函数所有花费时间 以微秒算(一百万分之一秒) IWall% 调用的包括子函数所有花费时间的百分比 Excl. Wall Time (microsec) 函数执行本身花费的时间,不包括子树执行时间,以微秒算(一百万分之一秒) EWall% 函数执行本身花费的时间的百分比,不包括子树执行时间 Incl. CPU(microsecs) 调用的包括子函数所有花费的cpu时间。减Incl. Wall Time即为等待cpu的时间 减Excl. Wall Time即为等待cpu的时间 ICpu% Incl. CPU(microsecs)的百分比 Excl. CPU(microsec) 函数执行本身花费的cpu时间,不包括子树执行时间,以微秒算(一百万分之一秒)。 ECPU% Excl. CPU(microsec)的百分比 Incl.MemUse(bytes) 包括子函数执行使用的内存。 IMemUse% Incl.MemUse(bytes)的百分比 Excl.MemUse(bytes) 函数执行本身内存,以字节算 EMemUse% Excl.MemUse(bytes)的百分比 Incl.PeakMemUse(bytes) Incl.MemUse的峰值 IPeakMemUse% Incl.PeakMemUse(bytes) 的峰值百分比 Excl.PeakMemUse(bytes) Excl.MemUse的峰值 EPeakMemUse% EMemUse% 峰值百分比 |
centOS下 php xprof 性能测试