From 350e6dc985d118dd004fca60276e3766eb86d073 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Mon, 18 May 2015 10:48:52 -0700 Subject: Add Debug.MemoryInfo.getMemoryStats API. The initial list of supported memory stats is: summary.java-heap summary.native-heap summary.code summary.stack summary.graphics summary.private-other summary.system summary.total-pss summary.total-swap Bug: 21266903 Change-Id: Ic3b0e16a8eca4325f3738c389f069933618f66b0 --- api/current.txt | 2 + api/system-current.txt | 2 + core/java/android/os/Debug.java | 127 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/api/current.txt b/api/current.txt index 39444bc..bc26f69 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22861,6 +22861,8 @@ package android.os { public static class Debug.MemoryInfo implements android.os.Parcelable { ctor public Debug.MemoryInfo(); method public int describeContents(); + method public java.lang.String getMemoryStat(java.lang.String); + method public java.util.Map getMemoryStats(); method public int getTotalPrivateClean(); method public int getTotalPrivateDirty(); method public int getTotalPss(); diff --git a/api/system-current.txt b/api/system-current.txt index d75a9a0..d5faac6 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24772,6 +24772,8 @@ package android.os { public static class Debug.MemoryInfo implements android.os.Parcelable { ctor public Debug.MemoryInfo(); method public int describeContents(); + method public java.lang.String getMemoryStat(java.lang.String); + method public java.util.Map getMemoryStats(); method public int getTotalPrivateClean(); method public int getTotalPrivateDirty(); method public int getTotalPss(); diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 19c8fa9..87e8c5e 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -34,6 +34,7 @@ import java.lang.annotation.Target; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.HashMap; import java.util.Map; import org.apache.harmony.dalvik.ddmc.Chunk; @@ -389,6 +390,132 @@ public final class Debug } } + /** + * Returns the value of a particular memory statistic or {@code null} if no + * such memory statistic exists. + * + *

The following table lists the memory statistics that are supported. + * Note that memory statistics may be added or removed in a future API level.

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Memory statistic nameMeaningExampleSupported (API Levels)
summary.java-heapThe private Java Heap usage in kB. This corresponds to the Java Heap field + * in the App Summary section output by dumpsys meminfo.{@code 1442}23
summary.native-heapThe private Native Heap usage in kB. This corresponds to the Native Heap + * field in the App Summary section output by dumpsys meminfo.{@code 1442}23
summary.codeThe memory usage for static code and resources in kB. This corresponds to + * the Code field in the App Summary section output by dumpsys meminfo.{@code 1442}23
summary.stackThe stack usage in kB. This corresponds to the Stack field in the + * App Summary section output by dumpsys meminfo.{@code 1442}23
summary.graphicsThe graphics usage in kB. This corresponds to the Graphics field in the + * App Summary section output by dumpsys meminfo.{@code 1442}23
summary.private-otherOther private memory usage in kB. This corresponds to the Private Other + * field output in the App Summary section by dumpsys meminfo.{@code 1442}23
summary.systemShared and system memory usage in kB. This corresponds to the System + * field output in the App Summary section by dumpsys meminfo.{@code 1442}23
summary.total-pssTotal PPS memory usage in kB.{@code 1442}23
summary.total-swapTotal swap usage in kB.{@code 1442}23
+ */ + public String getMemoryStat(String statName) { + switch(statName) { + case "summary.java-heap": + return Integer.toString(getSummaryJavaHeap()); + case "summary.native-heap": + return Integer.toString(getSummaryNativeHeap()); + case "summary.code": + return Integer.toString(getSummaryCode()); + case "summary.stack": + return Integer.toString(getSummaryStack()); + case "summary.graphics": + return Integer.toString(getSummaryGraphics()); + case "summary.private-other": + return Integer.toString(getSummaryPrivateOther()); + case "summary.system": + return Integer.toString(getSummarySystem()); + case "summary.total-pss": + return Integer.toString(getSummaryTotalPss()); + case "summary.total-swap": + return Integer.toString(getSummaryTotalSwap()); + default: + return null; + } + } + + /** + * Returns a map of the names/values of the memory statistics + * that {@link #getMemoryStat(String)} supports. + * + * @return a map of the names/values of the supported memory statistics. + */ + public Map getMemoryStats() { + Map stats = new HashMap(); + stats.put("summary.java-heap", Integer.toString(getSummaryJavaHeap())); + stats.put("summary.native-heap", Integer.toString(getSummaryNativeHeap())); + stats.put("summary.code", Integer.toString(getSummaryCode())); + stats.put("summary.stack", Integer.toString(getSummaryStack())); + stats.put("summary.graphics", Integer.toString(getSummaryGraphics())); + stats.put("summary.private-other", Integer.toString(getSummaryPrivateOther())); + stats.put("summary.system", Integer.toString(getSummarySystem())); + stats.put("summary.total-pss", Integer.toString(getSummaryTotalPss())); + stats.put("summary.total-swap", Integer.toString(getSummaryTotalSwap())); + return stats; + } + /** * Pss of Java Heap bytes in KB due to the application. * Notes: -- cgit v1.1