HPROF工具能搜集CPU使用信息通过注入代码到每个方法进入点和退出点.因此能够统计方法真实调用次数和花费的时间.
它使用BCI(Byte Code Injection),所以比cpu=samples慢.下面是样例输出
$ javac -J-agentlib:hprof=cpu=times Hello.java
CPU TIME (ms) BEGIN (total = 2082665289) Wed oct 4 13:43:42 2006
rank self     accum     count   trace     method
1       3.70% 3.70%     1        311243 com.sun.tools.javac.Main.compile
2       3.64% 7.34%     1        311242 com.sun.tools.javac.main.Main.compile
3       3.64% 10.97%    1        311241 com.sun.tools.javac.main.Main.compile
4       3.11% 14.08%    1        311173 com.sun.tools.javac.main.JavaCompiler.compile
5       2.54% 16.62%    8        306183 com.sun.tools.javac.jvm.ClassReader.listAll
6       2.53% 19.15%    36       306182 com.sun.tools.javac.jvm.ClassReader.list
7       2.03% 21.18%    1        307195 com.sun.tools.javac.comp.Enter.main
8       2.03% 23.21%    1        307194 com.sun.tools.javac.comp.Enter.complete
9       1.68% 24.90%    1        306392 com.sun.tools.javac.comp.Enter.classEnter
10      1.68% 26.58%    1        306388 com.sun.tools.javac.comp.Enter.classEnter
...
CPU TIME (ms) END
count列代表方法真实的进入次数,百分比表示线程调用这些方法花费的CPU时间.