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

Commit 165c521e authored by Ryan Zuklie's avatar Ryan Zuklie Committed by Cherrypicker Worker
Browse files

Trace events while not recording history.

This makes the ATrace events be recorded even when the history events
are not. History recording may be disabled when the device is on a
charger and the batter is nearly fully charged. BatteryStats will reset
history around this time so it may be fine to stop history, but the same
is not true for tracing.

Note: this introduces two new fields to record the state since when
history is not recorded, mHistoryLastWritten isn't updated.

Test: atest FrameworksServicesTests:BatteryStatsHistoryTest
Bug: 286818006
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e1b5dc72c4eb910c3c70b7eda697a6ad6511010b)
Merged-In: I52fc02cd8336adcb6f12305c584206242c40f507
Change-Id: I52fc02cd8336adcb6f12305c584206242c40f507
parent f338ffa8
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -259,6 +259,8 @@ public class BatteryStatsHistory {
    }

    private TraceDelegate mTracer;
    private int mTraceLastState = 0;
    private int mTraceLastState2 = 0;

    /**
     * Constructor
@@ -1241,7 +1243,6 @@ public class BatteryStatsHistory {
     */
    private void recordTraceEvents(int code, HistoryTag tag) {
        if (code == HistoryItem.EVENT_NONE) return;
        if (!mTracer.tracingEnabled()) return;

        final int idx = code & HistoryItem.EVENT_TYPE_MASK;
        final String prefix = (code & HistoryItem.EVENT_FLAG_START) != 0 ? "+" :
@@ -1270,8 +1271,6 @@ public class BatteryStatsHistory {
     * Writes changes to a HistoryItem state bitmap to Atrace.
     */
    private void recordTraceCounters(int oldval, int newval, BitDescription[] descriptions) {
        if (!mTracer.tracingEnabled()) return;

        int diff = oldval ^ newval;
        if (diff == 0) return;

@@ -1324,6 +1323,16 @@ public class BatteryStatsHistory {
    }

    private void writeHistoryItem(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) {
        if (mTracer != null && mTracer.tracingEnabled()) {
            recordTraceEvents(cur.eventCode, cur.eventTag);
            recordTraceCounters(mTraceLastState, cur.states,
                    BatteryStats.HISTORY_STATE_DESCRIPTIONS);
            recordTraceCounters(mTraceLastState2, cur.states2,
                    BatteryStats.HISTORY_STATE2_DESCRIPTIONS);
            mTraceLastState = cur.states;
            mTraceLastState2 = cur.states2;
        }

        if (!mHaveBatteryLevel || !mRecordingHistory) {
            return;
        }
@@ -1345,12 +1354,6 @@ public class BatteryStatsHistory {
                    + Integer.toHexString(lastDiffStates2));
        }

        recordTraceEvents(cur.eventCode, cur.eventTag);
        recordTraceCounters(mHistoryLastWritten.states,
                cur.states, BatteryStats.HISTORY_STATE_DESCRIPTIONS);
        recordTraceCounters(mHistoryLastWritten.states2,
                cur.states2, BatteryStats.HISTORY_STATE2_DESCRIPTIONS);

        if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE
                && timeDiffMs < 1000 && (diffStates & lastDiffStates) == 0
                && (diffStates2 & lastDiffStates2) == 0
+0 −8
Original line number Diff line number Diff line
@@ -93,8 +93,6 @@ public class BatteryStatsHistoryTest {

    @Test
    public void testAtraceBinaryState1() {
        mHistory.forceRecordAllHistory();

        InOrder inOrder = Mockito.inOrder(mTracer);
        Mockito.when(mTracer.tracingEnabled()).thenReturn(true);

@@ -112,8 +110,6 @@ public class BatteryStatsHistoryTest {

    @Test
    public void testAtraceBinaryState2() {
        mHistory.forceRecordAllHistory();

        InOrder inOrder = Mockito.inOrder(mTracer);
        Mockito.when(mTracer.tracingEnabled()).thenReturn(true);

@@ -131,8 +127,6 @@ public class BatteryStatsHistoryTest {

    @Test
    public void testAtraceNumericalState() {
        mHistory.forceRecordAllHistory();

        InOrder inOrder = Mockito.inOrder(mTracer);
        Mockito.when(mTracer.tracingEnabled()).thenReturn(true);

@@ -150,8 +144,6 @@ public class BatteryStatsHistoryTest {

    @Test
    public void testAtraceInstantEvent() {
        mHistory.forceRecordAllHistory();

        InOrder inOrder = Mockito.inOrder(mTracer);
        Mockito.when(mTracer.tracingEnabled()).thenReturn(true);