Home > Erlang性能测试 > 使用fprof进行性能分析

使用fprof进行性能分析

数据分析的大部分内容参考至(litaocheng–>靓仔): http://erlangdisplay.javaeye.com/blog/318975

代码演示

1
2
3
4
5
6
7
8
9
10
11
12
fprof:trace(start),%%文档说可以设置cpu_time 可我设置了 就分析不了了 神奇怪异
%%....先要感谢国家....这里是某一段函数的调用或者干脆就是代码片段....
fprof:trace(stop),
fprof:profile(),%%读取tracing出来的数据

%%no_callers 不显示调用者 这样内容看起来爽点 要不太多

%%append 在这段代码被重复调用时 分析数据会被逐条插入到存储文件的后面
%%否则会直接覆盖旧文件
fprof:analyse([{dest, "存放分析数据的文件路径"}, no_callers, append]),
ok
%%.....省略很多东西.....

分析结果
“%%%” 三个百分号 区别了总计数和下面的详细统计
只有在开启details的时候 你才能看到 “%%%” 后面的东西(默认是开启的)
后面三个数字分别代表:CNT ACC OWN
[{ totals, 216, 0.757, 0.757}].
[{ "<0.142.0>", 216, undefined, 0.757}].
{ {mgeec_role,handle_cast,2}, 0, 0.698, 0.095}.
….省略N行差不多的数据….

数据说明
CNT:总调用次数
ACC:Trace起始经历的时间(单位:微秒)
OWN:函数自身执行时间(单位:微秒)

一些疑问
fprof的官方文档有这么一句话
fprof tries to collect cpu time timestamps, if the host machine OS supports it. Therefore the times may be wallclock times and OS scheduling will randomly strike all called functions in a presumably fair way.
我google翻译后的理解是,fprof会尝试先去读取cpu time 而不是 wall clock。 这样看来,在trace中设置cpu_time不一定成功咯?怎么理解~~折腾人啊~

fprof的工作流程
1.tracing 就是搜集所有函数调用,我的理解是
2.profiling 读取tracing 搜集到的数据
3.analysing 分析统计排序数据
这样对fprof的几个函数的调用应该就清楚一点了~
这个流程的更详细说明(E文,看完可能脑残,慎重):

http://ns.erlang.org/documentation/doc-5.3.6.13/lib/tools-2.3/doc/html/fprof.html

POSTED ON 2010年08月8日,

Leave a Reply

Trackbacks:0

Listed below are links to weblogs that reference
使用fprof进行性能分析 from Flexsns-关注富互联网
TOP