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

Commit 99ab9530 authored by Olivier Gaillard's avatar Olivier Gaillard
Browse files

Bug fix: Do not track the looper exception if the session is not sampled

Test: atest LooperStatsTest
Change-Id: I1811ad12bdf9830699c615fff02f5aceea74c175
parent 41589388
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -126,10 +126,12 @@ public class LooperStats implements Looper.Observer {
        }

        DispatchSession session = (DispatchSession) token;
        Entry entry = findEntry(msg, /* allowCreateNew= */true);
        Entry entry = findEntry(msg, /* allowCreateNew= */session != DispatchSession.NOT_SAMPLED);
        if (entry != null) {
            synchronized (entry) {
                entry.exceptionCount++;
            }
        }

        recycleSession(session);
    }
+20 −0
Original line number Diff line number Diff line
@@ -137,6 +137,26 @@ public final class LooperStatsTest {
        assertThat(entry.maxCpuUsageMicros).isEqualTo(0);
    }

    @Test
    public void testThrewException_notSampled() {
        TestableLooperStats looperStats = new TestableLooperStats(2, 100);

        Object token = looperStats.messageDispatchStarting();
        looperStats.tickRealtime(10);
        looperStats.tickThreadTime(10);
        looperStats.messageDispatched(token, mHandlerFirst.obtainMessage(0));
        assertThat(looperStats.getEntries()).hasSize(1);

        // Will not be sampled so does not contribute to any entries.
        Object token2 = looperStats.messageDispatchStarting();
        looperStats.tickRealtime(100);
        looperStats.tickThreadTime(10);
        looperStats.dispatchingThrewException(
                token2, mHandlerSecond.obtainMessage(7), new ArithmeticException());
        assertThat(looperStats.getEntries()).hasSize(1);
        assertThat(looperStats.getEntries().get(0).messageCount).isEqualTo(1);
    }

    @Test
    public void testMultipleMessagesDispatched() {
        TestableLooperStats looperStats = new TestableLooperStats(2, 100);