Bug fix: Do not track the looper exception if the session is not sampled
Test: atest LooperStatsTest Change-Id: I1811ad12bdf9830699c615fff02f5aceea74c175
This commit is contained in:
@@ -126,9 +126,11 @@ public class LooperStats implements Looper.Observer {
|
||||
}
|
||||
|
||||
DispatchSession session = (DispatchSession) token;
|
||||
Entry entry = findEntry(msg, /* allowCreateNew= */true);
|
||||
synchronized (entry) {
|
||||
entry.exceptionCount++;
|
||||
Entry entry = findEntry(msg, /* allowCreateNew= */session != DispatchSession.NOT_SAMPLED);
|
||||
if (entry != null) {
|
||||
synchronized (entry) {
|
||||
entry.exceptionCount++;
|
||||
}
|
||||
}
|
||||
|
||||
recycleSession(session);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user