From e17b445b6c813f6f9bc93a5e3811128a197ef50b Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 10 Jan 2018 13:15:40 -0800 Subject: Reduce pss collection amount, improve logging. Tuned rates that we collect PSS, to reduce how much we do that heavy operation. Added a new way to determine whether a process has changed to a state for the "first" time -- now this is when it has gone to that state for the first time since it was in a lower state. This will reduce the amount of time we consider a process to be first to only when it has previously gone into a higher state than it had before. Keep track of more fine-grained information about why we collect a PSS sample (not just internal, but for a single process, all processes because of a mem state change, all processes because of a poll). Started collecting RSS in various places, so we can start looking at that w.r.t. PSS and see about transitioning to it is a new primary metric. Added logging for many of the places where the system writes its configuration files, so we can more easily see any bad behavior going on in those areas. Added some currently disabled code to read smaps directly instead of using fgets(). Probably won't help, but want tot test. Bug: 70859548 Test: atest CtsAppTestCases Change-Id: I400dba0f3ae9c024df51c946cfa592561028b598 --- core/java/android/os/Debug.java | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'core/java/android/os/Debug.java') diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 33e8c3e47b44..6599391fe1c9 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -116,6 +116,8 @@ public final class Debug /** The proportional set size that is swappable for dalvik heap. */ /** @hide We may want to expose this, eventually. */ public int dalvikSwappablePss; + /** @hide The resident set size for dalvik heap. (Without other Dalvik overhead.) */ + public int dalvikRss; /** The private dirty pages used by dalvik heap. */ public int dalvikPrivateDirty; /** The shared dirty pages used by dalvik heap. */ @@ -138,6 +140,8 @@ public final class Debug /** The proportional set size that is swappable for the native heap. */ /** @hide We may want to expose this, eventually. */ public int nativeSwappablePss; + /** @hide The resident set size for the native heap. */ + public int nativeRss; /** The private dirty pages used by the native heap. */ public int nativePrivateDirty; /** The shared dirty pages used by the native heap. */ @@ -160,6 +164,8 @@ public final class Debug /** The proportional set size that is swappable for everything else. */ /** @hide We may want to expose this, eventually. */ public int otherSwappablePss; + /** @hide The resident set size for everything else. */ + public int otherRss; /** The private dirty pages used by everything else. */ public int otherPrivateDirty; /** The shared dirty pages used by everything else. */ @@ -288,24 +294,26 @@ public final class Debug public static final int NUM_DVK_STATS = 14; /** @hide */ - public static final int NUM_CATEGORIES = 8; + public static final int NUM_CATEGORIES = 9; /** @hide */ - public static final int offsetPss = 0; + public static final int OFFSET_PSS = 0; /** @hide */ - public static final int offsetSwappablePss = 1; + public static final int OFFSET_SWAPPABLE_PSS = 1; /** @hide */ - public static final int offsetPrivateDirty = 2; + public static final int OFFSET_RSS = 2; /** @hide */ - public static final int offsetSharedDirty = 3; + public static final int OFFSET_PRIVATE_DIRTY = 3; /** @hide */ - public static final int offsetPrivateClean = 4; + public static final int OFFSET_SHARED_DIRTY = 4; /** @hide */ - public static final int offsetSharedClean = 5; + public static final int OFFSET_PRIVATE_CLEAN = 5; /** @hide */ - public static final int offsetSwappedOut = 6; + public static final int OFFSET_SHARED_CLEAN = 6; /** @hide */ - public static final int offsetSwappedOutPss = 7; + public static final int OFFSET_SWAPPED_OUT = 7; + /** @hide */ + public static final int OFFSET_SWAPPED_OUT_PSS = 8; private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES]; @@ -336,6 +344,13 @@ public final class Debug return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss; } + /** + * @hide Return total RSS memory usage in kB. + */ + public int getTotalRss() { + return dalvikRss + nativeRss + otherRss; + } + /** * Return total private dirty memory usage in kB. */ @@ -382,29 +397,32 @@ public final class Debug /** @hide */ public int getOtherPss(int which) { - return otherStats[which*NUM_CATEGORIES + offsetPss]; + return otherStats[which * NUM_CATEGORIES + OFFSET_PSS]; } - /** @hide */ public int getOtherSwappablePss(int which) { - return otherStats[which*NUM_CATEGORIES + offsetSwappablePss]; + return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPABLE_PSS]; } + /** @hide */ + public int getOtherRss(int which) { + return otherStats[which * NUM_CATEGORIES + OFFSET_RSS]; + } /** @hide */ public int getOtherPrivateDirty(int which) { - return otherStats[which*NUM_CATEGORIES + offsetPrivateDirty]; + return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_DIRTY]; } /** @hide */ public int getOtherSharedDirty(int which) { - return otherStats[which*NUM_CATEGORIES + offsetSharedDirty]; + return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_DIRTY]; } /** @hide */ public int getOtherPrivateClean(int which) { - return otherStats[which*NUM_CATEGORIES + offsetPrivateClean]; + return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_CLEAN]; } /** @hide */ @@ -414,17 +432,17 @@ public final class Debug /** @hide */ public int getOtherSharedClean(int which) { - return otherStats[which*NUM_CATEGORIES + offsetSharedClean]; + return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_CLEAN]; } /** @hide */ public int getOtherSwappedOut(int which) { - return otherStats[which*NUM_CATEGORIES + offsetSwappedOut]; + return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT]; } /** @hide */ public int getOtherSwappedOutPss(int which) { - return otherStats[which*NUM_CATEGORIES + offsetSwappedOutPss]; + return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT_PSS]; } /** @hide */ @@ -741,6 +759,7 @@ public final class Debug public void writeToParcel(Parcel dest, int flags) { dest.writeInt(dalvikPss); dest.writeInt(dalvikSwappablePss); + dest.writeInt(dalvikRss); dest.writeInt(dalvikPrivateDirty); dest.writeInt(dalvikSharedDirty); dest.writeInt(dalvikPrivateClean); @@ -749,6 +768,7 @@ public final class Debug dest.writeInt(dalvikSwappedOutPss); dest.writeInt(nativePss); dest.writeInt(nativeSwappablePss); + dest.writeInt(nativeRss); dest.writeInt(nativePrivateDirty); dest.writeInt(nativeSharedDirty); dest.writeInt(nativePrivateClean); @@ -757,6 +777,7 @@ public final class Debug dest.writeInt(nativeSwappedOutPss); dest.writeInt(otherPss); dest.writeInt(otherSwappablePss); + dest.writeInt(otherRss); dest.writeInt(otherPrivateDirty); dest.writeInt(otherSharedDirty); dest.writeInt(otherPrivateClean); @@ -770,6 +791,7 @@ public final class Debug public void readFromParcel(Parcel source) { dalvikPss = source.readInt(); dalvikSwappablePss = source.readInt(); + dalvikRss = source.readInt(); dalvikPrivateDirty = source.readInt(); dalvikSharedDirty = source.readInt(); dalvikPrivateClean = source.readInt(); @@ -778,6 +800,7 @@ public final class Debug dalvikSwappedOutPss = source.readInt(); nativePss = source.readInt(); nativeSwappablePss = source.readInt(); + nativeRss = source.readInt(); nativePrivateDirty = source.readInt(); nativeSharedDirty = source.readInt(); nativePrivateClean = source.readInt(); @@ -786,6 +809,7 @@ public final class Debug nativeSwappedOutPss = source.readInt(); otherPss = source.readInt(); otherSwappablePss = source.readInt(); + otherRss = source.readInt(); otherPrivateDirty = source.readInt(); otherSharedDirty = source.readInt(); otherPrivateClean = source.readInt(); -- cgit v1.2.3