Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fa297d3 authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Add debug support for native compactions

This allows for performing compactions using shell
command which is useful for testing and debugging
compaction locally automated tests to allow compacting
applications not managed by ActivityManager such as
purely native binaries.

Test: am compact native full <pid>
Bug: 267188919
Change-Id: I355bd4c55c96ada392d81cf89381870b9dc79c17
parent 94ea572a
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -1103,6 +1103,28 @@ final class ActivityManagerShellCommand extends ShellCommand {
                mInternal.mOomAdjuster.mCachedAppOptimizer.compactAllSystem();
            }
            pw.println("Finished system compaction");
        } else if (op.equals("native")) {
            op = getNextArgRequired();
            isFullCompact = op.equals("full");
            isSomeCompact = op.equals("some");
            int pid;
            String pidStr = getNextArgRequired();
            try {
                pid = Integer.parseInt(pidStr);
            } catch (Exception e) {
                getErrPrintWriter().println("Error: failed to parse '" + pidStr + "' as a PID");
                return -1;
            }
            if (isFullCompact) {
                mInternal.mOomAdjuster.mCachedAppOptimizer.compactNative(
                        CachedAppOptimizer.CompactProfile.FULL, pid);
            } else if (isSomeCompact) {
                mInternal.mOomAdjuster.mCachedAppOptimizer.compactNative(
                        CachedAppOptimizer.CompactProfile.SOME, pid);
            } else {
                getErrPrintWriter().println("Error: unknown compaction type '" + op + "'");
                return -1;
            }
        } else {
            getErrPrintWriter().println("Error: unknown compact command '" + op + "'");
            return -1;
@@ -4007,11 +4029,17 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      --allow-background-activity-starts: The receiver may start activities");
            pw.println("          even if in the background.");
            pw.println("      --async: Send without waiting for the completion of the receiver.");
            pw.println("  compact [some|full|system] <process_name> [--user <USER_ID>]");
            pw.println("      Force process compaction.");
            pw.println("  compact [some|full] <process_name> [--user <USER_ID>]");
            pw.println("      Perform a single process compaction.");
            pw.println("      some: execute file compaction.");
            pw.println("      full: execute anon + file compaction.");
            pw.println("      system: system compaction.");
            pw.println("  compact system");
            pw.println("      Perform a full system compaction.");
            pw.println("  compact native [some|full] <pid>");
            pw.println("      Perform a native compaction for process with <pid>.");
            pw.println("      some: execute file compaction.");
            pw.println("      full: execute anon + file compaction.");
            pw.println("  instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]");
            pw.println("          [--user <USER_ID> | current]");
            pw.println("          [--no-hidden-api-checks [--no-test-api-access]]");
+21 −0
Original line number Diff line number Diff line
@@ -169,6 +169,7 @@ public final class CachedAppOptimizer {
    static final int COMPACT_SYSTEM_MSG = 2;
    static final int SET_FROZEN_PROCESS_MSG = 3;
    static final int REPORT_UNFREEZE_MSG = 4;
    static final int COMPACT_NATIVE_MSG = 5;

    // When free swap falls below this percentage threshold any full (file + anon)
    // compactions will be downgraded to file only compactions to reduce pressure
@@ -731,6 +732,11 @@ public final class CachedAppOptimizer {
        return false;
    }

    void compactNative(CompactProfile compactProfile, int pid) {
        mCompactionHandler.sendMessage(mCompactionHandler.obtainMessage(
                COMPACT_NATIVE_MSG, pid, compactProfile.ordinal()));
    }

    private AggregatedProcessCompactionStats getPerProcessAggregatedCompactStat(
            String processName) {
        if (processName == null) {
@@ -1864,6 +1870,21 @@ public final class CachedAppOptimizer {
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    break;
                }
                case COMPACT_NATIVE_MSG: {
                    int pid = msg.arg1;
                    CompactProfile compactProfile = CompactProfile.values()[msg.arg2];
                    Slog.d(TAG_AM,
                            "Performing native compaction for pid=" + pid
                                    + " type=" + compactProfile.name());
                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "compactSystem");
                    try {
                        mProcessDependencies.performCompaction(compactProfile, pid);
                    } catch (Exception e) {
                        Slog.d(TAG_AM, "Failed compacting native pid= " + pid);
                    }
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    break;
                }
            }
        }
    }