blob: 75fea52536743df57e21dc4ccc22eda68d629012 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.os;
18
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -060019import android.app.AppGlobals;
20import android.content.Context;
Dave Bort1ce5bd32009-04-22 17:36:56 -070021import android.util.Log;
22
Narayan Kamathf013daa2017-05-09 12:55:02 +010023import com.android.internal.util.FastPrintWriter;
24import com.android.internal.util.TypedProperties;
25
26import dalvik.bytecode.OpcodeInfo;
27import dalvik.system.VMDebug;
28
29import org.apache.harmony.dalvik.ddmc.Chunk;
30import org.apache.harmony.dalvik.ddmc.ChunkHandler;
31import org.apache.harmony.dalvik.ddmc.DdmServer;
32
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -060033import java.io.File;
Dianne Hackborn9c8dd552009-06-23 19:22:52 -070034import java.io.FileDescriptor;
Dave Bort1ce5bd32009-04-22 17:36:56 -070035import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import java.io.FileOutputStream;
Dave Bort1ce5bd32009-04-22 17:36:56 -070037import java.io.FileReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.PrintWriter;
Dave Bort1ce5bd32009-04-22 17:36:56 -070040import java.io.Reader;
Romain Guyc4b11a72009-05-13 15:46:37 -070041import java.lang.annotation.ElementType;
42import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
Narayan Kamathf013daa2017-05-09 12:55:02 +010044import java.lang.annotation.Target;
45import java.lang.reflect.Field;
46import java.lang.reflect.Modifier;
Richard Uhler350e6dc2015-05-18 10:48:52 -070047import java.util.HashMap;
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -070048import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52
53/**
Ian Rogersfe067a42013-02-22 19:59:23 -080054 * Provides various debugging methods for Android applications, including
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 * 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
59href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for
60 * information about reading trace files. To start logging trace files, call one
61 * of the startMethodTracing() methods. To stop tracing, call
62 * {@link #stopMethodTracing()}.
63 */
64public final class Debug
65{
Dan Egnor3eda9792010-03-05 13:28:36 -080066 private static final String TAG = "Debug";
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 /**
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 Yamauchi172da262015-03-04 12:29:19 -080073 *
74 * @deprecated Accurate counting is a burden on the runtime and may be removed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -080076 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 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 Project9066cfe2009-03-03 19:31:44 -0800106 private static final String DEFAULT_TRACE_BODY = "dmtrace";
107 private static final String DEFAULT_TRACE_EXTENSION = ".trace";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108
109 /**
110 * This class is used to retrieved various statistics about the memory mappings for this
justinmuller64551382013-10-16 22:06:55 -0600111 * process. The returned info is broken down by dalvik, native, and other. All results are in kB.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700113 public static class MemoryInfo implements Parcelable {
Dianne Hackborn64770d12013-05-23 17:51:19 -0700114 /** The proportional set size for dalvik heap. (Doesn't include other Dalvik overhead.) */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 public int dalvikPss;
Dianne Hackborn64770d12013-05-23 17:51:19 -0700116 /** The proportional set size that is swappable for dalvik heap. */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700117 /** @hide We may want to expose this, eventually. */
118 public int dalvikSwappablePss;
Dianne Hackborn64770d12013-05-23 17:51:19 -0700119 /** The private dirty pages used by dalvik heap. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 public int dalvikPrivateDirty;
Dianne Hackborn64770d12013-05-23 17:51:19 -0700121 /** The shared dirty pages used by dalvik heap. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 public int dalvikSharedDirty;
Dianne Hackborn64770d12013-05-23 17:51:19 -0700123 /** The private clean pages used by dalvik heap. */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700124 /** @hide We may want to expose this, eventually. */
125 public int dalvikPrivateClean;
Dianne Hackborn64770d12013-05-23 17:51:19 -0700126 /** The shared clean pages used by dalvik heap. */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700127 /** @hide We may want to expose this, eventually. */
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700128 public int dalvikSharedClean;
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700129 /** The dirty dalvik pages that have been swapped out. */
130 /** @hide We may want to expose this, eventually. */
131 public int dalvikSwappedOut;
Martijn Coenene0764852016-01-07 17:04:22 -0800132 /** The dirty dalvik pages that have been swapped out, proportional. */
133 /** @hide We may want to expose this, eventually. */
134 public int dalvikSwappedOutPss;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135
136 /** The proportional set size for the native heap. */
137 public int nativePss;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700138 /** The proportional set size that is swappable for the native heap. */
139 /** @hide We may want to expose this, eventually. */
140 public int nativeSwappablePss;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 /** The private dirty pages used by the native heap. */
142 public int nativePrivateDirty;
143 /** The shared dirty pages used by the native heap. */
144 public int nativeSharedDirty;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700145 /** The private clean pages used by the native heap. */
146 /** @hide We may want to expose this, eventually. */
147 public int nativePrivateClean;
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700148 /** The shared clean pages used by the native heap. */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700149 /** @hide We may want to expose this, eventually. */
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700150 public int nativeSharedClean;
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700151 /** The dirty native pages that have been swapped out. */
152 /** @hide We may want to expose this, eventually. */
153 public int nativeSwappedOut;
Martijn Coenene0764852016-01-07 17:04:22 -0800154 /** The dirty native pages that have been swapped out, proportional. */
155 /** @hide We may want to expose this, eventually. */
156 public int nativeSwappedOutPss;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157
158 /** The proportional set size for everything else. */
159 public int otherPss;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700160 /** The proportional set size that is swappable for everything else. */
161 /** @hide We may want to expose this, eventually. */
162 public int otherSwappablePss;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 /** The private dirty pages used by everything else. */
164 public int otherPrivateDirty;
165 /** The shared dirty pages used by everything else. */
166 public int otherSharedDirty;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700167 /** The private clean pages used by everything else. */
168 /** @hide We may want to expose this, eventually. */
169 public int otherPrivateClean;
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700170 /** The shared clean pages used by everything else. */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700171 /** @hide We may want to expose this, eventually. */
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700172 public int otherSharedClean;
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700173 /** The dirty pages used by anyting else that have been swapped out. */
174 /** @hide We may want to expose this, eventually. */
175 public int otherSwappedOut;
Martijn Coenene0764852016-01-07 17:04:22 -0800176 /** The dirty pages used by anyting else that have been swapped out, proportional. */
177 /** @hide We may want to expose this, eventually. */
178 public int otherSwappedOutPss;
179
180 /** Whether the kernel reports proportional swap usage */
181 /** @hide */
182 public boolean hasSwappedOutPss;
Christian Mehlmauer798e2d32010-06-17 18:24:07 +0200183
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700184 /** @hide */
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700185 public static final int HEAP_UNKNOWN = 0;
186 /** @hide */
187 public static final int HEAP_DALVIK = 1;
188 /** @hide */
189 public static final int HEAP_NATIVE = 2;
190
191 /** @hide */
192 public static final int OTHER_DALVIK_OTHER = 0;
193 /** @hide */
194 public static final int OTHER_STACK = 1;
195 /** @hide */
196 public static final int OTHER_CURSOR = 2;
197 /** @hide */
198 public static final int OTHER_ASHMEM = 3;
199 /** @hide */
200 public static final int OTHER_GL_DEV = 4;
201 /** @hide */
202 public static final int OTHER_UNKNOWN_DEV = 5;
203 /** @hide */
204 public static final int OTHER_SO = 6;
205 /** @hide */
206 public static final int OTHER_JAR = 7;
207 /** @hide */
208 public static final int OTHER_APK = 8;
209 /** @hide */
210 public static final int OTHER_TTF = 9;
211 /** @hide */
212 public static final int OTHER_DEX = 10;
213 /** @hide */
214 public static final int OTHER_OAT = 11;
215 /** @hide */
216 public static final int OTHER_ART = 12;
217 /** @hide */
218 public static final int OTHER_UNKNOWN_MAP = 13;
219 /** @hide */
220 public static final int OTHER_GRAPHICS = 14;
221 /** @hide */
222 public static final int OTHER_GL = 15;
223 /** @hide */
224 public static final int OTHER_OTHER_MEMTRACK = 16;
225
Mathieu Chartiercb862452017-07-13 15:01:34 -0700226 // Needs to be declared here for the DVK_STAT ranges below.
227 /** @hide */
228 public static final int NUM_OTHER_STATS = 17;
229
230 // Dalvik subsections.
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700231 /** @hide */
232 public static final int OTHER_DALVIK_NORMAL = 17;
233 /** @hide */
234 public static final int OTHER_DALVIK_LARGE = 18;
235 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700236 public static final int OTHER_DALVIK_ZYGOTE = 19;
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700237 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700238 public static final int OTHER_DALVIK_NON_MOVING = 20;
239 // Section begins and ends for dumpsys, relative to the DALVIK categories.
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700240 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700241 public static final int OTHER_DVK_STAT_DALVIK_START =
242 OTHER_DALVIK_NORMAL - NUM_OTHER_STATS;
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700243 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700244 public static final int OTHER_DVK_STAT_DALVIK_END =
245 OTHER_DALVIK_NON_MOVING - NUM_OTHER_STATS;
246
247 // Dalvik Other subsections.
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700248 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700249 public static final int OTHER_DALVIK_OTHER_LINEARALLOC = 21;
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700250 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700251 public static final int OTHER_DALVIK_OTHER_ACCOUNTING = 22;
252 /** @hide */
253 public static final int OTHER_DALVIK_OTHER_CODE_CACHE = 23;
254 /** @hide */
255 public static final int OTHER_DALVIK_OTHER_COMPILER_METADATA = 24;
256 /** @hide */
257 public static final int OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE = 25;
258 /** @hide */
259 public static final int OTHER_DVK_STAT_DALVIK_OTHER_START =
260 OTHER_DALVIK_OTHER_LINEARALLOC - NUM_OTHER_STATS;
261 /** @hide */
262 public static final int OTHER_DVK_STAT_DALVIK_OTHER_END =
263 OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE - NUM_OTHER_STATS;
264
265 // Dex subsections (Boot vdex, App dex, and App vdex).
266 /** @hide */
267 public static final int OTHER_DEX_BOOT_VDEX = 26;
268 /** @hide */
269 public static final int OTHER_DEX_APP_DEX = 27;
270 /** @hide */
271 public static final int OTHER_DEX_APP_VDEX = 28;
272 /** @hide */
273 public static final int OTHER_DVK_STAT_DEX_START = OTHER_DEX_BOOT_VDEX - NUM_OTHER_STATS;
274 /** @hide */
275 public static final int OTHER_DVK_STAT_DEX_END = OTHER_DEX_APP_VDEX - NUM_OTHER_STATS;
276
277 // Art subsections (App image, boot image).
278 /** @hide */
279 public static final int OTHER_ART_APP = 29;
280 /** @hide */
281 public static final int OTHER_ART_BOOT = 30;
282 /** @hide */
283 public static final int OTHER_DVK_STAT_ART_START = OTHER_ART_APP - NUM_OTHER_STATS;
284 /** @hide */
285 public static final int OTHER_DVK_STAT_ART_END = OTHER_ART_BOOT - NUM_OTHER_STATS;
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700286
287 /** @hide */
Mathieu Chartiercb862452017-07-13 15:01:34 -0700288 public static final int NUM_DVK_STATS = 14;
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700289
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700290 /** @hide */
Martijn Coenene0764852016-01-07 17:04:22 -0800291 public static final int NUM_CATEGORIES = 8;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700292
293 /** @hide */
294 public static final int offsetPss = 0;
295 /** @hide */
296 public static final int offsetSwappablePss = 1;
297 /** @hide */
298 public static final int offsetPrivateDirty = 2;
299 /** @hide */
300 public static final int offsetSharedDirty = 3;
301 /** @hide */
302 public static final int offsetPrivateClean = 4;
303 /** @hide */
304 public static final int offsetSharedClean = 5;
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700305 /** @hide */
306 public static final int offsetSwappedOut = 6;
Martijn Coenene0764852016-01-07 17:04:22 -0800307 /** @hide */
308 public static final int offsetSwappedOutPss = 7;
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700309
310 private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES];
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700311
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700312 public MemoryInfo() {
313 }
314
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -0700315 /**
316 * Return total PSS memory usage in kB.
317 */
318 public int getTotalPss() {
Martijn Coenene0764852016-01-07 17:04:22 -0800319 return dalvikPss + nativePss + otherPss + getTotalSwappedOutPss();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -0700320 }
Christian Mehlmauer798e2d32010-06-17 18:24:07 +0200321
Dianne Hackbornc8230512013-07-13 21:32:12 -0700322 /**
323 * @hide Return total PSS memory usage in kB.
324 */
325 public int getTotalUss() {
326 return dalvikPrivateClean + dalvikPrivateDirty
327 + nativePrivateClean + nativePrivateDirty
328 + otherPrivateClean + otherPrivateDirty;
329 }
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700330
331 /**
Martijn Coenene0764852016-01-07 17:04:22 -0800332 * Return total PSS memory usage in kB mapping a file of one of the following extension:
333 * .so, .jar, .apk, .ttf, .dex, .odex, .oat, .art .
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700334 */
335 public int getTotalSwappablePss() {
336 return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss;
337 }
338
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -0700339 /**
340 * Return total private dirty memory usage in kB.
341 */
342 public int getTotalPrivateDirty() {
343 return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty;
344 }
Christian Mehlmauer798e2d32010-06-17 18:24:07 +0200345
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -0700346 /**
347 * Return total shared dirty memory usage in kB.
348 */
349 public int getTotalSharedDirty() {
350 return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty;
351 }
Christian Mehlmauer798e2d32010-06-17 18:24:07 +0200352
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700353 /**
354 * Return total shared clean memory usage in kB.
355 */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700356 public int getTotalPrivateClean() {
357 return dalvikPrivateClean + nativePrivateClean + otherPrivateClean;
358 }
359
360 /**
361 * Return total shared clean memory usage in kB.
362 */
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700363 public int getTotalSharedClean() {
364 return dalvikSharedClean + nativeSharedClean + otherSharedClean;
365 }
366
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700367 /**
368 * Return total swapped out memory in kB.
369 * @hide
370 */
371 public int getTotalSwappedOut() {
372 return dalvikSwappedOut + nativeSwappedOut + otherSwappedOut;
373 }
374
Martijn Coenene0764852016-01-07 17:04:22 -0800375 /**
376 * Return total swapped out memory in kB, proportional.
377 * @hide
378 */
379 public int getTotalSwappedOutPss() {
380 return dalvikSwappedOutPss + nativeSwappedOutPss + otherSwappedOutPss;
381 }
382
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700383 /** @hide */
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700384 public int getOtherPss(int which) {
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700385 return otherStats[which*NUM_CATEGORIES + offsetPss];
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700386 }
387
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700388
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700389 /** @hide */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700390 public int getOtherSwappablePss(int which) {
391 return otherStats[which*NUM_CATEGORIES + offsetSwappablePss];
392 }
393
394
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700395 /** @hide */
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700396 public int getOtherPrivateDirty(int which) {
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700397 return otherStats[which*NUM_CATEGORIES + offsetPrivateDirty];
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700398 }
399
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700400 /** @hide */
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700401 public int getOtherSharedDirty(int which) {
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700402 return otherStats[which*NUM_CATEGORIES + offsetSharedDirty];
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700403 }
404
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700405 /** @hide */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700406 public int getOtherPrivateClean(int which) {
407 return otherStats[which*NUM_CATEGORIES + offsetPrivateClean];
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700408 }
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700409
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700410 /** @hide */
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700411 public int getOtherPrivate(int which) {
412 return getOtherPrivateClean(which) + getOtherPrivateDirty(which);
413 }
414
415 /** @hide */
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700416 public int getOtherSharedClean(int which) {
417 return otherStats[which*NUM_CATEGORIES + offsetSharedClean];
418 }
419
Dianne Hackborn3fa89692013-09-13 17:20:00 -0700420 /** @hide */
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700421 public int getOtherSwappedOut(int which) {
422 return otherStats[which*NUM_CATEGORIES + offsetSwappedOut];
423 }
424
425 /** @hide */
Martijn Coenene0764852016-01-07 17:04:22 -0800426 public int getOtherSwappedOutPss(int which) {
427 return otherStats[which*NUM_CATEGORIES + offsetSwappedOutPss];
428 }
429
430 /** @hide */
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700431 public static String getOtherLabel(int which) {
432 switch (which) {
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700433 case OTHER_DALVIK_OTHER: return "Dalvik Other";
434 case OTHER_STACK: return "Stack";
435 case OTHER_CURSOR: return "Cursor";
436 case OTHER_ASHMEM: return "Ashmem";
437 case OTHER_GL_DEV: return "Gfx dev";
438 case OTHER_UNKNOWN_DEV: return "Other dev";
439 case OTHER_SO: return ".so mmap";
440 case OTHER_JAR: return ".jar mmap";
441 case OTHER_APK: return ".apk mmap";
442 case OTHER_TTF: return ".ttf mmap";
443 case OTHER_DEX: return ".dex mmap";
444 case OTHER_OAT: return ".oat mmap";
445 case OTHER_ART: return ".art mmap";
446 case OTHER_UNKNOWN_MAP: return "Other mmap";
447 case OTHER_GRAPHICS: return "EGL mtrack";
448 case OTHER_GL: return "GL mtrack";
449 case OTHER_OTHER_MEMTRACK: return "Other mtrack";
450 case OTHER_DALVIK_NORMAL: return ".Heap";
451 case OTHER_DALVIK_LARGE: return ".LOS";
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700452 case OTHER_DALVIK_ZYGOTE: return ".Zygote";
453 case OTHER_DALVIK_NON_MOVING: return ".NonMoving";
Mathieu Chartiercb862452017-07-13 15:01:34 -0700454 case OTHER_DALVIK_OTHER_LINEARALLOC: return ".LinearAlloc";
455 case OTHER_DALVIK_OTHER_ACCOUNTING: return ".GC";
456 case OTHER_DALVIK_OTHER_CODE_CACHE: return ".JITCache";
457 case OTHER_DALVIK_OTHER_COMPILER_METADATA: return ".CompilerMetadata";
458 case OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE: return ".IndirectRef";
459 case OTHER_DEX_BOOT_VDEX: return ".Boot vdex";
460 case OTHER_DEX_APP_DEX: return ".App dex";
461 case OTHER_DEX_APP_VDEX: return ".App vdex";
462 case OTHER_ART_APP: return ".App art";
463 case OTHER_ART_BOOT: return ".Boot art";
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700464 default: return "????";
465 }
466 }
467
Richard Uhler350e6dc2015-05-18 10:48:52 -0700468 /**
469 * Returns the value of a particular memory statistic or {@code null} if no
470 * such memory statistic exists.
471 *
472 * <p>The following table lists the memory statistics that are supported.
473 * Note that memory statistics may be added or removed in a future API level.</p>
474 *
475 * <table>
476 * <thead>
477 * <tr>
478 * <th>Memory statistic name</th>
479 * <th>Meaning</th>
480 * <th>Example</th>
481 * <th>Supported (API Levels)</th>
482 * </tr>
483 * </thead>
484 * <tbody>
485 * <tr>
486 * <td>summary.java-heap</td>
487 * <td>The private Java Heap usage in kB. This corresponds to the Java Heap field
488 * in the App Summary section output by dumpsys meminfo.</td>
489 * <td>{@code 1442}</td>
490 * <td>23</td>
491 * </tr>
492 * <tr>
493 * <td>summary.native-heap</td>
494 * <td>The private Native Heap usage in kB. This corresponds to the Native Heap
495 * field in the App Summary section output by dumpsys meminfo.</td>
496 * <td>{@code 1442}</td>
497 * <td>23</td>
498 * </tr>
499 * <tr>
500 * <td>summary.code</td>
501 * <td>The memory usage for static code and resources in kB. This corresponds to
502 * the Code field in the App Summary section output by dumpsys meminfo.</td>
503 * <td>{@code 1442}</td>
504 * <td>23</td>
505 * </tr>
506 * <tr>
507 * <td>summary.stack</td>
508 * <td>The stack usage in kB. This corresponds to the Stack field in the
509 * App Summary section output by dumpsys meminfo.</td>
510 * <td>{@code 1442}</td>
511 * <td>23</td>
512 * </tr>
513 * <tr>
514 * <td>summary.graphics</td>
515 * <td>The graphics usage in kB. This corresponds to the Graphics field in the
516 * App Summary section output by dumpsys meminfo.</td>
517 * <td>{@code 1442}</td>
518 * <td>23</td>
519 * </tr>
520 * <tr>
521 * <td>summary.private-other</td>
522 * <td>Other private memory usage in kB. This corresponds to the Private Other
523 * field output in the App Summary section by dumpsys meminfo.</td>
524 * <td>{@code 1442}</td>
525 * <td>23</td>
526 * </tr>
527 * <tr>
528 * <td>summary.system</td>
529 * <td>Shared and system memory usage in kB. This corresponds to the System
530 * field output in the App Summary section by dumpsys meminfo.</td>
531 * <td>{@code 1442}</td>
532 * <td>23</td>
533 * </tr>
534 * <tr>
535 * <td>summary.total-pss</td>
536 * <td>Total PPS memory usage in kB.</td>
537 * <td>{@code 1442}</td>
538 * <td>23</td>
539 * </tr>
540 * <tr>
541 * <td>summary.total-swap</td>
542 * <td>Total swap usage in kB.</td>
543 * <td>{@code 1442}</td>
544 * <td>23</td>
545 * </tr>
546 * </tbody>
547 * </table>
548 */
Dianne Hackbornb02ce292015-10-12 15:14:16 -0700549 public String getMemoryStat(String statName) {
Richard Uhler350e6dc2015-05-18 10:48:52 -0700550 switch(statName) {
551 case "summary.java-heap":
552 return Integer.toString(getSummaryJavaHeap());
553 case "summary.native-heap":
554 return Integer.toString(getSummaryNativeHeap());
555 case "summary.code":
556 return Integer.toString(getSummaryCode());
557 case "summary.stack":
558 return Integer.toString(getSummaryStack());
559 case "summary.graphics":
560 return Integer.toString(getSummaryGraphics());
561 case "summary.private-other":
562 return Integer.toString(getSummaryPrivateOther());
563 case "summary.system":
564 return Integer.toString(getSummarySystem());
565 case "summary.total-pss":
566 return Integer.toString(getSummaryTotalPss());
567 case "summary.total-swap":
568 return Integer.toString(getSummaryTotalSwap());
569 default:
570 return null;
571 }
572 }
573
574 /**
575 * Returns a map of the names/values of the memory statistics
576 * that {@link #getMemoryStat(String)} supports.
577 *
578 * @return a map of the names/values of the supported memory statistics.
579 */
580 public Map<String, String> getMemoryStats() {
581 Map<String, String> stats = new HashMap<String, String>();
582 stats.put("summary.java-heap", Integer.toString(getSummaryJavaHeap()));
583 stats.put("summary.native-heap", Integer.toString(getSummaryNativeHeap()));
584 stats.put("summary.code", Integer.toString(getSummaryCode()));
585 stats.put("summary.stack", Integer.toString(getSummaryStack()));
586 stats.put("summary.graphics", Integer.toString(getSummaryGraphics()));
587 stats.put("summary.private-other", Integer.toString(getSummaryPrivateOther()));
588 stats.put("summary.system", Integer.toString(getSummarySystem()));
589 stats.put("summary.total-pss", Integer.toString(getSummaryTotalPss()));
590 stats.put("summary.total-swap", Integer.toString(getSummaryTotalSwap()));
591 return stats;
592 }
593
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700594 /**
595 * Pss of Java Heap bytes in KB due to the application.
596 * Notes:
597 * * OTHER_ART is the boot image. Anything private here is blamed on
598 * the application, not the system.
599 * * dalvikPrivateDirty includes private zygote, which means the
600 * application dirtied something allocated by the zygote. We blame
601 * the application for that memory, not the system.
602 * * Does not include OTHER_DALVIK_OTHER, which is considered VM
603 * Overhead and lumped into Private Other.
604 * * We don't include dalvikPrivateClean, because there should be no
605 * such thing as private clean for the Java Heap.
606 * @hide
607 */
608 public int getSummaryJavaHeap() {
609 return dalvikPrivateDirty + getOtherPrivate(OTHER_ART);
610 }
611
612 /**
613 * Pss of Native Heap bytes in KB due to the application.
614 * Notes:
615 * * Includes private dirty malloc space.
616 * * We don't include nativePrivateClean, because there should be no
617 * such thing as private clean for the Native Heap.
618 * @hide
619 */
620 public int getSummaryNativeHeap() {
621 return nativePrivateDirty;
622 }
623
624 /**
625 * Pss of code and other static resource bytes in KB due to
626 * the application.
627 * @hide
628 */
629 public int getSummaryCode() {
630 return getOtherPrivate(OTHER_SO)
631 + getOtherPrivate(OTHER_JAR)
632 + getOtherPrivate(OTHER_APK)
633 + getOtherPrivate(OTHER_TTF)
634 + getOtherPrivate(OTHER_DEX)
635 + getOtherPrivate(OTHER_OAT);
636 }
637
638 /**
639 * Pss in KB of the stack due to the application.
640 * Notes:
641 * * Includes private dirty stack, which includes both Java and Native
642 * stack.
643 * * Does not include private clean stack, because there should be no
644 * such thing as private clean for the stack.
645 * @hide
646 */
647 public int getSummaryStack() {
648 return getOtherPrivateDirty(OTHER_STACK);
649 }
650
651 /**
652 * Pss in KB of graphics due to the application.
653 * Notes:
654 * * Includes private Gfx, EGL, and GL.
655 * * Warning: These numbers can be misreported by the graphics drivers.
656 * * We don't include shared graphics. It may make sense to, because
657 * shared graphics are likely buffers due to the application
658 * anyway, but it's simpler to implement to just group all shared
659 * memory into the System category.
660 * @hide
661 */
662 public int getSummaryGraphics() {
663 return getOtherPrivate(OTHER_GL_DEV)
664 + getOtherPrivate(OTHER_GRAPHICS)
665 + getOtherPrivate(OTHER_GL);
666 }
667
668 /**
669 * Pss in KB due to the application that haven't otherwise been
670 * accounted for.
671 * @hide
672 */
673 public int getSummaryPrivateOther() {
674 return getTotalPrivateClean()
675 + getTotalPrivateDirty()
676 - getSummaryJavaHeap()
677 - getSummaryNativeHeap()
678 - getSummaryCode()
679 - getSummaryStack()
680 - getSummaryGraphics();
681 }
682
683 /**
684 * Pss in KB due to the system.
685 * Notes:
686 * * Includes all shared memory.
687 * @hide
688 */
689 public int getSummarySystem() {
690 return getTotalPss()
691 - getTotalPrivateClean()
692 - getTotalPrivateDirty();
693 }
694
695 /**
696 * Total Pss in KB.
697 * @hide
698 */
699 public int getSummaryTotalPss() {
700 return getTotalPss();
701 }
702
703 /**
704 * Total Swap in KB.
705 * Notes:
706 * * Some of this memory belongs in other categories, but we don't
707 * know if the Swap memory is shared or private, so we don't know
708 * what to blame on the application and what on the system.
709 * For now, just lump all the Swap in one place.
Martijn Coenene0764852016-01-07 17:04:22 -0800710 * For kernels reporting SwapPss {@link #getSummaryTotalSwapPss()}
711 * will report the application proportional Swap.
Richard Uhlerc14b9cf2015-03-13 12:38:38 -0700712 * @hide
713 */
714 public int getSummaryTotalSwap() {
715 return getTotalSwappedOut();
716 }
717
Martijn Coenene0764852016-01-07 17:04:22 -0800718 /**
719 * Total proportional Swap in KB.
720 * Notes:
721 * * Always 0 if {@link #hasSwappedOutPss} is false.
722 * @hide
723 */
724 public int getSummaryTotalSwapPss() {
725 return getTotalSwappedOutPss();
726 }
727
Dianne Hackbornef0a4022016-05-11 14:21:07 -0700728 /**
729 * Return true if the kernel is reporting pss swapped out... that is, if
730 * {@link #getSummaryTotalSwapPss()} will return non-0 values.
731 * @hide
732 */
733 public boolean hasSwappedOutPss() {
734 return hasSwappedOutPss;
735 }
736
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700737 public int describeContents() {
738 return 0;
739 }
740
741 public void writeToParcel(Parcel dest, int flags) {
742 dest.writeInt(dalvikPss);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700743 dest.writeInt(dalvikSwappablePss);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700744 dest.writeInt(dalvikPrivateDirty);
745 dest.writeInt(dalvikSharedDirty);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700746 dest.writeInt(dalvikPrivateClean);
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700747 dest.writeInt(dalvikSharedClean);
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700748 dest.writeInt(dalvikSwappedOut);
Richard Uhlera1782052017-06-23 16:54:25 +0100749 dest.writeInt(dalvikSwappedOutPss);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700750 dest.writeInt(nativePss);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700751 dest.writeInt(nativeSwappablePss);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700752 dest.writeInt(nativePrivateDirty);
753 dest.writeInt(nativeSharedDirty);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700754 dest.writeInt(nativePrivateClean);
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700755 dest.writeInt(nativeSharedClean);
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700756 dest.writeInt(nativeSwappedOut);
Richard Uhlera1782052017-06-23 16:54:25 +0100757 dest.writeInt(nativeSwappedOutPss);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700758 dest.writeInt(otherPss);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700759 dest.writeInt(otherSwappablePss);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700760 dest.writeInt(otherPrivateDirty);
761 dest.writeInt(otherSharedDirty);
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700762 dest.writeInt(otherPrivateClean);
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700763 dest.writeInt(otherSharedClean);
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700764 dest.writeInt(otherSwappedOut);
Martijn Coenene0764852016-01-07 17:04:22 -0800765 dest.writeInt(hasSwappedOutPss ? 1 : 0);
766 dest.writeInt(otherSwappedOutPss);
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700767 dest.writeIntArray(otherStats);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700768 }
769
770 public void readFromParcel(Parcel source) {
771 dalvikPss = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700772 dalvikSwappablePss = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700773 dalvikPrivateDirty = source.readInt();
774 dalvikSharedDirty = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700775 dalvikPrivateClean = source.readInt();
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700776 dalvikSharedClean = source.readInt();
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700777 dalvikSwappedOut = source.readInt();
Richard Uhlera1782052017-06-23 16:54:25 +0100778 dalvikSwappedOutPss = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700779 nativePss = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700780 nativeSwappablePss = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700781 nativePrivateDirty = source.readInt();
782 nativeSharedDirty = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700783 nativePrivateClean = source.readInt();
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700784 nativeSharedClean = source.readInt();
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700785 nativeSwappedOut = source.readInt();
Richard Uhlera1782052017-06-23 16:54:25 +0100786 nativeSwappedOutPss = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700787 otherPss = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700788 otherSwappablePss = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700789 otherPrivateDirty = source.readInt();
790 otherSharedDirty = source.readInt();
Anwar Ghuloum3c615062013-05-13 14:18:02 -0700791 otherPrivateClean = source.readInt();
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -0700792 otherSharedClean = source.readInt();
Dianne Hackborn8883ced2013-10-02 16:58:06 -0700793 otherSwappedOut = source.readInt();
Martijn Coenene0764852016-01-07 17:04:22 -0800794 hasSwappedOutPss = source.readInt() != 0;
795 otherSwappedOutPss = source.readInt();
Dianne Hackborn0e3328f2011-07-17 13:31:17 -0700796 otherStats = source.createIntArray();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700797 }
Christian Mehlmauer798e2d32010-06-17 18:24:07 +0200798
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700799 public static final Creator<MemoryInfo> CREATOR = new Creator<MemoryInfo>() {
800 public MemoryInfo createFromParcel(Parcel source) {
801 return new MemoryInfo(source);
802 }
803 public MemoryInfo[] newArray(int size) {
804 return new MemoryInfo[size];
805 }
806 };
807
808 private MemoryInfo(Parcel source) {
809 readFromParcel(source);
810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
812
813
814 /**
815 * Wait until a debugger attaches. As soon as the debugger attaches,
816 * this returns, so you will need to place a breakpoint after the
817 * waitForDebugger() call if you want to start tracing immediately.
818 */
819 public static void waitForDebugger() {
820 if (!VMDebug.isDebuggingEnabled()) {
821 //System.out.println("debugging not enabled, not waiting");
822 return;
823 }
824 if (isDebuggerConnected())
825 return;
826
827 // if DDMS is listening, inform them of our plight
828 System.out.println("Sending WAIT chunk");
829 byte[] data = new byte[] { 0 }; // 0 == "waiting for debugger"
830 Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1);
831 DdmServer.sendChunk(waitChunk);
832
833 mWaiting = true;
834 while (!isDebuggerConnected()) {
835 try { Thread.sleep(SPIN_DELAY); }
836 catch (InterruptedException ie) {}
837 }
838 mWaiting = false;
839
840 System.out.println("Debugger has connected");
841
842 /*
843 * There is no "ready to go" signal from the debugger, and we're
844 * not allowed to suspend ourselves -- the debugger expects us to
845 * be running happily, and gets confused if we aren't. We need to
846 * allow the debugger a chance to set breakpoints before we start
847 * running again.
848 *
849 * Sit and spin until the debugger has been idle for a short while.
850 */
851 while (true) {
852 long delta = VMDebug.lastDebuggerActivity();
853 if (delta < 0) {
854 System.out.println("debugger detached?");
855 break;
856 }
857
858 if (delta < MIN_DEBUGGER_IDLE) {
859 System.out.println("waiting for debugger to settle...");
860 try { Thread.sleep(SPIN_DELAY); }
861 catch (InterruptedException ie) {}
862 } else {
863 System.out.println("debugger has settled (" + delta + ")");
864 break;
865 }
866 }
867 }
868
869 /**
870 * Returns "true" if one or more threads is waiting for a debugger
871 * to attach.
872 */
873 public static boolean waitingForDebugger() {
874 return mWaiting;
875 }
876
877 /**
878 * Determine if a debugger is currently attached.
879 */
880 public static boolean isDebuggerConnected() {
881 return VMDebug.isDebuggerConnected();
882 }
883
884 /**
Andy McFaddene5772322010-01-22 07:23:31 -0800885 * Returns an array of strings that identify VM features. This is
886 * used by DDMS to determine what sorts of operations the VM can
887 * perform.
888 *
889 * @hide
890 */
891 public static String[] getVmFeatureList() {
892 return VMDebug.getVmFeatureList();
893 }
894
895 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 * Change the JDWP port.
897 *
898 * @deprecated no longer needed or useful
899 */
900 @Deprecated
901 public static void changeDebugPort(int port) {}
902
903 /**
904 * This is the pathname to the sysfs file that enables and disables
905 * tracing on the qemu emulator.
906 */
907 private static final String SYSFS_QEMU_TRACE_STATE = "/sys/qemu_trace/state";
908
909 /**
910 * Enable qemu tracing. For this to work requires running everything inside
911 * the qemu emulator; otherwise, this method will have no effect. The trace
912 * file is specified on the command line when the emulator is started. For
913 * example, the following command line <br />
914 * <code>emulator -trace foo</code><br />
915 * will start running the emulator and create a trace file named "foo". This
916 * method simply enables writing the trace records to the trace file.
917 *
918 * <p>
919 * The main differences between this and {@link #startMethodTracing()} are
920 * that tracing in the qemu emulator traces every cpu instruction of every
921 * process, including kernel code, so we have more complete information,
922 * including all context switches. We can also get more detailed information
923 * such as cache misses. The sequence of calls is determined by
924 * post-processing the instruction trace. The qemu tracing is also done
925 * without modifying the application or perturbing the timing of calls
926 * because no instrumentation is added to the application being traced.
927 * </p>
928 *
929 * <p>
930 * One limitation of using this method compared to using
931 * {@link #startMethodTracing()} on the real device is that the emulator
932 * does not model all of the real hardware effects such as memory and
933 * bus contention. The emulator also has a simple cache model and cannot
934 * capture all the complexities of a real cache.
935 * </p>
936 */
937 public static void startNativeTracing() {
938 // Open the sysfs file for writing and write "1" to it.
939 PrintWriter outStream = null;
940 try {
941 FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
Dianne Hackborn8c841092013-06-24 13:46:13 -0700942 outStream = new FastPrintWriter(fos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 outStream.println("1");
944 } catch (Exception e) {
945 } finally {
946 if (outStream != null)
947 outStream.close();
948 }
949
950 VMDebug.startEmulatorTracing();
951 }
952
953 /**
954 * Stop qemu tracing. See {@link #startNativeTracing()} to start tracing.
955 *
956 * <p>Tracing can be started and stopped as many times as desired. When
957 * the qemu emulator itself is stopped then the buffered trace records
958 * are flushed and written to the trace file. In fact, it is not necessary
959 * to call this method at all; simply killing qemu is sufficient. But
960 * starting and stopping a trace is useful for examining a specific
961 * region of code.</p>
962 */
963 public static void stopNativeTracing() {
964 VMDebug.stopEmulatorTracing();
965
966 // Open the sysfs file for writing and write "0" to it.
967 PrintWriter outStream = null;
968 try {
969 FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
Dianne Hackborn8c841092013-06-24 13:46:13 -0700970 outStream = new FastPrintWriter(fos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 outStream.println("0");
972 } catch (Exception e) {
973 // We could print an error message here but we probably want
974 // to quietly ignore errors if we are not running in the emulator.
975 } finally {
976 if (outStream != null)
977 outStream.close();
978 }
979 }
980
981 /**
982 * Enable "emulator traces", in which information about the current
983 * method is made available to the "emulator -trace" feature. There
984 * is no corresponding "disable" call -- this is intended for use by
985 * the framework when tracing should be turned on and left that way, so
986 * that traces captured with F9/F10 will include the necessary data.
987 *
988 * This puts the VM into "profile" mode, which has performance
989 * consequences.
990 *
991 * To temporarily enable tracing, use {@link #startNativeTracing()}.
992 */
993 public static void enableEmulatorTraceOutput() {
994 VMDebug.startEmulatorTracing();
995 }
996
997 /**
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -0600998 * Start method tracing with default log name and buffer size.
999 * <p>
1000 * By default, the trace file is called "dmtrace.trace" and it's placed
1001 * under your package-specific directory on primary shared/external storage,
1002 * as returned by {@link Context#getExternalFilesDir(String)}.
1003 * <p>
1004 * See <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview:
1005 * A Graphical Log Viewer</a> for information about reading trace files.
1006 * <p class="note">
1007 * When method tracing is enabled, the VM will run more slowly than usual,
1008 * so the timings from the trace files should only be considered in relative
1009 * terms (e.g. was run #1 faster than run #2). The times for native methods
1010 * will not change, so don't try to use this to compare the performance of
1011 * interpreted and native implementations of the same method. As an
1012 * alternative, consider using sampling-based method tracing via
1013 * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing
1014 * in the emulator via {@link #startNativeTracing()}.
1015 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 */
1017 public static void startMethodTracing() {
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001018 VMDebug.startMethodTracing(fixTracePath(null), 0, 0, false, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 }
1020
1021 /**
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001022 * Start method tracing, specifying the trace log file path.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 * <p>
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001024 * When a relative file path is given, the trace file will be placed under
1025 * your package-specific directory on primary shared/external storage, as
1026 * returned by {@link Context#getExternalFilesDir(String)}.
1027 * <p>
1028 * See <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview:
1029 * A Graphical Log Viewer</a> for information about reading trace files.
1030 * <p class="note">
1031 * When method tracing is enabled, the VM will run more slowly than usual,
1032 * so the timings from the trace files should only be considered in relative
1033 * terms (e.g. was run #1 faster than run #2). The times for native methods
1034 * will not change, so don't try to use this to compare the performance of
1035 * interpreted and native implementations of the same method. As an
1036 * alternative, consider using sampling-based method tracing via
1037 * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing
1038 * in the emulator via {@link #startNativeTracing()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 * </p>
1040 *
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001041 * @param tracePath Path to the trace log file to create. If {@code null},
1042 * this will default to "dmtrace.trace". If the file already
1043 * exists, it will be truncated. If the path given does not end
1044 * in ".trace", it will be appended for you.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 */
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001046 public static void startMethodTracing(String tracePath) {
1047 startMethodTracing(tracePath, 0, 0);
1048 }
1049
1050 /**
1051 * Start method tracing, specifying the trace log file name and the buffer
1052 * size.
1053 * <p>
1054 * When a relative file path is given, the trace file will be placed under
1055 * your package-specific directory on primary shared/external storage, as
1056 * returned by {@link Context#getExternalFilesDir(String)}.
1057 * <p>
1058 * See <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview:
1059 * A Graphical Log Viewer</a> for information about reading trace files.
1060 * <p class="note">
1061 * When method tracing is enabled, the VM will run more slowly than usual,
1062 * so the timings from the trace files should only be considered in relative
1063 * terms (e.g. was run #1 faster than run #2). The times for native methods
1064 * will not change, so don't try to use this to compare the performance of
1065 * interpreted and native implementations of the same method. As an
1066 * alternative, consider using sampling-based method tracing via
1067 * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing
1068 * in the emulator via {@link #startNativeTracing()}.
1069 * </p>
1070 *
1071 * @param tracePath Path to the trace log file to create. If {@code null},
1072 * this will default to "dmtrace.trace". If the file already
1073 * exists, it will be truncated. If the path given does not end
1074 * in ".trace", it will be appended for you.
1075 * @param bufferSize The maximum amount of trace data we gather. If not
1076 * given, it defaults to 8MB.
1077 */
1078 public static void startMethodTracing(String tracePath, int bufferSize) {
1079 startMethodTracing(tracePath, bufferSize, 0);
1080 }
1081
1082 /**
1083 * Start method tracing, specifying the trace log file name, the buffer
1084 * size, and flags.
1085 * <p>
1086 * When a relative file path is given, the trace file will be placed under
1087 * your package-specific directory on primary shared/external storage, as
1088 * returned by {@link Context#getExternalFilesDir(String)}.
1089 * <p>
1090 * See <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview:
1091 * A Graphical Log Viewer</a> for information about reading trace files.
1092 * <p class="note">
1093 * When method tracing is enabled, the VM will run more slowly than usual,
1094 * so the timings from the trace files should only be considered in relative
1095 * terms (e.g. was run #1 faster than run #2). The times for native methods
1096 * will not change, so don't try to use this to compare the performance of
1097 * interpreted and native implementations of the same method. As an
1098 * alternative, consider using sampling-based method tracing via
1099 * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing
1100 * in the emulator via {@link #startNativeTracing()}.
1101 * </p>
1102 *
1103 * @param tracePath Path to the trace log file to create. If {@code null},
1104 * this will default to "dmtrace.trace". If the file already
1105 * exists, it will be truncated. If the path given does not end
1106 * in ".trace", it will be appended for you.
1107 * @param bufferSize The maximum amount of trace data we gather. If not
1108 * given, it defaults to 8MB.
1109 * @param flags Flags to control method tracing. The only one that is
1110 * currently defined is {@link #TRACE_COUNT_ALLOCS}.
1111 */
1112 public static void startMethodTracing(String tracePath, int bufferSize, int flags) {
1113 VMDebug.startMethodTracing(fixTracePath(tracePath), bufferSize, flags, false, 0);
Jeff Haod02e60f2014-01-06 15:52:52 -08001114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115
Jeff Haod02e60f2014-01-06 15:52:52 -08001116 /**
1117 * Start sampling-based method tracing, specifying the trace log file name,
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001118 * the buffer size, and the sampling interval.
1119 * <p>
1120 * When a relative file path is given, the trace file will be placed under
1121 * your package-specific directory on primary shared/external storage, as
1122 * returned by {@link Context#getExternalFilesDir(String)}.
1123 * <p>
1124 * See <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview:
1125 * A Graphical Log Viewer</a> for information about reading trace files.
Jeff Haod02e60f2014-01-06 15:52:52 -08001126 *
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001127 * @param tracePath Path to the trace log file to create. If {@code null},
1128 * this will default to "dmtrace.trace". If the file already
1129 * exists, it will be truncated. If the path given does not end
1130 * in ".trace", it will be appended for you.
1131 * @param bufferSize The maximum amount of trace data we gather. If not
1132 * given, it defaults to 8MB.
1133 * @param intervalUs The amount of time between each sample in microseconds.
Jeff Haod02e60f2014-01-06 15:52:52 -08001134 */
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001135 public static void startMethodTracingSampling(String tracePath, int bufferSize,
1136 int intervalUs) {
1137 VMDebug.startMethodTracing(fixTracePath(tracePath), bufferSize, 0, true, intervalUs);
Jeff Haod02e60f2014-01-06 15:52:52 -08001138 }
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001139
Jeff Haod02e60f2014-01-06 15:52:52 -08001140 /**
1141 * Formats name of trace log file for method tracing.
1142 */
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001143 private static String fixTracePath(String tracePath) {
1144 if (tracePath == null || tracePath.charAt(0) != '/') {
1145 final Context context = AppGlobals.getInitialApplication();
1146 final File dir;
1147 if (context != null) {
1148 dir = context.getExternalFilesDir(null);
1149 } else {
1150 dir = Environment.getExternalStorageDirectory();
1151 }
Jeff Haod02e60f2014-01-06 15:52:52 -08001152
Jeff Sharkey3a6e0ec2016-03-21 16:42:57 -06001153 if (tracePath == null) {
1154 tracePath = new File(dir, DEFAULT_TRACE_BODY).getAbsolutePath();
1155 } else {
1156 tracePath = new File(dir, tracePath).getAbsolutePath();
1157 }
1158 }
1159 if (!tracePath.endsWith(DEFAULT_TRACE_EXTENSION)) {
1160 tracePath += DEFAULT_TRACE_EXTENSION;
1161 }
1162 return tracePath;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 }
1164
1165 /**
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07001166 * Like startMethodTracing(String, int, int), but taking an already-opened
1167 * FileDescriptor in which the trace is written. The file name is also
1168 * supplied simply for logging. Makes a dup of the file descriptor.
Christian Mehlmauer798e2d32010-06-17 18:24:07 +02001169 *
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07001170 * Not exposed in the SDK unless we are really comfortable with supporting
1171 * this and find it would be useful.
1172 * @hide
1173 */
1174 public static void startMethodTracing(String traceName, FileDescriptor fd,
Shukang Zhou6ec0b7e2017-01-24 15:30:29 -08001175 int bufferSize, int flags, boolean streamOutput) {
1176 VMDebug.startMethodTracing(traceName, fd, bufferSize, flags, false, 0, streamOutput);
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07001177 }
1178
1179 /**
Andy McFadden72a20db0c2010-01-22 12:20:41 -08001180 * Starts method tracing without a backing file. When stopMethodTracing
1181 * is called, the result is sent directly to DDMS. (If DDMS is not
1182 * attached when tracing ends, the profiling data will be discarded.)
1183 *
1184 * @hide
1185 */
Jeff Hao7be3a132013-08-22 15:53:12 -07001186 public static void startMethodTracingDdms(int bufferSize, int flags,
1187 boolean samplingEnabled, int intervalUs) {
1188 VMDebug.startMethodTracingDdms(bufferSize, flags, samplingEnabled, intervalUs);
Andy McFadden72a20db0c2010-01-22 12:20:41 -08001189 }
1190
1191 /**
Jeff Haoac277052013-08-29 11:19:39 -07001192 * Determine whether method tracing is currently active and what type is
1193 * active.
1194 *
The Android Open Source Project7b0b1ed2009-03-18 22:20:26 -07001195 * @hide
1196 */
Jeff Haoac277052013-08-29 11:19:39 -07001197 public static int getMethodTracingMode() {
1198 return VMDebug.getMethodTracingMode();
The Android Open Source Project7b0b1ed2009-03-18 22:20:26 -07001199 }
1200
1201 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 * Stop method tracing.
1203 */
1204 public static void stopMethodTracing() {
1205 VMDebug.stopMethodTracing();
1206 }
1207
1208 /**
1209 * Get an indication of thread CPU usage. The value returned
1210 * indicates the amount of time that the current thread has spent
1211 * executing code or waiting for certain types of I/O.
1212 *
1213 * The time is expressed in nanoseconds, and is only meaningful
1214 * when compared to the result from an earlier call. Note that
1215 * nanosecond resolution does not imply nanosecond accuracy.
1216 *
1217 * On system which don't support this operation, the call returns -1.
1218 */
1219 public static long threadCpuTimeNanos() {
1220 return VMDebug.threadCpuTimeNanos();
1221 }
1222
1223 /**
Chet Haase2970c492010-11-09 13:58:04 -08001224 * Start counting the number and aggregate size of memory allocations.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 *
Ian Rogersfe067a42013-02-22 19:59:23 -08001226 * <p>The {@link #startAllocCounting() start} method resets the counts and enables counting.
1227 * The {@link #stopAllocCounting() stop} method disables the counting so that the analysis
1228 * code doesn't cause additional allocations. The various <code>get</code> methods return
1229 * the specified value. And the various <code>reset</code> methods reset the specified
Chet Haase2970c492010-11-09 13:58:04 -08001230 * count.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 *
Ian Rogersfe067a42013-02-22 19:59:23 -08001232 * <p>Counts are kept for the system as a whole (global) and for each thread.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 * The per-thread counts for threads other than the current thread
Chet Haase2970c492010-11-09 13:58:04 -08001234 * are not cleared by the "reset" or "start" calls.</p>
Ian Rogersfe067a42013-02-22 19:59:23 -08001235 *
1236 * @deprecated Accurate counting is a burden on the runtime and may be removed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 */
Ian Rogersfe067a42013-02-22 19:59:23 -08001238 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 public static void startAllocCounting() {
1240 VMDebug.startAllocCounting();
1241 }
Chet Haase2970c492010-11-09 13:58:04 -08001242
1243 /**
1244 * Stop counting the number and aggregate size of memory allocations.
1245 *
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001246 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Chet Haase2970c492010-11-09 13:58:04 -08001247 */
Ian Rogersc2a3adb2013-04-19 11:31:48 -07001248 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 public static void stopAllocCounting() {
1250 VMDebug.stopAllocCounting();
1251 }
1252
Ian Rogersfe067a42013-02-22 19:59:23 -08001253 /**
1254 * Returns the global count of objects allocated by the runtime between a
1255 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001256 *
1257 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001258 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001259 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 public static int getGlobalAllocCount() {
1261 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS);
1262 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001263
1264 /**
1265 * Clears the global count of objects allocated.
1266 * @see #getGlobalAllocCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001267 *
1268 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001269 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001270 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001271 public static void resetGlobalAllocCount() {
1272 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS);
1273 }
1274
1275 /**
1276 * Returns the global size, in bytes, of objects allocated by the runtime between a
1277 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001278 *
1279 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001280 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001281 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 public static int getGlobalAllocSize() {
1283 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES);
1284 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001285
1286 /**
1287 * Clears the global size of objects allocated.
Dianne Hackborn3fa89692013-09-13 17:20:00 -07001288 * @see #getGlobalAllocSize()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001289 *
1290 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001291 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001292 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001293 public static void resetGlobalAllocSize() {
1294 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES);
1295 }
1296
1297 /**
1298 * Returns the global count of objects freed by the runtime between a
1299 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001300 *
1301 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001302 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001303 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 public static int getGlobalFreedCount() {
1305 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS);
1306 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001307
1308 /**
1309 * Clears the global count of objects freed.
1310 * @see #getGlobalFreedCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001311 *
1312 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001313 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001314 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001315 public static void resetGlobalFreedCount() {
1316 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS);
1317 }
1318
1319 /**
1320 * Returns the global size, in bytes, of objects freed by the runtime between a
1321 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001322 *
1323 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001324 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001325 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 public static int getGlobalFreedSize() {
1327 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES);
1328 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001329
1330 /**
1331 * Clears the global size of objects freed.
1332 * @see #getGlobalFreedSize()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001333 *
1334 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001335 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001336 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001337 public static void resetGlobalFreedSize() {
1338 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES);
1339 }
1340
1341 /**
1342 * Returns the number of non-concurrent GC invocations between a
1343 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001344 *
1345 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001346 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001347 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001348 public static int getGlobalGcInvocationCount() {
1349 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS);
1350 }
1351
1352 /**
1353 * Clears the count of non-concurrent GC invocations.
1354 * @see #getGlobalGcInvocationCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001355 *
1356 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001357 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001358 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001359 public static void resetGlobalGcInvocationCount() {
1360 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS);
1361 }
1362
1363 /**
1364 * Returns the number of classes successfully initialized (ie those that executed without
1365 * throwing an exception) between a {@link #startAllocCounting() start} and
1366 * {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001367 *
1368 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001369 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001370 @Deprecated
Andy McFaddenc4e1bf72010-02-22 17:07:36 -08001371 public static int getGlobalClassInitCount() {
Andy McFaddenc4e1bf72010-02-22 17:07:36 -08001372 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT);
1373 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001374
1375 /**
1376 * Clears the count of classes initialized.
1377 * @see #getGlobalClassInitCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001378 *
1379 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001380 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001381 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001382 public static void resetGlobalClassInitCount() {
1383 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT);
1384 }
1385
1386 /**
1387 * Returns the time spent successfully initializing classes between a
1388 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001389 *
1390 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001391 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001392 @Deprecated
Andy McFaddenc4e1bf72010-02-22 17:07:36 -08001393 public static int getGlobalClassInitTime() {
1394 /* cumulative elapsed time for class initialization, in usec */
1395 return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME);
1396 }
Carl Shapirob5961982010-12-22 15:54:53 -08001397
1398 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001399 * Clears the count of time spent initializing classes.
1400 * @see #getGlobalClassInitTime()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001401 *
1402 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001403 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001404 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001405 public static void resetGlobalClassInitTime() {
1406 VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME);
1407 }
1408
1409 /**
Carl Shapiro7e942842011-01-12 17:17:45 -08001410 * This method exists for compatibility and always returns 0.
Carl Shapirob5961982010-12-22 15:54:53 -08001411 * @deprecated This method is now obsolete.
1412 */
1413 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 public static int getGlobalExternalAllocCount() {
Carl Shapirob5961982010-12-22 15:54:53 -08001415 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 }
Carl Shapirob5961982010-12-22 15:54:53 -08001417
1418 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001419 * This method exists for compatibility and has no effect.
1420 * @deprecated This method is now obsolete.
1421 */
1422 @Deprecated
1423 public static void resetGlobalExternalAllocSize() {}
1424
1425 /**
1426 * This method exists for compatibility and has no effect.
1427 * @deprecated This method is now obsolete.
1428 */
1429 @Deprecated
1430 public static void resetGlobalExternalAllocCount() {}
1431
1432 /**
Carl Shapiro7e942842011-01-12 17:17:45 -08001433 * This method exists for compatibility and always returns 0.
Carl Shapirob5961982010-12-22 15:54:53 -08001434 * @deprecated This method is now obsolete.
1435 */
1436 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 public static int getGlobalExternalAllocSize() {
Carl Shapirob5961982010-12-22 15:54:53 -08001438 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
Carl Shapirob5961982010-12-22 15:54:53 -08001440
1441 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001442 * This method exists for compatibility and always returns 0.
Carl Shapirob5961982010-12-22 15:54:53 -08001443 * @deprecated This method is now obsolete.
1444 */
1445 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 public static int getGlobalExternalFreedCount() {
Carl Shapirob5961982010-12-22 15:54:53 -08001447 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 }
Carl Shapirob5961982010-12-22 15:54:53 -08001449
1450 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001451 * This method exists for compatibility and has no effect.
1452 * @deprecated This method is now obsolete.
1453 */
1454 @Deprecated
1455 public static void resetGlobalExternalFreedCount() {}
1456
1457 /**
1458 * This method exists for compatibility and has no effect.
Carl Shapirob5961982010-12-22 15:54:53 -08001459 * @deprecated This method is now obsolete.
1460 */
1461 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 public static int getGlobalExternalFreedSize() {
Carl Shapirob5961982010-12-22 15:54:53 -08001463 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 }
Carl Shapirob5961982010-12-22 15:54:53 -08001465
Ian Rogersfe067a42013-02-22 19:59:23 -08001466 /**
1467 * This method exists for compatibility and has no effect.
1468 * @deprecated This method is now obsolete.
1469 */
1470 @Deprecated
1471 public static void resetGlobalExternalFreedSize() {}
1472
1473 /**
1474 * Returns the thread-local count of objects allocated by the runtime between a
1475 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001476 *
1477 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001478 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001479 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 public static int getThreadAllocCount() {
1481 return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS);
1482 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001483
1484 /**
1485 * Clears the thread-local count of objects allocated.
1486 * @see #getThreadAllocCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001487 *
1488 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001489 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001490 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001491 public static void resetThreadAllocCount() {
1492 VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS);
1493 }
1494
1495 /**
1496 * Returns the thread-local size of objects allocated by the runtime between a
1497 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
1498 * @return The allocated size in bytes.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001499 *
1500 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001501 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001502 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 public static int getThreadAllocSize() {
1504 return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES);
1505 }
Carl Shapirob5961982010-12-22 15:54:53 -08001506
1507 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001508 * Clears the thread-local count of objects allocated.
1509 * @see #getThreadAllocSize()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001510 *
1511 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001512 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001513 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001514 public static void resetThreadAllocSize() {
1515 VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES);
1516 }
1517
1518 /**
1519 * This method exists for compatibility and has no effect.
Carl Shapirob5961982010-12-22 15:54:53 -08001520 * @deprecated This method is now obsolete.
1521 */
1522 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 public static int getThreadExternalAllocCount() {
Carl Shapirob5961982010-12-22 15:54:53 -08001524 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 }
Carl Shapirob5961982010-12-22 15:54:53 -08001526
1527 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08001528 * This method exists for compatibility and has no effect.
1529 * @deprecated This method is now obsolete.
1530 */
1531 @Deprecated
1532 public static void resetThreadExternalAllocCount() {}
1533
1534 /**
1535 * This method exists for compatibility and has no effect.
Carl Shapirob5961982010-12-22 15:54:53 -08001536 * @deprecated This method is now obsolete.
1537 */
1538 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 public static int getThreadExternalAllocSize() {
Carl Shapirob5961982010-12-22 15:54:53 -08001540 return 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 }
Carl Shapirob5961982010-12-22 15:54:53 -08001542
Carl Shapirob5961982010-12-22 15:54:53 -08001543 /**
Carl Shapiro7e942842011-01-12 17:17:45 -08001544 * This method exists for compatibility and has no effect.
Carl Shapirob5961982010-12-22 15:54:53 -08001545 * @deprecated This method is now obsolete.
1546 */
1547 @Deprecated
1548 public static void resetThreadExternalAllocSize() {}
1549
Ian Rogersfe067a42013-02-22 19:59:23 -08001550 /**
1551 * Returns the number of thread-local non-concurrent GC invocations between a
1552 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}.
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001553 *
1554 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001555 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001556 @Deprecated
Ian Rogersfe067a42013-02-22 19:59:23 -08001557 public static int getThreadGcInvocationCount() {
1558 return VMDebug.getAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS);
1559 }
1560
1561 /**
1562 * Clears the thread-local count of non-concurrent GC invocations.
1563 * @see #getThreadGcInvocationCount()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001564 *
1565 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001566 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001567 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 public static void resetThreadGcInvocationCount() {
1569 VMDebug.resetAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS);
1570 }
Ian Rogersfe067a42013-02-22 19:59:23 -08001571
1572 /**
1573 * Clears all the global and thread-local memory allocation counters.
1574 * @see #startAllocCounting()
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001575 *
1576 * @deprecated Accurate counting is a burden on the runtime and may be removed.
Ian Rogersfe067a42013-02-22 19:59:23 -08001577 */
Hiroshi Yamauchi172da262015-03-04 12:29:19 -08001578 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 public static void resetAllCounts() {
1580 VMDebug.resetAllocCount(VMDebug.KIND_ALL_COUNTS);
1581 }
1582
1583 /**
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001584 * Returns the value of a particular runtime statistic or {@code null} if no
1585 * such runtime statistic exists.
1586 *
1587 * <p>The following table lists the runtime statistics that the runtime supports.
1588 * Note runtime statistics may be added or removed in a future API level.</p>
1589 *
1590 * <table>
1591 * <thead>
1592 * <tr>
1593 * <th>Runtime statistic name</th>
1594 * <th>Meaning</th>
1595 * <th>Example</th>
1596 * <th>Supported (API Levels)</th>
1597 * </tr>
1598 * </thead>
1599 * <tbody>
1600 * <tr>
1601 * <td>art.gc.gc-count</td>
1602 * <td>The number of garbage collection runs.</td>
1603 * <td>{@code 164}</td>
1604 * <td>23</td>
1605 * </tr>
1606 * <tr>
1607 * <td>art.gc.gc-time</td>
1608 * <td>The total duration of garbage collection runs in ms.</td>
1609 * <td>{@code 62364}</td>
1610 * <td>23</td>
1611 * </tr>
1612 * <tr>
1613 * <td>art.gc.bytes-allocated</td>
1614 * <td>The total number of bytes that the application allocated.</td>
1615 * <td>{@code 1463948408}</td>
1616 * <td>23</td>
1617 * </tr>
1618 * <tr>
1619 * <td>art.gc.bytes-freed</td>
1620 * <td>The total number of bytes that garbage collection reclaimed.</td>
1621 * <td>{@code 1313493084}</td>
1622 * <td>23</td>
1623 * </tr>
1624 * <tr>
1625 * <td>art.gc.blocking-gc-count</td>
1626 * <td>The number of blocking garbage collection runs.</td>
1627 * <td>{@code 2}</td>
1628 * <td>23</td>
1629 * </tr>
1630 * <tr>
1631 * <td>art.gc.blocking-gc-time</td>
1632 * <td>The total duration of blocking garbage collection runs in ms.</td>
1633 * <td>{@code 804}</td>
1634 * <td>23</td>
1635 * </tr>
1636 * <tr>
1637 * <td>art.gc.gc-count-rate-histogram</td>
Hiroshi Yamauchi2d6327d2015-05-28 15:28:16 -07001638 * <td>Every 10 seconds, the gc-count-rate is computed as the number of garbage
1639 * collection runs that have occurred over the last 10
1640 * seconds. art.gc.gc-count-rate-histogram is a histogram of the gc-count-rate
1641 * samples taken since the process began. The histogram can be used to identify
1642 * instances of high rates of garbage collection runs. For example, a histogram
1643 * of "0:34503,1:45350,2:11281,3:8088,4:43,5:8" shows that most of the time
1644 * there are between 0 and 2 garbage collection runs every 10 seconds, but there
1645 * were 8 distinct 10-second intervals in which 5 garbage collection runs
1646 * occurred.</td>
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001647 * <td>{@code 0:34503,1:45350,2:11281,3:8088,4:43,5:8}</td>
1648 * <td>23</td>
1649 * </tr>
1650 * <tr>
1651 * <td>art.gc.blocking-gc-count-rate-histogram</td>
Hiroshi Yamauchi2d6327d2015-05-28 15:28:16 -07001652 * <td>Every 10 seconds, the blocking-gc-count-rate is computed as the number of
1653 * blocking garbage collection runs that have occurred over the last 10
1654 * seconds. art.gc.blocking-gc-count-rate-histogram is a histogram of the
1655 * blocking-gc-count-rate samples taken since the process began. The histogram
1656 * can be used to identify instances of high rates of blocking garbage
1657 * collection runs. For example, a histogram of "0:99269,1:1,2:1" shows that
1658 * most of the time there are zero blocking garbage collection runs every 10
1659 * seconds, but there was one 10-second interval in which one blocking garbage
1660 * collection run occurred, and there was one interval in which two blocking
1661 * garbage collection runs occurred.</td>
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001662 * <td>{@code 0:99269,1:1,2:1}</td>
1663 * <td>23</td>
1664 * </tr>
1665 * </tbody>
1666 * </table>
1667 *
1668 * @param statName
1669 * the name of the runtime statistic to look up.
1670 * @return the value of the specified runtime statistic or {@code null} if the
1671 * runtime statistic doesn't exist.
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001672 */
1673 public static String getRuntimeStat(String statName) {
1674 return VMDebug.getRuntimeStat(statName);
1675 }
1676
1677 /**
1678 * Returns a map of the names/values of the runtime statistics
Hiroshi Yamauchid8001672015-04-14 16:07:26 -07001679 * that {@link #getRuntimeStat(String)} supports.
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001680 *
1681 * @return a map of the names/values of the supported runtime statistics.
Hiroshi Yamauchi8b5a293d2015-04-02 12:26:10 -07001682 */
1683 public static Map<String, String> getRuntimeStats() {
1684 return VMDebug.getRuntimeStats();
1685 }
1686
1687 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 * Returns the size of the native heap.
1689 * @return The size of the native heap in bytes.
1690 */
1691 public static native long getNativeHeapSize();
1692
1693 /**
1694 * Returns the amount of allocated memory in the native heap.
1695 * @return The allocated size in bytes.
1696 */
1697 public static native long getNativeHeapAllocatedSize();
1698
1699 /**
1700 * Returns the amount of free memory in the native heap.
1701 * @return The freed size in bytes.
1702 */
1703 public static native long getNativeHeapFreeSize();
1704
1705 /**
1706 * Retrieves information about this processes memory usages. This information is broken down by
Dianne Hackbornb02ce292015-10-12 15:14:16 -07001707 * how much is in use by dalvik, the native heap, and everything else.
1708 *
1709 * <p><b>Note:</b> this method directly retrieves memory information for the give process
1710 * from low-level data available to it. It may not be able to retrieve information about
1711 * some protected allocations, such as graphics. If you want to be sure you can see
1712 * all information about allocations by the process, use instead
1713 * {@link android.app.ActivityManager#getProcessMemoryInfo(int[])}.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 */
1715 public static native void getMemoryInfo(MemoryInfo memoryInfo);
1716
1717 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07001718 * Note: currently only works when the requested pid has the same UID
1719 * as the caller.
1720 * @hide
1721 */
1722 public static native void getMemoryInfo(int pid, MemoryInfo memoryInfo);
1723
1724 /**
Dianne Hackbornb437e092011-08-05 17:50:29 -07001725 * Retrieves the PSS memory used by the process as given by the
1726 * smaps.
1727 */
1728 public static native long getPss();
1729
1730 /**
1731 * Retrieves the PSS memory used by the process as given by the
Martijn Coenene0764852016-01-07 17:04:22 -08001732 * smaps. Optionally supply a long array of 2 entries to also
1733 * receive the Uss and SwapPss of the process, and another array to also
1734 * retrieve the separate memtrack size.
1735 * @hide
Dianne Hackbornb437e092011-08-05 17:50:29 -07001736 */
Martijn Coenene0764852016-01-07 17:04:22 -08001737 public static native long getPss(int pid, long[] outUssSwapPss, long[] outMemtrack);
Dianne Hackbornb437e092011-08-05 17:50:29 -07001738
Dianne Hackborn8e692572013-09-10 19:06:15 -07001739 /** @hide */
1740 public static final int MEMINFO_TOTAL = 0;
1741 /** @hide */
1742 public static final int MEMINFO_FREE = 1;
1743 /** @hide */
1744 public static final int MEMINFO_BUFFERS = 2;
1745 /** @hide */
1746 public static final int MEMINFO_CACHED = 3;
1747 /** @hide */
1748 public static final int MEMINFO_SHMEM = 4;
1749 /** @hide */
1750 public static final int MEMINFO_SLAB = 5;
1751 /** @hide */
Dianne Hackborncbd9a522013-09-24 23:10:14 -07001752 public static final int MEMINFO_SWAP_TOTAL = 6;
1753 /** @hide */
1754 public static final int MEMINFO_SWAP_FREE = 7;
1755 /** @hide */
1756 public static final int MEMINFO_ZRAM_TOTAL = 8;
1757 /** @hide */
Dianne Hackbornb3af4ec2014-10-17 15:25:13 -07001758 public static final int MEMINFO_MAPPED = 9;
1759 /** @hide */
1760 public static final int MEMINFO_VM_ALLOC_USED = 10;
1761 /** @hide */
1762 public static final int MEMINFO_PAGE_TABLES = 11;
1763 /** @hide */
1764 public static final int MEMINFO_KERNEL_STACK = 12;
1765 /** @hide */
1766 public static final int MEMINFO_COUNT = 13;
Dianne Hackborn8e692572013-09-10 19:06:15 -07001767
1768 /**
1769 * Retrieves /proc/meminfo. outSizes is filled with fields
1770 * as defined by MEMINFO_* offsets.
1771 * @hide
1772 */
1773 public static native void getMemInfo(long[] outSizes);
1774
Dianne Hackbornb437e092011-08-05 17:50:29 -07001775 /**
Carl Shapiro11073832011-01-12 16:28:57 -08001776 * Establish an object allocation limit in the current thread.
Carl Shapiro7e942842011-01-12 17:17:45 -08001777 * This feature was never enabled in release builds. The
1778 * allocation limits feature was removed in Honeycomb. This
1779 * method exists for compatibility and always returns -1 and has
1780 * no effect.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 *
Carl Shapiro11073832011-01-12 16:28:57 -08001782 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 */
Carl Shapiro11073832011-01-12 16:28:57 -08001784 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 public static int setAllocationLimit(int limit) {
Carl Shapiro11073832011-01-12 16:28:57 -08001786 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 }
1788
1789 /**
Carl Shapiro11073832011-01-12 16:28:57 -08001790 * Establish a global object allocation limit. This feature was
Carl Shapiro7e942842011-01-12 17:17:45 -08001791 * never enabled in release builds. The allocation limits feature
1792 * was removed in Honeycomb. This method exists for compatibility
1793 * and always returns -1 and has no effect.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 *
Carl Shapiro11073832011-01-12 16:28:57 -08001795 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 */
Carl Shapiro11073832011-01-12 16:28:57 -08001797 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 public static int setGlobalAllocationLimit(int limit) {
Carl Shapiro11073832011-01-12 16:28:57 -08001799 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 }
1801
1802 /**
1803 * Dump a list of all currently loaded class to the log file.
1804 *
1805 * @param flags See constants above.
1806 */
1807 public static void printLoadedClasses(int flags) {
1808 VMDebug.printLoadedClasses(flags);
1809 }
1810
1811 /**
1812 * Get the number of loaded classes.
1813 * @return the number of loaded classes.
1814 */
1815 public static int getLoadedClassCount() {
1816 return VMDebug.getLoadedClassCount();
1817 }
1818
1819 /**
Andy McFadden824c5102010-07-09 16:26:57 -07001820 * Dump "hprof" data to the specified file. This may cause a GC.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 *
1822 * @param fileName Full pathname of output file (e.g. "/sdcard/dump.hprof").
1823 * @throws UnsupportedOperationException if the VM was built without
1824 * HPROF support.
1825 * @throws IOException if an error occurs while opening or writing files.
1826 */
1827 public static void dumpHprofData(String fileName) throws IOException {
1828 VMDebug.dumpHprofData(fileName);
1829 }
1830
1831 /**
Andy McFadden824c5102010-07-09 16:26:57 -07001832 * Like dumpHprofData(String), but takes an already-opened
1833 * FileDescriptor to which the trace is written. The file name is also
1834 * supplied simply for logging. Makes a dup of the file descriptor.
1835 *
1836 * Primarily for use by the "am" shell command.
1837 *
1838 * @hide
1839 */
1840 public static void dumpHprofData(String fileName, FileDescriptor fd)
1841 throws IOException {
1842 VMDebug.dumpHprofData(fileName, fd);
1843 }
1844
1845 /**
1846 * Collect "hprof" and send it to DDMS. This may cause a GC.
Andy McFadden07a96612010-01-28 16:54:37 -08001847 *
1848 * @throws UnsupportedOperationException if the VM was built without
1849 * HPROF support.
Andy McFadden07a96612010-01-28 16:54:37 -08001850 * @hide
1851 */
1852 public static void dumpHprofDataDdms() {
1853 VMDebug.dumpHprofDataDdms();
1854 }
1855
1856 /**
Andy McFadden06a6b552010-07-13 16:28:09 -07001857 * Writes native heap data to the specified file descriptor.
1858 *
1859 * @hide
1860 */
1861 public static native void dumpNativeHeap(FileDescriptor fd);
1862
1863 /**
Brian Carlstromc21550a2010-10-05 21:34:06 -07001864 * Returns a count of the extant instances of a class.
1865 *
1866 * @hide
1867 */
1868 public static long countInstancesOfClass(Class cls) {
Brian Carlstrom7495cfa2010-11-30 18:06:00 -08001869 return VMDebug.countInstancesOfClass(cls, true);
Brian Carlstromc21550a2010-10-05 21:34:06 -07001870 }
1871
1872 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001873 * Returns the number of sent transactions from this process.
1874 * @return The number of sent transactions or -1 if it could not read t.
1875 */
1876 public static native int getBinderSentTransactions();
1877
1878 /**
1879 * Returns the number of received transactions from the binder driver.
1880 * @return The number of received transactions or -1 if it could not read the stats.
1881 */
1882 public static native int getBinderReceivedTransactions();
1883
1884 /**
1885 * Returns the number of active local Binder objects that exist in the
1886 * current process.
1887 */
1888 public static final native int getBinderLocalObjectCount();
1889
1890 /**
1891 * Returns the number of references to remote proxy Binder objects that
1892 * exist in the current process.
1893 */
1894 public static final native int getBinderProxyObjectCount();
1895
1896 /**
1897 * Returns the number of death notification links to Binder objects that
1898 * exist in the current process.
1899 */
1900 public static final native int getBinderDeathObjectCount();
1901
1902 /**
Andy McFadden599c9182009-04-08 00:35:56 -07001903 * Primes the register map cache.
1904 *
1905 * Only works for classes in the bootstrap class loader. Does not
1906 * cause classes to be loaded if they're not already present.
1907 *
1908 * The classAndMethodDesc argument is a concatentation of the VM-internal
1909 * class descriptor, method name, and method descriptor. Examples:
1910 * Landroid/os/Looper;.loop:()V
1911 * Landroid/app/ActivityThread;.main:([Ljava/lang/String;)V
1912 *
1913 * @param classAndMethodDesc the method to prepare
1914 *
1915 * @hide
1916 */
1917 public static final boolean cacheRegisterMap(String classAndMethodDesc) {
1918 return VMDebug.cacheRegisterMap(classAndMethodDesc);
1919 }
1920
1921 /**
Andy McFaddenbfd6d482009-10-22 17:25:57 -07001922 * Dumps the contents of VM reference tables (e.g. JNI locals and
1923 * globals) to the log file.
1924 *
1925 * @hide
1926 */
1927 public static final void dumpReferenceTables() {
1928 VMDebug.dumpReferenceTables();
1929 }
1930
1931 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 * API for gathering and querying instruction counts.
1933 *
1934 * Example usage:
Chet Haase2970c492010-11-09 13:58:04 -08001935 * <pre>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 * Debug.InstructionCount icount = new Debug.InstructionCount();
1937 * icount.resetAndStart();
1938 * [... do lots of stuff ...]
1939 * if (icount.collect()) {
1940 * System.out.println("Total instructions executed: "
1941 * + icount.globalTotal());
1942 * System.out.println("Method invocations: "
1943 * + icount.globalMethodInvocations());
1944 * }
Chet Haase2970c492010-11-09 13:58:04 -08001945 * </pre>
Jeff Hao7d0b3d42014-09-17 15:45:05 -07001946 *
1947 * @deprecated Instruction counting is no longer supported.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 */
Jeff Hao7d0b3d42014-09-17 15:45:05 -07001949 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 public static class InstructionCount {
Dan Bornsteinb96f5892010-12-02 17:19:53 -08001951 private static final int NUM_INSTR =
1952 OpcodeInfo.MAXIMUM_PACKED_VALUE + 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953
1954 private int[] mCounts;
1955
1956 public InstructionCount() {
1957 mCounts = new int[NUM_INSTR];
1958 }
1959
1960 /**
1961 * Reset counters and ensure counts are running. Counts may
1962 * have already been running.
1963 *
1964 * @return true if counting was started
1965 */
1966 public boolean resetAndStart() {
1967 try {
1968 VMDebug.startInstructionCounting();
1969 VMDebug.resetInstructionCount();
1970 } catch (UnsupportedOperationException uoe) {
1971 return false;
1972 }
1973 return true;
1974 }
1975
1976 /**
1977 * Collect instruction counts. May or may not stop the
1978 * counting process.
1979 */
1980 public boolean collect() {
1981 try {
1982 VMDebug.stopInstructionCounting();
1983 VMDebug.getInstructionCount(mCounts);
1984 } catch (UnsupportedOperationException uoe) {
1985 return false;
1986 }
1987 return true;
1988 }
1989
1990 /**
1991 * Return the total number of instructions executed globally (i.e. in
1992 * all threads).
1993 */
1994 public int globalTotal() {
1995 int count = 0;
Dan Bornstein1d99b062010-11-30 12:26:52 -08001996
1997 for (int i = 0; i < NUM_INSTR; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 count += mCounts[i];
Dan Bornstein1d99b062010-11-30 12:26:52 -08001999 }
2000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 return count;
2002 }
2003
2004 /**
2005 * Return the total number of method-invocation instructions
2006 * executed globally.
2007 */
2008 public int globalMethodInvocations() {
2009 int count = 0;
2010
Dan Bornstein1d99b062010-11-30 12:26:52 -08002011 for (int i = 0; i < NUM_INSTR; i++) {
2012 if (OpcodeInfo.isInvoke(i)) {
2013 count += mCounts[i];
2014 }
2015 }
2016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 return count;
2018 }
Dave Bort1ce5bd32009-04-22 17:36:56 -07002019 }
2020
Dave Bort1ce5bd32009-04-22 17:36:56 -07002021 /**
2022 * A Map of typed debug properties.
2023 */
2024 private static final TypedProperties debugProperties;
2025
2026 /*
2027 * Load the debug properties from the standard files into debugProperties.
2028 */
2029 static {
Joe Onorato43a17652011-04-06 19:22:23 -07002030 if (false) {
Dave Bort1ce5bd32009-04-22 17:36:56 -07002031 final String TAG = "DebugProperties";
2032 final String[] files = { "/system/debug.prop", "/debug.prop", "/data/debug.prop" };
2033 final TypedProperties tp = new TypedProperties();
2034
2035 // Read the properties from each of the files, if present.
Dave Borte9bfd9b2009-05-04 14:35:23 -07002036 for (String file : files) {
Dave Bort1ce5bd32009-04-22 17:36:56 -07002037 Reader r;
2038 try {
2039 r = new FileReader(file);
2040 } catch (FileNotFoundException ex) {
2041 // It's ok if a file is missing.
2042 continue;
2043 }
2044
Dave Bort1ce5bd32009-04-22 17:36:56 -07002045 try {
2046 tp.load(r);
Dave Borte9bfd9b2009-05-04 14:35:23 -07002047 } catch (Exception ex) {
2048 throw new RuntimeException("Problem loading " + file, ex);
2049 } finally {
2050 try {
2051 r.close();
2052 } catch (IOException ex) {
2053 // Ignore this error.
2054 }
Dave Bort1ce5bd32009-04-22 17:36:56 -07002055 }
2056 }
2057
2058 debugProperties = tp.isEmpty() ? null : tp;
2059 } else {
2060 debugProperties = null;
2061 }
2062 }
2063
2064
2065 /**
2066 * Returns true if the type of the field matches the specified class.
2067 * Handles the case where the class is, e.g., java.lang.Boolean, but
2068 * the field is of the primitive "boolean" type. Also handles all of
2069 * the java.lang.Number subclasses.
2070 */
2071 private static boolean fieldTypeMatches(Field field, Class<?> cl) {
2072 Class<?> fieldClass = field.getType();
2073 if (fieldClass == cl) {
2074 return true;
2075 }
2076 Field primitiveTypeField;
2077 try {
2078 /* All of the classes we care about (Boolean, Integer, etc.)
2079 * have a Class field called "TYPE" that points to the corresponding
2080 * primitive class.
2081 */
2082 primitiveTypeField = cl.getField("TYPE");
2083 } catch (NoSuchFieldException ex) {
2084 return false;
2085 }
2086 try {
Dave Borte9bfd9b2009-05-04 14:35:23 -07002087 return fieldClass == (Class<?>) primitiveTypeField.get(null);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002088 } catch (IllegalAccessException ex) {
2089 return false;
2090 }
2091 }
2092
2093
2094 /**
2095 * Looks up the property that corresponds to the field, and sets the field's value
2096 * if the types match.
2097 */
Dave Borte9bfd9b2009-05-04 14:35:23 -07002098 private static void modifyFieldIfSet(final Field field, final TypedProperties properties,
2099 final String propertyName) {
Dave Bort1ce5bd32009-04-22 17:36:56 -07002100 if (field.getType() == java.lang.String.class) {
Dave Borte9bfd9b2009-05-04 14:35:23 -07002101 int stringInfo = properties.getStringInfo(propertyName);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002102 switch (stringInfo) {
Dave Borte9bfd9b2009-05-04 14:35:23 -07002103 case TypedProperties.STRING_SET:
2104 // Handle as usual below.
2105 break;
2106 case TypedProperties.STRING_NULL:
2107 try {
2108 field.set(null, null); // null object for static fields; null string
2109 } catch (IllegalAccessException ex) {
2110 throw new IllegalArgumentException(
2111 "Cannot set field for " + propertyName, ex);
2112 }
2113 return;
2114 case TypedProperties.STRING_NOT_SET:
2115 return;
2116 case TypedProperties.STRING_TYPE_MISMATCH:
Dave Bort1ce5bd32009-04-22 17:36:56 -07002117 throw new IllegalArgumentException(
Dave Borte9bfd9b2009-05-04 14:35:23 -07002118 "Type of " + propertyName + " " +
2119 " does not match field type (" + field.getType() + ")");
2120 default:
2121 throw new IllegalStateException(
2122 "Unexpected getStringInfo(" + propertyName + ") return value " +
2123 stringInfo);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002124 }
2125 }
Dave Borte9bfd9b2009-05-04 14:35:23 -07002126 Object value = properties.get(propertyName);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002127 if (value != null) {
2128 if (!fieldTypeMatches(field, value.getClass())) {
2129 throw new IllegalArgumentException(
2130 "Type of " + propertyName + " (" + value.getClass() + ") " +
2131 " does not match field type (" + field.getType() + ")");
2132 }
2133 try {
2134 field.set(null, value); // null object for static fields
2135 } catch (IllegalAccessException ex) {
2136 throw new IllegalArgumentException(
2137 "Cannot set field for " + propertyName, ex);
2138 }
2139 }
2140 }
2141
2142
2143 /**
Romain Guyc4b11a72009-05-13 15:46:37 -07002144 * Equivalent to <code>setFieldsOn(cl, false)</code>.
2145 *
2146 * @see #setFieldsOn(Class, boolean)
Romain Guyd4103d02009-05-14 12:24:21 -07002147 *
2148 * @hide
Romain Guyc4b11a72009-05-13 15:46:37 -07002149 */
2150 public static void setFieldsOn(Class<?> cl) {
2151 setFieldsOn(cl, false);
2152 }
2153
2154 /**
Dave Bort1ce5bd32009-04-22 17:36:56 -07002155 * Reflectively sets static fields of a class based on internal debugging
Joe Onorato43a17652011-04-06 19:22:23 -07002156 * properties. This method is a no-op if false is
Dave Bort1ce5bd32009-04-22 17:36:56 -07002157 * false.
2158 * <p>
Joe Onorato43a17652011-04-06 19:22:23 -07002159 * <strong>NOTE TO APPLICATION DEVELOPERS</strong>: false will
Dave Bort1ce5bd32009-04-22 17:36:56 -07002160 * always be false in release builds. This API is typically only useful
2161 * for platform developers.
2162 * </p>
2163 * Class setup: define a class whose only fields are non-final, static
2164 * primitive types (except for "char") or Strings. In a static block
2165 * after the field definitions/initializations, pass the class to
Romain Guyc4b11a72009-05-13 15:46:37 -07002166 * this method, Debug.setFieldsOn(). Example:
Dave Bort1ce5bd32009-04-22 17:36:56 -07002167 * <pre>
2168 * package com.example;
2169 *
2170 * import android.os.Debug;
2171 *
2172 * public class MyDebugVars {
2173 * public static String s = "a string";
2174 * public static String s2 = "second string";
2175 * public static String ns = null;
2176 * public static boolean b = false;
2177 * public static int i = 5;
Romain Guyc4b11a72009-05-13 15:46:37 -07002178 * @Debug.DebugProperty
Dave Bort1ce5bd32009-04-22 17:36:56 -07002179 * public static float f = 0.1f;
Romain Guyc4b11a72009-05-13 15:46:37 -07002180 * @@Debug.DebugProperty
Dave Bort1ce5bd32009-04-22 17:36:56 -07002181 * public static double d = 0.5d;
2182 *
2183 * // This MUST appear AFTER all fields are defined and initialized!
2184 * static {
Romain Guyc4b11a72009-05-13 15:46:37 -07002185 * // Sets all the fields
Dave Borte9bfd9b2009-05-04 14:35:23 -07002186 * Debug.setFieldsOn(MyDebugVars.class);
Christian Mehlmauer798e2d32010-06-17 18:24:07 +02002187 *
Romain Guyc4b11a72009-05-13 15:46:37 -07002188 * // Sets only the fields annotated with @Debug.DebugProperty
2189 * // Debug.setFieldsOn(MyDebugVars.class, true);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002190 * }
2191 * }
2192 * </pre>
Dave Borte9bfd9b2009-05-04 14:35:23 -07002193 * setFieldsOn() may override the value of any field in the class based
Dave Bort1ce5bd32009-04-22 17:36:56 -07002194 * on internal properties that are fixed at boot time.
2195 * <p>
2196 * These properties are only set during platform debugging, and are not
2197 * meant to be used as a general-purpose properties store.
2198 *
2199 * {@hide}
2200 *
2201 * @param cl The class to (possibly) modify
Romain Guyc4b11a72009-05-13 15:46:37 -07002202 * @param partial If false, sets all static fields, otherwise, only set
2203 * fields with the {@link android.os.Debug.DebugProperty}
2204 * annotation
Dave Bort1ce5bd32009-04-22 17:36:56 -07002205 * @throws IllegalArgumentException if any fields are final or non-static,
2206 * or if the type of the field does not match the type of
2207 * the internal debugging property value.
2208 */
Romain Guyc4b11a72009-05-13 15:46:37 -07002209 public static void setFieldsOn(Class<?> cl, boolean partial) {
Joe Onorato43a17652011-04-06 19:22:23 -07002210 if (false) {
Dave Bort1ce5bd32009-04-22 17:36:56 -07002211 if (debugProperties != null) {
2212 /* Only look for fields declared directly by the class,
2213 * so we don't mysteriously change static fields in superclasses.
2214 */
2215 for (Field field : cl.getDeclaredFields()) {
Romain Guyc4b11a72009-05-13 15:46:37 -07002216 if (!partial || field.getAnnotation(DebugProperty.class) != null) {
2217 final String propertyName = cl.getName() + "." + field.getName();
2218 boolean isStatic = Modifier.isStatic(field.getModifiers());
2219 boolean isFinal = Modifier.isFinal(field.getModifiers());
2220
2221 if (!isStatic || isFinal) {
2222 throw new IllegalArgumentException(propertyName +
2223 " must be static and non-final");
2224 }
2225 modifyFieldIfSet(field, debugProperties, propertyName);
Dave Bort1ce5bd32009-04-22 17:36:56 -07002226 }
Dave Bort1ce5bd32009-04-22 17:36:56 -07002227 }
2228 }
2229 } else {
Dan Egnor3eda9792010-03-05 13:28:36 -08002230 Log.wtf(TAG,
Dave Borte9bfd9b2009-05-04 14:35:23 -07002231 "setFieldsOn(" + (cl == null ? "null" : cl.getName()) +
Dave Bort1ce5bd32009-04-22 17:36:56 -07002232 ") called in non-DEBUG build");
2233 }
2234 }
Romain Guyc4b11a72009-05-13 15:46:37 -07002235
2236 /**
2237 * Annotation to put on fields you want to set with
2238 * {@link Debug#setFieldsOn(Class, boolean)}.
2239 *
2240 * @hide
2241 */
2242 @Target({ ElementType.FIELD })
2243 @Retention(RetentionPolicy.RUNTIME)
2244 public @interface DebugProperty {
2245 }
Dan Egnor3eda9792010-03-05 13:28:36 -08002246
2247 /**
2248 * Get a debugging dump of a system service by name.
2249 *
2250 * <p>Most services require the caller to hold android.permission.DUMP.
2251 *
2252 * @param name of the service to dump
2253 * @param fd to write dump output to (usually an output log file)
2254 * @param args to pass to the service's dump method, may be null
2255 * @return true if the service was dumped successfully, false if
2256 * the service could not be found or had an error while dumping
2257 */
2258 public static boolean dumpService(String name, FileDescriptor fd, String[] args) {
2259 IBinder service = ServiceManager.getService(name);
2260 if (service == null) {
2261 Log.e(TAG, "Can't find service to dump: " + name);
2262 return false;
2263 }
2264
2265 try {
2266 service.dump(fd, args);
2267 return true;
2268 } catch (RemoteException e) {
2269 Log.e(TAG, "Can't dump service: " + name, e);
2270 return false;
2271 }
2272 }
Craig Mautnera51a9562012-04-17 17:05:26 -07002273
2274 /**
Narayan Kamathf013daa2017-05-09 12:55:02 +01002275 * Append the Java stack traces of a given native process to a specified file.
2276 *
songjinshie02e3ea2016-12-16 17:48:21 +08002277 * @param pid pid to dump.
2278 * @param file path of file to append dump to.
2279 * @param timeoutSecs time to wait in seconds, or 0 to wait forever.
Dianne Hackbornf72467a2012-06-08 17:23:59 -07002280 * @hide
2281 */
Narayan Kamathf013daa2017-05-09 12:55:02 +01002282 public static native boolean dumpJavaBacktraceToFileTimeout(int pid, String file,
2283 int timeoutSecs);
2284
2285 /**
2286 * Append the native stack traces of a given process to a specified file.
2287 *
2288 * @param pid pid to dump.
2289 * @param file path of file to append dump to.
2290 * @param timeoutSecs time to wait in seconds, or 0 to wait forever.
2291 * @hide
2292 */
2293 public static native boolean dumpNativeBacktraceToFileTimeout(int pid, String file,
2294 int timeoutSecs);
Dianne Hackbornf72467a2012-06-08 17:23:59 -07002295
2296 /**
Colin Crossc4fb5f92016-02-02 16:51:15 -08002297 * Get description of unreachable native memory.
2298 * @param limit the number of leaks to provide info on, 0 to only get a summary.
2299 * @param contents true to include a hex dump of the contents of unreachable memory.
2300 * @return the String containing a description of unreachable memory.
2301 * @hide */
2302 public static native String getUnreachableMemory(int limit, boolean contents);
2303
2304 /**
Craig Mautnera51a9562012-04-17 17:05:26 -07002305 * Return a String describing the calling method and location at a particular stack depth.
Anwar Ghuloum3a8ce1b2013-04-26 16:18:28 -07002306 * @param callStack the Thread stack
Craig Mautnera51a9562012-04-17 17:05:26 -07002307 * @param depth the depth of stack to return information for.
2308 * @return the String describing the caller at that depth.
2309 */
2310 private static String getCaller(StackTraceElement callStack[], int depth) {
2311 // callStack[4] is the caller of the method that called getCallers()
2312 if (4 + depth >= callStack.length) {
2313 return "<bottom of call stack>";
2314 }
2315 StackTraceElement caller = callStack[4 + depth];
2316 return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber();
2317 }
2318
2319 /**
2320 * Return a string consisting of methods and locations at multiple call stack levels.
2321 * @param depth the number of levels to return, starting with the immediate caller.
2322 * @return a string describing the call stack.
2323 * {@hide}
2324 */
2325 public static String getCallers(final int depth) {
2326 final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
2327 StringBuffer sb = new StringBuffer();
2328 for (int i = 0; i < depth; i++) {
2329 sb.append(getCaller(callStack, i)).append(" ");
2330 }
2331 return sb.toString();
2332 }
2333
2334 /**
Dianne Hackbornfd6c7b12013-10-03 10:42:26 -07002335 * Return a string consisting of methods and locations at multiple call stack levels.
2336 * @param depth the number of levels to return, starting with the immediate caller.
2337 * @return a string describing the call stack.
2338 * {@hide}
2339 */
2340 public static String getCallers(final int start, int depth) {
2341 final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
2342 StringBuffer sb = new StringBuffer();
2343 depth += start;
2344 for (int i = start; i < depth; i++) {
2345 sb.append(getCaller(callStack, i)).append(" ");
2346 }
2347 return sb.toString();
2348 }
2349
2350 /**
Dianne Hackbornef03a7f2012-10-29 18:46:52 -07002351 * Like {@link #getCallers(int)}, but each location is append to the string
2352 * as a new line with <var>linePrefix</var> in front of it.
2353 * @param depth the number of levels to return, starting with the immediate caller.
2354 * @param linePrefix prefix to put in front of each location.
2355 * @return a string describing the call stack.
2356 * {@hide}
2357 */
2358 public static String getCallers(final int depth, String linePrefix) {
2359 final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
2360 StringBuffer sb = new StringBuffer();
2361 for (int i = 0; i < depth; i++) {
2362 sb.append(linePrefix).append(getCaller(callStack, i)).append("\n");
2363 }
2364 return sb.toString();
2365 }
2366
2367 /**
Ian Rogersfe067a42013-02-22 19:59:23 -08002368 * @return a String describing the immediate caller of the calling method.
Craig Mautnera51a9562012-04-17 17:05:26 -07002369 * {@hide}
2370 */
2371 public static String getCaller() {
2372 return getCaller(Thread.currentThread().getStackTrace(), 0);
2373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374}