Pass JVM arguments to JMH

若如初见. 提交于 2020-01-03 07:26:48

问题


I have some JMH benchmarks that I'm trying to analyze. I want to enable GC logging to see how much garbage is being generated, but I can't figure out how to pass JVM arguments. I know JMH runs benchmarks in a forked JVM, so it's not immediately obvious to me how to do this. I'm using SBT.


回答1:


If I read sbt-jmh docs right, it passes the application options to JMH runner with jmh:run .... So, having that JMH command line accepts --jvmArgs "...", I would try to do jmh:run --jvmArgs "-XX:+PrintGCDetails". Or, as @apangin mentions, add @Fork(jvmArgsAppend = "-XX:+PrintGCDetails").

But for your particular use case -- "see how much garbage is generated" -- it might be even better idea to use a bundled GC profiler, activated with -prof gc. See the example at JMHSample_35_Profilers.java#l71.




回答2:


Use @Fork annotation:

@Benchmark
@Fork(jvmArgsAppend = "-XX:+PrintGCDetails")
public void someBenchmark() {
    ...
}

Note that JVM arguments passed to JMH are also propagated to forked benchmarks.



来源:https://stackoverflow.com/questions/36293445/pass-jvm-arguments-to-jmh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!