Total method time in Java VisualVM

In Java VisualVM, is there any way to display total method time, rather than "self time"? (The latter is not particularly useful, since it doesn't tell you anything about how much time methods actually take to run.)

If not, is there any standalone free Java profiler that does calculate total method time?


Solution 1:

Looking at the trace data in a "snapshot" view allows you to see the total as well as the self time.

Press the "snapshot" button that appears about the table of results. This will create a new tab that contains a "Call Tree" view which breaks down the self vs. total time. The "combined" view also provides this information, but splits the screen space with a "Hot Spots" view that is similar to the standard profiling view.

Snapshots can be created from either standard "Profiler" or "Sampler" data. However, "Profiler" snapshots can only be created before the application is closed, while "Sampler" ones can be created at any time.

(The above information is based on VisualVM 1.3.1)

Solution 2:

Just take a snapshot of the profiling results. You will get the wall-clock time as well as self time there.

Solution 3:

There's a simple way to get total time of a routine as a percent of wall-clock execution time (rather than milliseconds). Just use ctrl-break to get a bunch of stackshots while you're waiting for it. The fraction of them containing the routine is the % of time it takes. The accuracy depends on how many shots you take. If you're just looking for where the problems are, you don't need precision time measurement. Here's a short explanation of how it works.