Skip to content

Commit 672342c

Browse files
author
Dianne Hackborn
committed
Another attempt at getting OOM reports to batch.
We now generate a stack-trace looking thing at the top of the report. Also fix a bug I hit where the phone window manager was sending a broadcast before the boot had completed. Change-Id: I0cee16180e4d05c9bd3fe715212a28f504ec91ac
1 parent e571552 commit 672342c

File tree

2 files changed

+72
-26
lines changed

2 files changed

+72
-26
lines changed

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3476,7 +3476,8 @@ public void run() {
34763476
}
34773477
if (component != null) {
34783478
// dismiss the notification shade, recents, etc.
3479-
mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
3479+
mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
3480+
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT));
34803481

34813482
ComponentName cn = ComponentName.unflattenFromString(component);
34823483
Intent intent = new Intent(Intent.ACTION_MAIN)

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
import java.io.FileNotFoundException;
130130
import java.io.FileOutputStream;
131131
import java.io.IOException;
132-
import java.io.InputStream;
133132
import java.io.InputStreamReader;
134133
import java.io.PrintWriter;
135134
import java.io.StringWriter;
@@ -1222,6 +1221,23 @@ public void handleMessage(Message msg) {
12221221
@Override public void run() {
12231222
StringBuilder dropBuilder = new StringBuilder(1024);
12241223
StringBuilder logBuilder = new StringBuilder(1024);
1224+
StringWriter oomSw = new StringWriter();
1225+
PrintWriter oomPw = new PrintWriter(oomSw);
1226+
StringWriter catSw = new StringWriter();
1227+
PrintWriter catPw = new PrintWriter(catSw);
1228+
String[] emptyArgs = new String[] { };
1229+
StringBuilder tag = new StringBuilder(128);
1230+
StringBuilder stack = new StringBuilder(128);
1231+
tag.append("Low on memory -- ");
1232+
dumpApplicationMemoryUsage(null, oomPw, " ", emptyArgs, true, catPw,
1233+
tag, stack);
1234+
dropBuilder.append(stack);
1235+
dropBuilder.append('\n');
1236+
dropBuilder.append('\n');
1237+
String oomString = oomSw.toString();
1238+
dropBuilder.append(oomString);
1239+
dropBuilder.append('\n');
1240+
logBuilder.append(oomString);
12251241
try {
12261242
java.lang.Process proc = Runtime.getRuntime().exec(new String[] {
12271243
"procrank", });
@@ -1244,27 +1260,15 @@ public void handleMessage(Message msg) {
12441260
converter.close();
12451261
} catch (IOException e) {
12461262
}
1247-
StringWriter sw = new StringWriter();
1248-
PrintWriter pw = new PrintWriter(sw);
1249-
StringWriter catSw = new StringWriter();
1250-
PrintWriter catPw = new PrintWriter(catSw);
1251-
String[] emptyArgs = new String[] { };
1252-
StringBuilder tag = new StringBuilder(128);
12531263
synchronized (ActivityManagerService.this) {
1264+
catPw.println();
12541265
dumpProcessesLocked(null, catPw, emptyArgs, 0, false, null);
12551266
catPw.println();
12561267
dumpServicesLocked(null, catPw, emptyArgs, 0, false, false, null);
12571268
catPw.println();
12581269
dumpActivitiesLocked(null, catPw, emptyArgs, 0, false, false, null);
1259-
catPw.println();
12601270
}
1261-
tag.append("Low on memory -- ");
1262-
dumpApplicationMemoryUsage(null, pw, " ", emptyArgs, true, catPw, tag);
1263-
String memUsage = sw.toString();
1264-
dropBuilder.append('\n');
1265-
dropBuilder.append(memUsage);
12661271
dropBuilder.append(catSw.toString());
1267-
logBuilder.append(memUsage);
12681272
addErrorToDropBox("lowmem", null, "system_server", null,
12691273
null, tag.toString(), dropBuilder.toString(), null, null);
12701274
Slog.i(TAG, logBuilder.toString());
@@ -1420,7 +1424,7 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
14201424
}
14211425

14221426
mActivityManagerService.dumpApplicationMemoryUsage(fd, pw, " ", args,
1423-
false, null, null);
1427+
false, null, null, null);
14241428
}
14251429
}
14261430

@@ -9416,7 +9420,7 @@ public int compare(Pair<ProcessRecord, Integer> object1,
94169420
} else if (r.setAdj >= ProcessList.SERVICE_ADJ) {
94179421
oomAdj = buildOomTag("svc ", null, r.setAdj, ProcessList.SERVICE_ADJ);
94189422
} else if (r.setAdj >= ProcessList.BACKUP_APP_ADJ) {
9419-
oomAdj = buildOomTag("bckup", null, r.setAdj, ProcessList.BACKUP_APP_ADJ);
9423+
oomAdj = buildOomTag("bkup ", null, r.setAdj, ProcessList.BACKUP_APP_ADJ);
94209424
} else if (r.setAdj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
94219425
oomAdj = buildOomTag("hvy ", null, r.setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ);
94229426
} else if (r.setAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
@@ -9645,7 +9649,8 @@ public int compare(MemItem lhs, MemItem rhs) {
96459649
1*1024*1024, 2*1024*1024, 5*1024*1024, 10*1024*1024, 20*1024*1024
96469650
};
96479651

9648-
static final void appendMemBucket(StringBuilder out, long memKB, String label) {
9652+
static final void appendMemBucket(StringBuilder out, long memKB, String label,
9653+
boolean stackLike) {
96499654
int start = label.lastIndexOf('.');
96509655
if (start >= 0) start++;
96519656
else start = 0;
@@ -9654,13 +9659,13 @@ static final void appendMemBucket(StringBuilder out, long memKB, String label) {
96549659
if (DUMP_MEM_BUCKETS[i] >= memKB) {
96559660
long bucket = DUMP_MEM_BUCKETS[i]/1024;
96569661
out.append(bucket);
9657-
out.append("MB ");
9662+
out.append(stackLike ? "MB." : "MB ");
96589663
out.append(label, start, end);
96599664
return;
96609665
}
96619666
}
96629667
out.append(memKB/1024);
9663-
out.append("MB ");
9668+
out.append(stackLike ? "MB." : "MB ");
96649669
out.append(label, start, end);
96659670
}
96669671

@@ -9679,7 +9684,7 @@ static final void appendMemBucket(StringBuilder out, long memKB, String label) {
96799684

96809685
final void dumpApplicationMemoryUsage(FileDescriptor fd,
96819686
PrintWriter pw, String prefix, String[] args, boolean brief,
9682-
PrintWriter categoryPw, StringBuilder outTag) {
9687+
PrintWriter categoryPw, StringBuilder outTag, StringBuilder outStack) {
96839688
boolean dumpAll = false;
96849689
boolean oomOnly = false;
96859690

@@ -9816,8 +9821,14 @@ final void dumpApplicationMemoryUsage(FileDescriptor fd,
98169821
}
98179822
}
98189823

9819-
if (outTag != null) {
9820-
appendMemBucket(outTag, totalPss, "total");
9824+
if (outTag != null || outStack != null) {
9825+
if (outTag != null) {
9826+
appendMemBucket(outTag, totalPss, "total", false);
9827+
}
9828+
if (outStack != null) {
9829+
appendMemBucket(outStack, totalPss, "total", true);
9830+
}
9831+
boolean firstLine = true;
98219832
for (int i=0; i<oomMems.size(); i++) {
98229833
MemItem miCat = oomMems.get(i);
98239834
if (miCat.subitems == null || miCat.subitems.size() < 1) {
@@ -9826,13 +9837,47 @@ final void dumpApplicationMemoryUsage(FileDescriptor fd,
98269837
if (miCat.id < ProcessList.SERVICE_ADJ
98279838
|| miCat.id == ProcessList.HOME_APP_ADJ
98289839
|| miCat.id == ProcessList.PREVIOUS_APP_ADJ) {
9829-
outTag.append(" / ");
9840+
if (outTag != null && miCat.id <= ProcessList.FOREGROUND_APP_ADJ) {
9841+
outTag.append(" / ");
9842+
}
9843+
if (outStack != null) {
9844+
if (miCat.id >= ProcessList.FOREGROUND_APP_ADJ) {
9845+
if (firstLine) {
9846+
outStack.append(":");
9847+
firstLine = false;
9848+
}
9849+
outStack.append("\n\t at ");
9850+
} else {
9851+
outStack.append("$");
9852+
}
9853+
}
98309854
for (int j=0; j<miCat.subitems.size(); j++) {
98319855
MemItem mi = miCat.subitems.get(j);
98329856
if (j > 0) {
9833-
outTag.append(" ");
9857+
if (outTag != null) {
9858+
outTag.append(" ");
9859+
}
9860+
if (outStack != null) {
9861+
outStack.append("$");
9862+
}
9863+
}
9864+
if (outTag != null && miCat.id <= ProcessList.FOREGROUND_APP_ADJ) {
9865+
appendMemBucket(outTag, mi.pss, mi.shortLabel, false);
9866+
}
9867+
if (outStack != null) {
9868+
appendMemBucket(outStack, mi.pss, mi.shortLabel, true);
9869+
}
9870+
}
9871+
if (outStack != null && miCat.id >= ProcessList.FOREGROUND_APP_ADJ) {
9872+
outStack.append("(");
9873+
for (int k=0; k<DUMP_MEM_OOM_ADJ.length; k++) {
9874+
if (DUMP_MEM_OOM_ADJ[k] == miCat.id) {
9875+
outStack.append(DUMP_MEM_OOM_LABEL[k]);
9876+
outStack.append(":");
9877+
outStack.append(DUMP_MEM_OOM_ADJ[k]);
9878+
}
98349879
}
9835-
appendMemBucket(outTag, mi.pss, mi.shortLabel);
9880+
outStack.append(")");
98369881
}
98379882
}
98389883
}

0 commit comments

Comments
 (0)