android 打印内存信息

来源:互联网 发布:js 时间戳定义 编辑:程序博客网 时间:2024/05/19 14:39
public static void logMemoryStats() {        String text = "";        text += "\nLoadedClassCount="               + toMib(android.os.Debug.getLoadedClassCount());        text += "\nGlobalAllocSize="                + toMib(android.os.Debug.getGlobalAllocSize());        text += "\nGlobalFreedSize="                + toMib(android.os.Debug.getGlobalFreedSize());        text += "\nGlobalExternalAllocSize="        + toMib(android.os.Debug.getGlobalExternalAllocSize());        text += "\nGlobalExternalFreedSize="        + toMib(android.os.Debug.getGlobalExternalFreedSize());        text += "\nEpicPixels="                     + toMib(EpicBitmap.getGlobalPixelCount()*4);        text += "\nNativeHeapSize="                 + toMib(android.os.Debug.getNativeHeapSize());        text += "\nNativeHeapFree="                 + toMib(android.os.Debug.getNativeHeapFreeSize());        text += "\nNativeHeapAllocSize="            + toMib(android.os.Debug.getNativeHeapAllocatedSize());        text += "\nThreadAllocSize="                + toMib(android.os.Debug.getThreadAllocSize());           text += "\ntotalMemory()="                  + toMib(Runtime.getRuntime().totalMemory());        text += "\nmaxMemory()="                    + toMib(Runtime.getRuntime().maxMemory());        text += "\nfreeMemory()="                   + toMib(Runtime.getRuntime().freeMemory());           android.app.ActivityManager.MemoryInfo mi1 = new android.app.ActivityManager.MemoryInfo();        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);        am.getMemoryInfo(mi1);        text += "\napp.mi.availMem="                + toMib(mi1.availMem);        text += "\napp.mi.threshold="               + toMib(mi1.threshold);        text += "\napp.mi.lowMemory="               + mi1.lowMemory;           android.os.Debug.MemoryInfo mi2 = new android.os.Debug.MemoryInfo();                Debug.getMemoryInfo(mi2);        text += "\ndbg.mi.dalvikPrivateDirty="      + toMib(mi2.dalvikPrivateDirty);        text += "\ndbg.mi.dalvikPss="               + toMib(mi2.dalvikPss);        text += "\ndbg.mi.dalvikSharedDirty="       + toMib(mi2.dalvikSharedDirty);        text += "\ndbg.mi.nativePrivateDirty="      + toMib(mi2.nativePrivateDirty);        text += "\ndbg.mi.nativePss="               + toMib(mi2.nativePss);        text += "\ndbg.mi.nativeSharedDirty="       + toMib(mi2.nativeSharedDirty);        text += "\ndbg.mi.otherPrivateDirty="       + toMib(mi2.otherPrivateDirty);        text += "\ndbg.mi.otherPss"                 + toMib(mi2.otherPss);        text += "\ndbg.mi.otherSharedDirty="        + toMib(mi2.otherSharedDirty);           EpicLog.i("ArchPlatform[android].logStats() - " + text);    }