Find my application memory foot print programmatically

后端 未结 1 1850
攒了一身酷
攒了一身酷 2021-01-14 02:07

I am trying to measure my application memory foot print pragmatically. I am using java.lang.management class to calculate this

val heap = ManagementFactory.g         


        
相关标签:
1条回答
  • 2021-01-14 02:49

    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

    • Java Heap;
    • Metaspace (for class metadata);
    • Code Cache (the place for JIT-compiled methods and all the generated code);
    • Direct ByteBuffers;
    • Memory-mapped files, including files mapped by JVM, e.g. all JAR files on the classpath;
    • Thread stacks;
    • JVM code itself and all the dynamic libraries loaded by Java Runtime;
    • Many other internal JVM structures.
    0 讨论(0)
提交回复
热议问题