Loading core/java/com/android/internal/os/BatteryStatsHistory.java +12 −5 Original line number Diff line number Diff line Loading @@ -129,6 +129,13 @@ public class BatteryStatsHistory { static final int EXTENSION_CPU_USAGE_HEADER_FLAG = 0x00000004; static final int EXTENSION_CPU_USAGE_FLAG = 0x00000008; // For state1, trace everything except the wakelock bit (which can race with // suspend) and the running bit (which isn't meaningful in traces). static final int STATE1_TRACE_MASK = ~(HistoryItem.STATE_WAKE_LOCK_FLAG | HistoryItem.STATE_CPU_RUNNING_FLAG); // For state2, trace all bit changes. static final int STATE2_TRACE_MASK = ~0; private final Parcel mHistoryBuffer; private final File mSystemDir; private final HistoryStepDetailsCalculator mStepDetailsCalculator; Loading Loading @@ -1270,8 +1277,9 @@ public class BatteryStatsHistory { /** * Writes changes to a HistoryItem state bitmap to Atrace. */ private void recordTraceCounters(int oldval, int newval, BitDescription[] descriptions) { int diff = oldval ^ newval; private void recordTraceCounters(int oldval, int newval, int mask, BitDescription[] descriptions) { int diff = (oldval ^ newval) & mask; if (diff == 0) return; for (int i = 0; i < descriptions.length; i++) { Loading @@ -1284,7 +1292,6 @@ public class BatteryStatsHistory { } else { value = (newval & bd.mask) >> bd.shift; } mTracer.traceCounter("battery_stats." + bd.name, value); } } Loading Loading @@ -1325,9 +1332,9 @@ 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, recordTraceCounters(mTraceLastState, cur.states, STATE1_TRACE_MASK, BatteryStats.HISTORY_STATE_DESCRIPTIONS); recordTraceCounters(mTraceLastState2, cur.states2, recordTraceCounters(mTraceLastState2, cur.states2, STATE2_TRACE_MASK, BatteryStats.HISTORY_STATE2_DESCRIPTIONS); mTraceLastState = cur.states; mTraceLastState2 = cur.states2; Loading services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,19 @@ public class BatteryStatsHistoryTest { inOrder.verify(mTracer).traceCounter("battery_stats.wifi", 1); } @Test public void testAtraceExcludedState() { mHistory.forceRecordAllHistory(); Mockito.when(mTracer.tracingEnabled()).thenReturn(true); mHistory.recordStateStartEvent(mClock.elapsedRealtime(), mClock.uptimeMillis(), HistoryItem.STATE_WAKE_LOCK_FLAG); Mockito.verify(mTracer, Mockito.never()).traceCounter( Mockito.anyString(), Mockito.anyInt()); } @Test public void testAtraceNumericalState() { InOrder inOrder = Mockito.inOrder(mTracer); Loading Loading
core/java/com/android/internal/os/BatteryStatsHistory.java +12 −5 Original line number Diff line number Diff line Loading @@ -129,6 +129,13 @@ public class BatteryStatsHistory { static final int EXTENSION_CPU_USAGE_HEADER_FLAG = 0x00000004; static final int EXTENSION_CPU_USAGE_FLAG = 0x00000008; // For state1, trace everything except the wakelock bit (which can race with // suspend) and the running bit (which isn't meaningful in traces). static final int STATE1_TRACE_MASK = ~(HistoryItem.STATE_WAKE_LOCK_FLAG | HistoryItem.STATE_CPU_RUNNING_FLAG); // For state2, trace all bit changes. static final int STATE2_TRACE_MASK = ~0; private final Parcel mHistoryBuffer; private final File mSystemDir; private final HistoryStepDetailsCalculator mStepDetailsCalculator; Loading Loading @@ -1270,8 +1277,9 @@ public class BatteryStatsHistory { /** * Writes changes to a HistoryItem state bitmap to Atrace. */ private void recordTraceCounters(int oldval, int newval, BitDescription[] descriptions) { int diff = oldval ^ newval; private void recordTraceCounters(int oldval, int newval, int mask, BitDescription[] descriptions) { int diff = (oldval ^ newval) & mask; if (diff == 0) return; for (int i = 0; i < descriptions.length; i++) { Loading @@ -1284,7 +1292,6 @@ public class BatteryStatsHistory { } else { value = (newval & bd.mask) >> bd.shift; } mTracer.traceCounter("battery_stats." + bd.name, value); } } Loading Loading @@ -1325,9 +1332,9 @@ 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, recordTraceCounters(mTraceLastState, cur.states, STATE1_TRACE_MASK, BatteryStats.HISTORY_STATE_DESCRIPTIONS); recordTraceCounters(mTraceLastState2, cur.states2, recordTraceCounters(mTraceLastState2, cur.states2, STATE2_TRACE_MASK, BatteryStats.HISTORY_STATE2_DESCRIPTIONS); mTraceLastState = cur.states; mTraceLastState2 = cur.states2; Loading
services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,19 @@ public class BatteryStatsHistoryTest { inOrder.verify(mTracer).traceCounter("battery_stats.wifi", 1); } @Test public void testAtraceExcludedState() { mHistory.forceRecordAllHistory(); Mockito.when(mTracer.tracingEnabled()).thenReturn(true); mHistory.recordStateStartEvent(mClock.elapsedRealtime(), mClock.uptimeMillis(), HistoryItem.STATE_WAKE_LOCK_FLAG); Mockito.verify(mTracer, Mockito.never()).traceCounter( Mockito.anyString(), Mockito.anyInt()); } @Test public void testAtraceNumericalState() { InOrder inOrder = Mockito.inOrder(mTracer); Loading