I would like to get the equivalent of the ouput of jmap -histo
programmatically, from inside the monitored application. I see triggering a heap dump is possible through the HotSpot diagnostic bean, but I can't see how to get the histogram data. Is it possible ?
How to get jmap histogram programmatically?
Asked Answered
It may be not the best example/code, but have a look at this
(I think it's only working on Hotspot JVMs)
Thanks for the link. I guess this means there is no "internal" way to do this, you have to anyhow attach an agent to get this information ? –
Quirt
This is an internal way (it's not executing the jmap application), but it's not a jvm-independent way, because non-standardized classes/methods are used, which do not even exist in other jvm implementations. –
Carolecarolee
It's not internal, it attaches an agent externally. –
Quirt
Looks like it is ultimately invoking e.g.
sun.tools.attach.HotSpotVirtualMachine.heapHisto("-all")
(via reflection of course), though you have to call VirtualMachine.attach($myOwnPID)
first. Not clear this is much preferable to just running the jmap
executable. –
Hamal © 2022 - 2024 — McMap. All rights reserved.