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

Commit 6ee8c249 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Add looper profiling to adb shell am"

parents d7a374f6 7eabe55d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -22714,10 +22714,8 @@ package android.view {
    ctor public ViewDebug();
    method public static void dumpCapturedView(java.lang.String, java.lang.Object);
    method public static void startHierarchyTracing(java.lang.String, android.view.View);
    method public static void startLooperProfiling(java.io.File);
    method public static void startRecyclerTracing(java.lang.String, android.view.View);
    method public static void stopHierarchyTracing();
    method public static void stopLooperProfiling();
    method public static void stopRecyclerTracing();
    method public static void trace(android.view.View, android.view.ViewDebug.RecyclerTraceType, int...);
    method public static void trace(android.view.View, android.view.ViewDebug.HierarchyTraceType);
+9 −3
Original line number Diff line number Diff line
@@ -468,10 +468,16 @@ public class Am {
        String profileFile = null;
        boolean start = false;
        boolean wall = false;
        int profileType = 0;
        
        String process = null;
        
        String cmd = nextArgRequired();
        if ("looper".equals(cmd)) {
            cmd = nextArgRequired();
            profileType = 1;
        }

        if ("start".equals(cmd)) {
            start = true;
            wall = "--wall".equals(nextOption());
@@ -516,7 +522,7 @@ public class Am {
            } else if (start) {
                //removeWallOption();
            }
            if (!mAm.profileControl(process, start, profileFile, fd)) {
            if (!mAm.profileControl(process, start, profileFile, fd, profileType)) {
                wall = false;
                throw new AndroidException("PROFILE FAILED on process " + process);
            }
@@ -1076,8 +1082,8 @@ public class Am {
                "       am broadcast <INTENT>\n" +
                "       am instrument [-r] [-e <NAME> <VALUE>] [-p] [-w]\n" +
                "               [--no-window-animation] <COMPONENT>\n" +
                "       am profile start <PROCESS> <FILE>\n" +
                "       am profile stop <PROCESS>\n" +
                "       am profile [looper] start <PROCESS> <FILE>\n" +
                "       am profile [looper] stop <PROCESS>\n" +
                "       am dumpheap [flags] <PROCESS> <FILE>\n" +
                "       am monitor [--gdb <port>]\n" +
                "       am screen-compat [on|off] <PACKAGE>\n" +
+4 −2
Original line number Diff line number Diff line
@@ -1107,7 +1107,8 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            String path = data.readString();
            ParcelFileDescriptor fd = data.readInt() != 0
                    ? data.readFileDescriptor() : null;
            boolean res = profileControl(process, start, path, fd);
            int profileType = data.readInt();
            boolean res = profileControl(process, start, path, fd, profileType);
            reply.writeNoException();
            reply.writeInt(res ? 1 : 0);
            return true;
@@ -2888,7 +2889,7 @@ class ActivityManagerProxy implements IActivityManager
    }
    
    public boolean profileControl(String process, boolean start,
            String path, ParcelFileDescriptor fd) throws RemoteException
            String path, ParcelFileDescriptor fd, int profileType) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
@@ -2902,6 +2903,7 @@ class ActivityManagerProxy implements IActivityManager
        } else {
            data.writeInt(0);
        }
        data.writeInt(profileType);
        mRemote.transact(PROFILE_CONTROL_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean res = reply.readInt() != 0;
+23 −7
Original line number Diff line number Diff line
@@ -676,11 +676,12 @@ public final class ActivityThread {
            queueOrSendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, token);
        }

        public void profilerControl(boolean start, String path, ParcelFileDescriptor fd) {
        public void profilerControl(boolean start, String path, ParcelFileDescriptor fd,
                int profileType) {
            ProfilerControlData pcd = new ProfilerControlData();
            pcd.path = path;
            pcd.fd = fd;
            queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0);
            queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0, profileType);
        }

        public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) {
@@ -1148,7 +1149,7 @@ public final class ActivityThread {
                    handleActivityConfigurationChanged((IBinder)msg.obj);
                    break;
                case PROFILER_CONTROL:
                    handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj);
                    handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj, msg.arg2);
                    break;
                case CREATE_BACKUP_AGENT:
                    handleCreateBackupAgent((CreateBackupAgentData)msg.obj);
@@ -3469,11 +3470,18 @@ public final class ActivityThread {
        performConfigurationChanged(r.activity, mCompatConfiguration);
    }

    final void handleProfilerControl(boolean start, ProfilerControlData pcd) {
    final void handleProfilerControl(boolean start, ProfilerControlData pcd, int profileType) {
        if (start) {
            try {
                switch (profileType) {
                    case 1:
                        ViewDebug.startLooperProfiling(pcd.path, pcd.fd.getFileDescriptor());
                        break;
                    default:
                        Debug.startMethodTracing(pcd.path, pcd.fd.getFileDescriptor(),
                                8 * 1024 * 1024, 0);
                        break;
                }
            } catch (RuntimeException e) {
                Slog.w(TAG, "Profiling failed on path " + pcd.path
                        + " -- can the process access this path?");
@@ -3485,7 +3493,15 @@ public final class ActivityThread {
                }
            }
        } else {
            switch (profileType) {
                case 1:
                    ViewDebug.stopLooperProfiling();
                    break;
                default:
                    Debug.stopMethodTracing();
                    break;
                    
            }
        }
    }

+4 −2
Original line number Diff line number Diff line
@@ -379,7 +379,8 @@ public abstract class ApplicationThreadNative extends Binder
            String path = data.readString();
            ParcelFileDescriptor fd = data.readInt() != 0
                    ? data.readFileDescriptor() : null;
            profilerControl(start, path, fd);
            int profileType = data.readInt();
            profilerControl(start, path, fd, profileType);
            return true;
        }
        
@@ -936,7 +937,7 @@ class ApplicationThreadProxy implements IApplicationThread {
    }
    
    public void profilerControl(boolean start, String path,
            ParcelFileDescriptor fd) throws RemoteException {
            ParcelFileDescriptor fd, int profileType) throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        data.writeInt(start ? 1 : 0);
@@ -947,6 +948,7 @@ class ApplicationThreadProxy implements IApplicationThread {
        } else {
            data.writeInt(0);
        }
        data.writeInt(profileType);
        mRemote.transact(PROFILER_CONTROL_TRANSACTION, data, null,
                IBinder.FLAG_ONEWAY);
        data.recycle();
Loading