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

Commit 421a6874 authored by Siim Sammul's avatar Siim Sammul
Browse files

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

is unknown.

Test: unit test
Bug: 180584913
Change-Id: I2e4234b764e4341cea54172309d1f804a7cd5a88
parent 9a6bdd9f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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) {
+17 −0
Original line number Diff line number Diff line
@@ -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();