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

Commit 4556b7b8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add "-g" option to run GC to "am dumpheap".

Bug: 62144301
Test: manual test
Change-Id: I187e3acc3c3a97e6799192ab10b1bf16c7fee02f
parent 3771c46e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -658,6 +658,7 @@ public final class ActivityThread {
    }

    static final class DumpHeapData {
        public boolean runGc;
        String path;
        ParcelFileDescriptor fd;
    }
@@ -1023,8 +1024,10 @@ public final class ActivityThread {
            sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType);
        }

        public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) {
        @Override
        public void dumpHeap(boolean managed, boolean runGc, String path, ParcelFileDescriptor fd) {
            DumpHeapData dhd = new DumpHeapData();
            dhd.runGc = runGc;
            dhd.path = path;
            dhd.fd = fd;
            sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/);
@@ -5171,6 +5174,11 @@ public final class ActivityThread {
    }

    static final void handleDumpHeap(boolean managed, DumpHeapData dhd) {
        if (dhd.runGc) {
            System.gc();
            System.runFinalization();
            System.gc();
        }
        if (managed) {
            try {
                Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor());
+1 −1
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ interface IActivityManager {
    int checkGrantUriPermission(int callingUid, in String targetPkg, in Uri uri,
            int modeFlags, int userId);
    // Cause the specified process to dump the specified heap.
    boolean dumpHeap(in String process, int userId, boolean managed, in String path,
    boolean dumpHeap(in String process, int userId, boolean managed, boolean runGc, in String path,
            in ParcelFileDescriptor fd);
    int startActivities(in IApplicationThread caller, in String callingPackage,
            in Intent[] intents, in String[] resolvedTypes, in IBinder resultTo,
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ oneway interface IApplicationThread {
    void scheduleSuicide();
    void dispatchPackageBroadcast(int cmd, in String[] packages);
    void scheduleCrash(in String msg);
    void dumpHeap(boolean managed, in String path, in ParcelFileDescriptor fd);
    void dumpHeap(boolean managed, boolean runGc, in String path, in ParcelFileDescriptor fd);
    void dumpActivity(in ParcelFileDescriptor fd, IBinder servicetoken, in String prefix,
            in String[] args);
    void clearDnsCache();
+4 −3
Original line number Diff line number Diff line
@@ -21617,7 +21617,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                                        if (DEBUG_PSS) Slog.d(TAG_PSS,
                                                "Requesting dump heap from "
                                                + myProc + " to " + heapdumpFile);
                                        thread.dumpHeap(true, heapdumpFile.toString(), fd);
                                        thread.dumpHeap(/* managed=*/ true, /* runGc= */ false,
                                                heapdumpFile.toString(), fd);
                                    } catch (RemoteException e) {
                                    }
                                }
@@ -23348,7 +23349,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        return proc;
    }
    public boolean dumpHeap(String process, int userId, boolean managed,
    public boolean dumpHeap(String process, int userId, boolean managed, boolean runGc,
            String path, ParcelFileDescriptor fd) throws RemoteException {
        try {
@@ -23377,7 +23378,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    }
                }
                proc.thread.dumpHeap(managed, path, fd);
                proc.thread.dumpHeap(managed, runGc, path, fd);
                fd = null;
                return true;
            }
+6 −2
Original line number Diff line number Diff line
@@ -785,6 +785,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
        final PrintWriter err = getErrPrintWriter();
        boolean managed = true;
        int userId = UserHandle.USER_CURRENT;
        boolean runGc = false;

        String opt;
        while ((opt=getNextOption()) != null) {
@@ -796,6 +797,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
                }
            } else if (opt.equals("-n")) {
                managed = false;
            } else if (opt.equals("-g")) {
                runGc = true;
            } else {
                err.println("Error: Unknown option: " + opt);
                return -1;
@@ -811,7 +814,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
            return -1;
        }

        if (!mInterface.dumpHeap(process, userId, managed, heapFile, fd)) {
        if (!mInterface.dumpHeap(process, userId, managed, runGc, heapFile, fd)) {
            err.println("HEAP DUMP FAILED on process " + process);
            return -1;
        }
@@ -2555,10 +2558,11 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      --sampling INTERVAL: use sample profiling with INTERVAL microseconds");
            pw.println("          between samples");
            pw.println("      --streaming: stream the profiling output to the specified file");
            pw.println("  dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE>");
            pw.println("  dumpheap [--user <USER_ID> current] [-n] [-g] <PROCESS> <FILE>");
            pw.println("      Dump the heap of a process.  The given <PROCESS> argument may");
            pw.println("        be either a process name or pid.  Options are:");
            pw.println("      -n: dump native heap instead of managed heap");
            pw.println("      -g: force GC before dumping the heap");
            pw.println("      --user <USER_ID> | current: When supplying a process name,");
            pw.println("          specify user of process to dump; uses current user if not specified.");
            pw.println("  set-debug-app [-w] [--persistent] <PACKAGE>");