stop Debug Trace - Android App

Android examples for App:Log

Description

stop Debug Trace

Demo Code


import java.util.Random;
import android.os.Debug;
import android.os.Debug.MemoryInfo;
import android.util.Log;

public class Main{
    private static final String TAG = "";
    public static boolean isMethodTrace = false;
    public static boolean isAllocCounting = false;
    public static void stopTrace() {
        if (isMethodTrace) {
            forcelog(TAG, "Stopping methid tracing..");
            isMethodTrace = false;//from  w  ww  .j  av a  2s  .com
            Debug.stopMethodTracing();
        }
        if (isAllocCounting) {
            forcelog(TAG, "Stopping alloc counting..");
            isAllocCounting = false;
            Debug.stopAllocCounting();
            printMemoryInfo();
        }
    }
    public static void forcelog(String tag, String msg) {
        Log.d(tag, msg);
    }
    private static void printMemoryInfo() {
        MemoryInfo meminfo = new MemoryInfo();
        Debug.getMemoryInfo(meminfo);
        forcelog(TAG, "dalvikPrivateDirty:" + meminfo.dalvikPrivateDirty);
        forcelog(TAG, "dalvikPss:" + meminfo.dalvikPss);
        forcelog(TAG, "dalvikSharedDirty:" + meminfo.dalvikSharedDirty);
        forcelog(TAG, "nativePrivateDirty:" + meminfo.nativePrivateDirty);
        forcelog(TAG, "nativePss:" + meminfo.nativePss);
        forcelog(TAG, "nativeSharedDirty:" + meminfo.nativeSharedDirty);
        forcelog(TAG, "otherPrivateDirty:" + meminfo.otherPrivateDirty);
        forcelog(TAG, "otherePss:" + meminfo.otherPss);
        forcelog(TAG, "otherSharedDirty:" + meminfo.otherSharedDirty);

        int globalAllocSize = Debug.getGlobalAllocSize();

        long nativeHeapAllocSize = Debug.getNativeHeapAllocatedSize();
        forcelog(TAG, "globalAllocSize:" + globalAllocSize);
        forcelog(TAG, "nativeHeapAllocSize:" + nativeHeapAllocSize);
    }
}

Related Tutorials