Print out memory info when we get into a low memory situation.
Change-Id: I2c8b8847a0f38135d8bf9ff9b7198517c3b0262e
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 0d6f405..2a867af 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -120,6 +120,7 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
@@ -128,8 +129,10 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.lang.IllegalStateException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -844,9 +847,11 @@
static final int SHOW_COMPAT_MODE_DIALOG_MSG = 30;
static final int DISPATCH_FOREGROUND_ACTIVITIES_CHANGED = 31;
static final int DISPATCH_PROCESS_DIED = 32;
+ static final int REPORT_MEM_USAGE = 33;
AlertDialog mUidAlert;
CompatModeDialog mCompatModeDialog;
+ long mLastMemUsageReportTime = 0;
final Handler mHandler = new Handler() {
//public Handler() {
@@ -1186,6 +1191,56 @@
dispatchProcessDied(pid, uid);
break;
}
+ case REPORT_MEM_USAGE: {
+ boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+ if (!isDebuggable) {
+ return;
+ }
+ synchronized (ActivityManagerService.this) {
+ long now = SystemClock.uptimeMillis();
+ if (now < (mLastMemUsageReportTime+10000)) {
+ // Don't report more than every 10 seconds to somewhat
+ // avoid spamming.
+ return;
+ }
+ mLastMemUsageReportTime = now;
+ }
+ Thread thread = new Thread() {
+ @Override public void run() {
+ try {
+ java.lang.Process proc = Runtime.getRuntime().exec(new String[] {
+ "procrank", });
+ final InputStreamReader converter = new InputStreamReader(
+ proc.getInputStream());
+ BufferedReader in = new BufferedReader(converter);
+ String line;
+ while (true) {
+ line = in.readLine();
+ if (line == null) {
+ break;
+ }
+ if (line.length() > 0) {
+ Slog.i(TAG, line);
+ }
+ }
+ converter.close();
+ } catch (IOException e) {
+ }
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ dumpApplicationMemoryUsage(null, pw, " ", new String[] { }, true);
+ Slog.i(TAG, sw.toString());
+ synchronized (ActivityManagerService.this) {
+ long now = SystemClock.uptimeMillis();
+ if (mLastMemUsageReportTime < now) {
+ mLastMemUsageReportTime = now;
+ }
+ }
+ }
+ };
+ thread.start();
+ break;
+ }
}
}
};
@@ -1326,7 +1381,7 @@
return;
}
- mActivityManagerService.dumpApplicationMemoryUsage(fd, pw, " ", args);
+ mActivityManagerService.dumpApplicationMemoryUsage(fd, pw, " ", args, false);
}
}
@@ -2755,6 +2810,7 @@
addProcessToGcListLocked(rec);
}
}
+ mHandler.sendEmptyMessage(REPORT_MEM_USAGE);
scheduleAppGcsLocked();
}
}
@@ -9216,7 +9272,7 @@
}
final void dumpApplicationMemoryUsage(FileDescriptor fd,
- PrintWriter pw, String prefix, String[] args) {
+ PrintWriter pw, String prefix, String[] args, boolean brief) {
boolean dumpAll = false;
int opti = 0;
@@ -9354,15 +9410,19 @@
}
}
- pw.println();
- pw.println("Total PSS by process:");
- dumpMemItems(pw, " ", procMems, true);
- pw.println();
+ if (!brief) {
+ pw.println();
+ pw.println("Total PSS by process:");
+ dumpMemItems(pw, " ", procMems, true);
+ pw.println();
+ }
pw.println("Total PSS by OOM adjustment:");
dumpMemItems(pw, " ", oomMems, false);
- pw.println();
- pw.println("Total PSS by category:");
- dumpMemItems(pw, " ", catMems, true);
+ if (!brief) {
+ pw.println();
+ pw.println("Total PSS by category:");
+ dumpMemItems(pw, " ", catMems, true);
+ }
pw.println();
pw.print("Total PSS: "); pw.print(totalPss); pw.println(" Kb");
}