Search in sources :

Example 6 with MemInfoReader

use of com.android.internal.util.MemInfoReader in project android_frameworks_base by DirtyUnicorns.

the class ActivityManagerService method dumpApplicationMemoryUsage.

final void dumpApplicationMemoryUsage(FileDescriptor fd, PrintWriter pw, String prefix, String[] args, boolean brief, PrintWriter categoryPw) {
    boolean dumpDetails = false;
    boolean dumpFullDetails = false;
    boolean dumpDalvik = false;
    boolean dumpSummaryOnly = false;
    boolean dumpUnreachable = false;
    boolean oomOnly = false;
    boolean isCompact = false;
    boolean localOnly = false;
    boolean packages = false;
    boolean isCheckinRequest = false;
    boolean dumpSwapPss = false;
    int opti = 0;
    while (opti < args.length) {
        String opt = args[opti];
        if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
            break;
        }
        opti++;
        if ("-a".equals(opt)) {
            dumpDetails = true;
            dumpFullDetails = true;
            dumpDalvik = true;
            dumpSwapPss = true;
        } else if ("-d".equals(opt)) {
            dumpDalvik = true;
        } else if ("-c".equals(opt)) {
            isCompact = true;
        } else if ("-s".equals(opt)) {
            dumpDetails = true;
            dumpSummaryOnly = true;
        } else if ("-S".equals(opt)) {
            dumpSwapPss = true;
        } else if ("--unreachable".equals(opt)) {
            dumpUnreachable = true;
        } else if ("--oom".equals(opt)) {
            oomOnly = true;
        } else if ("--local".equals(opt)) {
            localOnly = true;
        } else if ("--package".equals(opt)) {
            packages = true;
        } else if ("--checkin".equals(opt)) {
            isCheckinRequest = true;
        } else if ("-h".equals(opt)) {
            pw.println("meminfo dump options: [-a] [-d] [-c] [-s] [--oom] [process]");
            pw.println("  -a: include all available information for each process.");
            pw.println("  -d: include dalvik details.");
            pw.println("  -c: dump in a compact machine-parseable representation.");
            pw.println("  -s: dump only summary of application memory usage.");
            pw.println("  -S: dump also SwapPss.");
            pw.println("  --oom: only show processes organized by oom adj.");
            pw.println("  --local: only collect details locally, don't call process.");
            pw.println("  --package: interpret process arg as package, dumping all");
            pw.println("             processes that have loaded that package.");
            pw.println("  --checkin: dump data for a checkin");
            pw.println("If [process] is specified it can be the name or ");
            pw.println("pid of a specific process to dump.");
            return;
        } else {
            pw.println("Unknown argument: " + opt + "; use -h for help");
        }
    }
    long uptime = SystemClock.uptimeMillis();
    long realtime = SystemClock.elapsedRealtime();
    final long[] tmpLong = new long[1];
    ArrayList<ProcessRecord> procs = collectProcesses(pw, opti, packages, args);
    if (procs == null) {
        // No Java processes.  Maybe they want to print a native process.
        if (args != null && args.length > opti && args[opti].charAt(0) != '-') {
            ArrayList<ProcessCpuTracker.Stats> nativeProcs = new ArrayList<ProcessCpuTracker.Stats>();
            updateCpuStatsNow();
            int findPid = -1;
            try {
                findPid = Integer.parseInt(args[opti]);
            } catch (NumberFormatException e) {
            }
            synchronized (mProcessCpuTracker) {
                final int N = mProcessCpuTracker.countStats();
                for (int i = 0; i < N; i++) {
                    ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
                    if (st.pid == findPid || (st.baseName != null && st.baseName.equals(args[opti]))) {
                        nativeProcs.add(st);
                    }
                }
            }
            if (nativeProcs.size() > 0) {
                dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest, isCompact);
                Debug.MemoryInfo mi = null;
                for (int i = nativeProcs.size() - 1; i >= 0; i--) {
                    final ProcessCpuTracker.Stats r = nativeProcs.get(i);
                    final int pid = r.pid;
                    if (!isCheckinRequest && dumpDetails) {
                        pw.println("\n** MEMINFO in pid " + pid + " [" + r.baseName + "] **");
                    }
                    if (mi == null) {
                        mi = new Debug.MemoryInfo();
                    }
                    if (dumpDetails || (!brief && !oomOnly)) {
                        Debug.getMemoryInfo(pid, mi);
                    } else {
                        mi.dalvikPss = (int) Debug.getPss(pid, tmpLong, null);
                        mi.dalvikPrivateDirty = (int) tmpLong[0];
                    }
                    ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails, dumpDalvik, dumpSummaryOnly, pid, r.baseName, 0, 0, 0, 0, 0, 0);
                    if (isCheckinRequest) {
                        pw.println();
                    }
                }
                return;
            }
        }
        pw.println("No process found for: " + args[opti]);
        return;
    }
    if (!brief && !oomOnly && (procs.size() == 1 || isCheckinRequest || packages)) {
        dumpDetails = true;
    }
    dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest, isCompact);
    String[] innerArgs = new String[args.length - opti];
    System.arraycopy(args, opti, innerArgs, 0, args.length - opti);
    ArrayList<MemItem> procMems = new ArrayList<MemItem>();
    final SparseArray<MemItem> procMemsMap = new SparseArray<MemItem>();
    long nativePss = 0;
    long nativeSwapPss = 0;
    long dalvikPss = 0;
    long dalvikSwapPss = 0;
    long[] dalvikSubitemPss = dumpDalvik ? new long[Debug.MemoryInfo.NUM_DVK_STATS] : EmptyArray.LONG;
    long[] dalvikSubitemSwapPss = dumpDalvik ? new long[Debug.MemoryInfo.NUM_DVK_STATS] : EmptyArray.LONG;
    long otherPss = 0;
    long otherSwapPss = 0;
    long[] miscPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS];
    long[] miscSwapPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS];
    long[] oomPss = new long[DUMP_MEM_OOM_LABEL.length];
    long[] oomSwapPss = new long[DUMP_MEM_OOM_LABEL.length];
    ArrayList<MemItem>[] oomProcs = (ArrayList<MemItem>[]) new ArrayList[DUMP_MEM_OOM_LABEL.length];
    long totalPss = 0;
    long totalSwapPss = 0;
    long cachedPss = 0;
    long cachedSwapPss = 0;
    boolean hasSwapPss = false;
    Debug.MemoryInfo mi = null;
    for (int i = procs.size() - 1; i >= 0; i--) {
        final ProcessRecord r = procs.get(i);
        final IApplicationThread thread;
        final int pid;
        final int oomAdj;
        final boolean hasActivities;
        synchronized (this) {
            thread = r.thread;
            pid = r.pid;
            oomAdj = r.getSetAdjWithServices();
            hasActivities = r.activities.size() > 0;
        }
        if (thread != null) {
            if (!isCheckinRequest && dumpDetails) {
                pw.println("\n** MEMINFO in pid " + pid + " [" + r.processName + "] **");
            }
            if (mi == null) {
                mi = new Debug.MemoryInfo();
            }
            if (dumpDetails || (!brief && !oomOnly)) {
                Debug.getMemoryInfo(pid, mi);
                hasSwapPss = mi.hasSwappedOutPss;
            } else {
                mi.dalvikPss = (int) Debug.getPss(pid, tmpLong, null);
                mi.dalvikPrivateDirty = (int) tmpLong[0];
            }
            if (dumpDetails) {
                if (localOnly) {
                    ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails, dumpDalvik, dumpSummaryOnly, pid, r.processName, 0, 0, 0, 0, 0, 0);
                    if (isCheckinRequest) {
                        pw.println();
                    }
                } else {
                    try {
                        pw.flush();
                        thread.dumpMemInfo(fd, mi, isCheckinRequest, dumpFullDetails, dumpDalvik, dumpSummaryOnly, dumpUnreachable, innerArgs);
                    } catch (RemoteException e) {
                        if (!isCheckinRequest) {
                            pw.println("Got RemoteException!");
                            pw.flush();
                        }
                    }
                }
            }
            final long myTotalPss = mi.getTotalPss();
            final long myTotalUss = mi.getTotalUss();
            final long myTotalSwapPss = mi.getTotalSwappedOutPss();
            synchronized (this) {
                if (r.thread != null && oomAdj == r.getSetAdjWithServices()) {
                    // Record this for posterity if the process has been stable.
                    r.baseProcessTracker.addPss(myTotalPss, myTotalUss, true, r.pkgList);
                }
            }
            if (!isCheckinRequest && mi != null) {
                totalPss += myTotalPss;
                totalSwapPss += myTotalSwapPss;
                MemItem pssItem = new MemItem(r.processName + " (pid " + pid + (hasActivities ? " / activities)" : ")"), r.processName, myTotalPss, myTotalSwapPss, pid, hasActivities);
                procMems.add(pssItem);
                procMemsMap.put(pid, pssItem);
                nativePss += mi.nativePss;
                nativeSwapPss += mi.nativeSwappedOutPss;
                dalvikPss += mi.dalvikPss;
                dalvikSwapPss += mi.dalvikSwappedOutPss;
                for (int j = 0; j < dalvikSubitemPss.length; j++) {
                    dalvikSubitemPss[j] += mi.getOtherPss(Debug.MemoryInfo.NUM_OTHER_STATS + j);
                    dalvikSubitemSwapPss[j] += mi.getOtherSwappedOutPss(Debug.MemoryInfo.NUM_OTHER_STATS + j);
                }
                otherPss += mi.otherPss;
                otherSwapPss += mi.otherSwappedOutPss;
                for (int j = 0; j < Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
                    long mem = mi.getOtherPss(j);
                    miscPss[j] += mem;
                    otherPss -= mem;
                    mem = mi.getOtherSwappedOutPss(j);
                    miscSwapPss[j] += mem;
                    otherSwapPss -= mem;
                }
                if (oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
                    cachedPss += myTotalPss;
                    cachedSwapPss += myTotalSwapPss;
                }
                for (int oomIndex = 0; oomIndex < oomPss.length; oomIndex++) {
                    if (oomIndex == (oomPss.length - 1) || (oomAdj >= DUMP_MEM_OOM_ADJ[oomIndex] && oomAdj < DUMP_MEM_OOM_ADJ[oomIndex + 1])) {
                        oomPss[oomIndex] += myTotalPss;
                        oomSwapPss[oomIndex] += myTotalSwapPss;
                        if (oomProcs[oomIndex] == null) {
                            oomProcs[oomIndex] = new ArrayList<MemItem>();
                        }
                        oomProcs[oomIndex].add(pssItem);
                        break;
                    }
                }
            }
        }
    }
    long nativeProcTotalPss = 0;
    if (!isCheckinRequest && procs.size() > 1 && !packages) {
        // If we are showing aggregations, also look for native processes to
        // include so that our aggregations are more accurate.
        updateCpuStatsNow();
        mi = null;
        synchronized (mProcessCpuTracker) {
            final int N = mProcessCpuTracker.countStats();
            for (int i = 0; i < N; i++) {
                ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
                if (st.vsize > 0 && procMemsMap.indexOfKey(st.pid) < 0) {
                    if (mi == null) {
                        mi = new Debug.MemoryInfo();
                    }
                    if (!brief && !oomOnly) {
                        Debug.getMemoryInfo(st.pid, mi);
                    } else {
                        mi.nativePss = (int) Debug.getPss(st.pid, tmpLong, null);
                        mi.nativePrivateDirty = (int) tmpLong[0];
                    }
                    final long myTotalPss = mi.getTotalPss();
                    final long myTotalSwapPss = mi.getTotalSwappedOutPss();
                    totalPss += myTotalPss;
                    nativeProcTotalPss += myTotalPss;
                    MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")", st.name, myTotalPss, mi.getSummaryTotalSwapPss(), st.pid, false);
                    procMems.add(pssItem);
                    nativePss += mi.nativePss;
                    nativeSwapPss += mi.nativeSwappedOutPss;
                    dalvikPss += mi.dalvikPss;
                    dalvikSwapPss += mi.dalvikSwappedOutPss;
                    for (int j = 0; j < dalvikSubitemPss.length; j++) {
                        dalvikSubitemPss[j] += mi.getOtherPss(Debug.MemoryInfo.NUM_OTHER_STATS + j);
                        dalvikSubitemSwapPss[j] += mi.getOtherSwappedOutPss(Debug.MemoryInfo.NUM_OTHER_STATS + j);
                    }
                    otherPss += mi.otherPss;
                    otherSwapPss += mi.otherSwappedOutPss;
                    for (int j = 0; j < Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
                        long mem = mi.getOtherPss(j);
                        miscPss[j] += mem;
                        otherPss -= mem;
                        mem = mi.getOtherSwappedOutPss(j);
                        miscSwapPss[j] += mem;
                        otherSwapPss -= mem;
                    }
                    oomPss[0] += myTotalPss;
                    oomSwapPss[0] += myTotalSwapPss;
                    if (oomProcs[0] == null) {
                        oomProcs[0] = new ArrayList<MemItem>();
                    }
                    oomProcs[0].add(pssItem);
                }
            }
        }
        ArrayList<MemItem> catMems = new ArrayList<MemItem>();
        catMems.add(new MemItem("Native", "Native", nativePss, nativeSwapPss, -1));
        final MemItem dalvikItem = new MemItem("Dalvik", "Dalvik", dalvikPss, dalvikSwapPss, -2);
        if (dalvikSubitemPss.length > 0) {
            dalvikItem.subitems = new ArrayList<MemItem>();
            for (int j = 0; j < dalvikSubitemPss.length; j++) {
                final String name = Debug.MemoryInfo.getOtherLabel(Debug.MemoryInfo.NUM_OTHER_STATS + j);
                dalvikItem.subitems.add(new MemItem(name, name, dalvikSubitemPss[j], dalvikSubitemSwapPss[j], j));
            }
        }
        catMems.add(dalvikItem);
        catMems.add(new MemItem("Unknown", "Unknown", otherPss, otherSwapPss, -3));
        for (int j = 0; j < Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
            String label = Debug.MemoryInfo.getOtherLabel(j);
            catMems.add(new MemItem(label, label, miscPss[j], miscSwapPss[j], j));
        }
        ArrayList<MemItem> oomMems = new ArrayList<MemItem>();
        for (int j = 0; j < oomPss.length; j++) {
            if (oomPss[j] != 0) {
                String label = isCompact ? DUMP_MEM_OOM_COMPACT_LABEL[j] : DUMP_MEM_OOM_LABEL[j];
                MemItem item = new MemItem(label, label, oomPss[j], oomSwapPss[j], DUMP_MEM_OOM_ADJ[j]);
                item.subitems = oomProcs[j];
                oomMems.add(item);
            }
        }
        dumpSwapPss = dumpSwapPss && hasSwapPss && totalSwapPss != 0;
        if (!brief && !oomOnly && !isCompact) {
            pw.println();
            pw.println("Total PSS by process:");
            dumpMemItems(pw, "  ", "proc", procMems, true, isCompact, dumpSwapPss);
            pw.println();
        }
        if (!isCompact) {
            pw.println("Total PSS by OOM adjustment:");
        }
        dumpMemItems(pw, "  ", "oom", oomMems, false, isCompact, dumpSwapPss);
        if (!brief && !oomOnly) {
            PrintWriter out = categoryPw != null ? categoryPw : pw;
            if (!isCompact) {
                out.println();
                out.println("Total PSS by category:");
            }
            dumpMemItems(out, "  ", "cat", catMems, true, isCompact, dumpSwapPss);
        }
        if (!isCompact) {
            pw.println();
        }
        MemInfoReader memInfo = new MemInfoReader();
        memInfo.readMemInfo();
        if (nativeProcTotalPss > 0) {
            synchronized (this) {
                final long cachedKb = memInfo.getCachedSizeKb();
                final long freeKb = memInfo.getFreeSizeKb();
                final long zramKb = memInfo.getZramTotalSizeKb();
                final long kernelKb = memInfo.getKernelUsedSizeKb();
                EventLogTags.writeAmMeminfo(cachedKb * 1024, freeKb * 1024, zramKb * 1024, kernelKb * 1024, nativeProcTotalPss * 1024);
                mProcessStats.addSysMemUsageLocked(cachedKb, freeKb, zramKb, kernelKb, nativeProcTotalPss);
            }
        }
        if (!brief) {
            if (!isCompact) {
                pw.print("Total RAM: ");
                pw.print(stringifyKBSize(memInfo.getTotalSizeKb()));
                pw.print(" (status ");
                switch(mLastMemoryLevel) {
                    case ProcessStats.ADJ_MEM_FACTOR_NORMAL:
                        pw.println("normal)");
                        break;
                    case ProcessStats.ADJ_MEM_FACTOR_MODERATE:
                        pw.println("moderate)");
                        break;
                    case ProcessStats.ADJ_MEM_FACTOR_LOW:
                        pw.println("low)");
                        break;
                    case ProcessStats.ADJ_MEM_FACTOR_CRITICAL:
                        pw.println("critical)");
                        break;
                    default:
                        pw.print(mLastMemoryLevel);
                        pw.println(")");
                        break;
                }
                pw.print(" Free RAM: ");
                pw.print(stringifyKBSize(cachedPss + memInfo.getCachedSizeKb() + memInfo.getFreeSizeKb()));
                pw.print(" (");
                pw.print(stringifyKBSize(cachedPss));
                pw.print(" cached pss + ");
                pw.print(stringifyKBSize(memInfo.getCachedSizeKb()));
                pw.print(" cached kernel + ");
                pw.print(stringifyKBSize(memInfo.getFreeSizeKb()));
                pw.println(" free)");
            } else {
                pw.print("ram,");
                pw.print(memInfo.getTotalSizeKb());
                pw.print(",");
                pw.print(cachedPss + memInfo.getCachedSizeKb() + memInfo.getFreeSizeKb());
                pw.print(",");
                pw.println(totalPss - cachedPss);
            }
        }
        long lostRAM = memInfo.getTotalSizeKb() - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() - memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb();
        if (!isCompact) {
            pw.print(" Used RAM: ");
            pw.print(stringifyKBSize(totalPss - cachedPss + memInfo.getKernelUsedSizeKb()));
            pw.print(" (");
            pw.print(stringifyKBSize(totalPss - cachedPss));
            pw.print(" used pss + ");
            pw.print(stringifyKBSize(memInfo.getKernelUsedSizeKb()));
            pw.print(" kernel)\n");
            pw.print(" Lost RAM: ");
            pw.println(stringifyKBSize(lostRAM));
        } else {
            pw.print("lostram,");
            pw.println(lostRAM);
        }
        if (!brief) {
            if (memInfo.getZramTotalSizeKb() != 0) {
                if (!isCompact) {
                    pw.print("     ZRAM: ");
                    pw.print(stringifyKBSize(memInfo.getZramTotalSizeKb()));
                    pw.print(" physical used for ");
                    pw.print(stringifyKBSize(memInfo.getSwapTotalSizeKb() - memInfo.getSwapFreeSizeKb()));
                    pw.print(" in swap (");
                    pw.print(stringifyKBSize(memInfo.getSwapTotalSizeKb()));
                    pw.println(" total swap)");
                } else {
                    pw.print("zram,");
                    pw.print(memInfo.getZramTotalSizeKb());
                    pw.print(",");
                    pw.print(memInfo.getSwapTotalSizeKb());
                    pw.print(",");
                    pw.println(memInfo.getSwapFreeSizeKb());
                }
            }
            final long[] ksm = getKsmInfo();
            if (!isCompact) {
                if (ksm[KSM_SHARING] != 0 || ksm[KSM_SHARED] != 0 || ksm[KSM_UNSHARED] != 0 || ksm[KSM_VOLATILE] != 0) {
                    pw.print("      KSM: ");
                    pw.print(stringifyKBSize(ksm[KSM_SHARING]));
                    pw.print(" saved from shared ");
                    pw.print(stringifyKBSize(ksm[KSM_SHARED]));
                    pw.print("           ");
                    pw.print(stringifyKBSize(ksm[KSM_UNSHARED]));
                    pw.print(" unshared; ");
                    pw.print(stringifyKBSize(ksm[KSM_VOLATILE]));
                    pw.println(" volatile");
                }
                pw.print("   Tuning: ");
                pw.print(ActivityManager.staticGetMemoryClass());
                pw.print(" (large ");
                pw.print(ActivityManager.staticGetLargeMemoryClass());
                pw.print("), oom ");
                pw.print(stringifySize(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ), 1024));
                pw.print(", restore limit ");
                pw.print(stringifyKBSize(mProcessList.getCachedRestoreThresholdKb()));
                if (ActivityManager.isLowRamDeviceStatic()) {
                    pw.print(" (low-ram)");
                }
                if (ActivityManager.isHighEndGfx()) {
                    pw.print(" (high-end-gfx)");
                }
                pw.println();
            } else {
                pw.print("ksm,");
                pw.print(ksm[KSM_SHARING]);
                pw.print(",");
                pw.print(ksm[KSM_SHARED]);
                pw.print(",");
                pw.print(ksm[KSM_UNSHARED]);
                pw.print(",");
                pw.println(ksm[KSM_VOLATILE]);
                pw.print("tuning,");
                pw.print(ActivityManager.staticGetMemoryClass());
                pw.print(',');
                pw.print(ActivityManager.staticGetLargeMemoryClass());
                pw.print(',');
                pw.print(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ) / 1024);
                if (ActivityManager.isLowRamDeviceStatic()) {
                    pw.print(",low-ram");
                }
                if (ActivityManager.isHighEndGfx()) {
                    pw.print(",high-end-gfx");
                }
                pw.println();
            }
        }
    }
}
Also used : ProcessCpuTracker(com.android.internal.os.ProcessCpuTracker) ArrayList(java.util.ArrayList) MemInfoReader(com.android.internal.util.MemInfoReader) IApplicationThread(android.app.IApplicationThread) Debug(android.os.Debug) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) Point(android.graphics.Point) SparseArray(android.util.SparseArray) BatteryStats(android.os.BatteryStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) RemoteException(android.os.RemoteException)

Example 7 with MemInfoReader

use of com.android.internal.util.MemInfoReader in project android_frameworks_base by DirtyUnicorns.

the class ActivityManagerService method reportMemUsage.

void reportMemUsage(ArrayList<ProcessMemInfo> memInfos) {
    final SparseArray<ProcessMemInfo> infoMap = new SparseArray<>(memInfos.size());
    for (int i = 0, N = memInfos.size(); i < N; i++) {
        ProcessMemInfo mi = memInfos.get(i);
        infoMap.put(mi.pid, mi);
    }
    updateCpuStatsNow();
    long[] memtrackTmp = new long[1];
    final List<ProcessCpuTracker.Stats> stats;
    // Get a list of Stats that have vsize > 0
    synchronized (mProcessCpuTracker) {
        stats = mProcessCpuTracker.getStats((st) -> {
            return st.vsize > 0;
        });
    }
    final int statsCount = stats.size();
    for (int i = 0; i < statsCount; i++) {
        ProcessCpuTracker.Stats st = stats.get(i);
        long pss = Debug.getPss(st.pid, null, memtrackTmp);
        if (pss > 0) {
            if (infoMap.indexOfKey(st.pid) < 0) {
                ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid, ProcessList.NATIVE_ADJ, -1, "native", null);
                mi.pss = pss;
                mi.memtrack = memtrackTmp[0];
                memInfos.add(mi);
            }
        }
    }
    long totalPss = 0;
    long totalMemtrack = 0;
    for (int i = 0, N = memInfos.size(); i < N; i++) {
        ProcessMemInfo mi = memInfos.get(i);
        if (mi.pss == 0) {
            mi.pss = Debug.getPss(mi.pid, null, memtrackTmp);
            mi.memtrack = memtrackTmp[0];
        }
        totalPss += mi.pss;
        totalMemtrack += mi.memtrack;
    }
    Collections.sort(memInfos, new Comparator<ProcessMemInfo>() {

        @Override
        public int compare(ProcessMemInfo lhs, ProcessMemInfo rhs) {
            if (lhs.oomAdj != rhs.oomAdj) {
                return lhs.oomAdj < rhs.oomAdj ? -1 : 1;
            }
            if (lhs.pss != rhs.pss) {
                return lhs.pss < rhs.pss ? 1 : -1;
            }
            return 0;
        }
    });
    StringBuilder tag = new StringBuilder(128);
    StringBuilder stack = new StringBuilder(128);
    tag.append("Low on memory -- ");
    appendMemBucket(tag, totalPss, "total", false);
    appendMemBucket(stack, totalPss, "total", true);
    StringBuilder fullNativeBuilder = new StringBuilder(1024);
    StringBuilder shortNativeBuilder = new StringBuilder(1024);
    StringBuilder fullJavaBuilder = new StringBuilder(1024);
    boolean firstLine = true;
    int lastOomAdj = Integer.MIN_VALUE;
    long extraNativeRam = 0;
    long extraNativeMemtrack = 0;
    long cachedPss = 0;
    for (int i = 0, N = memInfos.size(); i < N; i++) {
        ProcessMemInfo mi = memInfos.get(i);
        if (mi.oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
            cachedPss += mi.pss;
        }
        if (mi.oomAdj != ProcessList.NATIVE_ADJ && (mi.oomAdj < ProcessList.SERVICE_ADJ || mi.oomAdj == ProcessList.HOME_APP_ADJ || mi.oomAdj == ProcessList.PREVIOUS_APP_ADJ)) {
            if (lastOomAdj != mi.oomAdj) {
                lastOomAdj = mi.oomAdj;
                if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
                    tag.append(" / ");
                }
                if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ) {
                    if (firstLine) {
                        stack.append(":");
                        firstLine = false;
                    }
                    stack.append("\n\t at ");
                } else {
                    stack.append("$");
                }
            } else {
                tag.append(" ");
                stack.append("$");
            }
            if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
                appendMemBucket(tag, mi.pss, mi.name, false);
            }
            appendMemBucket(stack, mi.pss, mi.name, true);
            if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ && ((i + 1) >= N || memInfos.get(i + 1).oomAdj != lastOomAdj)) {
                stack.append("(");
                for (int k = 0; k < DUMP_MEM_OOM_ADJ.length; k++) {
                    if (DUMP_MEM_OOM_ADJ[k] == mi.oomAdj) {
                        stack.append(DUMP_MEM_OOM_LABEL[k]);
                        stack.append(":");
                        stack.append(DUMP_MEM_OOM_ADJ[k]);
                    }
                }
                stack.append(")");
            }
        }
        appendMemInfo(fullNativeBuilder, mi);
        if (mi.oomAdj == ProcessList.NATIVE_ADJ) {
            // The short form only has native processes that are >= 512K.
            if (mi.pss >= 512) {
                appendMemInfo(shortNativeBuilder, mi);
            } else {
                extraNativeRam += mi.pss;
                extraNativeMemtrack += mi.memtrack;
            }
        } else {
            // from smaller native processes let's dump a summary of that.
            if (extraNativeRam > 0) {
                appendBasicMemEntry(shortNativeBuilder, ProcessList.NATIVE_ADJ, -1, extraNativeRam, extraNativeMemtrack, "(Other native)");
                shortNativeBuilder.append('\n');
                extraNativeRam = 0;
            }
            appendMemInfo(fullJavaBuilder, mi);
        }
    }
    fullJavaBuilder.append("           ");
    ProcessList.appendRamKb(fullJavaBuilder, totalPss);
    fullJavaBuilder.append(": TOTAL");
    if (totalMemtrack > 0) {
        fullJavaBuilder.append(" (");
        fullJavaBuilder.append(stringifyKBSize(totalMemtrack));
        fullJavaBuilder.append(" memtrack)");
    } else {
    }
    fullJavaBuilder.append("\n");
    MemInfoReader memInfo = new MemInfoReader();
    memInfo.readMemInfo();
    final long[] infos = memInfo.getRawInfo();
    StringBuilder memInfoBuilder = new StringBuilder(1024);
    Debug.getMemInfo(infos);
    memInfoBuilder.append("  MemInfo: ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_SLAB])).append(" slab, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_SHMEM])).append(" shmem, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_VM_ALLOC_USED])).append(" vm alloc, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_PAGE_TABLES])).append(" page tables ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_KERNEL_STACK])).append(" kernel stack\n");
    memInfoBuilder.append("           ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_BUFFERS])).append(" buffers, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_CACHED])).append(" cached, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_MAPPED])).append(" mapped, ");
    memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_FREE])).append(" free\n");
    if (infos[Debug.MEMINFO_ZRAM_TOTAL] != 0) {
        memInfoBuilder.append("  ZRAM: ");
        memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_ZRAM_TOTAL]));
        memInfoBuilder.append(" RAM, ");
        memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_SWAP_TOTAL]));
        memInfoBuilder.append(" swap total, ");
        memInfoBuilder.append(stringifyKBSize(infos[Debug.MEMINFO_SWAP_FREE]));
        memInfoBuilder.append(" swap free\n");
    }
    final long[] ksm = getKsmInfo();
    if (ksm[KSM_SHARING] != 0 || ksm[KSM_SHARED] != 0 || ksm[KSM_UNSHARED] != 0 || ksm[KSM_VOLATILE] != 0) {
        memInfoBuilder.append("  KSM: ");
        memInfoBuilder.append(stringifyKBSize(ksm[KSM_SHARING]));
        memInfoBuilder.append(" saved from shared ");
        memInfoBuilder.append(stringifyKBSize(ksm[KSM_SHARED]));
        memInfoBuilder.append("\n       ");
        memInfoBuilder.append(stringifyKBSize(ksm[KSM_UNSHARED]));
        memInfoBuilder.append(" unshared; ");
        memInfoBuilder.append(stringifyKBSize(ksm[KSM_VOLATILE]));
        memInfoBuilder.append(" volatile\n");
    }
    memInfoBuilder.append("  Free RAM: ");
    memInfoBuilder.append(stringifyKBSize(cachedPss + memInfo.getCachedSizeKb() + memInfo.getFreeSizeKb()));
    memInfoBuilder.append("\n");
    memInfoBuilder.append("  Used RAM: ");
    memInfoBuilder.append(stringifyKBSize(totalPss - cachedPss + memInfo.getKernelUsedSizeKb()));
    memInfoBuilder.append("\n");
    memInfoBuilder.append("  Lost RAM: ");
    memInfoBuilder.append(stringifyKBSize(memInfo.getTotalSizeKb() - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() - memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb()));
    memInfoBuilder.append("\n");
    Slog.i(TAG, "Low on memory:");
    Slog.i(TAG, shortNativeBuilder.toString());
    Slog.i(TAG, fullJavaBuilder.toString());
    Slog.i(TAG, memInfoBuilder.toString());
    StringBuilder dropBuilder = new StringBuilder(1024);
    /*
        StringWriter oomSw = new StringWriter();
        PrintWriter oomPw = new FastPrintWriter(oomSw, false, 256);
        StringWriter catSw = new StringWriter();
        PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
        String[] emptyArgs = new String[] { };
        dumpApplicationMemoryUsage(null, oomPw, "  ", emptyArgs, true, catPw);
        oomPw.flush();
        String oomString = oomSw.toString();
        */
    dropBuilder.append("Low on memory:");
    dropBuilder.append(stack);
    dropBuilder.append('\n');
    dropBuilder.append(fullNativeBuilder);
    dropBuilder.append(fullJavaBuilder);
    dropBuilder.append('\n');
    dropBuilder.append(memInfoBuilder);
    dropBuilder.append('\n');
    /*
        dropBuilder.append(oomString);
        dropBuilder.append('\n');
        */
    StringWriter catSw = new StringWriter();
    synchronized (ActivityManagerService.this) {
        PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
        String[] emptyArgs = new String[] {};
        catPw.println();
        dumpProcessesLocked(null, catPw, emptyArgs, 0, false, null);
        catPw.println();
        mServices.newServiceDumperLocked(null, catPw, emptyArgs, 0, false, null).dumpLocked();
        catPw.println();
        dumpActivitiesLocked(null, catPw, emptyArgs, 0, false, false, null);
        catPw.flush();
    }
    dropBuilder.append(catSw.toString());
    addErrorToDropBox("lowmem", null, "system_server", null, null, tag.toString(), dropBuilder.toString(), null, null);
    //Slog.i(TAG, dropBuilder.toString());
    synchronized (ActivityManagerService.this) {
        long now = SystemClock.uptimeMillis();
        if (mLastMemUsageReportTime < now) {
            mLastMemUsageReportTime = now;
        }
    }
}
Also used : POSTFIX_PSS(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PSS) Bundle(android.os.Bundle) TaskThumbnailInfo(android.app.ActivityManager.TaskThumbnailInfo) FEATURE_FREEFORM_WINDOW_MANAGEMENT(android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT) Time(android.text.format.Time) IApplicationThread(android.app.IApplicationThread) ON_TOP(com.android.server.am.ActivityStackSupervisor.ON_TOP) XmlSerializer(org.xmlpull.v1.XmlSerializer) ActivityManagerInternal(android.app.ActivityManagerInternal) DEBUG_RECENTS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS) FEATURE_PICTURE_IN_PICTURE(android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE) LOCK_TASK_AUTH_DONT_LOCK(com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK) IResultReceiver(com.android.internal.os.IResultReceiver) PRESERVE_WINDOWS(com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS) DeviceIdleController(com.android.server.DeviceIdleController) IVoiceInteractionSession(android.service.voice.IVoiceInteractionSession) Handler(android.os.Handler) Map(java.util.Map) Display(android.view.Display) IIntentReceiver(android.content.IIntentReceiver) INVALID_STACK_ID(android.app.ActivityManager.StackId.INVALID_STACK_ID) POSTFIX_PROCESS_OBSERVERS(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PROCESS_OBSERVERS) IActivityContainer(android.app.IActivityContainer) IoUtils(libcore.io.IoUtils) Log(android.util.Log) XmlPullParser(org.xmlpull.v1.XmlPullParser) IProgressListener(android.os.IProgressListener) IVoiceInteractor(com.android.internal.app.IVoiceInteractor) ActivityManagerNative(android.app.ActivityManagerNative) IntentFilter(android.content.IntentFilter) Watchdog(com.android.server.Watchdog) DEBUG_ANR(com.android.server.am.ActivityManagerDebugConfig.DEBUG_ANR) DumpHeapActivity(com.android.internal.app.DumpHeapActivity) PathPermission(android.content.pm.PathPermission) IUidObserver(android.app.IUidObserver) Installer(com.android.server.pm.Installer) INotificationManager(android.app.INotificationManager) PROC_PARENS(android.os.Process.PROC_PARENS) POSTFIX_CLEANUP(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CLEANUP) Preconditions(com.android.internal.util.Preconditions) FactoryTest(android.os.FactoryTest) SleepToken(android.app.ActivityManagerInternal.SleepToken) IProcessObserver(android.app.IProcessObserver) DEBUG_MU(com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU) TRANSIT_ACTIVITY_OPEN(com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN) PackageManagerInternal(android.content.pm.PackageManagerInternal) RemoteException(android.os.RemoteException) SystemClock(android.os.SystemClock) LOCK_TASK_AUTH_PINNABLE(com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE) SystemServiceManager(com.android.server.SystemServiceManager) UpdateLock(android.os.UpdateLock) POSTFIX_LOCKTASK(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK) TAG_AM(com.android.server.am.ActivityManagerDebugConfig.TAG_AM) POSTFIX_MU(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_MU) DEBUG_TASKS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS) Settings(android.provider.Settings) MATCH_DIRECT_BOOT_UNAWARE(android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE) IActivityController(android.app.IActivityController) StackId(android.app.ActivityManager.StackId) XmlUtils.writeBooleanAttribute(com.android.internal.util.XmlUtils.writeBooleanAttribute) POSTFIX_BROADCAST(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_BROADCAST) UserManager(android.os.UserManager) DEBUG_LRU(com.android.server.am.ActivityManagerDebugConfig.DEBUG_LRU) ServiceManager(android.os.ServiceManager) ComponentName(android.content.ComponentName) ParceledListSlice(android.content.pm.ParceledListSlice) IOverlayManager(android.content.om.IOverlayManager) BackgroundThread(com.android.internal.os.BackgroundThread) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DEBUG_ALL(com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL) IntentResolver(com.android.server.IntentResolver) SystemProperties(android.os.SystemProperties) UI_MODE_TYPE_TELEVISION(android.content.res.Configuration.UI_MODE_TYPE_TELEVISION) DEBUG_PROCESS_OBSERVERS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_PROCESS_OBSERVERS) AtomicLong(java.util.concurrent.atomic.AtomicLong) XmlUtils.readIntAttribute(com.android.internal.util.XmlUtils.readIntAttribute) IAppTask(android.app.IAppTask) TRANSIT_TASK_TO_FRONT(com.android.server.wm.AppTransition.TRANSIT_TASK_TO_FRONT) ServiceThread(com.android.server.ServiceThread) TelecomManager(android.telecom.TelecomManager) Manifest.permission(android.Manifest.permission) FileObserver(android.os.FileObserver) XmlUtils.writeLongAttribute(com.android.internal.util.XmlUtils.writeLongAttribute) ALWAYS_FINISH_ACTIVITIES(android.provider.Settings.Global.ALWAYS_FINISH_ACTIVITIES) DEBUG_PROCESSES(com.android.server.am.ActivityManagerDebugConfig.DEBUG_PROCESSES) Rect(android.graphics.Rect) Trace(android.os.Trace) POSTFIX_UID_OBSERVERS(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_UID_OBSERVERS) Zygote(com.android.internal.os.Zygote) MANAGE_ACTIVITY_STACKS(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) VrManagerInternal(com.android.server.vr.VrManagerInternal) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) DEBUG_IMMERSIVE(com.android.server.am.ActivityManagerDebugConfig.DEBUG_IMMERSIVE) ProviderInfo(android.content.pm.ProviderInfo) IPermissionController(android.os.IPermissionController) POSTFIX_OOM_ADJ(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_OOM_ADJ) VMRuntime(dalvik.system.VMRuntime) DEBUG_BROADCAST_BACKGROUND(com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST_BACKGROUND) ContentResolver(android.content.ContentResolver) Locale(java.util.Locale) IAppOpsCallback(com.android.internal.app.IAppOpsCallback) ActivityInfo(android.content.pm.ActivityInfo) PersistableBundle(android.os.PersistableBundle) InstrumentationInfo(android.content.pm.InstrumentationInfo) Proxy(android.net.Proxy) WAIT_FOR_DEBUGGER(android.provider.Settings.Global.WAIT_FOR_DEBUGGER) Debug(android.os.Debug) IProcessInfoService(android.os.IProcessInfoService) END_DOCUMENT(org.xmlpull.v1.XmlPullParser.END_DOCUMENT) DEBUG_POWER_QUICK(com.android.server.am.ActivityManagerDebugConfig.DEBUG_POWER_QUICK) DEBUG_UID_OBSERVERS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_UID_OBSERVERS) RemoteCallbackList(android.os.RemoteCallbackList) DEBUG_POWER(com.android.server.am.ActivityManagerDebugConfig.DEBUG_POWER) DisplayMetrics(android.util.DisplayMetrics) GET_PROVIDERS(android.content.pm.PackageManager.GET_PROVIDERS) DEBUG_APP(android.provider.Settings.Global.DEBUG_APP) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Objects(java.util.Objects) IMountService(android.os.storage.IMountService) ActivityNotFoundException(android.content.ActivityNotFoundException) Notification(android.app.Notification) IPackageManager(android.content.pm.IPackageManager) BroadcastOptions(android.app.BroadcastOptions) SystemUserHomeActivity(com.android.internal.app.SystemUserHomeActivity) AppGlobals(android.app.AppGlobals) POSTFIX_LOCKSCREEN(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKSCREEN) UserIdInt(android.annotation.UserIdInt) LocationManager(android.location.LocationManager) DEBUG_LOCKTASK(com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK) ActivityManager(android.app.ActivityManager) DEBUG_USAGE_STATS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_USAGE_STATS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IIntentSender(android.content.IIntentSender) PackageInfo(android.content.pm.PackageInfo) POSTFIX_FOCUS(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS) Slog(android.util.Slog) RESIZE_MODE_PRESERVE_WINDOW(android.app.ActivityManager.RESIZE_MODE_PRESERVE_WINDOW) Binder(android.os.Binder) HashSet(java.util.HashSet) ApplicationThreadNative(android.app.ApplicationThreadNative) LOCK_TASK_AUTH_LAUNCHABLE_PRIV(com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV) POSTFIX_IMMERSIVE(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IMMERSIVE) POSTFIX_BACKUP(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_BACKUP) LocalServices(com.android.server.LocalServices) IAppOpsService(com.android.internal.app.IAppOpsService) UserInfo(android.content.pm.UserInfo) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) DEBUG_PERMISSIONS_REVIEW(com.android.server.am.ActivityManagerDebugConfig.DEBUG_PERMISSIONS_REVIEW) EmptyArray(libcore.util.EmptyArray) ArrayMap(android.util.ArrayMap) TRANSIT_ACTIVITY_RELAUNCH(com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_RELAUNCH) TransactionTooLargeException(android.os.TransactionTooLargeException) MATCH_DIRECT_BOOT_AWARE(android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE) LayoutInflater(android.view.LayoutInflater) POSTFIX_SERVICE(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SERVICE) FileInputStream(java.io.FileInputStream) DOCKED_STACK_ID(android.app.ActivityManager.StackId.DOCKED_STACK_ID) Bitmap(android.graphics.Bitmap) FORCE_FOCUS(com.android.server.am.ActivityStackSupervisor.FORCE_FOCUS) DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT(android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT) ServiceInfo(android.content.pm.ServiceInfo) BatteryStats(android.os.BatteryStats) DEBUG_WHITELISTS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_WHITELISTS) ProfilerInfo(android.app.ProfilerInfo) Comparator(java.util.Comparator) Activity(android.app.Activity) Resources(android.content.res.Resources) SuggestionSpan(android.text.style.SuggestionSpan) PermissionInfo(android.content.pm.PermissionInfo) Arrays(java.util.Arrays) DEBUG_VISIBLE_BEHIND(com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBLE_BEHIND) ParcelFileDescriptor(android.os.ParcelFileDescriptor) DEBUG_BACKUP(com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKUP) ConfigurationInfo(android.content.pm.ConfigurationInfo) GuardedBy(com.android.internal.annotations.GuardedBy) IServiceConnection(android.app.IServiceConnection) Uri(android.net.Uri) Process(android.os.Process) FREEFORM_WORKSPACE_STACK_ID(android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID) DEVELOPMENT_FORCE_RTL(android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL) Manifest(android.Manifest) StatusBarManagerInternal(com.android.server.statusbar.StatusBarManagerInternal) IUserSwitchObserver(android.app.IUserSwitchObserver) ProcessStats(com.android.internal.app.procstats.ProcessStats) Looper(android.os.Looper) Maps(com.google.android.collect.Maps) TimeUtils(android.util.TimeUtils) DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES(android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES) DEBUG_PSS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_PSS) PrintWriter(java.io.PrintWriter) POSTFIX_LRU(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LRU) POSTFIX_URI_PERMISSION(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_URI_PERMISSION) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) DEBUG_PROVIDER(com.android.server.am.ActivityManagerDebugConfig.DEBUG_PROVIDER) DEBUG_BROADCAST(com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST) DropBoxManager(android.os.DropBoxManager) POSTFIX_CONFIGURATION(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION) PINNED_STACK_ID(android.app.ActivityManager.StackId.PINNED_STACK_ID) Set(java.util.Set) POSTFIX_PROVIDER(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PROVIDER) POSTFIX_VISIBLE_BEHIND(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND) StandardCharsets(java.nio.charset.StandardCharsets) Message(android.os.Message) AssistUtils(com.android.internal.app.AssistUtils) WindowManagerService(com.android.server.wm.WindowManagerService) DEBUG_VISIBILITY(com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY) CompatibilityInfo(android.content.res.CompatibilityInfo) Environment(android.os.Environment) IUiAutomationConnection(android.app.IUiAutomationConnection) Dialog(android.app.Dialog) Instrumentation(android.app.Instrumentation) AssistStructure(android.app.assist.AssistStructure) XmlUtils.readLongAttribute(com.android.internal.util.XmlUtils.readLongAttribute) FULLSCREEN_WORKSPACE_STACK_ID(android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID) FEATURE_LEANBACK_ONLY(android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY) Parcel(android.os.Parcel) ArrayList(java.util.ArrayList) IntentSender(android.content.IntentSender) PowerManagerInternal(android.os.PowerManagerInternal) DEBUG_CLEANUP(com.android.server.am.ActivityManagerDebugConfig.DEBUG_CLEANUP) PROC_SPACE_TERM(android.os.Process.PROC_SPACE_TERM) DebugUtils(android.util.DebugUtils) UserHandle(android.os.UserHandle) DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT(android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT) POSTFIX_STACK(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK) DEBUG_STACK(com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK) IBackupManager(android.app.backup.IBackupManager) FONT_SCALE(android.provider.Settings.System.FONT_SCALE) StorageManager(android.os.storage.StorageManager) Xml(android.util.Xml) POSTFIX_SWITCH(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH) AttributeCache(com.android.server.AttributeCache) EventLog(android.util.EventLog) FastPrintWriter(com.android.internal.util.FastPrintWriter) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) IContentProvider(android.content.IContentProvider) IPackageDataObserver(android.content.pm.IPackageDataObserver) WorkSource(android.os.WorkSource) LENIENT_BACKGROUND_CHECK(android.provider.Settings.Global.LENIENT_BACKGROUND_CHECK) DEFER_RESUME(com.android.server.am.ActivityStackSupervisor.DEFER_RESUME) TRANSIT_TASK_IN_PLACE(com.android.server.wm.AppTransition.TRANSIT_TASK_IN_PLACE) File(java.io.File) AppWidgetManager(android.appwidget.AppWidgetManager) Gravity(android.view.Gravity) ComponentCallbacks2(android.content.ComponentCallbacks2) TransferPipe(com.android.internal.os.TransferPipe) MemInfoReader(com.android.internal.util.MemInfoReader) ActivityState(com.android.server.am.ActivityStack.ActivityState) ITaskStackListener(android.app.ITaskStackListener) Configuration(android.content.res.Configuration) MATCH_UNINSTALLED_PACKAGES(android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES) DEBUG_BROADCAST_LIGHT(com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST_LIGHT) ResultReceiver(android.os.ResultReceiver) INTERACT_ACROSS_USERS(android.Manifest.permission.INTERACT_ACROSS_USERS) IStopUserCallback(android.app.IStopUserCallback) AppOpsManager(android.app.AppOpsManager) DateUtils(android.text.format.DateUtils) UsageEvents(android.app.usage.UsageEvents) POSTFIX_PROCESSES(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PROCESSES) ProcessCpuTracker(com.android.internal.os.ProcessCpuTracker) PendingIntent(android.app.PendingIntent) DEBUG_OOM_ADJ(com.android.server.am.ActivityManagerDebugConfig.DEBUG_OOM_ADJ) LockGuard(com.android.server.LockGuard) VoiceInteractionSession(android.service.voice.VoiceInteractionSession) INTERACT_ACROSS_USERS_FULL(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) MATCH_SYSTEM_ONLY(android.content.pm.PackageManager.MATCH_SYSTEM_ONLY) IBinder(android.os.IBinder) ActivityOptions(android.app.ActivityOptions) OverlayInfo(android.content.om.OverlayInfo) PowerManager(android.os.PowerManager) VoiceInteractionManagerInternal(android.service.voice.VoiceInteractionManagerInternal) XmlUtils.writeIntAttribute(com.android.internal.util.XmlUtils.writeIntAttribute) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) View(android.view.View) XmlUtils.readBooleanAttribute(com.android.internal.util.XmlUtils.readBooleanAttribute) DEBUG_SERVICE(com.android.server.am.ActivityManagerDebugConfig.DEBUG_SERVICE) START_TASKS_FROM_RECENTS(android.Manifest.permission.START_TASKS_FROM_RECENTS) ProxyInfo(android.net.ProxyInfo) IInstrumentationWatcher(android.app.IInstrumentationWatcher) NotificationManager(android.app.NotificationManager) SystemService(com.android.server.SystemService) AssistContent(android.app.assist.AssistContent) RESTORE_FROM_RECENTS(com.android.server.am.ActivityStackSupervisor.RESTORE_FROM_RECENTS) NonNull(android.annotation.NonNull) BroadcastReceiver(android.content.BroadcastReceiver) AtomicFile(android.util.AtomicFile) FileNotFoundException(java.io.FileNotFoundException) ContentObserver(android.database.ContentObserver) AlertDialog(android.app.AlertDialog) SparseArray(android.util.SparseArray) List(java.util.List) DEBUG_URI_PERMISSION(com.android.server.am.ActivityManagerDebugConfig.DEBUG_URI_PERMISSION) AppOpsService(com.android.server.AppOpsService) IntentFirewall(com.android.server.firewall.IntentFirewall) ApplicationInfo(android.content.pm.ApplicationInfo) StackInfo(android.app.ActivityManager.StackInfo) HOME_STACK_ID(android.app.ActivityManager.StackId.HOME_STACK_ID) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Context(android.content.Context) DEBUG_FOCUS(com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) DEBUG_CONFIGURATION(com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION) Downloads(android.provider.Downloads) Pair(android.util.Pair) Intent(android.content.Intent) PrintWriterPrinter(android.util.PrintWriterPrinter) HashMap(java.util.HashMap) MATCH_DEBUG_TRIAGED_MISSING(android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING) START_TAG(org.xmlpull.v1.XmlPullParser.START_TAG) InstallerException(com.android.internal.os.InstallerConnection.InstallerException) LocaleList(android.os.LocaleList) ClipData(android.content.ClipData) POSTFIX_VISIBILITY(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY) DevicePolicyManager(android.app.admin.DevicePolicyManager) RECENTS_ACTIVITY_TYPE(com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE) FORCE_NEW_TASK_FLAGS(com.android.server.am.ActivityStackSupervisor.ActivityContainer.FORCE_NEW_TASK_FLAGS) ArraySet(android.util.ArraySet) INVALID_TASK_ID(com.android.server.am.TaskRecord.INVALID_TASK_ID) R(com.android.internal.R) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) DialogInterface(android.content.DialogInterface) ProcessMap(com.android.internal.app.ProcessMap) ApplicationErrorReport(android.app.ApplicationErrorReport) POSTFIX_POWER(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_POWER) Iterator(java.util.Iterator) ActivityThread(android.app.ActivityThread) TAG_WITH_CLASS_NAME(com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME) Point(android.graphics.Point) Lists(com.google.android.collect.Lists) ContentProvider(android.content.ContentProvider) PROC_CHAR(android.os.Process.PROC_CHAR) IActivityContainerCallback(android.app.IActivityContainerCallback) ResolveInfo(android.content.pm.ResolveInfo) DEBUG_LOCKSCREEN(com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN) FileUtils(android.os.FileUtils) TRANSIT_TASK_OPEN(com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN) TelephonyIntents(com.android.internal.telephony.TelephonyIntents) POSTFIX_RECENTS(com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS) StrictMode(android.os.StrictMode) DEBUG_SWITCH(com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH) FileDescriptor(java.io.FileDescriptor) ArrayUtils(com.android.internal.util.ArrayUtils) Collections(java.util.Collections) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) MountServiceInternal(android.os.storage.MountServiceInternal) PROC_OUT_LONG(android.os.Process.PROC_OUT_LONG) ProcessCpuTracker(com.android.internal.os.ProcessCpuTracker) FastPrintWriter(com.android.internal.util.FastPrintWriter) MemInfoReader(com.android.internal.util.MemInfoReader) Point(android.graphics.Point) SparseArray(android.util.SparseArray) StringWriter(java.io.StringWriter) BatteryStats(android.os.BatteryStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 8 with MemInfoReader

use of com.android.internal.util.MemInfoReader in project XobotOS by xamarin.

the class ActivityManager method isLargeRAM.

/**
     * Use to decide whether the running device can be considered a "large
     * RAM" device.  Exactly what memory limit large RAM is will vary, but
     * it essentially means there is plenty of RAM to have lots of background
     * processes running under decent loads.
     * @hide
     */
public static boolean isLargeRAM() {
    MemInfoReader reader = new MemInfoReader();
    reader.readMemInfo();
    if (reader.getTotalSize() >= (640 * 1024 * 1024)) {
        // which we have plenty of RAM to spare.
        return true;
    }
    return false;
}
Also used : MemInfoReader(com.android.internal.util.MemInfoReader)

Example 9 with MemInfoReader

use of com.android.internal.util.MemInfoReader in project XobotOS by xamarin.

the class ActivityManager method isHighEndGfx.

/**
     * Used by persistent processes to determine if they are running on a
     * higher-end device so should be okay using hardware drawing acceleration
     * (which tends to consume a lot more RAM).
     * @hide
     */
public static boolean isHighEndGfx(Display display) {
    MemInfoReader reader = new MemInfoReader();
    reader.readMemInfo();
    if (reader.getTotalSize() >= (512 * 1024 * 1024)) {
        // we can afford the overhead of graphics acceleration.
        return true;
    }
    Point p = new Point();
    display.getRealSize(p);
    int pixels = p.x * p.y;
    if (pixels >= (1024 * 600)) {
        // pixels on it that we'd really like to use hw drawing.
        return true;
    }
    return false;
}
Also used : MemInfoReader(com.android.internal.util.MemInfoReader) Point(android.graphics.Point) Point(android.graphics.Point)

Example 10 with MemInfoReader

use of com.android.internal.util.MemInfoReader in project android_packages_apps_Snap by LineageOS.

the class Camera2GraphView method isLongshotNeedCancel.

private boolean isLongshotNeedCancel() {
    if (PersistUtil.getSkipMemoryCheck()) {
        return false;
    }
    if (Storage.getAvailableSpace() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) {
        Log.w(TAG, "current storage is full");
        return true;
    }
    if (SECONDARY_SERVER_MEM == 0) {
        ActivityManager am = (ActivityManager) mActivity.getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(memInfo);
        SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold;
    }
    long totalMemory = Runtime.getRuntime().totalMemory();
    long maxMemory = Runtime.getRuntime().maxMemory();
    long remainMemory = maxMemory - totalMemory;
    MemInfoReader reader = new MemInfoReader();
    reader.readMemInfo();
    long[] info = reader.getRawInfo();
    long availMem = (info[Debug.MEMINFO_FREE] + info[Debug.MEMINFO_CACHED]) * 1024;
    if (availMem <= SECONDARY_SERVER_MEM || remainMemory <= LONGSHOT_CANCEL_THRESHOLD) {
        Log.e(TAG, "cancel longshot: free=" + info[Debug.MEMINFO_FREE] * 1024 + " cached=" + info[Debug.MEMINFO_CACHED] * 1024 + " threshold=" + SECONDARY_SERVER_MEM);
        RotateTextToast.makeText(mActivity, R.string.msg_cancel_longshot_for_limited_memory, Toast.LENGTH_SHORT).show();
        return true;
    }
    if (mIsRecordingVideo) {
        Log.e(TAG, " cancel longshot:not supported when recording");
        return true;
    }
    return false;
}
Also used : MemInfoReader(com.android.internal.util.MemInfoReader) ActivityManager(android.app.ActivityManager)

Aggregations

MemInfoReader (com.android.internal.util.MemInfoReader)10 Point (android.graphics.Point)5 ActivityManager (android.app.ActivityManager)4 IApplicationThread (android.app.IApplicationThread)4 BatteryStats (android.os.BatteryStats)3 Debug (android.os.Debug)3 RemoteException (android.os.RemoteException)3 SparseArray (android.util.SparseArray)3 ProcessStats (com.android.internal.app.procstats.ProcessStats)3 ProcessCpuTracker (com.android.internal.os.ProcessCpuTracker)3 FastPrintWriter (com.android.internal.util.FastPrintWriter)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 Manifest (android.Manifest)2 Manifest.permission (android.Manifest.permission)2 INTERACT_ACROSS_USERS (android.Manifest.permission.INTERACT_ACROSS_USERS)2 INTERACT_ACROSS_USERS_FULL (android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)2 MANAGE_ACTIVITY_STACKS (android.Manifest.permission.MANAGE_ACTIVITY_STACKS)2 START_TASKS_FROM_RECENTS (android.Manifest.permission.START_TASKS_FROM_RECENTS)2 NonNull (android.annotation.NonNull)2