我正在使用 JMH 對 JUnit 測驗進行基準測驗。我想開始使用 async-profiler 來分析基準并獲取有關 CPU 使用率的更多資訊。
我的基準賽跑者:
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.profile.AsyncProfiler;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.TimeValue;
import java.util.concurrent.TimeUnit;
public class BenchmarkRunner {
public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.include(Benchmarks.class.getSimpleName())
.addProfiler(AsyncProfiler.class, "output=flamegraph")
.mode(Mode.Throughput)
.resultFormat(ResultFormatType.CSV)
.result("target/test-classes/benchmarkcsv/BM " System.currentTimeMillis() ".csv")
.timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(3)
.warmupTime(TimeValue.seconds(1))
.measurementIterations(3)
.measurementTime(TimeValue.seconds(1))
.timeout(TimeValue.seconds(5))
.forks(1)
.warmupForks(1)
.threads(1)
.build();
new Runner(opt).run();
}
}
運行此程式時,我收到以下錯誤:
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 DummyApp.BenchmarkRunner.main(BenchmarkRunner.java:33)
Caused by: org.openjdk.jmh.profile.ProfilerException: Unable to load async-profiler. Ensure asyncProfiler library is on LD_LIBRARY_PATH (Linux), DYLD_LIBRARY_PATH (Mac OS), or -Djava.library.path. Alternatively, point to explicit library location with -prof async:libPath=<path>.
at org.openjdk.jmh.profile.AsyncProfiler.<init>(AsyncProfiler.java:237)
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
Caused by: java.lang.UnsatisfiedLinkError: no asyncProfiler in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.openjdk.jmh.profile.AsyncProfiler$JavaApi.<init>(AsyncProfiler.java:584)
at org.openjdk.jmh.profile.AsyncProfiler$JavaApi.getInstance(AsyncProfiler.java:573)
at org.openjdk.jmh.profile.AsyncProfiler.<init>(AsyncProfiler.java:234)
... 10 more
Process finished with exit code 1
根據 async-profiler Github 頁面,async-profiler 與 IntelliJ IDEA Ultimate 2018.3 及更高版本捆綁在一起。我正在我的系統上運行 IntelliJ IDEA Community Edition 2021.3.2,但我無法找到該庫。
我怎樣才能找到這個庫/解決我遇到的這個錯誤?
uj5u.com熱心網友回復:
例外訊息準確地說明了發生了什么以及如何解決它:
Unable to load async-profiler. Ensure asyncProfiler library is on
LD_LIBRARY_PATH (Linux), DYLD_LIBRARY_PATH (Mac OS), or -Djava.library.path.
Alternatively, point to explicit library location with -prof async:libPath=<path>.
從https://github.com/jvm-profiling-tools/async-profiler/releases獲取 async-profiler
,并將路徑設定為libasyncProfiler.so環境LD_LIBRARY_PATH變數或-Djava.library.pathJVM 選項。
在 Windows 上,您可以選擇另一個 JMH 分析器:-prof jfr或addProfiler(JavaFlightRecorderProfiler.class). 這將生成.jfr記錄,您可以直接在JDK Mission Control中打開或使用來自 async-profiler 的converter.jar轉換為火焰圖。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/466546.html
