Merge "BatteryStats: Record suspend abort reasons" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e69e4e1a3a
@@ -864,8 +864,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class WakeupReasonThread extends Thread {
|
final class WakeupReasonThread extends Thread {
|
||||||
final int[] mIrqs = new int[32];
|
final String[] mReason = new String[1];
|
||||||
final String[] mReasons = new String[32];
|
|
||||||
|
|
||||||
WakeupReasonThread() {
|
WakeupReasonThread() {
|
||||||
super("BatteryStats_wakeupReason");
|
super("BatteryStats_wakeupReason");
|
||||||
@@ -876,12 +875,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int num;
|
int num;
|
||||||
while ((num=nativeWaitWakeup(mIrqs, mReasons)) >= 0) {
|
while ((num = nativeWaitWakeup(mReason)) >= 0) {
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
|
// num will be either 0 or 1.
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
for (int i=0; i<num; i++) {
|
mStats.noteWakeupReasonLocked(mReason[0]);
|
||||||
mStats.noteWakeupReasonLocked(mReasons[i]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mStats.noteWakeupReasonLocked("unknown");
|
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) {
|
private void dumpHelp(PrintWriter pw) {
|
||||||
pw.println("Battery stats (batterystats) dump options:");
|
pw.println("Battery stats (batterystats) dump options:");
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ namespace android
|
|||||||
static bool wakeup_init = false;
|
static bool wakeup_init = false;
|
||||||
static sem_t wakeup_sem;
|
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);
|
int ret = sem_post(&wakeup_sem);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
char buf[80];
|
char buf[80];
|
||||||
@@ -59,10 +59,9 @@ static void wakeup_callback(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs,
|
static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jobjectArray outReasons)
|
||||||
jobjectArray outReasons)
|
|
||||||
{
|
{
|
||||||
if (outIrqs == NULL || outReasons == NULL) {
|
if (outReasons == NULL) {
|
||||||
jniThrowException(env, "java/lang/NullPointerException", "null argument");
|
jniThrowException(env, "java/lang/NullPointerException", "null argument");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -100,32 +99,47 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numOut = env->GetArrayLength(outIrqs);
|
ALOGV("Reading wakeup reasons");
|
||||||
ScopedIntArrayRW irqs(env, outIrqs);
|
|
||||||
|
|
||||||
ALOGV("Reading up to %d wakeup reasons", numOut);
|
|
||||||
|
|
||||||
char mergedreason[MAX_REASON_SIZE];
|
char mergedreason[MAX_REASON_SIZE];
|
||||||
char* mergedreasonpos = mergedreason;
|
char* mergedreasonpos = mergedreason;
|
||||||
int remainreasonlen = MAX_REASON_SIZE;
|
int remainreasonlen = MAX_REASON_SIZE;
|
||||||
int firstirq = 0;
|
|
||||||
char reasonline[128];
|
char reasonline[128];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (fgets(reasonline, sizeof(reasonline), fp) != NULL && i < numOut) {
|
while (fgets(reasonline, sizeof(reasonline), fp) != NULL) {
|
||||||
char* pos = reasonline;
|
char* pos = reasonline;
|
||||||
char* endPos;
|
char* endPos;
|
||||||
// First field is the index.
|
int len;
|
||||||
|
// First field is the index or 'Abort'.
|
||||||
int irq = (int)strtol(pos, &endPos, 10);
|
int irq = (int)strtol(pos, &endPos, 10);
|
||||||
if (pos == endPos) {
|
if (pos != endPos) {
|
||||||
// Ooops.
|
// Write the irq number to the merged reason string.
|
||||||
ALOGE("Bad reason line: %s", reasonline);
|
len = snprintf(mergedreasonpos, remainreasonlen, i == 0 ? "%d" : ":%d", irq);
|
||||||
continue;
|
} 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;
|
pos = endPos;
|
||||||
|
|
||||||
|
if (len >= 0 && len < remainreasonlen) {
|
||||||
|
mergedreasonpos += len;
|
||||||
|
remainreasonlen -= len;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip whitespace; rest of the buffer is the reason string.
|
// Skip whitespace; rest of the buffer is the reason string.
|
||||||
while (*pos == ' ') {
|
while (*pos == ' ') {
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chop newline at end.
|
// Chop newline at end.
|
||||||
char* endpos = pos;
|
char* endpos = pos;
|
||||||
while (*endpos != 0) {
|
while (*endpos != 0) {
|
||||||
@@ -135,38 +149,17 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs,
|
|||||||
}
|
}
|
||||||
endpos++;
|
endpos++;
|
||||||
}
|
}
|
||||||
// For now we are not separating out the first irq.
|
|
||||||
// This is because in practice there are always multiple
|
len = snprintf(mergedreasonpos, remainreasonlen, ":%s", pos);
|
||||||
// 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);
|
|
||||||
if (len >= 0 && len < remainreasonlen) {
|
if (len >= 0 && len < remainreasonlen) {
|
||||||
mergedreasonpos += len;
|
mergedreasonpos += len;
|
||||||
remainreasonlen -= 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++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALOGV("Got %d reasons", i);
|
ALOGV("Got %d reasons", i);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
irqs[0] = firstirq;
|
|
||||||
*mergedreasonpos = 0;
|
*mergedreasonpos = 0;
|
||||||
ScopedLocalRef<jstring> reasonString(env, env->NewStringUTF(mergedreason));
|
ScopedLocalRef<jstring> reasonString(env, env->NewStringUTF(mergedreason));
|
||||||
env->SetObjectArrayElement(outReasons, 0, reasonString.get());
|
env->SetObjectArrayElement(outReasons, 0, reasonString.get());
|
||||||
@@ -182,7 +175,7 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jintArray outIrqs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod method_table[] = {
|
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)
|
int register_android_server_BatteryStatsService(JNIEnv *env)
|
||||||
|
|||||||
Reference in New Issue
Block a user