diff --git a/api/current.txt b/api/current.txt index 0214001dd4a94..58ecc398e2e1a 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22899,6 +22899,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 dc1e1fb2e9e19..e3e178747a602 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24817,6 +24817,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 19c8fa9da1f98..87e8c5e6f8ee5 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: