Merge "Fix recording of battery history tags" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f19925afc9
@@ -167,7 +167,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
||||||
|
|
||||||
// Current on-disk Parcel version
|
// Current on-disk Parcel version
|
||||||
static final int VERSION = 207;
|
static final int VERSION = 208;
|
||||||
|
|
||||||
// The maximum number of names wakelocks we will keep track of
|
// The maximum number of names wakelocks we will keep track of
|
||||||
// per uid; once the limit is reached, we batch the remaining wakelocks
|
// per uid; once the limit is reached, we batch the remaining wakelocks
|
||||||
@@ -3981,8 +3981,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
if (idxObj != null) {
|
if (idxObj != null) {
|
||||||
idx = idxObj;
|
idx = idxObj;
|
||||||
if ((idx & TAG_FIRST_OCCURRENCE_FLAG) != 0) {
|
if ((idx & TAG_FIRST_OCCURRENCE_FLAG) != 0) {
|
||||||
idx &= ~TAG_FIRST_OCCURRENCE_FLAG;
|
mHistoryTagPool.put(tag, idx & ~TAG_FIRST_OCCURRENCE_FLAG);
|
||||||
mHistoryTagPool.put(tag, idx);
|
|
||||||
}
|
}
|
||||||
return idx;
|
return idx;
|
||||||
} else if (mNextHistoryTagIdx < HISTORY_TAG_INDEX_LIMIT) {
|
} else if (mNextHistoryTagIdx < HISTORY_TAG_INDEX_LIMIT) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import java.io.File;
|
|||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
@SuppressWarnings("GuardedBy")
|
||||||
public class BatteryStatsHistoryIteratorTest {
|
public class BatteryStatsHistoryIteratorTest {
|
||||||
private static final int APP_UID = Process.FIRST_APPLICATION_UID + 42;
|
private static final int APP_UID = Process.FIRST_APPLICATION_UID + 42;
|
||||||
|
|
||||||
@@ -124,7 +125,10 @@ public class BatteryStatsHistoryIteratorTest {
|
|||||||
// More than 32k strings
|
// More than 32k strings
|
||||||
final int eventCount = 0x7FFF + 100;
|
final int eventCount = 0x7FFF + 100;
|
||||||
for (int i = 0; i < eventCount; i++) {
|
for (int i = 0; i < eventCount; i++) {
|
||||||
mBatteryStats.noteAlarmStartLocked("a" + i, null, APP_UID, 3_000_000, 2_000_000);
|
// Names repeat in order to verify de-duping of identical history tags.
|
||||||
|
String name = "a" + (i % 10);
|
||||||
|
mBatteryStats.noteAlarmStartLocked(name, null, APP_UID, 3_000_000, 2_000_000);
|
||||||
|
mBatteryStats.noteAlarmFinishLocked(name, null, APP_UID, 3_500_000, 2_500_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
final BatteryStatsHistoryIterator iterator =
|
final BatteryStatsHistoryIterator iterator =
|
||||||
@@ -149,10 +153,23 @@ public class BatteryStatsHistoryIteratorTest {
|
|||||||
assertThat(item.time).isEqualTo(2_000_000);
|
assertThat(item.time).isEqualTo(2_000_000);
|
||||||
|
|
||||||
for (int i = 0; i < eventCount; i++) {
|
for (int i = 0; i < eventCount; i++) {
|
||||||
|
String name = "a" + (i % 10);
|
||||||
assertThat(iterator.next(item)).isTrue();
|
assertThat(iterator.next(item)).isTrue();
|
||||||
|
// Skip a blank event inserted at the start of every buffer
|
||||||
|
if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
|
||||||
|
assertThat(iterator.next(item)).isTrue();
|
||||||
|
}
|
||||||
assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_ALARM
|
assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_ALARM
|
||||||
| BatteryStats.HistoryItem.EVENT_FLAG_START);
|
| BatteryStats.HistoryItem.EVENT_FLAG_START);
|
||||||
assertThat(item.eventTag.string).isEqualTo("a" + i);
|
assertThat(item.eventTag.string).isEqualTo(name);
|
||||||
|
|
||||||
|
assertThat(iterator.next(item)).isTrue();
|
||||||
|
if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
|
||||||
|
assertThat(iterator.next(item)).isTrue();
|
||||||
|
}
|
||||||
|
assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_ALARM
|
||||||
|
| BatteryStats.HistoryItem.EVENT_FLAG_FINISH);
|
||||||
|
assertThat(item.eventTag.string).isEqualTo(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(iterator.next(item)).isFalse();
|
assertThat(iterator.next(item)).isFalse();
|
||||||
|
|||||||
Reference in New Issue
Block a user