I have JVM option -XX:+PrintGCApplicationStoppedTime which prints real \"GC stop the world time\".
Example:
Please note that PrintGCApplicationStoppedTime
prints safepoint time rather than GC time.
See this answer for details.
You can get cumulative time of safepoints through JDK-specific (i.e. unsupported) MXBean. This value is equal to the sum of all numbers printed in Total time for which application threads were stopped
messages.
sun.management.HotspotRuntimeMBean runtime =
sun.management.ManagementFactoryHelper.getHotspotRuntimeMBean();
System.out.println("Safepoint time: " + runtime.getTotalSafepointTime() + " ms");
System.out.println("Safepoint count: " + runtime.getSafepointCount());