summaryrefslogtreecommitdiffstats
path: root/core/java/android/util
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-03-03 17:04:12 -0800
committerDianne Hackborn <hackbod@google.com>2015-03-06 16:42:03 -0800
commitb9a5e4ad30c9add140fd13491419ae66e947809d (patch)
tree34000ecab4b9ef4175687e1cba78456524481a0f /core/java/android/util
parenteb803aef3b0f55785624e6a51deae867c1a95e88 (diff)
downloadframeworks_base-b9a5e4ad30c9add140fd13491419ae66e947809d.zip
frameworks_base-b9a5e4ad30c9add140fd13491419ae66e947809d.tar.gz
frameworks_base-b9a5e4ad30c9add140fd13491419ae66e947809d.tar.bz2
Add new debug feature to automatically create heap dumps.
Not yet working, unless you turn off SELinux enforcing. We need to update SElinux to allow the system process to give apps access to /data/system/heapdump/javaheap.bin. Currently watching can only be enabled through the shell, such as: adb shell am set-watch-heap com.android.systemui 1024 The last number is the process pss size in bytes, so this is asking us to warn if it goes about 1K which will be all the time. Change-Id: I2089e5db2927afca0bf01a363c6247ee5dcb26e8
Diffstat (limited to 'core/java/android/util')
-rw-r--r--core/java/android/util/DebugUtils.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/core/java/android/util/DebugUtils.java b/core/java/android/util/DebugUtils.java
index f607207..84d9ce8 100644
--- a/core/java/android/util/DebugUtils.java
+++ b/core/java/android/util/DebugUtils.java
@@ -16,6 +16,7 @@
package android.util;
+import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
@@ -123,4 +124,83 @@ public class DebugUtils {
}
}
+ /** @hide */
+ public static void printSizeValue(PrintWriter pw, long number) {
+ float result = number;
+ String suffix = "";
+ if (result > 900) {
+ suffix = "KB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "MB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "GB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "TB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "PB";
+ result = result / 1024;
+ }
+ String value;
+ if (result < 1) {
+ value = String.format("%.2f", result);
+ } else if (result < 10) {
+ value = String.format("%.1f", result);
+ } else if (result < 100) {
+ value = String.format("%.0f", result);
+ } else {
+ value = String.format("%.0f", result);
+ }
+ pw.print(value);
+ pw.print(suffix);
+ }
+
+ /** @hide */
+ public static String sizeValueToString(long number, StringBuilder outBuilder) {
+ if (outBuilder == null) {
+ outBuilder = new StringBuilder(32);
+ }
+ float result = number;
+ String suffix = "";
+ if (result > 900) {
+ suffix = "KB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "MB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "GB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "TB";
+ result = result / 1024;
+ }
+ if (result > 900) {
+ suffix = "PB";
+ result = result / 1024;
+ }
+ String value;
+ if (result < 1) {
+ value = String.format("%.2f", result);
+ } else if (result < 10) {
+ value = String.format("%.1f", result);
+ } else if (result < 100) {
+ value = String.format("%.0f", result);
+ } else {
+ value = String.format("%.0f", result);
+ }
+ outBuilder.append(value);
+ outBuilder.append(suffix);
+ return outBuilder.toString();
+ }
}