2009年8月25日星期二

[PerlChina] Re: 哪位可以详细的讲讲Devel::Dprofile么?

怎么看上去跟python里的profile模块差不多的啊
--
blog: http://hi.baidu.com/smallfish_xy


2009/8/26 agentzh <agentzh@gmail.com>
2009/8/26 Mike.G <hylinux@gmail.com>

我刚去看了那篇文章,有些地方不是太明白。
比如说: inclusive times
这个时间到底怎么理解呢?

通过一个小例子来解释它是最容易的 :) 记得好几年前我也曾犯过迷糊,哈哈!

考虑下面的程序:

sub a { for (1..100000) { print 'a' x 100 }; b() }
sub b { for (1..100000) { print 'b' x 100 } }
a();

将之保存为 test.pl,然后用 DProf 去运行:

perl -d:DProf test.pl

再观察 exclusive 输出:

$ dprofpp
Total Elapsed Time = 0.089996 Seconds
  User+System Time = 0.079996 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 50.0   0.040  0.040      1   0.0400 0.0400  main::b
 50.0   0.040  0.080      1   0.0400 0.0800  main::a

这里虽然函数 a 调用了函数 b,但这里的 a 函数的时间是不包括它自己调用的其他函数,比如 b 的时间的,即二者各占一半(50.0%)。

再看看 inclusive 输出:

$ dprofpp -I
Total Elapsed Time = 0.089996 Seconds
  User+System Time = 0.079996 Seconds
Inclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 100.   0.040  0.080      1   0.0400 0.0800  main::a
 50.0   0.040  0.040      1   0.0400 0.0400  main::b

这里 a 函数的时间就包括了其自身以及它调用的函数 b 的时间了,我们看到,达到 100%,呵呵。而 b 函数因为未调用其他函数,故时间比例无变化,依旧是 50.0% :)

Happy profiling!
-agentzh





--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
 要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
 要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛

-~----------~----~----~----~------~----~------~--~---

没有评论: