measure amount of memory used by java program 02-09-2015d1005

2015-03-02

measure amount of memory used by java program 02-09-2015d1005


Measure amount of memory used by java program
measure amount of ram used by java program

this forum page has some good info
http://stackoverflow.com/questions/74674/how-to-do-i-check-cpu-and-memory-usage-in-java

this page looks useful
http://www.inoneo.com/en/blog/9/java/get-the-jvm-peak-memory-usage

// Place this code just before the end of the program
try {
String memoryUsage = new String();
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (int i=0; i<pools.size(); i++) {
MemoryPoolMXBean pool = (MemoryPoolMXBean)pools.get(i);
MemoryUsage peak = pool.getPeakUsage();
memoryUsage += String.format("Peak %s memory used: %,d%n", pool.getName(),peak.getUsed());
memoryUsage += String.format("Peak %s memory reserved: %,d%n", pool.getName(), peak.getCommitted());


// we print the result in the console
System.out.println(memoryUsage);

} catch (Throwable t)

System.err.println("Exception in agent: " + t);

}