1

Is there a way to get the peak memory used at any given point during a java program run? So far I've only seen solutions that give total memory consumed.

  • 1
    What is the difference? How you tried to get that? Do you need information about java heap or about whole java process? – talex Apr 07 '21 at 16:37
  • can you explain the difference between the heap/process? @talex – stackoverflow Apr 07 '21 at 16:50
  • 1
    read [this](https://stackoverflow.com/questions/53451103/java-using-much-more-memory-than-heap-size-or-size-correctly-docker-memory-limi) for the memory used by a java process – Eugene Apr 07 '21 at 16:52
  • It will be long explanation. Couple of chapters in book. – talex Apr 07 '21 at 16:53

1 Answers1

6

You can try this JDK tools for heap analyzis:

  • VisualVM
  • jstat (console tool)

RSS mem usage can be found on unix by comman line tools ps or top, or by JDK tool:

  • jcmd <pid> VM.native_memory detail.diff (java process should be run with -XX:NativeMemoryTracking=summary JAVA_OPTS)

RSS Peak usage can be found on linux in /proc/<pid>/status file in VmHWM field (man).

Vitalii
  • 431
  • 4
  • 11
  • 1
    1+ `jcmd` is the one I wanted to add, but your edit made that obsolete – Eugene Apr 07 '21 at 16:58
  • 1
    native memory tracking doesn't include some memory areas e.g mapped byte buffers: https://stackoverflow.com/questions/53451103/java-using-much-more-memory-than-heap-size-or-size-correctly-docker-memory-limi/53624438#53624438 – Juraj Martinka Apr 08 '21 at 05:05
  • Mentioned `/proc//status` field `RssFile` (`VmHWM` includes it) and `/proc//smaps` shows mmap mem usage. – Vitalii Apr 08 '21 at 10:43
  • i've never run java in any other way other than through intelliJ. how would i run my code to get RSS mem/RSS Peak on a Windows machine? – stackoverflow Apr 09 '21 at 16:59