diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2015-04-02 12:07:36 -0700 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2015-04-13 16:21:38 -0700 |
commit | 1e698ad6f85699dc756bc208bc4566f67c8f9717 (patch) | |
tree | 4c030021395d5df3401167004b5924bb9035aba6 | |
parent | 5b398cacaaf6deafed24cf8b851ee5d5b5b6473f (diff) | |
download | libcore-1e698ad6f85699dc756bc208bc4566f67c8f9717.zip libcore-1e698ad6f85699dc756bc208bc4566f67c8f9717.tar.gz libcore-1e698ad6f85699dc756bc208bc4566f67c8f9717.tar.bz2 |
getRuntimeStat() support (libcore).
Export some runtime stats (currently GC stats) via
VMDebug.getRuntimeStat().
Bug: 19825248
Change-Id: I135b45134c143df28377ef512295570ad42698ae
-rw-r--r-- | dalvik/src/main/java/dalvik/system/VMDebug.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/VMDebug.java b/dalvik/src/main/java/dalvik/system/VMDebug.java index 4b606e6..59e28e2 100644 --- a/dalvik/src/main/java/dalvik/system/VMDebug.java +++ b/dalvik/src/main/java/dalvik/system/VMDebug.java @@ -18,6 +18,8 @@ package dalvik.system; import java.io.FileDescriptor; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; /** * Provides access to some VM-specific debug features. Though this class and @@ -389,4 +391,57 @@ public final class VMDebug { * @param data the array into which the stats are written. */ public static native void getHeapSpaceStats(long[] data); + + /* Map from the names of the runtime stats supported by getRuntimeStat() to their IDs */ + private static final HashMap<String, Integer> runtimeStatsMap = new HashMap<>(); + + static { + runtimeStatsMap.put("art.gc.gc-count", 0); + runtimeStatsMap.put("art.gc.gc-time", 1); + runtimeStatsMap.put("art.gc.bytes-allocated", 2); + runtimeStatsMap.put("art.gc.bytes-freed", 3); + runtimeStatsMap.put("art.gc.blocking-gc-count", 4); + runtimeStatsMap.put("art.gc.blocking-gc-time", 5); + runtimeStatsMap.put("art.gc.gc-count-rate-histogram", 6); + runtimeStatsMap.put("art.gc.blocking-gc-count-rate-histogram", 7); + } + + /** + * Returns the value of a particular runtime statistic or {@code null} if no + * such runtime statistic exists. + * + * @param statName + * the name of the runtime statistic to look up. + * @return the value of the runtime statistic. + */ + public static String getRuntimeStat(String statName) { + if (statName == null) { + throw new NullPointerException("statName == null"); + } + Integer statId = runtimeStatsMap.get(statName); + if (statId != null) { + return getRuntimeStatInternal(statId); + } + return null; + } + + /** + * Returns a map of the names/values of the runtime statistics + * that {@link #getRuntimeStat()} supports. + * + * @return a map of the names/values of the supported runtime statistics. + */ + public static Map<String, String> getRuntimeStats() { + HashMap<String, String> map = new HashMap<>(); + String[] values = getRuntimeStatsInternal(); + for (String name : runtimeStatsMap.keySet()) { + int id = runtimeStatsMap.get(name); + String value = values[id]; + map.put(name, value); + } + return map; + } + + private static native String getRuntimeStatInternal(int statId); + private static native String[] getRuntimeStatsInternal(); } |