安装xhprof过程就不说了
php.ini配置添加如下:
[xhprof]
extension = "xhprof.so"
xhprof.output_dir=/tmp/logs/xhprof //数据输出的目录
程序代码引用:(thinkphp案例)
<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
xhprof_enable();
$xhprof_on = true;
define('THINK_PATH', './ThinkPHP');
define('APP_NAME', 'test');
define('APP_PATH', './test');
require(THINK_PATH."/ThinkPHP.php");
App::run();
$xhprof_data = xhprof_disable();
$xhprof_root = '/htdoc/xhprof-0.9.2/';
include_once $xhprof_root."xhprof_lib/utils/xhprof_lib.php";
include_once $xhprof_root."xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "hx");
echo '<a href="http://debug.qq.com/xhprof_html/index.php?run='.$run_id.'&source=hx" target="_blank">统计</a>';
?>
再配置一个debug.qq.com的域名
server
{
listen 80;
server_name debug.qq.com;
index index.html index.htm index.php;
root /htdoc/xhprof-0.9.2/;
程序页面最底部会出现统计字样 点击查看即可
参数详解:
名词:
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% 峰值百分比