B
bassclar
A sun developer article
<http://java.sun.com/developer/technicalArticles/releases/j2se15/index.html#mnm>
suggests code similar to this:
import java.lang.management.*;
import java.util.*;
public class MemTest {
public static void main(String args[]) {
List<MemoryPoolMXBean> pools =
ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools) {
System.out.println("Memory type="+p.getType()
+", Pool name="+p.getName()
+", Memory usage="+p.getPeakUsage());
}
}
}
Running this (hotspot) might show:
Memory type=Non-heap memory, Pool name=Code Cache,
Memory usage=init = 163840(160K) used = 1724608(1684K) committed =
1736704(1696K) max = 33554432(32768K)
Memory type=Heap memory, Pool name=Eden Space,
Memory usage=init = 524288(512K) used = 287792(281K) committed =
524288(512K) max = 71565312(69888K)
Memory type=Heap memory, Pool name=Survivor Space,
Memory usage=init = 65536(64K) used = 65536(64K) committed = 65536(64K)
max = 8912896(8704K)
Memory type=Heap memory, Pool name=Tenured Gen,
Memory usage=init = 1441792(1408K) used = 1735896(1695K) committed =
2093056(2044K) max = 715915264(699136K)
Memory type=Non-heap memory, Pool name=Perm Gen,
Memory usage=init = 8388608(8192K) used = 11914720(11635K) committed =
12058624(11776K) max = 67108864(65536K)
Ok, this code is simple enough, but it doesn't quite let me do
what I want, which is to determine peak _total_ memory usage.
I could sum all the p.getPeakUsage() values in a loop, but
that isn't likely to be accurate because if a bunch of objects
move from the Eden space to the Survivor space they could
be counted twice.
What am I missing here?
<http://java.sun.com/developer/technicalArticles/releases/j2se15/index.html#mnm>
suggests code similar to this:
import java.lang.management.*;
import java.util.*;
public class MemTest {
public static void main(String args[]) {
List<MemoryPoolMXBean> pools =
ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools) {
System.out.println("Memory type="+p.getType()
+", Pool name="+p.getName()
+", Memory usage="+p.getPeakUsage());
}
}
}
Running this (hotspot) might show:
Memory type=Non-heap memory, Pool name=Code Cache,
Memory usage=init = 163840(160K) used = 1724608(1684K) committed =
1736704(1696K) max = 33554432(32768K)
Memory type=Heap memory, Pool name=Eden Space,
Memory usage=init = 524288(512K) used = 287792(281K) committed =
524288(512K) max = 71565312(69888K)
Memory type=Heap memory, Pool name=Survivor Space,
Memory usage=init = 65536(64K) used = 65536(64K) committed = 65536(64K)
max = 8912896(8704K)
Memory type=Heap memory, Pool name=Tenured Gen,
Memory usage=init = 1441792(1408K) used = 1735896(1695K) committed =
2093056(2044K) max = 715915264(699136K)
Memory type=Non-heap memory, Pool name=Perm Gen,
Memory usage=init = 8388608(8192K) used = 11914720(11635K) committed =
12058624(11776K) max = 67108864(65536K)
Ok, this code is simple enough, but it doesn't quite let me do
what I want, which is to determine peak _total_ memory usage.
I could sum all the p.getPeakUsage() values in a loop, but
that isn't likely to be accurate because if a bunch of objects
move from the Eden space to the Survivor space they could
be counted twice.
What am I missing here?