Example usage for android.os Debug getMemoryInfo

List of usage examples for android.os Debug getMemoryInfo

Introduction

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

Prototype

public static native void getMemoryInfo(MemoryInfo memoryInfo);

Source Link

Document

Retrieves information about this processes memory usages.

Usage

From source file:Main.java

public static double getCurrentUsedMemory() {
    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);

    return memoryInfo.nativePss;
}

From source file:org.chromium.base.PerfTraceEvent.java

/**
 * Save a perf trace event as a JSON dict.  The format mirrors a TraceEvent dict.
 *
 * @param name The trace data/* ww w .  j a  v  a 2 s .  co  m*/
 * @param id The id of the event
 * @param type the type of trace event (I, S, F)
 * @param includeMemory Whether to include current browser process memory usage in the trace.
 */
private static void savePerfString(String name, long id, EventType type, boolean includeMemory) {
    long timestampUs = (System.nanoTime() - sBeginNanoTime) / 1000;
    MemoryInfo memInfo = null;
    if (includeMemory) {
        memInfo = new MemoryInfo();
        Debug.getMemoryInfo(memInfo);
    }
    savePerfString(name, id, type, timestampUs, memInfo);
}

From source file:com.oakesville.mythling.util.HttpHelper.java

private byte[] extractResponseBytes(InputStream is, long requestStartTime) throws IOException {
    BufferedInputStream bis = null;
    BufferedReader br = null;/*from ww  w  . j  a  v  a  2 s .  co m*/

    try {
        ByteArrayBuffer baf = new ByteArrayBuffer(1024);
        bis = new BufferedInputStream(is);
        int b = 0;
        while ((b = bis.read()) != -1)
            baf.append((byte) b);
        long requestEndTime = System.currentTimeMillis();
        byte[] bytes = baf.toByteArray();
        if (BuildConfig.DEBUG) {
            Log.d(TAG, " -> (" + url + ") http request time: " + (requestEndTime - requestStartTime) + " ms");
            // how much memory are we using
            Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
            Debug.getMemoryInfo(memoryInfo);
            Log.d(TAG, " -> response byte array size: " + bytes.length / 1024 + " kb (Pss = "
                    + memoryInfo.getTotalPss() + " kb)");
        }
        if (!binary) {
            // detect character set
            UniversalDetector detector = new UniversalDetector(null);
            detector.handleData(bytes, 0, bytes.length);
            detector.dataEnd();
            String detected = detector.getDetectedCharset();
            if (BuildConfig.DEBUG)
                Log.d(TAG, " -> charset: " + detected + " - detect time: "
                        + (System.currentTimeMillis() - requestEndTime) + " ms");
            if (detected != null && !detected.equals(charset)) {
                try {
                    Charset.forName(detected);
                    charset = detected;
                } catch (UnsupportedCharsetException ex) {
                    // not supported -- stick with UTF-8
                }
            }
        }

        return bytes;

    } finally {
        try {
            if (bis != null)
                bis.close();
            if (br != null)
                br.close();
        } catch (IOException ex) {
            Log.e(TAG, ex.getMessage(), ex);
        }
    }
}