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

Commit 99966b01 authored by Olivier Gaillard's avatar Olivier Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Resolve codes to method names for binder call stats."

parents 53437f64 103aae20
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.os;

import android.annotation.Nullable;
import android.os.Binder;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -75,10 +76,10 @@ public class BinderCallsStats {
    }

    public CallSession callStarted(Binder binder, int code) {
        return callStarted(binder.getClass().getName(), code);
        return callStarted(binder.getClass().getName(), code, binder.getTransactionName(code));
    }

    private CallSession callStarted(String className, int code) {
    private CallSession callStarted(String className, int code, @Nullable String methodName) {
        if (!mEnabled) {
          return NOT_ENABLED;
        }
@@ -90,6 +91,7 @@ public class BinderCallsStats {

        s.callStat.className = className;
        s.callStat.msg = code;
        s.callStat.methodName = methodName;
        s.exceptionThrown = false;
        s.cpuTimeStarted = -1;
        s.timeStarted = -1;
@@ -169,6 +171,7 @@ public class BinderCallsStats {
                callStat = s.sampledCallStat;
            }
            callStat.callCount++;
            callStat.methodName = s.callStat.methodName;
            if (s.cpuTimeStarted >= 0) {
                callStat.cpuTimeMicros += duration;
                callStat.maxCpuTimeMicros = Math.max(callStat.maxCpuTimeMicros, duration);
@@ -250,6 +253,7 @@ public class BinderCallsStats {
                    sb.setLength(0);
                    sb.append("    ")
                            .append(uidToString(uidEntry.uid, appIdToPkgNameMap))
                            .append(",").append(e)
                            .append(',').append(e.cpuTimeMicros)
                            .append(',').append(e.maxCpuTimeMicros)
                            .append(',').append(e.latencyMicros)
@@ -372,6 +376,9 @@ public class BinderCallsStats {
    public static class CallStat {
        public String className;
        public int msg;
        // Method name might be null when we cannot resolve the transaction code. For instance, if
        // the binder was not generated by AIDL.
        public @Nullable String methodName;
        public long cpuTimeMicros;
        public long maxCpuTimeMicros;
        public long latencyMicros;
@@ -410,7 +417,7 @@ public class BinderCallsStats {

        @Override
        public String toString() {
            return className + "/" + msg;
            return className + "#" + (methodName == null ? msg : methodName);
        }
    }

+20 −0
Original line number Diff line number Diff line
@@ -225,6 +225,26 @@ public class BinderCallsStatsTest {
        assertEquals(1, sampledCallStatsList.size());
    }

    @Test
    public void testTransactionCodeResolved() {
        TestBinderCallsStats bcs = new TestBinderCallsStats();
        bcs.setDetailedTracking(true);
        Binder binder = new Binder() {
            @Override
            public String getTransactionName(int code) {
              return "resolved";
            }
        };
        BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1);
        bcs.time += 10;
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);

        List<BinderCallsStats.CallStat> callStatsList =
                bcs.getUidEntries().get(TEST_UID).getCallStatsList();
        assertEquals(1, callStatsList.get(0).msg);
        assertEquals("resolved", callStatsList.get(0).methodName);
    }

    @Test
    public void testParcelSize() {
        TestBinderCallsStats bcs = new TestBinderCallsStats();