From 03ad13e587962ad2cadb81df759afca3e7d15dab Mon Sep 17 00:00:00 2001 From: Kelly Rossmoyer Date: Tue, 13 Mar 2018 13:10:14 -0700 Subject: [PATCH] Increase size of BatteryStatsService stats buffer Increases the size of the buffer used to return data from JNI call to PowerHAL::getSubsystemLowPowerStats() from 512 bytes to 2048 bytes. As a rough calculation, the substring for a single subsystem sleep state will typically fit within ~105 characters, such as: "subsystem_2 name=Citadel state_1 name=Sleep time=99999999999 count=99999999999 last entry=99999999999 " Those numerical values work out to ~1157 days, so while the underlying data type can hold values larger than that, it seems like a reasonable basis for capacity estimation. Most currently known state names are either "Sleep" or "Deep-Sleep", and "Citadel" and "DISPLAY" are the longest currently known subsystem names, with the others more typically 3 or 4 characters long. There are up to 7 masters that each export data for a single sleep state and 4 currently anticipated subsystems that will probably each export data for 2 sleep states, which works out to 15 known/expected sleep states, which works out to 1575 characters. Add ~45 more chars for the header string at the beginning of the output: ",SubsystemPowerState SubsystemPowerState " And that leaves ~428 spare bytes from an allocation of 2048, which is enough to allow 4 more sleep states or 3 more and a slightly higher average number of characters per state. Test: Ran along with ag/3718639 code that implements 2018 PowerHAL low power stats, took a bugreport, and verified that truncation was addressed. Test: Calculated capacity of new buffer size to verify expected output will fit with some spare room left over. Bug:74594445 Change-Id: I5919388ada1c47b11e594582691e0faf1575faaa --- services/core/java/com/android/server/am/BatteryStatsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index 4541acde14b4..3db1da59b4ea 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -103,7 +103,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub .replaceWith("?"); private ByteBuffer mUtf8BufferStat = ByteBuffer.allocateDirect(MAX_LOW_POWER_STATS_SIZE); private CharBuffer mUtf16BufferStat = CharBuffer.allocate(MAX_LOW_POWER_STATS_SIZE); - private static final int MAX_LOW_POWER_STATS_SIZE = 512; + private static final int MAX_LOW_POWER_STATS_SIZE = 2048; /** * Replaces the information in the given rpmStats with up-to-date information. -- 2.11.0