I would like to track how much time is spent in GC and how much memory has been collected, but not by analysing GC logs (ie. analyzing what I got from -XX:+PrintGCWhatever).
I found that I can use Sun's ManagementFactory to get a GarbageCollectorMXBean that can give me some GCInfo object containing memory information but I have no guarantee I can collect all GC through this mean.
Does anybody know of a way to do this in code?
GarbageCollectorMXBean
is the best I've been able to find on the Sun JVM. In my experience, it actually comes pretty close to what you're asking for.
I imagine you could have a dedicated thread that would wake up from time to time to get the GC stats. This would add some determinism to when the stats are collected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With