JMH使用性能分析进行分析时给出<not counted =“”>值

时间:2018-09-14 15:18:20

标签: java profiling perf jmh

我想在Java中运行基准测试并获取硬件计数器。 我想使用JMH这样做,因为它似乎是一种成熟的工具。它还具有钩住配置文件的选项(例如,perf工具也很成熟)。 我的问题是,当使用java -jar benchmarks.jar -prof perf运行基准测试时,所有计数器都显示值<not counted>

Perf stats:
--------------------------------------------------

     <not counted>      task-clock
     <not counted>      context-switches
     <not counted>      cpu-migrations
     <not counted>      page-faults
     <not counted>      cycles
     <not counted>      instructions
     <not counted>      branches
     <not counted>      branch-misses
     <not counted>      L1-dcache-loads
     <not counted>      L1-dcache-load-misses
     <not counted>      LLC-loads
     <not counted>      LLC-load-misses
   <not supported>      L1-icache-loads
     <not counted>      L1-icache-load-misses
     <not counted>      dTLB-loads
     <not counted>      dTLB-load-misses
     <not counted>      iTLB-loads
     <not counted>      iTLB-load-misses
   <not supported>      L1-dcache-prefetches
   <not supported>      L1-dcache-prefetch-misses

       0,379402355 seconds time elapsed

如果我独立运行perf,例如通过键入perf stat sleep 5,那么我会得到结果:

Performance counter stats for 'sleep 5':

          0,588915      task-clock (msec)         #    0,000 CPUs utilized
                 1      context-switches          #    0,002 M/sec
                 0      cpu-migrations            #    0,000 K/sec
                60      page-faults               #    0,102 M/sec
         1 048 769      cycles                    #    1,781 GHz
           807 919      instructions              #    0,77  insn per cycle
           159 210      branches                  #  270,345 M/sec
             7 325      branch-misses             #    4,60% of all branches

       5,001500262 seconds time elapsed

1 个答案:

答案 0 :(得分:3)

我找到了答案,我把答案留给了遇到类似问题的其他人。

perf的调用具有参数--delay 21000,该参数引入了开始计数之前的延迟。由于基准时间短于基准时间,因此计数从未开始。

使用命令java -jar benchmarks.jar -prof perf:delay 0解决了该问题。 :用于将选项传递到探查器。