【问题标题】:DTraceAsmProfiler of JMH fails with '[sudo: a password is required' on MacJMH 的 DTraceAsmProfiler 在 Mac 上因“[sudo: a password is required”而失败
【发布时间】:2021-12-11 20:11:12
【问题描述】:

我正在使用 DTraceAsmProfiler 在 MacOS 上运行 IDEA 的基准测试,但它失败并出现以下错误:

Exception in thread "main" org.openjdk.jmh.runner.ProfilersFailedException: Profilers failed to initialize, exiting.
    at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:228)
    at org.openjdk.jmh.runner.Runner.run(Runner.java:209)
    at com.tsypanov.benchmark.BenchmarkRunner.main(BenchmarkRunner.java:45)
Caused by: org.openjdk.jmh.profile.ProfilerException: [sudo: a password is required
]
    at org.openjdk.jmh.profile.DTraceAsmProfiler.<init>(DTraceAsmProfiler.java:69)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openjdk.jmh.profile.ProfilerFactory.instantiate(ProfilerFactory.java:82)
    at org.openjdk.jmh.profile.ProfilerFactory.getProfiler(ProfilerFactory.java:77)
    at org.openjdk.jmh.profile.ProfilerFactory.getProfilerOrException(ProfilerFactory.java:37)
    at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:225)
    ... 2 more

我的代码:

public class BenchmarkRunner {

  public static void main(String[] args) throws RunnerException {
    Options opt = new OptionsBuilder()
            .include(CRHMBenchmark.class.getSimpleName())
            .warmupIterations(10)
            .warmupTime(TimeValue.seconds(1))
            .measurementIterations(10)
            .measurementTime(TimeValue.seconds(1))
            .addProfiler(DTraceAsmProfiler.class)
            .forks(5)
            .build();

    new Runner(opt).run();
  }
}

我也尝试从终端运行它并得到同样的错误:

% java -jar target/benchmarks.jar CRHMBenchmark -f 2 -w 1s -r 1s -prof dtraceasm
Profilers failed to initialize, exiting.
[sudo: a password is required
]

以前有人遇到过吗?

【问题讨论】:

  • 您是否尝试以提升的权限运行它(sudo 不需要密码)?
  • 我正在尝试shell stsypanov@MBP-SERGEYT assembly-profiling-and-all-all-all % sudo "/usr/bin/java" -jar target/benchmarks.jar CRHMBenchmark -f 2 -w 1s -r 1s -prof dtraceasm The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java. ,但也无济于事

标签: profiler jmh dtrace


【解决方案1】:

终于找到了解决办法:

sudo "/Users/stsypanov/Library/Java/JavaVirtualMachines/openjdk-17.0.1/Contents/Home/bin/java" -jar target/benchmarks.jar CRHMBenchmark -f 1 -w 1s -r 1s -prof dtraceasm -jvmArgsAppend "-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly"

【讨论】:

  • 顺便说一句,你有什么有意义的输出吗?一些time back我也尝试过玩这个,但最终我放弃了。
  • 在 jdk17 上我得到了这个:``` 43,04% 0x000000011cc129e8: ;*getfield references {reexecute=0 rethrow=0 return_oop=0} ; - org.springframework.util.ConcurrentReferenceHashMap$Segment::<init>@48(第 488 行); - org.springframework.util.ConcurrentReferenceHashMap::<init>@141 (line 184) 43,04% 0x000000011cc129e8: 458b 5620 1,30% 0x000000011cc129ec: ;隐式异常:调度到 0x000000011cc1369c ``` 要查看实际的 asm,我想我需要配置 hprof,请参阅 habr.com/ru/post/542148
  • 谢谢,我去看看。恭喜又一个精彩的演示,今天看了,很好,像往常一样!
猜你喜欢
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
  • 1970-01-01
  • 2016-08-13
  • 2022-12-13
相关资源
最近更新 更多