[英]How to measure peak heap memory usage in Java?
How to measure peak heap memory usage in Java? 如何衡量Java中的峰值堆内存使用情况? MemoryPoolMXBean keeps track of the peak usage per memory pool, but not the entire heap.
MemoryPoolMXBean跟踪每个内存池的峰值使用情况,但不记录整个堆。 And the peak heap usage is not simply the sum of different heap memory pools.
峰值堆使用量不仅仅是不同堆内存池的总和。
If you need the peak heap size, you can combine the peak used size of all the memory pools which are of type HEAP . 如果需要峰堆大小,可以组合HEAP类型的所有内存池的峰值使用大小 。
Here is an example: 这是一个例子:
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
long total = 0;
for (MemoryPoolMXBean memoryPoolMXBean : pools)
{
if (memoryPoolMXBean.getType() == MemoryType.HEAP)
{
long peakUsed = memoryPoolMXBean.getPeakUsage().getUsed();
System.out.println("Peak used for: " + memoryPoolMXBean.getName() + " is: " + peakUsed);
total = total + peakUsed;
}
}
System.out.println("Total heap peak used: " + Util.format(total));
看看这篇文章https://cruftex.net/2017/03/28/The-6-Memory-Metrics-You-Should-Track-in-Your-Java-Benchmarks.html ,它提到了GarbageCollectionNotificationInfo
并且有实现使用JMH (我还没试过)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.