安装xhprof
clone https://github.com/longxinH/xhprof
cd xhprof/extension/
phpize
./configure
make
make install
php.ini文件中添加 extension=xhprof.so
xhprof分析ci框架
xhprof参数含义
Function Name:方法名称。
Calls:方法被调用的次数。
Calls%:方法调用次数在同级方法总数调用次数中所占的百分比。
Incl.Wall Time(microsec):方法执行花费的时间,包括子方法的执行时间。(单位:微秒)
IWall%:方法执行花费的时间百分比。
Excl. Wall Time(microsec):方法本身执行花费的时间,不包括子方法的执行时间。(单位:微秒)
EWall%:方法本身执行花费的时间百分比。
cd xhprof
复制 xhprof_html xhprof_lib 两个文件夹到CI框架index.php同目录
复制 xhprof/xhprof_lib/utils/xhprof_lib.php
xhprof/xhprof_lib/utils/xhprof_runs.php
两个文件到CI框架index.php同目录
框架开始加入代码:
xhprof_enable();
//默认情况下只有调用次数和占用时间是记录了的。您也可以选择同时记录CPU时间和/或单纯记录内存使用量。将下面这一行:
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
结束加入代码:
$xhprof_data = xhprof_disable();
// display raw xhprof data for the profiler run
print_r($xhprof_data);
include_once "xhprof_lib.php";
include_once "xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
echo "---------------\n".
"Assuming you have set up the http based UI for \n".
"XHProf at some address, you can view run at \n".
"http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n".
"---------------\n";
访问网站www.test.com, 运行框架;
访问www.test.com/xhprof_html/index.php?run=$run_id&source=xhprof_foo得到分析结果
linux安装绘图工具
yum install libpng
yum install graphviz