本文介绍了将JVM参数传递给JMH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试分析一些JMH基准.我想启用GC日志记录以查看正在生成多少垃圾,但是我无法弄清楚如何传递JVM参数.我知道JMH在派生的JVM中运行基准测试,因此,如何做到这一点对我来说并不是立即显而易见的.我正在使用 SBT .

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.

推荐答案

如果我没看错sbt-jmh文档,它将使用jmh:run ...将应用程序选项传递给JMH运行程序.因此,让JMH命令行接受--jvmArgs "...",我将尝试执行jmh:run --jvmArgs "-XX:+PrintGCDetails".或者,如@apangin所述,添加@Fork(jvmArgsAppend = "-XX:+PrintGCDetails").

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").

但是对于您的特定用例-查看产生了多少垃圾"-最好使用捆绑的GC分析器(由-prof gc激活),这是更好的主意.请参见 JMHSample_35_Profilers.java#l71 .

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.

这篇关于将JVM参数传递给JMH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 12:17