Example usage for android.os Debug getNativeHeapFreeSize

List of usage examples for android.os Debug getNativeHeapFreeSize

Introduction

In this page you can find the example usage for android.os Debug getNativeHeapFreeSize.

Prototype

public static native long getNativeHeapFreeSize();

Source Link

Document

Returns the amount of free memory in the native heap.

Usage

From source file:com.midisheetmusicmemo.ChooseSongActivity.java

public static void logHeap() {
    Double allocated = new Double(Debug.getNativeHeapAllocatedSize()) / new Double((1048576));
    Double available = new Double(Debug.getNativeHeapSize()) / 1048576.0f;
    Double free = new Double(Debug.getNativeHeapFreeSize()) / 1048576.0f;
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);/*from   ww w . j  a v  a2 s. c  om*/
    df.setMinimumFractionDigits(2);

    Log.d("blah", "debug. =================================");
    Log.d("blah", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available)
            + "MB (" + df.format(free) + "MB free)");
    Log.d("blah",
            "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory() / 1048576))
                    + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory() / 1048576)) + "MB ("
                    + df.format(new Double(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");
    System.gc();
    System.gc();
}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static String logHeap(Class clazz) {
    Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576));
    Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0));
    Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0));
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);/*from  w ww  . ja va  2 s.  c  o  m*/
    df.setMinimumFractionDigits(2);

    // Log.d("Navit", "MemMem:DEBUG: =================================");
    Log.d("Navit",
            "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB ("
                    + df.format(free) + "MB free) in ["
                    + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]");
    Log.d("Navit",
            "MemMem:DEBUG:java memory: allc: "
                    + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum="
                    + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB ("
                    + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");

    calcAvailableMemory();

    String mem_type = "NATIVE";
    try {
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            mem_type = "JAVA";
        }
    } catch (Exception e) {
    }
    return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":"
            + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/"
            + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "("
            + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type);
}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static String logHeap_for_batch(Class clazz) {
    try {/*  w  w w .  j a  va2 s  .  c om*/
        Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576));
        Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0));
        Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0));
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        // Log.d("Navit", "MemMem:DEBUG: =================================");
        Log.d("Navit",
                "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size)
                        + "MB (" + df.format(free) + "MB free) in ["
                        + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]");
        Log.d("Navit",
                "MemMem:DEBUG:java memory: allc: "
                        + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum="
                        + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB ("
                        + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");

        // calcAvailableMemory();

        String mem_type = "NATIVE";
        try {
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                mem_type = "JAVA";
            }
        } catch (Exception e) {
        }
        // return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type);
        return ("==MEM==:" + "J:" + (Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + ":"
                + (Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + ",N:" + allocated + ":"
                + sum_size);
    } catch (Exception e2) {
        return ("==MEM==:ERROR");
    }
}