0

Does "total time (CPU)" column in CPU profiler tab of Java VisualVM contain time which CPU spent executing other processes?

For instance, let's consider such situation:

  • I run a program in which I have a method called myMethod() which does some computation. This computation takes 2 seconds - so if a CPU does nothing but only executes my code, then executing this method takes 2 seconds.
  • While I was profiling my application, CPU was executing several processes - my process and some other process as well (for instance, I had a browser running, or something like this).

  • CPU has started myMethod(), it was executing this method for some time, then started executing a browser's process and spent 1 second there, then again came back to executing myMethod() and has finished it. So between start of myMethod() and its end 3 seconds has passed, but only 2 seconds were used for executing myMethod().

Which time will be shown in "total time (CPU)" column in CPU profiler tab of Java VisualVM - 2 seconds or 3 seconds?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216

1 Answers1

1

When reporting CPU time, the profiler will report time spent by the JVM itself (possibly including "system" time).

CPU time used by (say) the browser should not be accounted in the CPU time column. If it was / is then the column heading should be "elapsed" or "real" time.

If you are not confident of this, write some simple test programs and profile them:

  • See what the profiler reports when your application calls Thread.sleep(....)

  • See what the profiler reports when your application blocks while reading a line from System.in.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216