Why aren't all methods displayed in VisualVM profiler?

后端 未结 3 2006
盖世英雄少女心
盖世英雄少女心 2021-02-15 00:00

I am using VisualVM to see where my application is slow. But it does not show all methods, probably does not show all methods that delays the application.

3条回答
  •  长情又很酷
    2021-02-15 00:54

    Other than the filters mentioned by Ryan Stewart, here are a couple of additional reasons why methods may not appear in the profiler:

    • Sampling profiles are inherently stochastic: a sample of the current stack of all threads is taken every N ms. Some methods which actually executed but which aren't caught in any sample during your run just won't appear. This is generally not too problematic since the very fact they didn't appear in any sample, means that with very high probability these are methods which aren't taking up a large part of your runtime.
    • When using instrumentation based sampling in visualvm (called "CPU profiling"), you need to define the entry point for profiled methods (the "Start profiling from" option). I have found this fails for methods in the default package, and also won't pick up time in methods which are current running when the profiler is attached (for the duration of the current invocation - it will get later invocations. This is probably because the instrumented method won't be swapped in until the current invocation finishes.
    • Sampling is subject to a potentially serious issue with stack traced based profiling, which is that samples are only taken at safe points in the code. When a trace is requested, each thread is forced to a safe point, then the stack is taken. In some cases you may have a hot spot in your code which does no safe point polling (common for simple loops that the JIT can guarantee terminate after a fixed number of iterations), interleaved with a bit of code that does have a safepoint poll. Your stacks will always show your process in the safe-point code, never in the safe-point free code, even though the latter may be taking the majority of CPU time.

提交回复
热议问题