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

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

Merge "Collect a few more binder stats when detailed tracking is enabled."

parents fa38f941 58b56e37
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public class BinderCallsStatsPerfTest {
        int i = 0;
        while (state.keepRunning()) {
            BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, i % 100);
            mBinderCallsStats.callEnded(s);
            mBinderCallsStats.callEnded(s, 0, 0);
            i++;
        }
    }
@@ -71,7 +71,7 @@ public class BinderCallsStatsPerfTest {
        mBinderCallsStats = new BinderCallsStats(false);
        while (state.keepRunning()) {
            BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, 0);
            mBinderCallsStats.callEnded(s);
            mBinderCallsStats.callEnded(s, 0, 0);
        }
    }

+3 −1
Original line number Diff line number Diff line
@@ -760,6 +760,8 @@ public class Binder implements IBinder {
            }
        }
        checkParcel(this, code, reply, "Unreasonably large binder reply buffer");
        int replySizeBytes = reply.dataSize();
        int requestSizeBytes = data.dataSize();
        reply.recycle();
        data.recycle();

@@ -769,7 +771,7 @@ public class Binder implements IBinder {
        // to the main transaction loop to wait for another incoming transaction.  Either
        // way, strict mode begone!
        StrictMode.clearGatheredViolations();
        binderCallsStats.callEnded(callSession);
        binderCallsStats.callEnded(callSession, requestSizeBytes, replySizeBytes);

        return res;
    }
+16 −4
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class BinderCallsStats {
        return s;
    }

    public void callEnded(CallSession s) {
    public void callEnded(CallSession s, int parcelRequestSize, int parcelReplySize) {
        Preconditions.checkNotNull(s);
        synchronized (mLock) {
            long duration;
@@ -129,6 +129,11 @@ public class BinderCallsStats {
                callStat.cpuTimeMicros += duration;
                callStat.latencyMicros += latencyDuration;
                callStat.exceptionCount += s.exceptionThrown ? 1 : 0;
                callStat.maxLatencyMicros = Math.max(callStat.maxLatencyMicros, latencyDuration);
                callStat.maxRequestSizeBytes =
                        Math.max(callStat.maxRequestSizeBytes, parcelRequestSize);
                callStat.maxReplySizeBytes =
                        Math.max(callStat.maxReplySizeBytes, parcelReplySize);
            } else {
                // update sampled timings in the beginning of each interval
                if (s.cpuTimeStarted >= 0) {
@@ -184,8 +189,9 @@ public class BinderCallsStats {
        StringBuilder sb = new StringBuilder();
        if (mDetailedTracking) {
            pw.println("Per-UID raw data " + datasetSizeDesc
                    + "(uid, call_desc, cpu_time_micros, latency_time_micros, exception_count, "
                    + "call_count):");
                    + "(uid, call_desc, cpu_time_micros, latency_time_micros, "
                    + "max_latency_time_micros, exception_count, max_request_size_bytes, "
                    + "max_reply_size_bytes, call_count):");
            List<UidEntry> topEntries = verbose ? entries
                    : getHighestValues(entries, value -> value.cpuTimeMicros, 0.9);
            for (UidEntry uidEntry : topEntries) {
@@ -195,7 +201,10 @@ public class BinderCallsStats {
                            .append(uidEntry.uid).append(",").append(e)
                            .append(',').append(e.cpuTimeMicros)
                            .append(',').append(e.latencyMicros)
                            .append(',').append(e.maxLatencyMicros)
                            .append(',').append(e.exceptionCount)
                            .append(',').append(e.maxRequestSizeBytes)
                            .append(',').append(e.maxReplySizeBytes)
                            .append(',').append(e.callCount);
                    pw.println(sb);
                }
@@ -280,6 +289,9 @@ public class BinderCallsStats {
        public int msg;
        public long cpuTimeMicros;
        public long latencyMicros;
        public long maxLatencyMicros;
        public long maxRequestSizeBytes;
        public long maxReplySizeBytes;
        public long callCount;
        public long exceptionCount;

+24 −7
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ import static org.junit.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
@Presubmit
public class BinderCallsStatsTest {
    public static final int TEST_UID = 1;
    private static final int TEST_UID = 1;
    private static final int REQUEST_SIZE = 2;
    private static final int REPLY_SIZE = 3;

    @Test
    public void testDetailedOff() {
@@ -43,7 +45,7 @@ public class BinderCallsStatsTest {
        Binder binder = new Binder();
        BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1);
        bcs.time += 10;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);

        SparseArray<BinderCallsStats.UidEntry> uidEntries = bcs.getUidEntries();
        assertEquals(1, uidEntries.size());
@@ -66,7 +68,7 @@ public class BinderCallsStatsTest {

        callSession = bcs.callStarted(binder, 1);
        bcs.time += 20;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);

        uidEntry = bcs.getUidEntries().get(TEST_UID);
        assertEquals(2, uidEntry.callCount);
@@ -79,7 +81,7 @@ public class BinderCallsStatsTest {

        callSession = bcs.callStarted(binder, 2);
        bcs.time += 50;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);
        uidEntry = bcs.getUidEntries().get(TEST_UID);
        assertEquals(3, uidEntry.callCount);

@@ -95,7 +97,7 @@ public class BinderCallsStatsTest {
        Binder binder = new Binder();
        BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1);
        bcs.time += 10;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);

        SparseArray<BinderCallsStats.UidEntry> uidEntries = bcs.getUidEntries();
        assertEquals(1, uidEntries.size());
@@ -117,7 +119,7 @@ public class BinderCallsStatsTest {

        callSession = bcs.callStarted(binder, 1);
        bcs.time += 20;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);

        uidEntry = bcs.getUidEntries().get(TEST_UID);
        assertEquals(2, uidEntry.callCount);
@@ -127,7 +129,7 @@ public class BinderCallsStatsTest {

        callSession = bcs.callStarted(binder, 2);
        bcs.time += 50;
        bcs.callEnded(callSession);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);
        uidEntry = bcs.getUidEntries().get(TEST_UID);
        assertEquals(3, uidEntry.callCount);

@@ -137,6 +139,21 @@ public class BinderCallsStatsTest {
        assertEquals(2, callStatsList.size());
    }

    @Test
    public void testParcelSize() {
        TestBinderCallsStats bcs = new TestBinderCallsStats(true);
        Binder binder = new Binder();
        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(REQUEST_SIZE, callStatsList.get(0).maxRequestSizeBytes);
        assertEquals(REPLY_SIZE, callStatsList.get(0).maxReplySizeBytes);
    }

    @Test
    public void testGetHighestValues() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);