How to see call tree profiling in JMH?
Asked Answered
S

1

6

I want to profile JMH tests and look at a call tree like in the VisualVM. But when I use the StackProfiler, it gives me native methods like that, which totally useless in my case.

....[Thread state distributions]....................................................................
 59,9%         TIMED_WAITING
 23,0%         WAITING
 17,0%         RUNNABLE

....[Thread state: TIMED_WAITING]...................................................................
 47,3%  78,9% sun.misc.Unsafe.park
  8,3%  13,8% java.lang.Thread.sleep
  4,4%   7,3% java.lang.Object.wait

....[Thread state: WAITING].........................................................................
 21,9%  95,1% sun.misc.Unsafe.park
  1,1%   4,9% java.lang.Object.wait

....[Thread state: RUNNABLE]........................................................................
 13,5%  79,0% sun.nio.ch.EPollArrayWrapper.epollWait
  2,0%  11,5% java.net.SocketInputStream.socketRead0
  1,0%   5,7% java.net.PlainSocketImpl.socketAccept
Sweetheart answered 2/6, 2017 at 16:42 Comment(0)
O
9

JMH's stack profiler is a rather simplistic implementation. Why not use the full-fledged profiler -- e.g. VisualVM you mentioned -- if you need something more? Alternatively, see -prof stack:help:

$ 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])
Oysterman answered 3/6, 2017 at 9:26 Comment(1)
Looks like you are right. In my case work such options creating like "new OptionsBuilder().addProfiler("stack", "lines=5;top=3;detailLine=true;excludePackages=true;period=1")...", but for complex long running methods easier to write a tiny class and use the VisualVM.Montelongo

© 2022 - 2024 — McMap. All rights reserved.