The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 19 | import com.android.internal.util.FastPrintWriter; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 20 | import com.android.internal.util.TypedProperties; |
| 21 | |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 22 | import android.util.Log; |
| 23 | |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 24 | import java.io.FileDescriptor; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 25 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import java.io.FileOutputStream; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 27 | import java.io.FileReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import java.io.PrintWriter; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 30 | import java.io.Reader; |
| 31 | import java.lang.reflect.Field; |
| 32 | import java.lang.reflect.Modifier; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 33 | import java.lang.annotation.Target; |
| 34 | import java.lang.annotation.ElementType; |
| 35 | import java.lang.annotation.Retention; |
| 36 | import java.lang.annotation.RetentionPolicy; |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 37 | import java.util.HashMap; |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 38 | import java.util.Map; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | import org.apache.harmony.dalvik.ddmc.Chunk; |
| 41 | import org.apache.harmony.dalvik.ddmc.ChunkHandler; |
| 42 | import org.apache.harmony.dalvik.ddmc.DdmServer; |
| 43 | |
Dan Bornstein | 9f31554 | 2010-11-19 18:12:55 -0800 | [diff] [blame] | 44 | import dalvik.bytecode.OpcodeInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import dalvik.system.VMDebug; |
| 46 | |
| 47 | |
| 48 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 49 | * Provides various debugging methods for Android applications, including |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | * tracing and allocation counts. |
| 51 | * <p><strong>Logging Trace Files</strong></p> |
| 52 | * <p>Debug can create log files that give details about an application, such as |
| 53 | * a call stack and start/stop times for any running methods. See <a |
| 54 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for |
| 55 | * information about reading trace files. To start logging trace files, call one |
| 56 | * of the startMethodTracing() methods. To stop tracing, call |
| 57 | * {@link #stopMethodTracing()}. |
| 58 | */ |
| 59 | public final class Debug |
| 60 | { |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 61 | private static final String TAG = "Debug"; |
| 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | /** |
| 64 | * Flags for startMethodTracing(). These can be ORed together. |
| 65 | * |
| 66 | * TRACE_COUNT_ALLOCS adds the results from startAllocCounting to the |
| 67 | * trace key file. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 68 | * |
| 69 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 71 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | public static final int TRACE_COUNT_ALLOCS = VMDebug.TRACE_COUNT_ALLOCS; |
| 73 | |
| 74 | /** |
| 75 | * Flags for printLoadedClasses(). Default behavior is to only show |
| 76 | * the class name. |
| 77 | */ |
| 78 | public static final int SHOW_FULL_DETAIL = 1; |
| 79 | public static final int SHOW_CLASSLOADER = (1 << 1); |
| 80 | public static final int SHOW_INITIALIZED = (1 << 2); |
| 81 | |
| 82 | // set/cleared by waitForDebugger() |
| 83 | private static volatile boolean mWaiting = false; |
| 84 | |
| 85 | private Debug() {} |
| 86 | |
| 87 | /* |
| 88 | * How long to wait for the debugger to finish sending requests. I've |
| 89 | * seen this hit 800msec on the device while waiting for a response |
| 90 | * to travel over USB and get processed, so we take that and add |
| 91 | * half a second. |
| 92 | */ |
| 93 | private static final int MIN_DEBUGGER_IDLE = 1300; // msec |
| 94 | |
| 95 | /* how long to sleep when polling for activity */ |
| 96 | private static final int SPIN_DELAY = 200; // msec |
| 97 | |
| 98 | /** |
| 99 | * Default trace file path and file |
| 100 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | private static final String DEFAULT_TRACE_BODY = "dmtrace"; |
| 102 | private static final String DEFAULT_TRACE_EXTENSION = ".trace"; |
Andreas Gampe | 8b9f494 | 2016-02-25 18:03:03 -0800 | [diff] [blame] | 103 | private static class NoPreloadHolder { |
| 104 | private static final String DEFAULT_TRACE_PATH_PREFIX = |
| 105 | Environment.getLegacyExternalStorageDirectory().getPath() + "/"; |
| 106 | private static final String DEFAULT_TRACE_FILE_PATH = |
| 107 | DEFAULT_TRACE_PATH_PREFIX + DEFAULT_TRACE_BODY |
| 108 | + DEFAULT_TRACE_EXTENSION; |
| 109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | |
| 112 | /** |
| 113 | * This class is used to retrieved various statistics about the memory mappings for this |
justinmuller | 6455138 | 2013-10-16 22:06:55 -0600 | [diff] [blame] | 114 | * process. The returned info is broken down by dalvik, native, and other. All results are in kB. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | */ |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 116 | public static class MemoryInfo implements Parcelable { |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 117 | /** The proportional set size for dalvik heap. (Doesn't include other Dalvik overhead.) */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | public int dalvikPss; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 119 | /** The proportional set size that is swappable for dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 120 | /** @hide We may want to expose this, eventually. */ |
| 121 | public int dalvikSwappablePss; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 122 | /** The private dirty pages used by dalvik heap. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | public int dalvikPrivateDirty; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 124 | /** The shared dirty pages used by dalvik heap. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | public int dalvikSharedDirty; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 126 | /** The private clean pages used by dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 127 | /** @hide We may want to expose this, eventually. */ |
| 128 | public int dalvikPrivateClean; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 129 | /** The shared clean pages used by dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 130 | /** @hide We may want to expose this, eventually. */ |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 131 | public int dalvikSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 132 | /** The dirty dalvik pages that have been swapped out. */ |
| 133 | /** @hide We may want to expose this, eventually. */ |
| 134 | public int dalvikSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 135 | /** The dirty dalvik pages that have been swapped out, proportional. */ |
| 136 | /** @hide We may want to expose this, eventually. */ |
| 137 | public int dalvikSwappedOutPss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
| 139 | /** The proportional set size for the native heap. */ |
| 140 | public int nativePss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 141 | /** The proportional set size that is swappable for the native heap. */ |
| 142 | /** @hide We may want to expose this, eventually. */ |
| 143 | public int nativeSwappablePss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** The private dirty pages used by the native heap. */ |
| 145 | public int nativePrivateDirty; |
| 146 | /** The shared dirty pages used by the native heap. */ |
| 147 | public int nativeSharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 148 | /** The private clean pages used by the native heap. */ |
| 149 | /** @hide We may want to expose this, eventually. */ |
| 150 | public int nativePrivateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 151 | /** The shared clean pages used by the native heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 152 | /** @hide We may want to expose this, eventually. */ |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 153 | public int nativeSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 154 | /** The dirty native pages that have been swapped out. */ |
| 155 | /** @hide We may want to expose this, eventually. */ |
| 156 | public int nativeSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 157 | /** The dirty native pages that have been swapped out, proportional. */ |
| 158 | /** @hide We may want to expose this, eventually. */ |
| 159 | public int nativeSwappedOutPss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | |
| 161 | /** The proportional set size for everything else. */ |
| 162 | public int otherPss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 163 | /** The proportional set size that is swappable for everything else. */ |
| 164 | /** @hide We may want to expose this, eventually. */ |
| 165 | public int otherSwappablePss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | /** The private dirty pages used by everything else. */ |
| 167 | public int otherPrivateDirty; |
| 168 | /** The shared dirty pages used by everything else. */ |
| 169 | public int otherSharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 170 | /** The private clean pages used by everything else. */ |
| 171 | /** @hide We may want to expose this, eventually. */ |
| 172 | public int otherPrivateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 173 | /** The shared clean pages used by everything else. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 174 | /** @hide We may want to expose this, eventually. */ |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 175 | public int otherSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 176 | /** The dirty pages used by anyting else that have been swapped out. */ |
| 177 | /** @hide We may want to expose this, eventually. */ |
| 178 | public int otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 179 | /** The dirty pages used by anyting else that have been swapped out, proportional. */ |
| 180 | /** @hide We may want to expose this, eventually. */ |
| 181 | public int otherSwappedOutPss; |
| 182 | |
| 183 | /** Whether the kernel reports proportional swap usage */ |
| 184 | /** @hide */ |
| 185 | public boolean hasSwappedOutPss; |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 186 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 187 | /** @hide */ |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 188 | public static final int HEAP_UNKNOWN = 0; |
| 189 | /** @hide */ |
| 190 | public static final int HEAP_DALVIK = 1; |
| 191 | /** @hide */ |
| 192 | public static final int HEAP_NATIVE = 2; |
| 193 | |
| 194 | /** @hide */ |
| 195 | public static final int OTHER_DALVIK_OTHER = 0; |
| 196 | /** @hide */ |
| 197 | public static final int OTHER_STACK = 1; |
| 198 | /** @hide */ |
| 199 | public static final int OTHER_CURSOR = 2; |
| 200 | /** @hide */ |
| 201 | public static final int OTHER_ASHMEM = 3; |
| 202 | /** @hide */ |
| 203 | public static final int OTHER_GL_DEV = 4; |
| 204 | /** @hide */ |
| 205 | public static final int OTHER_UNKNOWN_DEV = 5; |
| 206 | /** @hide */ |
| 207 | public static final int OTHER_SO = 6; |
| 208 | /** @hide */ |
| 209 | public static final int OTHER_JAR = 7; |
| 210 | /** @hide */ |
| 211 | public static final int OTHER_APK = 8; |
| 212 | /** @hide */ |
| 213 | public static final int OTHER_TTF = 9; |
| 214 | /** @hide */ |
| 215 | public static final int OTHER_DEX = 10; |
| 216 | /** @hide */ |
| 217 | public static final int OTHER_OAT = 11; |
| 218 | /** @hide */ |
| 219 | public static final int OTHER_ART = 12; |
| 220 | /** @hide */ |
| 221 | public static final int OTHER_UNKNOWN_MAP = 13; |
| 222 | /** @hide */ |
| 223 | public static final int OTHER_GRAPHICS = 14; |
| 224 | /** @hide */ |
| 225 | public static final int OTHER_GL = 15; |
| 226 | /** @hide */ |
| 227 | public static final int OTHER_OTHER_MEMTRACK = 16; |
| 228 | |
| 229 | /** @hide */ |
| 230 | public static final int OTHER_DALVIK_NORMAL = 17; |
| 231 | /** @hide */ |
| 232 | public static final int OTHER_DALVIK_LARGE = 18; |
| 233 | /** @hide */ |
| 234 | public static final int OTHER_DALVIK_LINEARALLOC = 19; |
| 235 | /** @hide */ |
| 236 | public static final int OTHER_DALVIK_ACCOUNTING = 20; |
| 237 | /** @hide */ |
| 238 | public static final int OTHER_DALVIK_CODE_CACHE = 21; |
| 239 | /** @hide */ |
| 240 | public static final int OTHER_DALVIK_ZYGOTE = 22; |
| 241 | /** @hide */ |
| 242 | public static final int OTHER_DALVIK_NON_MOVING = 23; |
| 243 | /** @hide */ |
| 244 | public static final int OTHER_DALVIK_INDIRECT_REFERENCE_TABLE = 24; |
| 245 | |
| 246 | /** @hide */ |
Dianne Hackborn | 1842930 | 2014-11-03 13:58:11 -0800 | [diff] [blame] | 247 | public static final int NUM_OTHER_STATS = 17; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 248 | |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 249 | /** @hide */ |
Mathieu Chartier | 25c5e2b | 2014-12-08 16:20:26 -0800 | [diff] [blame] | 250 | public static final int NUM_DVK_STATS = 8; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 251 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 252 | /** @hide */ |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 253 | public static final int NUM_CATEGORIES = 8; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 254 | |
| 255 | /** @hide */ |
| 256 | public static final int offsetPss = 0; |
| 257 | /** @hide */ |
| 258 | public static final int offsetSwappablePss = 1; |
| 259 | /** @hide */ |
| 260 | public static final int offsetPrivateDirty = 2; |
| 261 | /** @hide */ |
| 262 | public static final int offsetSharedDirty = 3; |
| 263 | /** @hide */ |
| 264 | public static final int offsetPrivateClean = 4; |
| 265 | /** @hide */ |
| 266 | public static final int offsetSharedClean = 5; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 267 | /** @hide */ |
| 268 | public static final int offsetSwappedOut = 6; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 269 | /** @hide */ |
| 270 | public static final int offsetSwappedOutPss = 7; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 271 | |
| 272 | private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 273 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 274 | public MemoryInfo() { |
| 275 | } |
| 276 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Return total PSS memory usage in kB. |
| 279 | */ |
| 280 | public int getTotalPss() { |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 281 | return dalvikPss + nativePss + otherPss + getTotalSwappedOutPss(); |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 282 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 283 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 284 | /** |
| 285 | * @hide Return total PSS memory usage in kB. |
| 286 | */ |
| 287 | public int getTotalUss() { |
| 288 | return dalvikPrivateClean + dalvikPrivateDirty |
| 289 | + nativePrivateClean + nativePrivateDirty |
| 290 | + otherPrivateClean + otherPrivateDirty; |
| 291 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 292 | |
| 293 | /** |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 294 | * Return total PSS memory usage in kB mapping a file of one of the following extension: |
| 295 | * .so, .jar, .apk, .ttf, .dex, .odex, .oat, .art . |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 296 | */ |
| 297 | public int getTotalSwappablePss() { |
| 298 | return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss; |
| 299 | } |
| 300 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 301 | /** |
| 302 | * Return total private dirty memory usage in kB. |
| 303 | */ |
| 304 | public int getTotalPrivateDirty() { |
| 305 | return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty; |
| 306 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 307 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 308 | /** |
| 309 | * Return total shared dirty memory usage in kB. |
| 310 | */ |
| 311 | public int getTotalSharedDirty() { |
| 312 | return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty; |
| 313 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 314 | |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 315 | /** |
| 316 | * Return total shared clean memory usage in kB. |
| 317 | */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 318 | public int getTotalPrivateClean() { |
| 319 | return dalvikPrivateClean + nativePrivateClean + otherPrivateClean; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Return total shared clean memory usage in kB. |
| 324 | */ |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 325 | public int getTotalSharedClean() { |
| 326 | return dalvikSharedClean + nativeSharedClean + otherSharedClean; |
| 327 | } |
| 328 | |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Return total swapped out memory in kB. |
| 331 | * @hide |
| 332 | */ |
| 333 | public int getTotalSwappedOut() { |
| 334 | return dalvikSwappedOut + nativeSwappedOut + otherSwappedOut; |
| 335 | } |
| 336 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 337 | /** |
| 338 | * Return total swapped out memory in kB, proportional. |
| 339 | * @hide |
| 340 | */ |
| 341 | public int getTotalSwappedOutPss() { |
| 342 | return dalvikSwappedOutPss + nativeSwappedOutPss + otherSwappedOutPss; |
| 343 | } |
| 344 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 345 | /** @hide */ |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 346 | public int getOtherPss(int which) { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 347 | return otherStats[which*NUM_CATEGORIES + offsetPss]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 350 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 351 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 352 | public int getOtherSwappablePss(int which) { |
| 353 | return otherStats[which*NUM_CATEGORIES + offsetSwappablePss]; |
| 354 | } |
| 355 | |
| 356 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 357 | /** @hide */ |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 358 | public int getOtherPrivateDirty(int which) { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 359 | return otherStats[which*NUM_CATEGORIES + offsetPrivateDirty]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 362 | /** @hide */ |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 363 | public int getOtherSharedDirty(int which) { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 364 | return otherStats[which*NUM_CATEGORIES + offsetSharedDirty]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 367 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 368 | public int getOtherPrivateClean(int which) { |
| 369 | return otherStats[which*NUM_CATEGORIES + offsetPrivateClean]; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 370 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 371 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 372 | /** @hide */ |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 373 | public int getOtherPrivate(int which) { |
| 374 | return getOtherPrivateClean(which) + getOtherPrivateDirty(which); |
| 375 | } |
| 376 | |
| 377 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 378 | public int getOtherSharedClean(int which) { |
| 379 | return otherStats[which*NUM_CATEGORIES + offsetSharedClean]; |
| 380 | } |
| 381 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 382 | /** @hide */ |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 383 | public int getOtherSwappedOut(int which) { |
| 384 | return otherStats[which*NUM_CATEGORIES + offsetSwappedOut]; |
| 385 | } |
| 386 | |
| 387 | /** @hide */ |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 388 | public int getOtherSwappedOutPss(int which) { |
| 389 | return otherStats[which*NUM_CATEGORIES + offsetSwappedOutPss]; |
| 390 | } |
| 391 | |
| 392 | /** @hide */ |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 393 | public static String getOtherLabel(int which) { |
| 394 | switch (which) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 395 | case OTHER_DALVIK_OTHER: return "Dalvik Other"; |
| 396 | case OTHER_STACK: return "Stack"; |
| 397 | case OTHER_CURSOR: return "Cursor"; |
| 398 | case OTHER_ASHMEM: return "Ashmem"; |
| 399 | case OTHER_GL_DEV: return "Gfx dev"; |
| 400 | case OTHER_UNKNOWN_DEV: return "Other dev"; |
| 401 | case OTHER_SO: return ".so mmap"; |
| 402 | case OTHER_JAR: return ".jar mmap"; |
| 403 | case OTHER_APK: return ".apk mmap"; |
| 404 | case OTHER_TTF: return ".ttf mmap"; |
| 405 | case OTHER_DEX: return ".dex mmap"; |
| 406 | case OTHER_OAT: return ".oat mmap"; |
| 407 | case OTHER_ART: return ".art mmap"; |
| 408 | case OTHER_UNKNOWN_MAP: return "Other mmap"; |
| 409 | case OTHER_GRAPHICS: return "EGL mtrack"; |
| 410 | case OTHER_GL: return "GL mtrack"; |
| 411 | case OTHER_OTHER_MEMTRACK: return "Other mtrack"; |
| 412 | case OTHER_DALVIK_NORMAL: return ".Heap"; |
| 413 | case OTHER_DALVIK_LARGE: return ".LOS"; |
| 414 | case OTHER_DALVIK_LINEARALLOC: return ".LinearAlloc"; |
| 415 | case OTHER_DALVIK_ACCOUNTING: return ".GC"; |
| 416 | case OTHER_DALVIK_CODE_CACHE: return ".JITCache"; |
| 417 | case OTHER_DALVIK_ZYGOTE: return ".Zygote"; |
| 418 | case OTHER_DALVIK_NON_MOVING: return ".NonMoving"; |
| 419 | case OTHER_DALVIK_INDIRECT_REFERENCE_TABLE: return ".IndirectRef"; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 420 | default: return "????"; |
| 421 | } |
| 422 | } |
| 423 | |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 424 | /** |
| 425 | * Returns the value of a particular memory statistic or {@code null} if no |
| 426 | * such memory statistic exists. |
| 427 | * |
| 428 | * <p>The following table lists the memory statistics that are supported. |
| 429 | * Note that memory statistics may be added or removed in a future API level.</p> |
| 430 | * |
| 431 | * <table> |
| 432 | * <thead> |
| 433 | * <tr> |
| 434 | * <th>Memory statistic name</th> |
| 435 | * <th>Meaning</th> |
| 436 | * <th>Example</th> |
| 437 | * <th>Supported (API Levels)</th> |
| 438 | * </tr> |
| 439 | * </thead> |
| 440 | * <tbody> |
| 441 | * <tr> |
| 442 | * <td>summary.java-heap</td> |
| 443 | * <td>The private Java Heap usage in kB. This corresponds to the Java Heap field |
| 444 | * in the App Summary section output by dumpsys meminfo.</td> |
| 445 | * <td>{@code 1442}</td> |
| 446 | * <td>23</td> |
| 447 | * </tr> |
| 448 | * <tr> |
| 449 | * <td>summary.native-heap</td> |
| 450 | * <td>The private Native Heap usage in kB. This corresponds to the Native Heap |
| 451 | * field in the App Summary section output by dumpsys meminfo.</td> |
| 452 | * <td>{@code 1442}</td> |
| 453 | * <td>23</td> |
| 454 | * </tr> |
| 455 | * <tr> |
| 456 | * <td>summary.code</td> |
| 457 | * <td>The memory usage for static code and resources in kB. This corresponds to |
| 458 | * the Code field in the App Summary section output by dumpsys meminfo.</td> |
| 459 | * <td>{@code 1442}</td> |
| 460 | * <td>23</td> |
| 461 | * </tr> |
| 462 | * <tr> |
| 463 | * <td>summary.stack</td> |
| 464 | * <td>The stack usage in kB. This corresponds to the Stack field in the |
| 465 | * App Summary section output by dumpsys meminfo.</td> |
| 466 | * <td>{@code 1442}</td> |
| 467 | * <td>23</td> |
| 468 | * </tr> |
| 469 | * <tr> |
| 470 | * <td>summary.graphics</td> |
| 471 | * <td>The graphics usage in kB. This corresponds to the Graphics field in the |
| 472 | * App Summary section output by dumpsys meminfo.</td> |
| 473 | * <td>{@code 1442}</td> |
| 474 | * <td>23</td> |
| 475 | * </tr> |
| 476 | * <tr> |
| 477 | * <td>summary.private-other</td> |
| 478 | * <td>Other private memory usage in kB. This corresponds to the Private Other |
| 479 | * field output in the App Summary section by dumpsys meminfo.</td> |
| 480 | * <td>{@code 1442}</td> |
| 481 | * <td>23</td> |
| 482 | * </tr> |
| 483 | * <tr> |
| 484 | * <td>summary.system</td> |
| 485 | * <td>Shared and system memory usage in kB. This corresponds to the System |
| 486 | * field output in the App Summary section by dumpsys meminfo.</td> |
| 487 | * <td>{@code 1442}</td> |
| 488 | * <td>23</td> |
| 489 | * </tr> |
| 490 | * <tr> |
| 491 | * <td>summary.total-pss</td> |
| 492 | * <td>Total PPS memory usage in kB.</td> |
| 493 | * <td>{@code 1442}</td> |
| 494 | * <td>23</td> |
| 495 | * </tr> |
| 496 | * <tr> |
| 497 | * <td>summary.total-swap</td> |
| 498 | * <td>Total swap usage in kB.</td> |
| 499 | * <td>{@code 1442}</td> |
| 500 | * <td>23</td> |
| 501 | * </tr> |
| 502 | * </tbody> |
| 503 | * </table> |
| 504 | */ |
Dianne Hackborn | b02ce29 | 2015-10-12 15:14:16 -0700 | [diff] [blame] | 505 | public String getMemoryStat(String statName) { |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 506 | switch(statName) { |
| 507 | case "summary.java-heap": |
| 508 | return Integer.toString(getSummaryJavaHeap()); |
| 509 | case "summary.native-heap": |
| 510 | return Integer.toString(getSummaryNativeHeap()); |
| 511 | case "summary.code": |
| 512 | return Integer.toString(getSummaryCode()); |
| 513 | case "summary.stack": |
| 514 | return Integer.toString(getSummaryStack()); |
| 515 | case "summary.graphics": |
| 516 | return Integer.toString(getSummaryGraphics()); |
| 517 | case "summary.private-other": |
| 518 | return Integer.toString(getSummaryPrivateOther()); |
| 519 | case "summary.system": |
| 520 | return Integer.toString(getSummarySystem()); |
| 521 | case "summary.total-pss": |
| 522 | return Integer.toString(getSummaryTotalPss()); |
| 523 | case "summary.total-swap": |
| 524 | return Integer.toString(getSummaryTotalSwap()); |
| 525 | default: |
| 526 | return null; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Returns a map of the names/values of the memory statistics |
| 532 | * that {@link #getMemoryStat(String)} supports. |
| 533 | * |
| 534 | * @return a map of the names/values of the supported memory statistics. |
| 535 | */ |
| 536 | public Map<String, String> getMemoryStats() { |
| 537 | Map<String, String> stats = new HashMap<String, String>(); |
| 538 | stats.put("summary.java-heap", Integer.toString(getSummaryJavaHeap())); |
| 539 | stats.put("summary.native-heap", Integer.toString(getSummaryNativeHeap())); |
| 540 | stats.put("summary.code", Integer.toString(getSummaryCode())); |
| 541 | stats.put("summary.stack", Integer.toString(getSummaryStack())); |
| 542 | stats.put("summary.graphics", Integer.toString(getSummaryGraphics())); |
| 543 | stats.put("summary.private-other", Integer.toString(getSummaryPrivateOther())); |
| 544 | stats.put("summary.system", Integer.toString(getSummarySystem())); |
| 545 | stats.put("summary.total-pss", Integer.toString(getSummaryTotalPss())); |
| 546 | stats.put("summary.total-swap", Integer.toString(getSummaryTotalSwap())); |
| 547 | return stats; |
| 548 | } |
| 549 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 550 | /** |
| 551 | * Pss of Java Heap bytes in KB due to the application. |
| 552 | * Notes: |
| 553 | * * OTHER_ART is the boot image. Anything private here is blamed on |
| 554 | * the application, not the system. |
| 555 | * * dalvikPrivateDirty includes private zygote, which means the |
| 556 | * application dirtied something allocated by the zygote. We blame |
| 557 | * the application for that memory, not the system. |
| 558 | * * Does not include OTHER_DALVIK_OTHER, which is considered VM |
| 559 | * Overhead and lumped into Private Other. |
| 560 | * * We don't include dalvikPrivateClean, because there should be no |
| 561 | * such thing as private clean for the Java Heap. |
| 562 | * @hide |
| 563 | */ |
| 564 | public int getSummaryJavaHeap() { |
| 565 | return dalvikPrivateDirty + getOtherPrivate(OTHER_ART); |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Pss of Native Heap bytes in KB due to the application. |
| 570 | * Notes: |
| 571 | * * Includes private dirty malloc space. |
| 572 | * * We don't include nativePrivateClean, because there should be no |
| 573 | * such thing as private clean for the Native Heap. |
| 574 | * @hide |
| 575 | */ |
| 576 | public int getSummaryNativeHeap() { |
| 577 | return nativePrivateDirty; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Pss of code and other static resource bytes in KB due to |
| 582 | * the application. |
| 583 | * @hide |
| 584 | */ |
| 585 | public int getSummaryCode() { |
| 586 | return getOtherPrivate(OTHER_SO) |
| 587 | + getOtherPrivate(OTHER_JAR) |
| 588 | + getOtherPrivate(OTHER_APK) |
| 589 | + getOtherPrivate(OTHER_TTF) |
| 590 | + getOtherPrivate(OTHER_DEX) |
| 591 | + getOtherPrivate(OTHER_OAT); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Pss in KB of the stack due to the application. |
| 596 | * Notes: |
| 597 | * * Includes private dirty stack, which includes both Java and Native |
| 598 | * stack. |
| 599 | * * Does not include private clean stack, because there should be no |
| 600 | * such thing as private clean for the stack. |
| 601 | * @hide |
| 602 | */ |
| 603 | public int getSummaryStack() { |
| 604 | return getOtherPrivateDirty(OTHER_STACK); |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Pss in KB of graphics due to the application. |
| 609 | * Notes: |
| 610 | * * Includes private Gfx, EGL, and GL. |
| 611 | * * Warning: These numbers can be misreported by the graphics drivers. |
| 612 | * * We don't include shared graphics. It may make sense to, because |
| 613 | * shared graphics are likely buffers due to the application |
| 614 | * anyway, but it's simpler to implement to just group all shared |
| 615 | * memory into the System category. |
| 616 | * @hide |
| 617 | */ |
| 618 | public int getSummaryGraphics() { |
| 619 | return getOtherPrivate(OTHER_GL_DEV) |
| 620 | + getOtherPrivate(OTHER_GRAPHICS) |
| 621 | + getOtherPrivate(OTHER_GL); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Pss in KB due to the application that haven't otherwise been |
| 626 | * accounted for. |
| 627 | * @hide |
| 628 | */ |
| 629 | public int getSummaryPrivateOther() { |
| 630 | return getTotalPrivateClean() |
| 631 | + getTotalPrivateDirty() |
| 632 | - getSummaryJavaHeap() |
| 633 | - getSummaryNativeHeap() |
| 634 | - getSummaryCode() |
| 635 | - getSummaryStack() |
| 636 | - getSummaryGraphics(); |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Pss in KB due to the system. |
| 641 | * Notes: |
| 642 | * * Includes all shared memory. |
| 643 | * @hide |
| 644 | */ |
| 645 | public int getSummarySystem() { |
| 646 | return getTotalPss() |
| 647 | - getTotalPrivateClean() |
| 648 | - getTotalPrivateDirty(); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Total Pss in KB. |
| 653 | * @hide |
| 654 | */ |
| 655 | public int getSummaryTotalPss() { |
| 656 | return getTotalPss(); |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * Total Swap in KB. |
| 661 | * Notes: |
| 662 | * * Some of this memory belongs in other categories, but we don't |
| 663 | * know if the Swap memory is shared or private, so we don't know |
| 664 | * what to blame on the application and what on the system. |
| 665 | * For now, just lump all the Swap in one place. |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 666 | * For kernels reporting SwapPss {@link #getSummaryTotalSwapPss()} |
| 667 | * will report the application proportional Swap. |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 668 | * @hide |
| 669 | */ |
| 670 | public int getSummaryTotalSwap() { |
| 671 | return getTotalSwappedOut(); |
| 672 | } |
| 673 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 674 | /** |
| 675 | * Total proportional Swap in KB. |
| 676 | * Notes: |
| 677 | * * Always 0 if {@link #hasSwappedOutPss} is false. |
| 678 | * @hide |
| 679 | */ |
| 680 | public int getSummaryTotalSwapPss() { |
| 681 | return getTotalSwappedOutPss(); |
| 682 | } |
| 683 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 684 | public int describeContents() { |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | public void writeToParcel(Parcel dest, int flags) { |
| 689 | dest.writeInt(dalvikPss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 690 | dest.writeInt(dalvikSwappablePss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 691 | dest.writeInt(dalvikPrivateDirty); |
| 692 | dest.writeInt(dalvikSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 693 | dest.writeInt(dalvikPrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 694 | dest.writeInt(dalvikSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 695 | dest.writeInt(dalvikSwappedOut); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 696 | dest.writeInt(nativePss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 697 | dest.writeInt(nativeSwappablePss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 698 | dest.writeInt(nativePrivateDirty); |
| 699 | dest.writeInt(nativeSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 700 | dest.writeInt(nativePrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 701 | dest.writeInt(nativeSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 702 | dest.writeInt(nativeSwappedOut); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 703 | dest.writeInt(otherPss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 704 | dest.writeInt(otherSwappablePss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 705 | dest.writeInt(otherPrivateDirty); |
| 706 | dest.writeInt(otherSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 707 | dest.writeInt(otherPrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 708 | dest.writeInt(otherSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 709 | dest.writeInt(otherSwappedOut); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 710 | dest.writeInt(hasSwappedOutPss ? 1 : 0); |
| 711 | dest.writeInt(otherSwappedOutPss); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 712 | dest.writeIntArray(otherStats); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | public void readFromParcel(Parcel source) { |
| 716 | dalvikPss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 717 | dalvikSwappablePss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 718 | dalvikPrivateDirty = source.readInt(); |
| 719 | dalvikSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 720 | dalvikPrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 721 | dalvikSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 722 | dalvikSwappedOut = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 723 | nativePss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 724 | nativeSwappablePss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 725 | nativePrivateDirty = source.readInt(); |
| 726 | nativeSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 727 | nativePrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 728 | nativeSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 729 | nativeSwappedOut = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 730 | otherPss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 731 | otherSwappablePss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 732 | otherPrivateDirty = source.readInt(); |
| 733 | otherSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 734 | otherPrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 735 | otherSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 736 | otherSwappedOut = source.readInt(); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 737 | hasSwappedOutPss = source.readInt() != 0; |
| 738 | otherSwappedOutPss = source.readInt(); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 739 | otherStats = source.createIntArray(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 740 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 741 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 742 | public static final Creator<MemoryInfo> CREATOR = new Creator<MemoryInfo>() { |
| 743 | public MemoryInfo createFromParcel(Parcel source) { |
| 744 | return new MemoryInfo(source); |
| 745 | } |
| 746 | public MemoryInfo[] newArray(int size) { |
| 747 | return new MemoryInfo[size]; |
| 748 | } |
| 749 | }; |
| 750 | |
| 751 | private MemoryInfo(Parcel source) { |
| 752 | readFromParcel(source); |
| 753 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
| 757 | /** |
| 758 | * Wait until a debugger attaches. As soon as the debugger attaches, |
| 759 | * this returns, so you will need to place a breakpoint after the |
| 760 | * waitForDebugger() call if you want to start tracing immediately. |
| 761 | */ |
| 762 | public static void waitForDebugger() { |
| 763 | if (!VMDebug.isDebuggingEnabled()) { |
| 764 | //System.out.println("debugging not enabled, not waiting"); |
| 765 | return; |
| 766 | } |
| 767 | if (isDebuggerConnected()) |
| 768 | return; |
| 769 | |
| 770 | // if DDMS is listening, inform them of our plight |
| 771 | System.out.println("Sending WAIT chunk"); |
| 772 | byte[] data = new byte[] { 0 }; // 0 == "waiting for debugger" |
| 773 | Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1); |
| 774 | DdmServer.sendChunk(waitChunk); |
| 775 | |
| 776 | mWaiting = true; |
| 777 | while (!isDebuggerConnected()) { |
| 778 | try { Thread.sleep(SPIN_DELAY); } |
| 779 | catch (InterruptedException ie) {} |
| 780 | } |
| 781 | mWaiting = false; |
| 782 | |
| 783 | System.out.println("Debugger has connected"); |
| 784 | |
| 785 | /* |
| 786 | * There is no "ready to go" signal from the debugger, and we're |
| 787 | * not allowed to suspend ourselves -- the debugger expects us to |
| 788 | * be running happily, and gets confused if we aren't. We need to |
| 789 | * allow the debugger a chance to set breakpoints before we start |
| 790 | * running again. |
| 791 | * |
| 792 | * Sit and spin until the debugger has been idle for a short while. |
| 793 | */ |
| 794 | while (true) { |
| 795 | long delta = VMDebug.lastDebuggerActivity(); |
| 796 | if (delta < 0) { |
| 797 | System.out.println("debugger detached?"); |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | if (delta < MIN_DEBUGGER_IDLE) { |
| 802 | System.out.println("waiting for debugger to settle..."); |
| 803 | try { Thread.sleep(SPIN_DELAY); } |
| 804 | catch (InterruptedException ie) {} |
| 805 | } else { |
| 806 | System.out.println("debugger has settled (" + delta + ")"); |
| 807 | break; |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Returns "true" if one or more threads is waiting for a debugger |
| 814 | * to attach. |
| 815 | */ |
| 816 | public static boolean waitingForDebugger() { |
| 817 | return mWaiting; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Determine if a debugger is currently attached. |
| 822 | */ |
| 823 | public static boolean isDebuggerConnected() { |
| 824 | return VMDebug.isDebuggerConnected(); |
| 825 | } |
| 826 | |
| 827 | /** |
Andy McFadden | e577232 | 2010-01-22 07:23:31 -0800 | [diff] [blame] | 828 | * Returns an array of strings that identify VM features. This is |
| 829 | * used by DDMS to determine what sorts of operations the VM can |
| 830 | * perform. |
| 831 | * |
| 832 | * @hide |
| 833 | */ |
| 834 | public static String[] getVmFeatureList() { |
| 835 | return VMDebug.getVmFeatureList(); |
| 836 | } |
| 837 | |
| 838 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | * Change the JDWP port. |
| 840 | * |
| 841 | * @deprecated no longer needed or useful |
| 842 | */ |
| 843 | @Deprecated |
| 844 | public static void changeDebugPort(int port) {} |
| 845 | |
| 846 | /** |
| 847 | * This is the pathname to the sysfs file that enables and disables |
| 848 | * tracing on the qemu emulator. |
| 849 | */ |
| 850 | private static final String SYSFS_QEMU_TRACE_STATE = "/sys/qemu_trace/state"; |
| 851 | |
| 852 | /** |
| 853 | * Enable qemu tracing. For this to work requires running everything inside |
| 854 | * the qemu emulator; otherwise, this method will have no effect. The trace |
| 855 | * file is specified on the command line when the emulator is started. For |
| 856 | * example, the following command line <br /> |
| 857 | * <code>emulator -trace foo</code><br /> |
| 858 | * will start running the emulator and create a trace file named "foo". This |
| 859 | * method simply enables writing the trace records to the trace file. |
| 860 | * |
| 861 | * <p> |
| 862 | * The main differences between this and {@link #startMethodTracing()} are |
| 863 | * that tracing in the qemu emulator traces every cpu instruction of every |
| 864 | * process, including kernel code, so we have more complete information, |
| 865 | * including all context switches. We can also get more detailed information |
| 866 | * such as cache misses. The sequence of calls is determined by |
| 867 | * post-processing the instruction trace. The qemu tracing is also done |
| 868 | * without modifying the application or perturbing the timing of calls |
| 869 | * because no instrumentation is added to the application being traced. |
| 870 | * </p> |
| 871 | * |
| 872 | * <p> |
| 873 | * One limitation of using this method compared to using |
| 874 | * {@link #startMethodTracing()} on the real device is that the emulator |
| 875 | * does not model all of the real hardware effects such as memory and |
| 876 | * bus contention. The emulator also has a simple cache model and cannot |
| 877 | * capture all the complexities of a real cache. |
| 878 | * </p> |
| 879 | */ |
| 880 | public static void startNativeTracing() { |
| 881 | // Open the sysfs file for writing and write "1" to it. |
| 882 | PrintWriter outStream = null; |
| 883 | try { |
| 884 | FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 885 | outStream = new FastPrintWriter(fos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | outStream.println("1"); |
| 887 | } catch (Exception e) { |
| 888 | } finally { |
| 889 | if (outStream != null) |
| 890 | outStream.close(); |
| 891 | } |
| 892 | |
| 893 | VMDebug.startEmulatorTracing(); |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Stop qemu tracing. See {@link #startNativeTracing()} to start tracing. |
| 898 | * |
| 899 | * <p>Tracing can be started and stopped as many times as desired. When |
| 900 | * the qemu emulator itself is stopped then the buffered trace records |
| 901 | * are flushed and written to the trace file. In fact, it is not necessary |
| 902 | * to call this method at all; simply killing qemu is sufficient. But |
| 903 | * starting and stopping a trace is useful for examining a specific |
| 904 | * region of code.</p> |
| 905 | */ |
| 906 | public static void stopNativeTracing() { |
| 907 | VMDebug.stopEmulatorTracing(); |
| 908 | |
| 909 | // Open the sysfs file for writing and write "0" to it. |
| 910 | PrintWriter outStream = null; |
| 911 | try { |
| 912 | FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 913 | outStream = new FastPrintWriter(fos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | outStream.println("0"); |
| 915 | } catch (Exception e) { |
| 916 | // We could print an error message here but we probably want |
| 917 | // to quietly ignore errors if we are not running in the emulator. |
| 918 | } finally { |
| 919 | if (outStream != null) |
| 920 | outStream.close(); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * Enable "emulator traces", in which information about the current |
| 926 | * method is made available to the "emulator -trace" feature. There |
| 927 | * is no corresponding "disable" call -- this is intended for use by |
| 928 | * the framework when tracing should be turned on and left that way, so |
| 929 | * that traces captured with F9/F10 will include the necessary data. |
| 930 | * |
| 931 | * This puts the VM into "profile" mode, which has performance |
| 932 | * consequences. |
| 933 | * |
| 934 | * To temporarily enable tracing, use {@link #startNativeTracing()}. |
| 935 | */ |
| 936 | public static void enableEmulatorTraceOutput() { |
| 937 | VMDebug.startEmulatorTracing(); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Start method tracing with default log name and buffer size. See <a |
| 942 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for |
| 943 | * information about reading these files. Call stopMethodTracing() to stop |
| 944 | * tracing. |
| 945 | */ |
| 946 | public static void startMethodTracing() { |
Andreas Gampe | 8b9f494 | 2016-02-25 18:03:03 -0800 | [diff] [blame] | 947 | VMDebug.startMethodTracing(fixTraceName(null), 0, 0, false, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Start method tracing, specifying the trace log file name. The trace |
| 952 | * file will be put under "/sdcard" unless an absolute path is given. |
| 953 | * See <a |
| 954 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for |
| 955 | * information about reading trace files. |
| 956 | * |
| 957 | * @param traceName Name for the trace log file to create. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 958 | * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace". |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | * If the files already exist, they will be truncated. |
| 960 | * If the trace file given does not end in ".trace", it will be appended for you. |
| 961 | */ |
| 962 | public static void startMethodTracing(String traceName) { |
| 963 | startMethodTracing(traceName, 0, 0); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Start method tracing, specifying the trace log file name and the |
| 968 | * buffer size. The trace files will be put under "/sdcard" unless an |
| 969 | * absolute path is given. See <a |
| 970 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for |
| 971 | * information about reading trace files. |
| 972 | * @param traceName Name for the trace log file to create. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 973 | * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace". |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | * If the files already exist, they will be truncated. |
| 975 | * If the trace file given does not end in ".trace", it will be appended for you. |
| 976 | * |
| 977 | * @param bufferSize The maximum amount of trace data we gather. If not given, it defaults to 8MB. |
| 978 | */ |
| 979 | public static void startMethodTracing(String traceName, int bufferSize) { |
| 980 | startMethodTracing(traceName, bufferSize, 0); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Start method tracing, specifying the trace log file name and the |
| 985 | * buffer size. The trace files will be put under "/sdcard" unless an |
| 986 | * absolute path is given. See <a |
| 987 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for |
| 988 | * information about reading trace files. |
| 989 | * |
| 990 | * <p> |
| 991 | * When method tracing is enabled, the VM will run more slowly than |
| 992 | * usual, so the timings from the trace files should only be considered |
| 993 | * in relative terms (e.g. was run #1 faster than run #2). The times |
| 994 | * for native methods will not change, so don't try to use this to |
| 995 | * compare the performance of interpreted and native implementations of the |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 996 | * same method. As an alternative, consider using sampling-based method |
| 997 | * tracing via {@link #startMethodTracingSampling(String, int, int)} or |
| 998 | * "native" tracing in the emulator via {@link #startNativeTracing()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | * </p> |
| 1000 | * |
| 1001 | * @param traceName Name for the trace log file to create. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1002 | * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace". |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | * If the files already exist, they will be truncated. |
| 1004 | * If the trace file given does not end in ".trace", it will be appended for you. |
| 1005 | * @param bufferSize The maximum amount of trace data we gather. If not given, it defaults to 8MB. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1006 | * @param flags Flags to control method tracing. The only one that is currently defined is {@link #TRACE_COUNT_ALLOCS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | */ |
| 1008 | public static void startMethodTracing(String traceName, int bufferSize, |
| 1009 | int flags) { |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1010 | VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, flags, false, 0); |
| 1011 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1013 | /** |
| 1014 | * Start sampling-based method tracing, specifying the trace log file name, |
| 1015 | * the buffer size, and the sampling interval. The trace files will be put |
| 1016 | * under "/sdcard" unless an absolute path is given. See <a |
| 1017 | href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> |
| 1018 | * for information about reading trace files. |
| 1019 | * |
| 1020 | * @param traceName Name for the trace log file to create. |
| 1021 | * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace". |
| 1022 | * If the files already exist, they will be truncated. |
| 1023 | * If the trace file given does not end in ".trace", it will be appended for you. |
| 1024 | * @param bufferSize The maximum amount of trace data we gather. If not given, it defaults to 8MB. |
| 1025 | * @param intervalUs The amount of time between each sample in microseconds. |
| 1026 | */ |
| 1027 | public static void startMethodTracingSampling(String traceName, |
| 1028 | int bufferSize, int intervalUs) { |
| 1029 | VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, 0, true, intervalUs); |
| 1030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1032 | /** |
| 1033 | * Formats name of trace log file for method tracing. |
| 1034 | */ |
| 1035 | private static String fixTraceName(String traceName) { |
| 1036 | if (traceName == null) |
Andreas Gampe | 8b9f494 | 2016-02-25 18:03:03 -0800 | [diff] [blame] | 1037 | traceName = NoPreloadHolder.DEFAULT_TRACE_FILE_PATH; |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1038 | if (traceName.charAt(0) != '/') |
Andreas Gampe | 8b9f494 | 2016-02-25 18:03:03 -0800 | [diff] [blame] | 1039 | traceName = NoPreloadHolder.DEFAULT_TRACE_PATH_PREFIX + traceName; |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1040 | if (!traceName.endsWith(DEFAULT_TRACE_EXTENSION)) |
| 1041 | traceName = traceName + DEFAULT_TRACE_EXTENSION; |
| 1042 | |
| 1043 | return traceName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /** |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1047 | * Like startMethodTracing(String, int, int), but taking an already-opened |
| 1048 | * FileDescriptor in which the trace is written. The file name is also |
| 1049 | * supplied simply for logging. Makes a dup of the file descriptor. |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 1050 | * |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1051 | * Not exposed in the SDK unless we are really comfortable with supporting |
| 1052 | * this and find it would be useful. |
| 1053 | * @hide |
| 1054 | */ |
| 1055 | public static void startMethodTracing(String traceName, FileDescriptor fd, |
| 1056 | int bufferSize, int flags) { |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1057 | VMDebug.startMethodTracing(traceName, fd, bufferSize, flags, false, 0); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /** |
Andy McFadden | 72a20db0c | 2010-01-22 12:20:41 -0800 | [diff] [blame] | 1061 | * Starts method tracing without a backing file. When stopMethodTracing |
| 1062 | * is called, the result is sent directly to DDMS. (If DDMS is not |
| 1063 | * attached when tracing ends, the profiling data will be discarded.) |
| 1064 | * |
| 1065 | * @hide |
| 1066 | */ |
Jeff Hao | 7be3a13 | 2013-08-22 15:53:12 -0700 | [diff] [blame] | 1067 | public static void startMethodTracingDdms(int bufferSize, int flags, |
| 1068 | boolean samplingEnabled, int intervalUs) { |
| 1069 | VMDebug.startMethodTracingDdms(bufferSize, flags, samplingEnabled, intervalUs); |
Andy McFadden | 72a20db0c | 2010-01-22 12:20:41 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /** |
Jeff Hao | ac27705 | 2013-08-29 11:19:39 -0700 | [diff] [blame] | 1073 | * Determine whether method tracing is currently active and what type is |
| 1074 | * active. |
| 1075 | * |
The Android Open Source Project | 7b0b1ed | 2009-03-18 22:20:26 -0700 | [diff] [blame] | 1076 | * @hide |
| 1077 | */ |
Jeff Hao | ac27705 | 2013-08-29 11:19:39 -0700 | [diff] [blame] | 1078 | public static int getMethodTracingMode() { |
| 1079 | return VMDebug.getMethodTracingMode(); |
The Android Open Source Project | 7b0b1ed | 2009-03-18 22:20:26 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | * Stop method tracing. |
| 1084 | */ |
| 1085 | public static void stopMethodTracing() { |
| 1086 | VMDebug.stopMethodTracing(); |
| 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * Get an indication of thread CPU usage. The value returned |
| 1091 | * indicates the amount of time that the current thread has spent |
| 1092 | * executing code or waiting for certain types of I/O. |
| 1093 | * |
| 1094 | * The time is expressed in nanoseconds, and is only meaningful |
| 1095 | * when compared to the result from an earlier call. Note that |
| 1096 | * nanosecond resolution does not imply nanosecond accuracy. |
| 1097 | * |
| 1098 | * On system which don't support this operation, the call returns -1. |
| 1099 | */ |
| 1100 | public static long threadCpuTimeNanos() { |
| 1101 | return VMDebug.threadCpuTimeNanos(); |
| 1102 | } |
| 1103 | |
| 1104 | /** |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1105 | * Start counting the number and aggregate size of memory allocations. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | * |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1107 | * <p>The {@link #startAllocCounting() start} method resets the counts and enables counting. |
| 1108 | * The {@link #stopAllocCounting() stop} method disables the counting so that the analysis |
| 1109 | * code doesn't cause additional allocations. The various <code>get</code> methods return |
| 1110 | * the specified value. And the various <code>reset</code> methods reset the specified |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1111 | * count.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | * |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1113 | * <p>Counts are kept for the system as a whole (global) and for each thread. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | * The per-thread counts for threads other than the current thread |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1115 | * are not cleared by the "reset" or "start" calls.</p> |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1116 | * |
| 1117 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | */ |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1119 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | public static void startAllocCounting() { |
| 1121 | VMDebug.startAllocCounting(); |
| 1122 | } |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1123 | |
| 1124 | /** |
| 1125 | * Stop counting the number and aggregate size of memory allocations. |
| 1126 | * |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1127 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1128 | */ |
Ian Rogers | c2a3adb | 2013-04-19 11:31:48 -0700 | [diff] [blame] | 1129 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | public static void stopAllocCounting() { |
| 1131 | VMDebug.stopAllocCounting(); |
| 1132 | } |
| 1133 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1134 | /** |
| 1135 | * Returns the global count of objects allocated by the runtime between a |
| 1136 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1137 | * |
| 1138 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1139 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1140 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | public static int getGlobalAllocCount() { |
| 1142 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS); |
| 1143 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1144 | |
| 1145 | /** |
| 1146 | * Clears the global count of objects allocated. |
| 1147 | * @see #getGlobalAllocCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1148 | * |
| 1149 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1150 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1151 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1152 | public static void resetGlobalAllocCount() { |
| 1153 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS); |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Returns the global size, in bytes, of objects allocated by the runtime between a |
| 1158 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1159 | * |
| 1160 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1161 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1162 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | public static int getGlobalAllocSize() { |
| 1164 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES); |
| 1165 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1166 | |
| 1167 | /** |
| 1168 | * Clears the global size of objects allocated. |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 1169 | * @see #getGlobalAllocSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1170 | * |
| 1171 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1172 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1173 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1174 | public static void resetGlobalAllocSize() { |
| 1175 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Returns the global count of objects freed by the runtime between a |
| 1180 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1181 | * |
| 1182 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1183 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1184 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | public static int getGlobalFreedCount() { |
| 1186 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS); |
| 1187 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1188 | |
| 1189 | /** |
| 1190 | * Clears the global count of objects freed. |
| 1191 | * @see #getGlobalFreedCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1192 | * |
| 1193 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1194 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1195 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1196 | public static void resetGlobalFreedCount() { |
| 1197 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS); |
| 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * Returns the global size, in bytes, of objects freed by the runtime between a |
| 1202 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1203 | * |
| 1204 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1205 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1206 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | public static int getGlobalFreedSize() { |
| 1208 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES); |
| 1209 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1210 | |
| 1211 | /** |
| 1212 | * Clears the global size of objects freed. |
| 1213 | * @see #getGlobalFreedSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1214 | * |
| 1215 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1216 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1217 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1218 | public static void resetGlobalFreedSize() { |
| 1219 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Returns the number of non-concurrent GC invocations between a |
| 1224 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1225 | * |
| 1226 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1227 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1228 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1229 | public static int getGlobalGcInvocationCount() { |
| 1230 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS); |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Clears the count of non-concurrent GC invocations. |
| 1235 | * @see #getGlobalGcInvocationCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1236 | * |
| 1237 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1238 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1239 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1240 | public static void resetGlobalGcInvocationCount() { |
| 1241 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS); |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Returns the number of classes successfully initialized (ie those that executed without |
| 1246 | * throwing an exception) between a {@link #startAllocCounting() start} and |
| 1247 | * {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1248 | * |
| 1249 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1250 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1251 | @Deprecated |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1252 | public static int getGlobalClassInitCount() { |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1253 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT); |
| 1254 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1255 | |
| 1256 | /** |
| 1257 | * Clears the count of classes initialized. |
| 1258 | * @see #getGlobalClassInitCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1259 | * |
| 1260 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1261 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1262 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1263 | public static void resetGlobalClassInitCount() { |
| 1264 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Returns the time spent successfully initializing classes between a |
| 1269 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1270 | * |
| 1271 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1272 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1273 | @Deprecated |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1274 | public static int getGlobalClassInitTime() { |
| 1275 | /* cumulative elapsed time for class initialization, in usec */ |
| 1276 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME); |
| 1277 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1278 | |
| 1279 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1280 | * Clears the count of time spent initializing classes. |
| 1281 | * @see #getGlobalClassInitTime() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1282 | * |
| 1283 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1284 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1285 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1286 | public static void resetGlobalClassInitTime() { |
| 1287 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME); |
| 1288 | } |
| 1289 | |
| 1290 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1291 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1292 | * @deprecated This method is now obsolete. |
| 1293 | */ |
| 1294 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | public static int getGlobalExternalAllocCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1296 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1298 | |
| 1299 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1300 | * This method exists for compatibility and has no effect. |
| 1301 | * @deprecated This method is now obsolete. |
| 1302 | */ |
| 1303 | @Deprecated |
| 1304 | public static void resetGlobalExternalAllocSize() {} |
| 1305 | |
| 1306 | /** |
| 1307 | * This method exists for compatibility and has no effect. |
| 1308 | * @deprecated This method is now obsolete. |
| 1309 | */ |
| 1310 | @Deprecated |
| 1311 | public static void resetGlobalExternalAllocCount() {} |
| 1312 | |
| 1313 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1314 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1315 | * @deprecated This method is now obsolete. |
| 1316 | */ |
| 1317 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | public static int getGlobalExternalAllocSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1319 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1321 | |
| 1322 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1323 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1324 | * @deprecated This method is now obsolete. |
| 1325 | */ |
| 1326 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | public static int getGlobalExternalFreedCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1328 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1330 | |
| 1331 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1332 | * This method exists for compatibility and has no effect. |
| 1333 | * @deprecated This method is now obsolete. |
| 1334 | */ |
| 1335 | @Deprecated |
| 1336 | public static void resetGlobalExternalFreedCount() {} |
| 1337 | |
| 1338 | /** |
| 1339 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1340 | * @deprecated This method is now obsolete. |
| 1341 | */ |
| 1342 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | public static int getGlobalExternalFreedSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1344 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1346 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1347 | /** |
| 1348 | * This method exists for compatibility and has no effect. |
| 1349 | * @deprecated This method is now obsolete. |
| 1350 | */ |
| 1351 | @Deprecated |
| 1352 | public static void resetGlobalExternalFreedSize() {} |
| 1353 | |
| 1354 | /** |
| 1355 | * Returns the thread-local count of objects allocated by the runtime between a |
| 1356 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1357 | * |
| 1358 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1359 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1360 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | public static int getThreadAllocCount() { |
| 1362 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS); |
| 1363 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1364 | |
| 1365 | /** |
| 1366 | * Clears the thread-local count of objects allocated. |
| 1367 | * @see #getThreadAllocCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1368 | * |
| 1369 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1370 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1371 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1372 | public static void resetThreadAllocCount() { |
| 1373 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Returns the thread-local size of objects allocated by the runtime between a |
| 1378 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
| 1379 | * @return The allocated size in bytes. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1380 | * |
| 1381 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1382 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1383 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | public static int getThreadAllocSize() { |
| 1385 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES); |
| 1386 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1387 | |
| 1388 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1389 | * Clears the thread-local count of objects allocated. |
| 1390 | * @see #getThreadAllocSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1391 | * |
| 1392 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1393 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1394 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1395 | public static void resetThreadAllocSize() { |
| 1396 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES); |
| 1397 | } |
| 1398 | |
| 1399 | /** |
| 1400 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1401 | * @deprecated This method is now obsolete. |
| 1402 | */ |
| 1403 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | public static int getThreadExternalAllocCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1405 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1407 | |
| 1408 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1409 | * This method exists for compatibility and has no effect. |
| 1410 | * @deprecated This method is now obsolete. |
| 1411 | */ |
| 1412 | @Deprecated |
| 1413 | public static void resetThreadExternalAllocCount() {} |
| 1414 | |
| 1415 | /** |
| 1416 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1417 | * @deprecated This method is now obsolete. |
| 1418 | */ |
| 1419 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | public static int getThreadExternalAllocSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1421 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1423 | |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1424 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1425 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1426 | * @deprecated This method is now obsolete. |
| 1427 | */ |
| 1428 | @Deprecated |
| 1429 | public static void resetThreadExternalAllocSize() {} |
| 1430 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1431 | /** |
| 1432 | * Returns the number of thread-local non-concurrent GC invocations between a |
| 1433 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1434 | * |
| 1435 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1436 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1437 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1438 | public static int getThreadGcInvocationCount() { |
| 1439 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS); |
| 1440 | } |
| 1441 | |
| 1442 | /** |
| 1443 | * Clears the thread-local count of non-concurrent GC invocations. |
| 1444 | * @see #getThreadGcInvocationCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1445 | * |
| 1446 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1447 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1448 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | public static void resetThreadGcInvocationCount() { |
| 1450 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS); |
| 1451 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1452 | |
| 1453 | /** |
| 1454 | * Clears all the global and thread-local memory allocation counters. |
| 1455 | * @see #startAllocCounting() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1456 | * |
| 1457 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1458 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1459 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | public static void resetAllCounts() { |
| 1461 | VMDebug.resetAllocCount(VMDebug.KIND_ALL_COUNTS); |
| 1462 | } |
| 1463 | |
| 1464 | /** |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1465 | * Returns the value of a particular runtime statistic or {@code null} if no |
| 1466 | * such runtime statistic exists. |
| 1467 | * |
| 1468 | * <p>The following table lists the runtime statistics that the runtime supports. |
| 1469 | * Note runtime statistics may be added or removed in a future API level.</p> |
| 1470 | * |
| 1471 | * <table> |
| 1472 | * <thead> |
| 1473 | * <tr> |
| 1474 | * <th>Runtime statistic name</th> |
| 1475 | * <th>Meaning</th> |
| 1476 | * <th>Example</th> |
| 1477 | * <th>Supported (API Levels)</th> |
| 1478 | * </tr> |
| 1479 | * </thead> |
| 1480 | * <tbody> |
| 1481 | * <tr> |
| 1482 | * <td>art.gc.gc-count</td> |
| 1483 | * <td>The number of garbage collection runs.</td> |
| 1484 | * <td>{@code 164}</td> |
| 1485 | * <td>23</td> |
| 1486 | * </tr> |
| 1487 | * <tr> |
| 1488 | * <td>art.gc.gc-time</td> |
| 1489 | * <td>The total duration of garbage collection runs in ms.</td> |
| 1490 | * <td>{@code 62364}</td> |
| 1491 | * <td>23</td> |
| 1492 | * </tr> |
| 1493 | * <tr> |
| 1494 | * <td>art.gc.bytes-allocated</td> |
| 1495 | * <td>The total number of bytes that the application allocated.</td> |
| 1496 | * <td>{@code 1463948408}</td> |
| 1497 | * <td>23</td> |
| 1498 | * </tr> |
| 1499 | * <tr> |
| 1500 | * <td>art.gc.bytes-freed</td> |
| 1501 | * <td>The total number of bytes that garbage collection reclaimed.</td> |
| 1502 | * <td>{@code 1313493084}</td> |
| 1503 | * <td>23</td> |
| 1504 | * </tr> |
| 1505 | * <tr> |
| 1506 | * <td>art.gc.blocking-gc-count</td> |
| 1507 | * <td>The number of blocking garbage collection runs.</td> |
| 1508 | * <td>{@code 2}</td> |
| 1509 | * <td>23</td> |
| 1510 | * </tr> |
| 1511 | * <tr> |
| 1512 | * <td>art.gc.blocking-gc-time</td> |
| 1513 | * <td>The total duration of blocking garbage collection runs in ms.</td> |
| 1514 | * <td>{@code 804}</td> |
| 1515 | * <td>23</td> |
| 1516 | * </tr> |
| 1517 | * <tr> |
| 1518 | * <td>art.gc.gc-count-rate-histogram</td> |
Hiroshi Yamauchi | 2d6327d | 2015-05-28 15:28:16 -0700 | [diff] [blame] | 1519 | * <td>Every 10 seconds, the gc-count-rate is computed as the number of garbage |
| 1520 | * collection runs that have occurred over the last 10 |
| 1521 | * seconds. art.gc.gc-count-rate-histogram is a histogram of the gc-count-rate |
| 1522 | * samples taken since the process began. The histogram can be used to identify |
| 1523 | * instances of high rates of garbage collection runs. For example, a histogram |
| 1524 | * of "0:34503,1:45350,2:11281,3:8088,4:43,5:8" shows that most of the time |
| 1525 | * there are between 0 and 2 garbage collection runs every 10 seconds, but there |
| 1526 | * were 8 distinct 10-second intervals in which 5 garbage collection runs |
| 1527 | * occurred.</td> |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1528 | * <td>{@code 0:34503,1:45350,2:11281,3:8088,4:43,5:8}</td> |
| 1529 | * <td>23</td> |
| 1530 | * </tr> |
| 1531 | * <tr> |
| 1532 | * <td>art.gc.blocking-gc-count-rate-histogram</td> |
Hiroshi Yamauchi | 2d6327d | 2015-05-28 15:28:16 -0700 | [diff] [blame] | 1533 | * <td>Every 10 seconds, the blocking-gc-count-rate is computed as the number of |
| 1534 | * blocking garbage collection runs that have occurred over the last 10 |
| 1535 | * seconds. art.gc.blocking-gc-count-rate-histogram is a histogram of the |
| 1536 | * blocking-gc-count-rate samples taken since the process began. The histogram |
| 1537 | * can be used to identify instances of high rates of blocking garbage |
| 1538 | * collection runs. For example, a histogram of "0:99269,1:1,2:1" shows that |
| 1539 | * most of the time there are zero blocking garbage collection runs every 10 |
| 1540 | * seconds, but there was one 10-second interval in which one blocking garbage |
| 1541 | * collection run occurred, and there was one interval in which two blocking |
| 1542 | * garbage collection runs occurred.</td> |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1543 | * <td>{@code 0:99269,1:1,2:1}</td> |
| 1544 | * <td>23</td> |
| 1545 | * </tr> |
| 1546 | * </tbody> |
| 1547 | * </table> |
| 1548 | * |
| 1549 | * @param statName |
| 1550 | * the name of the runtime statistic to look up. |
| 1551 | * @return the value of the specified runtime statistic or {@code null} if the |
| 1552 | * runtime statistic doesn't exist. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1553 | */ |
| 1554 | public static String getRuntimeStat(String statName) { |
| 1555 | return VMDebug.getRuntimeStat(statName); |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Returns a map of the names/values of the runtime statistics |
Hiroshi Yamauchi | d800167 | 2015-04-14 16:07:26 -0700 | [diff] [blame] | 1560 | * that {@link #getRuntimeStat(String)} supports. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1561 | * |
| 1562 | * @return a map of the names/values of the supported runtime statistics. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1563 | */ |
| 1564 | public static Map<String, String> getRuntimeStats() { |
| 1565 | return VMDebug.getRuntimeStats(); |
| 1566 | } |
| 1567 | |
| 1568 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | * Returns the size of the native heap. |
| 1570 | * @return The size of the native heap in bytes. |
| 1571 | */ |
| 1572 | public static native long getNativeHeapSize(); |
| 1573 | |
| 1574 | /** |
| 1575 | * Returns the amount of allocated memory in the native heap. |
| 1576 | * @return The allocated size in bytes. |
| 1577 | */ |
| 1578 | public static native long getNativeHeapAllocatedSize(); |
| 1579 | |
| 1580 | /** |
| 1581 | * Returns the amount of free memory in the native heap. |
| 1582 | * @return The freed size in bytes. |
| 1583 | */ |
| 1584 | public static native long getNativeHeapFreeSize(); |
| 1585 | |
| 1586 | /** |
| 1587 | * Retrieves information about this processes memory usages. This information is broken down by |
Dianne Hackborn | b02ce29 | 2015-10-12 15:14:16 -0700 | [diff] [blame] | 1588 | * how much is in use by dalvik, the native heap, and everything else. |
| 1589 | * |
| 1590 | * <p><b>Note:</b> this method directly retrieves memory information for the give process |
| 1591 | * from low-level data available to it. It may not be able to retrieve information about |
| 1592 | * some protected allocations, such as graphics. If you want to be sure you can see |
| 1593 | * all information about allocations by the process, use instead |
| 1594 | * {@link android.app.ActivityManager#getProcessMemoryInfo(int[])}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | */ |
| 1596 | public static native void getMemoryInfo(MemoryInfo memoryInfo); |
| 1597 | |
| 1598 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1599 | * Note: currently only works when the requested pid has the same UID |
| 1600 | * as the caller. |
| 1601 | * @hide |
| 1602 | */ |
| 1603 | public static native void getMemoryInfo(int pid, MemoryInfo memoryInfo); |
| 1604 | |
| 1605 | /** |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1606 | * Retrieves the PSS memory used by the process as given by the |
| 1607 | * smaps. |
| 1608 | */ |
| 1609 | public static native long getPss(); |
| 1610 | |
| 1611 | /** |
| 1612 | * Retrieves the PSS memory used by the process as given by the |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 1613 | * smaps. Optionally supply a long array of 2 entries to also |
| 1614 | * receive the Uss and SwapPss of the process, and another array to also |
| 1615 | * retrieve the separate memtrack size. |
| 1616 | * @hide |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1617 | */ |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 1618 | public static native long getPss(int pid, long[] outUssSwapPss, long[] outMemtrack); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1619 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1620 | /** @hide */ |
| 1621 | public static final int MEMINFO_TOTAL = 0; |
| 1622 | /** @hide */ |
| 1623 | public static final int MEMINFO_FREE = 1; |
| 1624 | /** @hide */ |
| 1625 | public static final int MEMINFO_BUFFERS = 2; |
| 1626 | /** @hide */ |
| 1627 | public static final int MEMINFO_CACHED = 3; |
| 1628 | /** @hide */ |
| 1629 | public static final int MEMINFO_SHMEM = 4; |
| 1630 | /** @hide */ |
| 1631 | public static final int MEMINFO_SLAB = 5; |
| 1632 | /** @hide */ |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 1633 | public static final int MEMINFO_SWAP_TOTAL = 6; |
| 1634 | /** @hide */ |
| 1635 | public static final int MEMINFO_SWAP_FREE = 7; |
| 1636 | /** @hide */ |
| 1637 | public static final int MEMINFO_ZRAM_TOTAL = 8; |
| 1638 | /** @hide */ |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 1639 | public static final int MEMINFO_MAPPED = 9; |
| 1640 | /** @hide */ |
| 1641 | public static final int MEMINFO_VM_ALLOC_USED = 10; |
| 1642 | /** @hide */ |
| 1643 | public static final int MEMINFO_PAGE_TABLES = 11; |
| 1644 | /** @hide */ |
| 1645 | public static final int MEMINFO_KERNEL_STACK = 12; |
| 1646 | /** @hide */ |
| 1647 | public static final int MEMINFO_COUNT = 13; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1648 | |
| 1649 | /** |
| 1650 | * Retrieves /proc/meminfo. outSizes is filled with fields |
| 1651 | * as defined by MEMINFO_* offsets. |
| 1652 | * @hide |
| 1653 | */ |
| 1654 | public static native void getMemInfo(long[] outSizes); |
| 1655 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1656 | /** |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1657 | * Establish an object allocation limit in the current thread. |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1658 | * This feature was never enabled in release builds. The |
| 1659 | * allocation limits feature was removed in Honeycomb. This |
| 1660 | * method exists for compatibility and always returns -1 and has |
| 1661 | * no effect. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | * |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1663 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | */ |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1665 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | public static int setAllocationLimit(int limit) { |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1667 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /** |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1671 | * Establish a global object allocation limit. This feature was |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1672 | * never enabled in release builds. The allocation limits feature |
| 1673 | * was removed in Honeycomb. This method exists for compatibility |
| 1674 | * and always returns -1 and has no effect. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | * |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1676 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | */ |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1678 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | public static int setGlobalAllocationLimit(int limit) { |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1680 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * Dump a list of all currently loaded class to the log file. |
| 1685 | * |
| 1686 | * @param flags See constants above. |
| 1687 | */ |
| 1688 | public static void printLoadedClasses(int flags) { |
| 1689 | VMDebug.printLoadedClasses(flags); |
| 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * Get the number of loaded classes. |
| 1694 | * @return the number of loaded classes. |
| 1695 | */ |
| 1696 | public static int getLoadedClassCount() { |
| 1697 | return VMDebug.getLoadedClassCount(); |
| 1698 | } |
| 1699 | |
| 1700 | /** |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1701 | * Dump "hprof" data to the specified file. This may cause a GC. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | * |
| 1703 | * @param fileName Full pathname of output file (e.g. "/sdcard/dump.hprof"). |
| 1704 | * @throws UnsupportedOperationException if the VM was built without |
| 1705 | * HPROF support. |
| 1706 | * @throws IOException if an error occurs while opening or writing files. |
| 1707 | */ |
| 1708 | public static void dumpHprofData(String fileName) throws IOException { |
| 1709 | VMDebug.dumpHprofData(fileName); |
| 1710 | } |
| 1711 | |
| 1712 | /** |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1713 | * Like dumpHprofData(String), but takes an already-opened |
| 1714 | * FileDescriptor to which the trace is written. The file name is also |
| 1715 | * supplied simply for logging. Makes a dup of the file descriptor. |
| 1716 | * |
| 1717 | * Primarily for use by the "am" shell command. |
| 1718 | * |
| 1719 | * @hide |
| 1720 | */ |
| 1721 | public static void dumpHprofData(String fileName, FileDescriptor fd) |
| 1722 | throws IOException { |
| 1723 | VMDebug.dumpHprofData(fileName, fd); |
| 1724 | } |
| 1725 | |
| 1726 | /** |
| 1727 | * Collect "hprof" and send it to DDMS. This may cause a GC. |
Andy McFadden | 07a9661 | 2010-01-28 16:54:37 -0800 | [diff] [blame] | 1728 | * |
| 1729 | * @throws UnsupportedOperationException if the VM was built without |
| 1730 | * HPROF support. |
Andy McFadden | 07a9661 | 2010-01-28 16:54:37 -0800 | [diff] [blame] | 1731 | * @hide |
| 1732 | */ |
| 1733 | public static void dumpHprofDataDdms() { |
| 1734 | VMDebug.dumpHprofDataDdms(); |
| 1735 | } |
| 1736 | |
| 1737 | /** |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1738 | * Writes native heap data to the specified file descriptor. |
| 1739 | * |
| 1740 | * @hide |
| 1741 | */ |
| 1742 | public static native void dumpNativeHeap(FileDescriptor fd); |
| 1743 | |
| 1744 | /** |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1745 | * Returns a count of the extant instances of a class. |
| 1746 | * |
| 1747 | * @hide |
| 1748 | */ |
| 1749 | public static long countInstancesOfClass(Class cls) { |
Brian Carlstrom | 7495cfa | 2010-11-30 18:06:00 -0800 | [diff] [blame] | 1750 | return VMDebug.countInstancesOfClass(cls, true); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1754 | * Returns the number of sent transactions from this process. |
| 1755 | * @return The number of sent transactions or -1 if it could not read t. |
| 1756 | */ |
| 1757 | public static native int getBinderSentTransactions(); |
| 1758 | |
| 1759 | /** |
| 1760 | * Returns the number of received transactions from the binder driver. |
| 1761 | * @return The number of received transactions or -1 if it could not read the stats. |
| 1762 | */ |
| 1763 | public static native int getBinderReceivedTransactions(); |
| 1764 | |
| 1765 | /** |
| 1766 | * Returns the number of active local Binder objects that exist in the |
| 1767 | * current process. |
| 1768 | */ |
| 1769 | public static final native int getBinderLocalObjectCount(); |
| 1770 | |
| 1771 | /** |
| 1772 | * Returns the number of references to remote proxy Binder objects that |
| 1773 | * exist in the current process. |
| 1774 | */ |
| 1775 | public static final native int getBinderProxyObjectCount(); |
| 1776 | |
| 1777 | /** |
| 1778 | * Returns the number of death notification links to Binder objects that |
| 1779 | * exist in the current process. |
| 1780 | */ |
| 1781 | public static final native int getBinderDeathObjectCount(); |
| 1782 | |
| 1783 | /** |
Andy McFadden | 599c918 | 2009-04-08 00:35:56 -0700 | [diff] [blame] | 1784 | * Primes the register map cache. |
| 1785 | * |
| 1786 | * Only works for classes in the bootstrap class loader. Does not |
| 1787 | * cause classes to be loaded if they're not already present. |
| 1788 | * |
| 1789 | * The classAndMethodDesc argument is a concatentation of the VM-internal |
| 1790 | * class descriptor, method name, and method descriptor. Examples: |
| 1791 | * Landroid/os/Looper;.loop:()V |
| 1792 | * Landroid/app/ActivityThread;.main:([Ljava/lang/String;)V |
| 1793 | * |
| 1794 | * @param classAndMethodDesc the method to prepare |
| 1795 | * |
| 1796 | * @hide |
| 1797 | */ |
| 1798 | public static final boolean cacheRegisterMap(String classAndMethodDesc) { |
| 1799 | return VMDebug.cacheRegisterMap(classAndMethodDesc); |
| 1800 | } |
| 1801 | |
| 1802 | /** |
Andy McFadden | bfd6d48 | 2009-10-22 17:25:57 -0700 | [diff] [blame] | 1803 | * Dumps the contents of VM reference tables (e.g. JNI locals and |
| 1804 | * globals) to the log file. |
| 1805 | * |
| 1806 | * @hide |
| 1807 | */ |
| 1808 | public static final void dumpReferenceTables() { |
| 1809 | VMDebug.dumpReferenceTables(); |
| 1810 | } |
| 1811 | |
| 1812 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | * API for gathering and querying instruction counts. |
| 1814 | * |
| 1815 | * Example usage: |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1816 | * <pre> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | * Debug.InstructionCount icount = new Debug.InstructionCount(); |
| 1818 | * icount.resetAndStart(); |
| 1819 | * [... do lots of stuff ...] |
| 1820 | * if (icount.collect()) { |
| 1821 | * System.out.println("Total instructions executed: " |
| 1822 | * + icount.globalTotal()); |
| 1823 | * System.out.println("Method invocations: " |
| 1824 | * + icount.globalMethodInvocations()); |
| 1825 | * } |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1826 | * </pre> |
Jeff Hao | 7d0b3d4 | 2014-09-17 15:45:05 -0700 | [diff] [blame] | 1827 | * |
| 1828 | * @deprecated Instruction counting is no longer supported. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | */ |
Jeff Hao | 7d0b3d4 | 2014-09-17 15:45:05 -0700 | [diff] [blame] | 1830 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | public static class InstructionCount { |
Dan Bornstein | b96f589 | 2010-12-02 17:19:53 -0800 | [diff] [blame] | 1832 | private static final int NUM_INSTR = |
| 1833 | OpcodeInfo.MAXIMUM_PACKED_VALUE + 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | |
| 1835 | private int[] mCounts; |
| 1836 | |
| 1837 | public InstructionCount() { |
| 1838 | mCounts = new int[NUM_INSTR]; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Reset counters and ensure counts are running. Counts may |
| 1843 | * have already been running. |
| 1844 | * |
| 1845 | * @return true if counting was started |
| 1846 | */ |
| 1847 | public boolean resetAndStart() { |
| 1848 | try { |
| 1849 | VMDebug.startInstructionCounting(); |
| 1850 | VMDebug.resetInstructionCount(); |
| 1851 | } catch (UnsupportedOperationException uoe) { |
| 1852 | return false; |
| 1853 | } |
| 1854 | return true; |
| 1855 | } |
| 1856 | |
| 1857 | /** |
| 1858 | * Collect instruction counts. May or may not stop the |
| 1859 | * counting process. |
| 1860 | */ |
| 1861 | public boolean collect() { |
| 1862 | try { |
| 1863 | VMDebug.stopInstructionCounting(); |
| 1864 | VMDebug.getInstructionCount(mCounts); |
| 1865 | } catch (UnsupportedOperationException uoe) { |
| 1866 | return false; |
| 1867 | } |
| 1868 | return true; |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * Return the total number of instructions executed globally (i.e. in |
| 1873 | * all threads). |
| 1874 | */ |
| 1875 | public int globalTotal() { |
| 1876 | int count = 0; |
Dan Bornstein | 1d99b06 | 2010-11-30 12:26:52 -0800 | [diff] [blame] | 1877 | |
| 1878 | for (int i = 0; i < NUM_INSTR; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | count += mCounts[i]; |
Dan Bornstein | 1d99b06 | 2010-11-30 12:26:52 -0800 | [diff] [blame] | 1880 | } |
| 1881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | return count; |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * Return the total number of method-invocation instructions |
| 1887 | * executed globally. |
| 1888 | */ |
| 1889 | public int globalMethodInvocations() { |
| 1890 | int count = 0; |
| 1891 | |
Dan Bornstein | 1d99b06 | 2010-11-30 12:26:52 -0800 | [diff] [blame] | 1892 | for (int i = 0; i < NUM_INSTR; i++) { |
| 1893 | if (OpcodeInfo.isInvoke(i)) { |
| 1894 | count += mCounts[i]; |
| 1895 | } |
| 1896 | } |
| 1897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | return count; |
| 1899 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1902 | /** |
| 1903 | * A Map of typed debug properties. |
| 1904 | */ |
| 1905 | private static final TypedProperties debugProperties; |
| 1906 | |
| 1907 | /* |
| 1908 | * Load the debug properties from the standard files into debugProperties. |
| 1909 | */ |
| 1910 | static { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 1911 | if (false) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1912 | final String TAG = "DebugProperties"; |
| 1913 | final String[] files = { "/system/debug.prop", "/debug.prop", "/data/debug.prop" }; |
| 1914 | final TypedProperties tp = new TypedProperties(); |
| 1915 | |
| 1916 | // Read the properties from each of the files, if present. |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1917 | for (String file : files) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1918 | Reader r; |
| 1919 | try { |
| 1920 | r = new FileReader(file); |
| 1921 | } catch (FileNotFoundException ex) { |
| 1922 | // It's ok if a file is missing. |
| 1923 | continue; |
| 1924 | } |
| 1925 | |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1926 | try { |
| 1927 | tp.load(r); |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1928 | } catch (Exception ex) { |
| 1929 | throw new RuntimeException("Problem loading " + file, ex); |
| 1930 | } finally { |
| 1931 | try { |
| 1932 | r.close(); |
| 1933 | } catch (IOException ex) { |
| 1934 | // Ignore this error. |
| 1935 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | debugProperties = tp.isEmpty() ? null : tp; |
| 1940 | } else { |
| 1941 | debugProperties = null; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | /** |
| 1947 | * Returns true if the type of the field matches the specified class. |
| 1948 | * Handles the case where the class is, e.g., java.lang.Boolean, but |
| 1949 | * the field is of the primitive "boolean" type. Also handles all of |
| 1950 | * the java.lang.Number subclasses. |
| 1951 | */ |
| 1952 | private static boolean fieldTypeMatches(Field field, Class<?> cl) { |
| 1953 | Class<?> fieldClass = field.getType(); |
| 1954 | if (fieldClass == cl) { |
| 1955 | return true; |
| 1956 | } |
| 1957 | Field primitiveTypeField; |
| 1958 | try { |
| 1959 | /* All of the classes we care about (Boolean, Integer, etc.) |
| 1960 | * have a Class field called "TYPE" that points to the corresponding |
| 1961 | * primitive class. |
| 1962 | */ |
| 1963 | primitiveTypeField = cl.getField("TYPE"); |
| 1964 | } catch (NoSuchFieldException ex) { |
| 1965 | return false; |
| 1966 | } |
| 1967 | try { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1968 | return fieldClass == (Class<?>) primitiveTypeField.get(null); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1969 | } catch (IllegalAccessException ex) { |
| 1970 | return false; |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | |
| 1975 | /** |
| 1976 | * Looks up the property that corresponds to the field, and sets the field's value |
| 1977 | * if the types match. |
| 1978 | */ |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1979 | private static void modifyFieldIfSet(final Field field, final TypedProperties properties, |
| 1980 | final String propertyName) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1981 | if (field.getType() == java.lang.String.class) { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1982 | int stringInfo = properties.getStringInfo(propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1983 | switch (stringInfo) { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1984 | case TypedProperties.STRING_SET: |
| 1985 | // Handle as usual below. |
| 1986 | break; |
| 1987 | case TypedProperties.STRING_NULL: |
| 1988 | try { |
| 1989 | field.set(null, null); // null object for static fields; null string |
| 1990 | } catch (IllegalAccessException ex) { |
| 1991 | throw new IllegalArgumentException( |
| 1992 | "Cannot set field for " + propertyName, ex); |
| 1993 | } |
| 1994 | return; |
| 1995 | case TypedProperties.STRING_NOT_SET: |
| 1996 | return; |
| 1997 | case TypedProperties.STRING_TYPE_MISMATCH: |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 1998 | throw new IllegalArgumentException( |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 1999 | "Type of " + propertyName + " " + |
| 2000 | " does not match field type (" + field.getType() + ")"); |
| 2001 | default: |
| 2002 | throw new IllegalStateException( |
| 2003 | "Unexpected getStringInfo(" + propertyName + ") return value " + |
| 2004 | stringInfo); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2005 | } |
| 2006 | } |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2007 | Object value = properties.get(propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2008 | if (value != null) { |
| 2009 | if (!fieldTypeMatches(field, value.getClass())) { |
| 2010 | throw new IllegalArgumentException( |
| 2011 | "Type of " + propertyName + " (" + value.getClass() + ") " + |
| 2012 | " does not match field type (" + field.getType() + ")"); |
| 2013 | } |
| 2014 | try { |
| 2015 | field.set(null, value); // null object for static fields |
| 2016 | } catch (IllegalAccessException ex) { |
| 2017 | throw new IllegalArgumentException( |
| 2018 | "Cannot set field for " + propertyName, ex); |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | |
| 2024 | /** |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2025 | * Equivalent to <code>setFieldsOn(cl, false)</code>. |
| 2026 | * |
| 2027 | * @see #setFieldsOn(Class, boolean) |
Romain Guy | d4103d0 | 2009-05-14 12:24:21 -0700 | [diff] [blame] | 2028 | * |
| 2029 | * @hide |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2030 | */ |
| 2031 | public static void setFieldsOn(Class<?> cl) { |
| 2032 | setFieldsOn(cl, false); |
| 2033 | } |
| 2034 | |
| 2035 | /** |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2036 | * Reflectively sets static fields of a class based on internal debugging |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2037 | * properties. This method is a no-op if false is |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2038 | * false. |
| 2039 | * <p> |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2040 | * <strong>NOTE TO APPLICATION DEVELOPERS</strong>: false will |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2041 | * always be false in release builds. This API is typically only useful |
| 2042 | * for platform developers. |
| 2043 | * </p> |
| 2044 | * Class setup: define a class whose only fields are non-final, static |
| 2045 | * primitive types (except for "char") or Strings. In a static block |
| 2046 | * after the field definitions/initializations, pass the class to |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2047 | * this method, Debug.setFieldsOn(). Example: |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2048 | * <pre> |
| 2049 | * package com.example; |
| 2050 | * |
| 2051 | * import android.os.Debug; |
| 2052 | * |
| 2053 | * public class MyDebugVars { |
| 2054 | * public static String s = "a string"; |
| 2055 | * public static String s2 = "second string"; |
| 2056 | * public static String ns = null; |
| 2057 | * public static boolean b = false; |
| 2058 | * public static int i = 5; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2059 | * @Debug.DebugProperty |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2060 | * public static float f = 0.1f; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2061 | * @@Debug.DebugProperty |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2062 | * public static double d = 0.5d; |
| 2063 | * |
| 2064 | * // This MUST appear AFTER all fields are defined and initialized! |
| 2065 | * static { |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2066 | * // Sets all the fields |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2067 | * Debug.setFieldsOn(MyDebugVars.class); |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 2068 | * |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2069 | * // Sets only the fields annotated with @Debug.DebugProperty |
| 2070 | * // Debug.setFieldsOn(MyDebugVars.class, true); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2071 | * } |
| 2072 | * } |
| 2073 | * </pre> |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2074 | * setFieldsOn() may override the value of any field in the class based |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2075 | * on internal properties that are fixed at boot time. |
| 2076 | * <p> |
| 2077 | * These properties are only set during platform debugging, and are not |
| 2078 | * meant to be used as a general-purpose properties store. |
| 2079 | * |
| 2080 | * {@hide} |
| 2081 | * |
| 2082 | * @param cl The class to (possibly) modify |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2083 | * @param partial If false, sets all static fields, otherwise, only set |
| 2084 | * fields with the {@link android.os.Debug.DebugProperty} |
| 2085 | * annotation |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2086 | * @throws IllegalArgumentException if any fields are final or non-static, |
| 2087 | * or if the type of the field does not match the type of |
| 2088 | * the internal debugging property value. |
| 2089 | */ |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2090 | public static void setFieldsOn(Class<?> cl, boolean partial) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2091 | if (false) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2092 | if (debugProperties != null) { |
| 2093 | /* Only look for fields declared directly by the class, |
| 2094 | * so we don't mysteriously change static fields in superclasses. |
| 2095 | */ |
| 2096 | for (Field field : cl.getDeclaredFields()) { |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2097 | if (!partial || field.getAnnotation(DebugProperty.class) != null) { |
| 2098 | final String propertyName = cl.getName() + "." + field.getName(); |
| 2099 | boolean isStatic = Modifier.isStatic(field.getModifiers()); |
| 2100 | boolean isFinal = Modifier.isFinal(field.getModifiers()); |
| 2101 | |
| 2102 | if (!isStatic || isFinal) { |
| 2103 | throw new IllegalArgumentException(propertyName + |
| 2104 | " must be static and non-final"); |
| 2105 | } |
| 2106 | modifyFieldIfSet(field, debugProperties, propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2107 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | } else { |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 2111 | Log.wtf(TAG, |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2112 | "setFieldsOn(" + (cl == null ? "null" : cl.getName()) + |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2113 | ") called in non-DEBUG build"); |
| 2114 | } |
| 2115 | } |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2116 | |
| 2117 | /** |
| 2118 | * Annotation to put on fields you want to set with |
| 2119 | * {@link Debug#setFieldsOn(Class, boolean)}. |
| 2120 | * |
| 2121 | * @hide |
| 2122 | */ |
| 2123 | @Target({ ElementType.FIELD }) |
| 2124 | @Retention(RetentionPolicy.RUNTIME) |
| 2125 | public @interface DebugProperty { |
| 2126 | } |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 2127 | |
| 2128 | /** |
| 2129 | * Get a debugging dump of a system service by name. |
| 2130 | * |
| 2131 | * <p>Most services require the caller to hold android.permission.DUMP. |
| 2132 | * |
| 2133 | * @param name of the service to dump |
| 2134 | * @param fd to write dump output to (usually an output log file) |
| 2135 | * @param args to pass to the service's dump method, may be null |
| 2136 | * @return true if the service was dumped successfully, false if |
| 2137 | * the service could not be found or had an error while dumping |
| 2138 | */ |
| 2139 | public static boolean dumpService(String name, FileDescriptor fd, String[] args) { |
| 2140 | IBinder service = ServiceManager.getService(name); |
| 2141 | if (service == null) { |
| 2142 | Log.e(TAG, "Can't find service to dump: " + name); |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
| 2146 | try { |
| 2147 | service.dump(fd, args); |
| 2148 | return true; |
| 2149 | } catch (RemoteException e) { |
| 2150 | Log.e(TAG, "Can't dump service: " + name, e); |
| 2151 | return false; |
| 2152 | } |
| 2153 | } |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2154 | |
| 2155 | /** |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 2156 | * Have the stack traces of the given native process dumped to the |
| 2157 | * specified file. Will be appended to the file. |
| 2158 | * @hide |
| 2159 | */ |
| 2160 | public static native void dumpNativeBacktraceToFile(int pid, String file); |
| 2161 | |
| 2162 | /** |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 2163 | * Get description of unreachable native memory. |
| 2164 | * @param limit the number of leaks to provide info on, 0 to only get a summary. |
| 2165 | * @param contents true to include a hex dump of the contents of unreachable memory. |
| 2166 | * @return the String containing a description of unreachable memory. |
| 2167 | * @hide */ |
| 2168 | public static native String getUnreachableMemory(int limit, boolean contents); |
| 2169 | |
| 2170 | /** |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2171 | * Return a String describing the calling method and location at a particular stack depth. |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 2172 | * @param callStack the Thread stack |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2173 | * @param depth the depth of stack to return information for. |
| 2174 | * @return the String describing the caller at that depth. |
| 2175 | */ |
| 2176 | private static String getCaller(StackTraceElement callStack[], int depth) { |
| 2177 | // callStack[4] is the caller of the method that called getCallers() |
| 2178 | if (4 + depth >= callStack.length) { |
| 2179 | return "<bottom of call stack>"; |
| 2180 | } |
| 2181 | StackTraceElement caller = callStack[4 + depth]; |
| 2182 | return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber(); |
| 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * Return a string consisting of methods and locations at multiple call stack levels. |
| 2187 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2188 | * @return a string describing the call stack. |
| 2189 | * {@hide} |
| 2190 | */ |
| 2191 | public static String getCallers(final int depth) { |
| 2192 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2193 | StringBuffer sb = new StringBuffer(); |
| 2194 | for (int i = 0; i < depth; i++) { |
| 2195 | sb.append(getCaller(callStack, i)).append(" "); |
| 2196 | } |
| 2197 | return sb.toString(); |
| 2198 | } |
| 2199 | |
| 2200 | /** |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 2201 | * Return a string consisting of methods and locations at multiple call stack levels. |
| 2202 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2203 | * @return a string describing the call stack. |
| 2204 | * {@hide} |
| 2205 | */ |
| 2206 | public static String getCallers(final int start, int depth) { |
| 2207 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2208 | StringBuffer sb = new StringBuffer(); |
| 2209 | depth += start; |
| 2210 | for (int i = start; i < depth; i++) { |
| 2211 | sb.append(getCaller(callStack, i)).append(" "); |
| 2212 | } |
| 2213 | return sb.toString(); |
| 2214 | } |
| 2215 | |
| 2216 | /** |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 2217 | * Like {@link #getCallers(int)}, but each location is append to the string |
| 2218 | * as a new line with <var>linePrefix</var> in front of it. |
| 2219 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2220 | * @param linePrefix prefix to put in front of each location. |
| 2221 | * @return a string describing the call stack. |
| 2222 | * {@hide} |
| 2223 | */ |
| 2224 | public static String getCallers(final int depth, String linePrefix) { |
| 2225 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2226 | StringBuffer sb = new StringBuffer(); |
| 2227 | for (int i = 0; i < depth; i++) { |
| 2228 | sb.append(linePrefix).append(getCaller(callStack, i)).append("\n"); |
| 2229 | } |
| 2230 | return sb.toString(); |
| 2231 | } |
| 2232 | |
| 2233 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 2234 | * @return a String describing the immediate caller of the calling method. |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2235 | * {@hide} |
| 2236 | */ |
| 2237 | public static String getCaller() { |
| 2238 | return getCaller(Thread.currentThread().getStackTrace(), 0); |
| 2239 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | } |