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

Commit a3686dd0 authored by Olivier Gaillard's avatar Olivier Gaillard
Browse files

Only keep one overflow entry per uid.

Test: atest binderLibTest BinderWorkSourceTest BinderCallsStatsServiceTest
Change-Id: I99ba18d894d3291f3b31fa07ba8a48131f30b2e9
parent 182b4ede
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -60,7 +60,11 @@ public class BinderCallsStats implements BinderInternal.Observer {
    private static final int CALL_SESSIONS_POOL_SIZE = 100;
    private static final int MAX_EXCEPTION_COUNT_SIZE = 50;
    private static final String EXCEPTION_COUNT_OVERFLOW_NAME = "overflow";
    // Default values for overflow entry. The work source uid does not use a default value in order
    // to have on overflow entry per work source uid.
    private static final Class<? extends Binder> OVERFLOW_BINDER = OverflowBinder.class;
    private static final boolean OVERFLOW_SCREEN_INTERACTIVE = false;
    private static final int OVERFLOW_DIRECT_CALLING_UID = -1;
    private static final int OVERFLOW_TRANSACTION_CODE = -1;

    // Whether to collect all the data: cpu + exceptions + reply/request sizes.
@@ -656,14 +660,16 @@ public class BinderCallsStats implements BinderInternal.Observer {
            // Only create CallStat if it's a new entry, otherwise update existing instance.
            if (mapCallStat == null) {
                if (maxCallStatsReached) {
                    mapCallStat = get(callingUid, OVERFLOW_BINDER, OVERFLOW_TRANSACTION_CODE,
                            screenInteractive);
                    mapCallStat = get(OVERFLOW_DIRECT_CALLING_UID, OVERFLOW_BINDER,
                            OVERFLOW_TRANSACTION_CODE, OVERFLOW_SCREEN_INTERACTIVE);
                    if (mapCallStat != null) {
                        return mapCallStat;
                    }

                    callingUid = OVERFLOW_DIRECT_CALLING_UID;
                    binderClass = OVERFLOW_BINDER;
                    transactionCode = OVERFLOW_TRANSACTION_CODE;
                    screenInteractive = OVERFLOW_SCREEN_INTERACTIVE;
                }

                mapCallStat = new CallStat(callingUid, binderClass, transactionCode,
+41 −3
Original line number Diff line number Diff line
@@ -575,12 +575,15 @@ public class BinderCallsStatsTest {

        Binder binder = new Binder();
        CallSession callSession = bcs.callStarted(binder, 1, WORKSOURCE_UID);
        bcs.time += 10;
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID);

        callSession = bcs.callStarted(binder, 2, WORKSOURCE_UID);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID);

        // Should use the same overflow entry.
        callSession = bcs.callStarted(binder, 3, WORKSOURCE_UID);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID);

        List<BinderCallsStats.ExportedCallStat> callStatsList = bcs.getExportedCallStats();
        assertEquals(2, callStatsList.size());
        BinderCallsStats.ExportedCallStat callStats = callStatsList.get(0);
@@ -590,11 +593,46 @@ public class BinderCallsStatsTest {
        assertEquals(CALLING_UID, callStats.callingUid);

        callStats = callStatsList.get(1);
        assertEquals(1, callStats.callCount);
        assertEquals(2, callStats.callCount);
        assertEquals("-1", callStats.methodName);
        assertEquals("com.android.internal.os.BinderCallsStats$OverflowBinder",
                callStats.className);
        assertEquals(CALLING_UID, callStats.callingUid);
        assertEquals(false , callStats.screenInteractive);
        assertEquals(-1 , callStats.callingUid);
    }

    @Test
    public void testOverflow_oneOverflowEntryPerUid() {
        TestBinderCallsStats bcs = new TestBinderCallsStats();
        bcs.setDetailedTracking(true);
        bcs.setSamplingInterval(1);
        bcs.setMaxBinderCallStats(1);

        Binder binder = new Binder();
        CallSession callSession = bcs.callStarted(binder, 1, WORKSOURCE_UID);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID);

        callSession = bcs.callStarted(binder, 2, WORKSOURCE_UID + 1);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID + 1);

        // Different uids have different overflow entries.
        callSession = bcs.callStarted(binder, 2, WORKSOURCE_UID + 2);
        bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID + 2);

        List<BinderCallsStats.ExportedCallStat> callStatsList = bcs.getExportedCallStats();
        assertEquals(3, callStatsList.size());

        BinderCallsStats.ExportedCallStat callStats = callStatsList.get(1);
        assertEquals(WORKSOURCE_UID + 1, callStats.workSourceUid);
        assertEquals(1, callStats.callCount);
        assertEquals("com.android.internal.os.BinderCallsStats$OverflowBinder",
                callStats.className);

        callStats = callStatsList.get(2);
        assertEquals(WORKSOURCE_UID + 2, callStats.workSourceUid);
        assertEquals(1, callStats.callCount);
        assertEquals("com.android.internal.os.BinderCallsStats$OverflowBinder",
                callStats.className);
    }

    @Test