在JMH中,StackProfiler.class接受几个参数:“line”、"top“、"detailLine”等等。
在命令行中,可以这样定义参数值:
java -jar my-benchmarks.jar -prof stack -jvmArgsAppend -Djmh.stack.lines=3看似明显
new OptionsBuilder().addProfiler("stack").jvmArgsAppend("-Djmh.stack.lines=3")或
@Fork(jvmArgsAppend="-Djmh.stack.lines=3")或
System.setProperty("jmh.stack.lines", "3");
...
new Runner(opt).run();并没有产生理想的效果。
发布于 2017-03-21 20:33:13
您一定是在使用非常老的JMH,因为堆栈分析器已经接受选项:
$ java -jar jmh-samples/target/benchmarks.jar -prof stack:help
Usage: -prof <profiler-name>:opt1=value1,value2;opt2=value3
Options accepted by org.openjdk.jmh.profile.StackProfiler:
[...]
lines=<int> Number of stack lines to save in each stack trace.
Larger values provide more insight into who is
calling the top stack method, as the expense of more
stack trace shapes to collect. (default: [1])
[...]无法从注释中访问此选项,但是Java接受分析器选项字符串:
/**
* Add the profiler in the run
* @param profiler profiler class
* @param initLine profiler options initialization line
* @return builder
*/
ChainedOptionsBuilder addProfiler(Class<? extends Profiler> profiler,
String initLine);
/**
* Add the profiler in the run
* @param profiler profiler class name, or profiler alias
* @param initLine profiler options initialization line
* @return builder
*/
ChainedOptionsBuilder addProfiler(String profiler, String initLine);所以,像这样的东西应该有效:
.addProfiler("stack", "lines=3")https://stackoverflow.com/questions/42917365
复制相似问题