I am trying to measure my application memory foot print pragmatically. I am using java.lang.management class to calculate this
val heap = ManagementFactory.getMemoryMXBean.getHeapMemoryUsage
val nonHeap = ManagementFactory.getMemoryMXBean.getNonHeapMemoryUsage
val total = heap + nonHeap + (?)
I assumed the sum of both will give me the total amount of memory used by application, but this is not the case, the actual size is greater which was provided by top command.
So I am trying to understand what am I missing? What else do I need to add to this equation in order to get the total memory usage of my application.
To find the memory usage as provided by top
, check the OS-level statistics for the process.
On Linux you can do this by reading /proc/self/stat
or /proc/self/status
.
More about proc
pseudo-file system.
Note that Application footprint is a different concept. From JVM point of view Java application footprint is roughly the amount of space occupied by Java objects (Heap) and Java classes (Non-heap). From OS point of view there are much more things to count, including JVM itself and all the components of Java Runtime that make your application work.
The memory used by the whole Java process include
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