以编程方式查找我的应用程序内存占用 [英] Find my application memory foot print programmatically

查看:240
本文介绍了以编程方式查找我的应用程序内存占用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用实际方法测量我的应用程序内存占用量。
我正在使用java.lang.management类来计算这个

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 + (?)

我假设两者的总和将给我应用程序使用的内存总量,但实际情况并非如此,top命令提供的实际大小更大。

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.

推荐答案

要查找由 top 提供的内存使用情况,检查进程的操作系统级统计信息。
在Linux上你可以通过阅读 / proc / self / stat / proc / self / status 。
更多关于 proc 伪文件系统

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.

请注意,应用程序足迹是一个不同的概念。从JVM的角度来看
Java应用程序占用空间大致是Java对象(Heap)
和Java类(非堆)占用的空间量。从操作系统的角度来看,还有很多东西可以计算,
包括JVM本身以及使你的应用程序工作的Java Runtime的所有组件。

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.

内存整个Java进程使用包括

The memory used by the whole Java process include


  • Java堆;

  • 元数据空间(用于类元数据);

  • 代码缓存(JIT编译方法和所有生成代码的位置);

  • 直接ByteBuffers;

  • 内存映射文件,包括由JVM映射的文件,例如类路径上的所有JAR文件;

  • 线程堆栈;

  • JVM代码本身以及Java Runtime加载的所有动态库;

  • 许多其他内部JVM结构。

  • 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.

这篇关于以编程方式查找我的应用程序内存占用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆