您的位置:首页 > 其它

【程序性能分析】xhprof的使用例子

2014-07-12 10:24 351 查看

说明:

来自
百度百科 :XHProf是一个分层PHP性能分析工具。它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况。

结果字段解释:

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% 峰值百分比


程序例子:

/**
* 现有一个文件company.txt,里面有1000条数据,使用文件相关的函数读取出来,
保存到一个大数组,然后对这个数组进行相关操作,在页面中展示出来的时候使用分页,每页显示20条,每页显示的时候把执行时间显示出来,同时要求按照第一列cid排序。
*/
//初始时间
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

//程序主体开始
header('Content-type:text/html;charset=utf-8');
define('zuoye',true);
require_once './lib/model.php';
require_once './lib/action.php';

//预定义路径变量
$dirName = dirname(__FILE__);
$filePath = "{$dirName}/data/company.txt";
$tplPath = "{$dirName}/tpl/show.html";

//获取数据
$action = new action($filePath);
$data = $action->getList();//获取要显示的数据
$pageShow = $action->getPageLink();//获取分页链接
$pageNow = $action->getPageNow();//获取当前页数
$sign = $action->getSignUpOrDown();//获取升序或者降序排列的标示

//加载模板显示
$publicPath = dirname($_SERVER['PHP_SELF']).'/public';
include $tplPath;

//程序主体结束

//继续xhprof
$xhprof_data = xhprof_disable();
$xhprof_root = "D:/wnmp/www/xhprof";

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, "test");//第二个参数在接下来的地方作为命名空间一样的概念来使用

echo $run_id;

echo '<br/>';
$profiler_url = sprintf('http://localhost/xhprof/xhprof_html/index.php?run=%s&source=%s', $run_id, "test");

echo "<a href=\"{$profiler_url}\" target=\"_blank\">Profiler output</a>";


php配置:

extension=php_xhprof.dll

[xhprof]
;; xhprof日志输出目(根据实际环境修改)
xhprof.output_dir="f:/xhprof/"


xhprof主文件:

注-就是例子中存放在 $xhprof_root = "D:/wnmp/www/xhprof"; 的文件

下载链接

我的博客:

http://www.sibowen.com/index.php?m=Home&c=Index&a=index&classifyId=7
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: