15

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 ?

trincot
  • 317,000
  • 35
  • 244
  • 286
nicoulaj
  • 3,463
  • 4
  • 27
  • 32

1 Answers1

3

It may be not the best example/code, but have a look at this

(I think it's only working on Hotspot JVMs)

MRalwasser
  • 15,605
  • 15
  • 101
  • 147
  • 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 ? – nicoulaj Feb 23 '12 at 18:49
  • 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. – MRalwasser Feb 23 '12 at 19:38
  • 1
    It's not internal, it attaches an agent externally. – nicoulaj Feb 26 '12 at 12:23
  • 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. – Jesse Glick Nov 22 '13 at 21:47