From 307edcd9c29ebc5c0b382f04cdee900bb9729a7b Mon Sep 17 00:00:00 2001 From: Ahmed ElArabawy Date: Fri, 7 Jul 2017 17:48:13 -0700 Subject: [PATCH] Fix format of subsystem power stats The Subsystem power stats string in batteryStats dumpsys has an extra newline that is causing PowerBug to skip the line when parsing the history information. Also, the string for subsystem power stats is missing a heading title and has some redundant text This commit fixes these format errors so powerbug can read and parse that line successfully Bug: 63447034 Test: Manual testing + Read the bugreport by historian and verify output Change-Id: Idf971823dd5f769e653b4788b00fc025593d0d3d Signed-off-by: Ahmed ElArabawy --- core/java/android/os/BatteryStats.java | 4 +- ..._android_server_am_BatteryStatsService.cpp | 58 ++++++++++--------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index b178d814a3f76..19fb15c56d40c 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -5606,8 +5606,10 @@ public abstract class BatteryStats implements Parcelable { pw.print(','); if (rec.stepDetails.statPlatformIdleState != null) { pw.print(rec.stepDetails.statPlatformIdleState); + if (rec.stepDetails.statSubsystemPowerState != null) { + pw.print(','); + } } - pw.println(); if (rec.stepDetails.statSubsystemPowerState != null) { pw.print(rec.stepDetails.statSubsystemPowerState); diff --git a/services/core/jni/com_android_server_am_BatteryStatsService.cpp b/services/core/jni/com_android_server_am_BatteryStatsService.cpp index 2dfd8b9fa1637..413f430a7e42b 100644 --- a/services/core/jni/com_android_server_am_BatteryStatsService.cpp +++ b/services/core/jni/com_android_server_am_BatteryStatsService.cpp @@ -301,30 +301,17 @@ static jint getSubsystemLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject if (status != Status::SUCCESS) return; - for (size_t i = 0; i < subsystems.size(); i++) { - int added; - const PowerStateSubsystem &subsystem = subsystems[i]; - - added = snprintf(offset, remaining, - "subsystem_%zu name=%s ", i + 1, subsystem.name.c_str()); - if (added < 0) { - break; - } - - if (added > remaining) { - added = remaining; - } - + if (subsystems.size() > 0) { + int added = snprintf(offset, remaining, "SubsystemPowerState "); offset += added; remaining -= added; total_added += added; - for (size_t j = 0; j < subsystem.states.size(); j++) { - const PowerStateSubsystemSleepState& state = subsystem.states[j]; + for (size_t i = 0; i < subsystems.size(); i++) { + const PowerStateSubsystem &subsystem = subsystems[i]; + added = snprintf(offset, remaining, - "state_%zu name=%s time=%" PRIu64 " count=%" PRIu64 " last entry TS(ms)=%" PRIu64 " ", - j + 1, state.name.c_str(), state.residencyInMsecSinceBoot, - state.totalTransitions, state.lastEntryTimestampMs); + "subsystem_%zu name=%s ", i + 1, subsystem.name.c_str()); if (added < 0) { break; } @@ -336,14 +323,33 @@ static jint getSubsystemLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject offset += added; remaining -= added; total_added += added; - } - if (remaining <= 0) { - /* rewrite NULL character*/ - offset--; - total_added--; - ALOGE("PowerHal: buffer not enough"); - break; + for (size_t j = 0; j < subsystem.states.size(); j++) { + const PowerStateSubsystemSleepState& state = subsystem.states[j]; + added = snprintf(offset, remaining, + "state_%zu name=%s time=%" PRIu64 " count=%" PRIu64 " last entry=%" PRIu64 " ", + j + 1, state.name.c_str(), state.residencyInMsecSinceBoot, + state.totalTransitions, state.lastEntryTimestampMs); + if (added < 0) { + break; + } + + if (added > remaining) { + added = remaining; + } + + offset += added; + remaining -= added; + total_added += added; + } + + if (remaining <= 0) { + /* rewrite NULL character*/ + offset--; + total_added--; + ALOGE("PowerHal: buffer not enough"); + break; + } } } }