Collect binder latency data even when device is charging / device state

is unknown.

Test: unit test
Bug: 180584913
Change-Id: I2e4234b764e4341cea54172309d1f804a7cd5a88
This commit is contained in:
Siim Sammul
2021-06-23 13:52:07 +01:00
parent 9a6bdd9fc1
commit 421a6874ee
2 changed files with 24 additions and 1 deletions

View File

@@ -220,7 +220,8 @@ public class BinderCallsStats implements BinderInternal.Observer {
public CallSession callStarted(Binder binder, int code, int workSourceUid) {
noteNativeThreadId();
if (!canCollect()) {
// We always want to collect data for latency if it's enabled, regardless of device state.
if (!mCollectLatencyData && !canCollect()) {
return null;
}
@@ -267,6 +268,11 @@ public class BinderCallsStats implements BinderInternal.Observer {
mLatencyObserver.callEnded(s);
}
// Latency collection has already been processed so check if the rest should be processed.
if (!canCollect()) {
return;
}
UidEntry uidEntry = null;
final boolean recordCall;
if (s.recordedCall) {

View File

@@ -19,6 +19,7 @@ package com.android.internal.os;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -968,6 +969,22 @@ public class BinderCallsStatsTest {
assertEquals(1, bcs.getLatencyObserver().getLatencyHistograms().size());
}
@Test
public void testLatencyCollectionActiveEvenWithoutDeviceState() {
TestBinderCallsStats bcs = new TestBinderCallsStats(null);
bcs.setCollectLatencyData(true);
Binder binder = new Binder();
CallSession callSession = bcs.callStarted(binder, 1, WORKSOURCE_UID);
assertNotEquals(null, callSession);
bcs.time += 10;
bcs.elapsedTime += 20;
bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE, WORKSOURCE_UID);
assertEquals(1, bcs.getLatencyObserver().getLatencyHistograms().size());
}
@Test
public void testLatencyCollectionEnabledByDefault() {
TestBinderCallsStats bcs = new TestBinderCallsStats();