Logging and partial fix for BatteryStats lock contention

Don't try to grab the write lock while holding BatteryStats lock.

Add some debugging to see if cpu stats gathering is causing a
delay in some cases.

Bug: 34961340
Test: Manual
Change-Id: I8c7d1abb239abd81a07171cd65be1fbfdbca5fdb
This commit is contained in:
Amith Yamasani
2017-02-07 15:58:24 -08:00
parent 391b1b82d2
commit d2450862f4

View File

@@ -9562,7 +9562,8 @@ public class BatteryStatsImpl extends BatteryStats {
}
});
if (DEBUG_ENERGY_CPU) {
// TODO: STOPSHIP, remove the "true" below after b/34961340 is fixed
if (DEBUG_ENERGY_CPU || true) {
Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) +
" ms");
}
@@ -10390,10 +10391,9 @@ public class BatteryStatsImpl extends BatteryStats {
if (next == null) {
return;
}
mWriteLock.lock();
}
mWriteLock.lock();
try {
FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite());
stream.write(next.marshall());