安装 wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar zxf xhprof-0.9.4.tgz //将xhprof-0.9.4下的xhprof_html和xhprof_lib复制到项目目录下 cd xhprof-0.9.4/extension/ #phpize ./configure --with-php-config=/usr/local/php/bin/php-config #make #make install
配置: [xhprof] extension=xhprof.so; ; directory used by default implementation of the iXHProfRuns ; interface (namely, the XHProfRuns_Default class) for storing ; XHProf runs. ; ;xhprof.output_dir=<directory_for_storing_xhprof_runs> ;调试信息的保存路径,建立目录/tmp/xhprof xhprof.output_dir=/tmp/xhprof
if(extension_loaded('xhprof')) { xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); } //PHP Code //........ if(extension_loaded('xhprof')) { $data = xhprof_disable(); //返回运行数据 $XHPROF_ROOT = realpath(dirname(__FILE__) .'/..'); include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT."/xhprof_lib/utils/xhprof_runs.php"; $objXhprofRun = new XHProfRuns_Default(); $run_id = $objXhprofRun->save_run($data, "xhprof"); var_dump($run_id); } ---------------------------------------------------------------------------- 会在上面设定的xhprof.output_dir目录里生成名字相似49bafaa3a3f66.xhprof_foo的数据文件, 能够很方便的经过Web方式浏览效果: 访问地址:http://test.cm/xhprof/xhprof_html/index.php?run=49bafaa3a3f66 结果分析主要指标: Inclusive Time (或子树时间):包括子函数全部执行时间。 Exclusive Time/Self Time:函数执行自己花费的时间,不包括子树执行时间。 Wall时间:花去了的时间或挂钟时间。 CPU时间:用户耗的时间+内核耗的时间 # 若是xhprof_enable函数写做: xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY)能够输出更多指标。 Function Name 函数名 Calls 调用次数 Calls% 调用百分比 # 消耗时间 Incl. Wall Time (microsec) 调用的包括子函数全部花费时间 以微秒算(一百万分之一秒) IWall% 调用的包括子函数全部花费时间的百分比 Excl. Wall Time (microsec) 函数执行自己花费的时间,不包括子树执行时间,以微秒算(一百万分之一秒) EWall% 函数执行自己花费的时间的百分比,不包括子树执行时间 # 消耗CPU Incl. CPU(microsecs) 调用的包括子函数全部花费的cpu时间。减Incl. 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% 峰值百分比