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