【问题标题】:JMH giving <not counted> values when profiling with perfJMH 在使用 perf 进行分析时给出 <not counted> 值
【发布时间】:2018-09-14 15:18:20
【问题描述】:

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

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

【问题讨论】:

    标签: java profiling perf jmh


    【解决方案1】:

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

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

    问题已通过使用命令java -jar benchmarks.jar -prof perf:delay 0 解决。 : 用于将选项传递给分析器。

    【讨论】:

    • 您可能需要一些延迟以允许 JVM 预热,并让它退出启动 perf 的代码并返回到基准测试本身。
    • 我同意!我在这里没有使用任何延迟来确保确实计算了某些东西,并且从硬件计数器获取数据没有问题。
    猜你喜欢
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多