Fix the missing longwake finish event problem.
When starting a new batteystats history file, before inserting a new CMD_CURRENT_TIME HistoryItem at beginning of the history buffer, make a copy of the current HistoryItem. Otherwise the current HistoryItem could be overriden by the CMD_CURRENT_TIME and we lose a HistoryItem. In b/130083227, the longwake start event happends before opening the new history file, after CMD_CURRENT_TIME event, the longwake finish event is missing. The fix is to make a copy of current HistoryItem before adding CMD_CURRENT_TIME event. Change-Id: I5048f98b6b47f54336fb01e354fb5a6284c84b43 Fix: 130083227 Test: b/130083227 can be reproduced by createFakeHistoryEvents() call, missing longwake finish event can be seen after "TIME:" record. With the fix, no more missing longwake finish event after "TIME:" record. “adb shell dumpsys batterystats --history-create-events 50000” to create enough events to start new history files, “adb shell dumpsys batterystats --history” to observe all history records.
This commit is contained in:
@@ -3609,8 +3609,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
|
||||
public void createFakeHistoryEvents(long numEvents) {
|
||||
for(long i = 0; i < numEvents; i++) {
|
||||
noteWifiOnLocked();
|
||||
noteWifiOffLocked();
|
||||
noteLongPartialWakelockStart("name1", "historyName1", 1000);
|
||||
noteLongPartialWakelockFinish("name1", "historyName1", 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3693,9 +3693,10 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mHistoryBufferLastPos = -1;
|
||||
final long elapsedRealtime = mClocks.elapsedRealtime();
|
||||
final long uptime = mClocks.uptimeMillis();
|
||||
HistoryItem newItem = new HistoryItem();
|
||||
newItem.setTo(cur);
|
||||
startRecordingHistory(elapsedRealtime, uptime, false);
|
||||
|
||||
addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur);
|
||||
addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, newItem);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user