List of utility methods to do Memory Usage
String | describeMemoryUsage() Returns a string that describes the JVM's memory conditions in this format: 36M used, 29M free, 533M max . Runtime runtime = Runtime.getRuntime(); long free = runtime.freeMemory(); return String.format("%sM used, %sM free, %sM max", (runtime.totalMemory() - free) / 1000000, free / 1000000, runtime.maxMemory() / 1000000); |
int | estimateMemoryUsage(String s) Estimates the memory usage of the given string. return 48 + s.length() * 2;
|
String | getMemberName(int number) get Member Name return historyClusterMemberPrefix + memberFormat.format(number);
|
String | getMemInfo() get Mem Info NumberFormat format = NumberFormat.getInstance(Locale.ITALIAN); StringBuilder sb = new StringBuilder(); long allocatedMemory = runtime.totalMemory(); sb.append(format.format(allocatedMemory / 1024 / 1024)).append(" MB"); return sb.toString(); |
String | getMemoryFootprint() get Memory Footprint Runtime runtime = Runtime.getRuntime(); String memoryInfo = "Memory - free:" + kbString(runtime.freeMemory()) + " - max:" + kbString(runtime.maxMemory()) + " - total:" + kbString(runtime.totalMemory()); return memoryInfo; |
String | getMemoryInfo() get Memory Info Runtime run = Runtime.getRuntime(); StringBuilder memoryInfo = new StringBuilder(); memoryInfo.append("Runtime free: ").append(kbString(run.freeMemory())).append("\nRuntime max:") .append(kbString(run.maxMemory())).append("\nRuntime total:").append(kbString(run.totalMemory())); Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator(); while (iter.hasNext()) { MemoryPoolMXBean item = iter.next(); MemoryUsage usage = item.getUsage(); ... |
StringBuffer | getMemoryInfo() get Memory Info StringBuffer buffer = new StringBuffer(); freeMemory(); Runtime runtime = Runtime.getRuntime(); double usedMemory = usedMemory(runtime); double maxMemory = maxMemory(runtime); NumberFormat f = new DecimalFormat("###,##0.0"); String lineSeparator = System.getProperty("line.separator"); buffer.append("Used memory: " + f.format(usedMemory) + "MB").append(lineSeparator); ... |
String | getMemoryInfo() get Memory Info DecimalFormat f1 = new DecimalFormat("#,###KB"); DecimalFormat f2 = new DecimalFormat("##.#"); Runtime rt = Runtime.getRuntime(); long free = rt.freeMemory() / 1024; long total = rt.totalMemory() / 1024; long max = rt.maxMemory() / 1024; long used = total - free; double ratio = (used * 100 / (double) total); ... |
String | getMemorySize(long size) get Memory Size String hrSize = null; double b = size; double k = size / 1024.0; double m = ((size / 1024.0) / 1024.0); double g = (((size / 1024.0) / 1024.0) / 1024.0); double t = ((((size / 1024.0) / 1024.0) / 1024.0) / 1024.0); DecimalFormat dec1 = new DecimalFormat("0.00"); DecimalFormat dec2 = new DecimalFormat("0"); ... |
String | getMemoryStatus() get Memory Status Runtime rt = Runtime.getRuntime(); NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(true); nf.setMinimumFractionDigits(0); long total_mem = rt.totalMemory(); long free_mem = rt.freeMemory(); long used_mem = total_mem - free_mem; return "Amount of used memory/free memory: " + nf.format(used_mem / 1000) + "KB / " ... |