diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-06-25 13:10:36 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-06-25 13:14:27 -0700 |
commit | 87fd322ecb5cd7582f449e5b4721a1e4dea062e6 (patch) | |
tree | fa3c92d594a843e6e9e4ffdd8417035aa41fefce | |
parent | 6b0f384f0042c21129466c100e20aec1a325a8da (diff) | |
download | frameworks_base-87fd322ecb5cd7582f449e5b4721a1e4dea062e6.zip frameworks_base-87fd322ecb5cd7582f449e5b4721a1e4dea062e6.tar.gz frameworks_base-87fd322ecb5cd7582f449e5b4721a1e4dea062e6.tar.bz2 |
BatteryStats: Record suspend abort reasons
Bug:18179405
Change-Id: I28c77f035400c32375dbe6d3c7057c0a2c093e8f
-rw-r--r-- | services/core/java/com/android/server/am/BatteryStatsService.java | 12 | ||||
-rw-r--r-- | services/core/jni/com_android_server_am_BatteryStatsService.cpp | 73 |
2 files changed, 38 insertions, 47 deletions
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index 78557634..6cc1b11 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -864,8 +864,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub } final class WakeupReasonThread extends Thread { - final int[] mIrqs = new int[32]; - final String[] mReasons = new String[32]; + final String[] mReason = new String[1]; WakeupReasonThread() { super("BatteryStats_wakeupReason"); @@ -876,12 +875,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub try { int num; - while ((num=nativeWaitWakeup(mIrqs, mReasons)) >= 0) { + while ((num = nativeWaitWakeup(mReason)) >= 0) { synchronized (mStats) { + // num will be either 0 or 1. if (num > 0) { - for (int i=0; i<num; i++) { - mStats.noteWakeupReasonLocked(mReasons[i]); - } + mStats.noteWakeupReasonLocked(mReason[0]); } else { mStats.noteWakeupReasonLocked("unknown"); } @@ -893,7 +891,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub } } - private static native int nativeWaitWakeup(int[] outIrqs, String[] outReasons); + private static native int nativeWaitWakeup(String[] outReason); private void dumpHelp(PrintWriter pw) { pw.println("Battery stats (batterystats) dump options:"); diff --git a/services/core/jni/com_android_server_am_BatteryStatsService.cpp b/services/core/jni/com_android_server_am_BatteryStatsService.cpp index 3b9cc9d..e257e89 100644 --- a/services/core/jni/com_android_server_am_BatteryStatsService.cpp +++ b/services/core/jni/com_android_server_am_BatteryStatsService.cpp @@ -48,9 +48,9 @@ namespace android static bool wakeup_init = false; static sem_t wakeup_sem; -static void wakeup_callback(void) +static void wakeup_callback(bool success) { - ALOGV("In wakeup_callback"); + ALOGV("In wakeup_callback: %s", success ? "resumed from suspend" : "suspend aborted"); int ret = sem_post(&wakeup_sem); if (ret < 0) { char buf[80]; @@ -59,10 +59,9 @@ static void wakeup_callback(void) } } -static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs, - jobjectArray outReasons) +static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jobjectArray outReasons) { - if (outIrqs == NULL || outReasons == NULL) { + if (outReasons == NULL) { jniThrowException(env, "java/lang/NullPointerException", "null argument"); return -1; } @@ -100,32 +99,47 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs, return -1; } - int numOut = env->GetArrayLength(outIrqs); - ScopedIntArrayRW irqs(env, outIrqs); - - ALOGV("Reading up to %d wakeup reasons", numOut); + ALOGV("Reading wakeup reasons"); char mergedreason[MAX_REASON_SIZE]; char* mergedreasonpos = mergedreason; int remainreasonlen = MAX_REASON_SIZE; - int firstirq = 0; char reasonline[128]; int i = 0; - while (fgets(reasonline, sizeof(reasonline), fp) != NULL && i < numOut) { + while (fgets(reasonline, sizeof(reasonline), fp) != NULL) { char* pos = reasonline; char* endPos; - // First field is the index. + int len; + // First field is the index or 'Abort'. int irq = (int)strtol(pos, &endPos, 10); - if (pos == endPos) { - // Ooops. - ALOGE("Bad reason line: %s", reasonline); - continue; + if (pos != endPos) { + // Write the irq number to the merged reason string. + len = snprintf(mergedreasonpos, remainreasonlen, i == 0 ? "%d" : ":%d", irq); + } else { + // The first field is not an irq, it may be the word Abort. + const size_t abortPrefixLen = strlen("Abort:"); + if (strncmp(pos, "Abort:", abortPrefixLen) != 0) { + // Ooops. + ALOGE("Bad reason line: %s", reasonline); + continue; + } + + // Write 'Abort' to the merged reason string. + len = snprintf(mergedreasonpos, remainreasonlen, i == 0 ? "Abort" : ":Abort"); + endPos = pos + abortPrefixLen; } pos = endPos; + + if (len >= 0 && len < remainreasonlen) { + mergedreasonpos += len; + remainreasonlen -= len; + } + // Skip whitespace; rest of the buffer is the reason string. while (*pos == ' ') { pos++; } + // Chop newline at end. char* endpos = pos; while (*endpos != 0) { @@ -135,38 +149,17 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs, } endpos++; } - // For now we are not separating out the first irq. - // This is because in practice there are always multiple - // lines of wakeup reasons, so it is better to just treat - // them all together as a single string. - if (false && i == 0) { - firstirq = irq; - } else { - int len = snprintf(mergedreasonpos, remainreasonlen, - i == 0 ? "%d" : ":%d", irq); - if (len >= 0 && len < remainreasonlen) { - mergedreasonpos += len; - remainreasonlen -= len; - } - } - int len = snprintf(mergedreasonpos, remainreasonlen, ":%s", pos); + + len = snprintf(mergedreasonpos, remainreasonlen, ":%s", pos); if (len >= 0 && len < remainreasonlen) { mergedreasonpos += len; remainreasonlen -= len; } - // For now it is better to combine all of these in to one entry in the - // battery history. In the future, it might be nice to figure out a way - // to efficiently store multiple lines as a single entry in the history. - //irqs[i] = irq; - //ScopedLocalRef<jstring> reasonString(env, env->NewStringUTF(pos)); - //env->SetObjectArrayElement(outReasons, i, reasonString.get()); - //ALOGV("Wakeup reason #%d: irw %d reason %s", i, irq, pos); i++; } ALOGV("Got %d reasons", i); if (i > 0) { - irqs[0] = firstirq; *mergedreasonpos = 0; ScopedLocalRef<jstring> reasonString(env, env->NewStringUTF(mergedreason)); env->SetObjectArrayElement(outReasons, 0, reasonString.get()); @@ -182,7 +175,7 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs, } static JNINativeMethod method_table[] = { - { "nativeWaitWakeup", "([I[Ljava/lang/String;)I", (void*)nativeWaitWakeup }, + { "nativeWaitWakeup", "([Ljava/lang/String;)I", (void*)nativeWaitWakeup }, }; int register_android_server_BatteryStatsService(JNIEnv *env) |