Merge changes I1811ad12,I8d8800a6
* changes: Bug fix: Do not track the looper exception if the session is not sampled Bug fix: looper not enabled
This commit is contained in:
committed by
Android (Google) Code Review
commit
d5aeeea815
@@ -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);
|
||||
|
||||
@@ -59,7 +59,8 @@ public class LooperStatsService extends Binder {
|
||||
|
||||
private final Context mContext;
|
||||
private final LooperStats mStats;
|
||||
private boolean mEnabled = DEFAULT_ENABLED;
|
||||
// Default should be false so that the first call to #setEnabled installed the looper observer.
|
||||
private boolean mEnabled = false;
|
||||
|
||||
private LooperStatsService(Context context, LooperStats stats) {
|
||||
this.mContext = context;
|
||||
|
||||
Reference in New Issue
Block a user