Loading services/core/java/com/android/server/MemoryPressureUtil.java→services/core/java/com/android/server/ResourcePressureUtil.java +78 −0 Original line number Diff line number Diff line Loading @@ -24,33 +24,55 @@ import libcore.io.IoUtils; import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; import java.util.List; /** * Utility method for memory pressure (PSI). * Utility method for resource pressure (PSI). */ public final class MemoryPressureUtil { private static final String FILE = "/proc/pressure/memory"; private static final String TAG = "MemoryPressure"; public final class ResourcePressureUtil { private static final String PSI_ROOT = "/proc/pressure"; private static final String TAG = "ResourcePressureUtil"; private static final List<String> PSI_FILES = Arrays.asList( PSI_ROOT + "/memory", PSI_ROOT + "/cpu", PSI_ROOT + "/io" ); private static String readResourcePsiState(String filePath) { StringWriter contents = new StringWriter(); try { if (new File(filePath).exists()) { contents.append("----- Output from " + filePath + " -----\n"); contents.append(IoUtils.readFileAsString(filePath)); contents.append("----- End output from " + filePath + " -----\n"); } } catch (IOException e) { Slog.e(TAG, " could not read " + filePath, e); } return contents.toString(); } /** * @return a stanza about memory PSI to add to a report. * @return a stanza about PSI to add to a report. */ public static String currentPsiState() { final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); StringWriter contents = new StringWriter(); StringWriter aggregatedState = new StringWriter(); try { if (new File(FILE).exists()) { contents.append("----- Output from /proc/pressure/memory -----\n"); contents.append(IoUtils.readFileAsString(FILE)); contents.append("----- End output from /proc/pressure/memory -----\n\n"); } } catch (IOException e) { Slog.e(TAG, "Could not read " + FILE, e); PSI_FILES.stream() .map(ResourcePressureUtil::readResourcePsiState) .forEach(aggregatedState::append); } finally { StrictMode.setThreadPolicy(savedPolicy); } return contents.toString(); String psiState = aggregatedState.toString(); return psiState.length() > 0 ? psiState + "\n" : psiState; } private MemoryPressureUtil(){} private ResourcePressureUtil(){} } services/core/java/com/android/server/Watchdog.java +1 −1 Original line number Diff line number Diff line Loading @@ -885,7 +885,7 @@ public class Watchdog implements Dumpable { long anrTime = SystemClock.uptimeMillis(); StringBuilder report = new StringBuilder(); report.append(MemoryPressureUtil.currentPsiState()); report.append(ResourcePressureUtil.currentPsiState()); ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(false); StringWriter tracesFileException = new StringWriter(); final File stack = ActivityManagerService.dumpStackTraces( Loading services/core/java/com/android/server/am/ProcessErrorStateRecord.java +2 −2 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.ProcessCpuTracker; import com.android.internal.util.FrameworkStatsLog; import com.android.server.MemoryPressureUtil; import com.android.server.ResourcePressureUtil; import com.android.server.criticalevents.CriticalEventLog; import com.android.server.wm.WindowProcessController; Loading Loading @@ -402,7 +402,7 @@ class ProcessErrorStateRecord { } StringBuilder report = new StringBuilder(); report.append(MemoryPressureUtil.currentPsiState()); report.append(ResourcePressureUtil.currentPsiState()); ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); // don't dump native PIDs for background ANRs unless it is the process of interest Loading Loading
services/core/java/com/android/server/MemoryPressureUtil.java→services/core/java/com/android/server/ResourcePressureUtil.java +78 −0 Original line number Diff line number Diff line Loading @@ -24,33 +24,55 @@ import libcore.io.IoUtils; import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; import java.util.List; /** * Utility method for memory pressure (PSI). * Utility method for resource pressure (PSI). */ public final class MemoryPressureUtil { private static final String FILE = "/proc/pressure/memory"; private static final String TAG = "MemoryPressure"; public final class ResourcePressureUtil { private static final String PSI_ROOT = "/proc/pressure"; private static final String TAG = "ResourcePressureUtil"; private static final List<String> PSI_FILES = Arrays.asList( PSI_ROOT + "/memory", PSI_ROOT + "/cpu", PSI_ROOT + "/io" ); private static String readResourcePsiState(String filePath) { StringWriter contents = new StringWriter(); try { if (new File(filePath).exists()) { contents.append("----- Output from " + filePath + " -----\n"); contents.append(IoUtils.readFileAsString(filePath)); contents.append("----- End output from " + filePath + " -----\n"); } } catch (IOException e) { Slog.e(TAG, " could not read " + filePath, e); } return contents.toString(); } /** * @return a stanza about memory PSI to add to a report. * @return a stanza about PSI to add to a report. */ public static String currentPsiState() { final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); StringWriter contents = new StringWriter(); StringWriter aggregatedState = new StringWriter(); try { if (new File(FILE).exists()) { contents.append("----- Output from /proc/pressure/memory -----\n"); contents.append(IoUtils.readFileAsString(FILE)); contents.append("----- End output from /proc/pressure/memory -----\n\n"); } } catch (IOException e) { Slog.e(TAG, "Could not read " + FILE, e); PSI_FILES.stream() .map(ResourcePressureUtil::readResourcePsiState) .forEach(aggregatedState::append); } finally { StrictMode.setThreadPolicy(savedPolicy); } return contents.toString(); String psiState = aggregatedState.toString(); return psiState.length() > 0 ? psiState + "\n" : psiState; } private MemoryPressureUtil(){} private ResourcePressureUtil(){} }
services/core/java/com/android/server/Watchdog.java +1 −1 Original line number Diff line number Diff line Loading @@ -885,7 +885,7 @@ public class Watchdog implements Dumpable { long anrTime = SystemClock.uptimeMillis(); StringBuilder report = new StringBuilder(); report.append(MemoryPressureUtil.currentPsiState()); report.append(ResourcePressureUtil.currentPsiState()); ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(false); StringWriter tracesFileException = new StringWriter(); final File stack = ActivityManagerService.dumpStackTraces( Loading
services/core/java/com/android/server/am/ProcessErrorStateRecord.java +2 −2 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.ProcessCpuTracker; import com.android.internal.util.FrameworkStatsLog; import com.android.server.MemoryPressureUtil; import com.android.server.ResourcePressureUtil; import com.android.server.criticalevents.CriticalEventLog; import com.android.server.wm.WindowProcessController; Loading Loading @@ -402,7 +402,7 @@ class ProcessErrorStateRecord { } StringBuilder report = new StringBuilder(); report.append(MemoryPressureUtil.currentPsiState()); report.append(ResourcePressureUtil.currentPsiState()); ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true); // don't dump native PIDs for background ANRs unless it is the process of interest Loading