Java Memory Information printMemory()

Here you can find the source of printMemory()

Description

print Memory

License

Open Source License

Declaration

public static String printMemory() 

Method Source Code

//package com.java2s;
/*/*from   w  ww .  j a v a2 s . c om*/
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2001-2005 Julian Hyde
// Copyright (C) 2005-2012 Pentaho and others
// All Rights Reserved.
*/

public class Main {
    public static String printMemory() {
        return printMemory(null);
    }

    public static String printMemory(String msg) {
        final Runtime rt = Runtime.getRuntime();
        final long freeMemory = rt.freeMemory();
        final long totalMemory = rt.totalMemory();
        final StringBuilder buf = new StringBuilder(64);

        buf.append("FREE_MEMORY:");
        if (msg != null) {
            buf.append(msg);
            buf.append(':');
        }
        buf.append(' ');
        buf.append(freeMemory / 1024);
        buf.append("kb ");

        long hundredths = (freeMemory * 10000) / totalMemory;

        buf.append(hundredths / 100);
        hundredths %= 100;
        if (hundredths >= 10) {
            buf.append('.');
        } else {
            buf.append(".0");
        }
        buf.append(hundredths);
        buf.append('%');

        return buf.toString();
    }
}

Related

  1. getTotalMemoryStringInMb()
  2. parseMemory(String s, int def)
  3. parseMemorySize(String arg)
  4. prettyPrintMemory(long size, boolean includeSpace)
  5. prettyPrintMemoryPerSecond(long rate)
  6. printMemory()
  7. printMemory(String label)
  8. printMemory(String str)
  9. printMemoryInfo()