Java Utililty Methods Memory Information

List of utility methods to do Memory Information

Description

The list of methods to do Memory Information are organized into topic(s).

Method

StringgetNowMemoryStatus()
get Now Memory Status
return nowMemoryStatus;
StringgetRuntimeMemoryStats()
Get stringified runtime memory stats
return String.format("Memory (free/total/max) = %.2fM / %.2fM / %.2fM", freeMemoryMB(), totalMemoryMB(),
        maxMemoryMB());
StringgetRuntimeMemoryStats()
Get stringified runtime memory stats
return "totalMem = " + (Runtime.getRuntime().totalMemory() / 1024f / 1024f) + "M, maxMem = "
        + (Runtime.getRuntime().maxMemory() / 1024f / 1024f) + "M, freeMem = "
        + (Runtime.getRuntime().freeMemory() / 1024f / 1024f) + "M";
String[]getSummaryMemoryReportHeader()
get Summary Memory Report Header
final String[] header = { "ontology", "query", "rew mem [Kb]", "depgraph mem [Kb]" };
return header;
StringgetTotalMemoryStringInMb()
get Total Memory String In Mb
return memroyFormat.format(getTotalMemoryInMb());
intparseMemory(String s, int def)
parse Memory
try {
    return Integer.parseInt(s);
} catch (Exception e) {
    int a = parseInt(s.substring(0, s.length() - 1), def);
    if (s.endsWith("g"))
        return a * 1024;
    else if (s.endsWith("k"))
        return a / 1024;
...
longparseMemorySize(String arg)
Parses a memory size with optional g/m/k quantifiers into its number representation.
if (arg.endsWith("g") || arg.endsWith("G"))
    return Long.parseLong(arg.substring(0, arg.length() - 1)) * 1024 * 1024 * 1024;
else if (arg.endsWith("m") || arg.endsWith("M"))
    return Long.parseLong(arg.substring(0, arg.length() - 1)) * 1024 * 1024;
else if (arg.endsWith("k") || arg.endsWith("K"))
    return Long.parseLong(arg.substring(0, arg.length() - 1)) * 1024;
else
    return Long.parseLong(arg.substring(0, arg.length()));
...
StringprettyPrintMemory(long size, boolean includeSpace)
pretty Print Memory
if (size >= 1 << 30)
    return String.format("%.3f%sGiB", size / (double) (1 << 30), includeSpace ? " " : "");
if (size >= 1 << 20)
    return String.format("%.3f%sMiB", size / (double) (1 << 20), includeSpace ? " " : "");
return String.format("%.3f%sKiB", size / (double) (1 << 10), includeSpace ? " " : "");
StringprettyPrintMemoryPerSecond(long rate)
pretty Print Memory Per Second
if (rate >= 1 << 30)
    return String.format("%.3fGiB/s", rate / (double) (1 << 30));
if (rate >= 1 << 20)
    return String.format("%.3fMiB/s", rate / (double) (1 << 20));
return String.format("%.3fKiB/s", rate / (double) (1 << 10));
StringprintMemory()
print Memory
return printMemory(null);