Class Debug
- java.lang.Object
-
- android.os.Debug
-
public final class Debug extends Object
Provides various debugging methods for Android applications, including tracing and allocation counts.Logging Trace Files
Debug can create log files that give details about an application, such as a call stack and start/stop times for any running methods. See Traceview: A Graphical Log Viewer for information about reading trace files. To start logging trace files, call one of the startMethodTracing() methods. To stop tracing, call
stopMethodTracing().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDebug.DebugPropertyAnnotation to put on fields you want to set withsetFieldsOn(Class, boolean).static classDebug.InstructionCountDeprecated.Instruction counting is no longer supported.static classDebug.MemoryInfoThis class is used to retrieved various statistics about the memory mappings for this process.
-
Field Summary
Fields Modifier and Type Field Description static intMEMINFO_BUFFERSstatic intMEMINFO_CACHEDstatic intMEMINFO_COUNTstatic intMEMINFO_FREEstatic intMEMINFO_KERNEL_STACKstatic intMEMINFO_MAPPEDstatic intMEMINFO_PAGE_TABLESstatic intMEMINFO_SHMEMstatic intMEMINFO_SLABstatic intMEMINFO_SWAP_FREEstatic intMEMINFO_SWAP_TOTALstatic intMEMINFO_TOTALstatic intMEMINFO_VM_ALLOC_USEDstatic intMEMINFO_ZRAM_TOTALstatic intSHOW_CLASSLOADERstatic intSHOW_FULL_DETAILFlags for printLoadedClasses().static intSHOW_INITIALIZEDstatic intTRACE_COUNT_ALLOCSDeprecated.Accurate counting is a burden on the runtime and may be removed.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleancacheRegisterMap(String classAndMethodDesc)Primes the register map cache.static voidchangeDebugPort(int port)Deprecated.no longer needed or usefulstatic longcountInstancesOfClass(Class cls)Returns a count of the extant instances of a class.static voiddumpHprofData(String fileName)Dump "hprof" data to the specified file.static voiddumpHprofData(String fileName, FileDescriptor fd)Like dumpHprofData(String), but takes an already-opened FileDescriptor to which the trace is written.static voiddumpHprofDataDdms()Collect "hprof" and send it to DDMS.static voiddumpNativeBacktraceToFile(int pid, String file)Have the stack traces of the given native process dumped to the specified file.static voiddumpNativeHeap(FileDescriptor fd)Writes native heap data to the specified file descriptor.static voiddumpReferenceTables()Dumps the contents of VM reference tables (e.g.static booleandumpService(String name, FileDescriptor fd, String[] args)Get a debugging dump of a system service by name.static voidenableEmulatorTraceOutput()Enable "emulator traces", in which information about the current method is made available to the "emulator -trace" feature.static intgetBinderDeathObjectCount()Returns the number of death notification links to Binder objects that exist in the current process.static intgetBinderLocalObjectCount()Returns the number of active local Binder objects that exist in the current process.static intgetBinderProxyObjectCount()Returns the number of references to remote proxy Binder objects that exist in the current process.static intgetBinderReceivedTransactions()Returns the number of received transactions from the binder driver.static intgetBinderSentTransactions()Returns the number of sent transactions from this process.static StringgetCaller()static StringgetCallers(int depth)Return a string consisting of methods and locations at multiple call stack levels.static StringgetCallers(int start, int depth)Return a string consisting of methods and locations at multiple call stack levels.static StringgetCallers(int depth, String linePrefix)LikegetCallers(int), but each location is append to the string as a new line with linePrefix in front of it.static intgetGlobalAllocCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalAllocSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalClassInitCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalClassInitTime()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalExternalAllocCount()Deprecated.This method is now obsolete.static intgetGlobalExternalAllocSize()Deprecated.This method is now obsolete.static intgetGlobalExternalFreedCount()Deprecated.This method is now obsolete.static intgetGlobalExternalFreedSize()Deprecated.This method is now obsolete.static intgetGlobalFreedCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalFreedSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetGlobalGcInvocationCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetLoadedClassCount()Get the number of loaded classes.static voidgetMemInfo(long[] outSizes)Retrieves /proc/meminfo.static voidgetMemoryInfo(int pid, Debug.MemoryInfo memoryInfo)Note: currently only works when the requested pid has the same UID as the caller.static voidgetMemoryInfo(Debug.MemoryInfo memoryInfo)Retrieves information about this processes memory usages.static intgetMethodTracingMode()Determine whether method tracing is currently active and what type is active.static longgetNativeHeapAllocatedSize()Returns the amount of allocated memory in the native heap.static longgetNativeHeapFreeSize()Returns the amount of free memory in the native heap.static longgetNativeHeapSize()Returns the size of the native heap.static longgetPss()Retrieves the PSS memory used by the process as given by the smaps.static longgetPss(int pid, long[] outUss, long[] outMemtrack)Retrieves the PSS memory used by the process as given by the smaps.static StringgetRuntimeStat(String statName)Returns the value of a particular runtime statistic ornullif no such runtime statistic exists.static Map<String,String>getRuntimeStats()Returns a map of the names/values of the runtime statistics thatgetRuntimeStat(String)supports.static intgetThreadAllocCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetThreadAllocSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intgetThreadExternalAllocCount()Deprecated.This method is now obsolete.static intgetThreadExternalAllocSize()Deprecated.This method is now obsolete.static intgetThreadGcInvocationCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static String[]getVmFeatureList()Returns an array of strings that identify VM features.static booleanisDebuggerConnected()Determine if a debugger is currently attached.static voidprintLoadedClasses(int flags)Dump a list of all currently loaded class to the log file.static voidresetAllCounts()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalAllocCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalAllocSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalClassInitCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalClassInitTime()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalExternalAllocCount()Deprecated.This method is now obsolete.static voidresetGlobalExternalAllocSize()Deprecated.This method is now obsolete.static voidresetGlobalExternalFreedCount()Deprecated.This method is now obsolete.static voidresetGlobalExternalFreedSize()Deprecated.This method is now obsolete.static voidresetGlobalFreedCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalFreedSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetGlobalGcInvocationCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetThreadAllocCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetThreadAllocSize()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidresetThreadExternalAllocCount()Deprecated.This method is now obsolete.static voidresetThreadExternalAllocSize()Deprecated.This method is now obsolete.static voidresetThreadGcInvocationCount()Deprecated.Accurate counting is a burden on the runtime and may be removed.static intsetAllocationLimit(int limit)Deprecated.This method is now obsolete.static voidsetFieldsOn(Class<?> cl)Equivalent tosetFieldsOn(cl, false).static voidsetFieldsOn(Class<?> cl, boolean partial)Reflectively sets static fields of a class based on internal debugging properties.static intsetGlobalAllocationLimit(int limit)Deprecated.This method is now obsolete.static voidstartAllocCounting()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidstartMethodTracing()Start method tracing with default log name and buffer size.static voidstartMethodTracing(String traceName)Start method tracing, specifying the trace log file name.static voidstartMethodTracing(String traceName, int bufferSize)Start method tracing, specifying the trace log file name and the buffer size.static voidstartMethodTracing(String traceName, int bufferSize, int flags)Start method tracing, specifying the trace log file name and the buffer size.static voidstartMethodTracing(String traceName, FileDescriptor fd, int bufferSize, int flags)Like startMethodTracing(String, int, int), but taking an already-opened FileDescriptor in which the trace is written.static voidstartMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Starts method tracing without a backing file.static voidstartMethodTracingSampling(String traceName, int bufferSize, int intervalUs)Start sampling-based method tracing, specifying the trace log file name, the buffer size, and the sampling interval.static voidstartNativeTracing()Enable qemu tracing.static voidstopAllocCounting()Deprecated.Accurate counting is a burden on the runtime and may be removed.static voidstopMethodTracing()Stop method tracing.static voidstopNativeTracing()Stop qemu tracing.static longthreadCpuTimeNanos()Get an indication of thread CPU usage.static voidwaitForDebugger()Wait until a debugger attaches.static booleanwaitingForDebugger()Returns "true" if one or more threads is waiting for a debugger to attach.
-
-
-
Field Detail
-
TRACE_COUNT_ALLOCS
@Deprecated public static final int TRACE_COUNT_ALLOCS
Deprecated.Accurate counting is a burden on the runtime and may be removed.Flags for startMethodTracing(). These can be ORed together. TRACE_COUNT_ALLOCS adds the results from startAllocCounting to the trace key file.- See Also:
- Constant Field Values
-
SHOW_FULL_DETAIL
public static final int SHOW_FULL_DETAIL
Flags for printLoadedClasses(). Default behavior is to only show the class name.- See Also:
- Constant Field Values
-
SHOW_CLASSLOADER
public static final int SHOW_CLASSLOADER
- See Also:
- Constant Field Values
-
SHOW_INITIALIZED
public static final int SHOW_INITIALIZED
- See Also:
- Constant Field Values
-
MEMINFO_TOTAL
public static final int MEMINFO_TOTAL
- See Also:
- Constant Field Values
-
MEMINFO_FREE
public static final int MEMINFO_FREE
- See Also:
- Constant Field Values
-
MEMINFO_BUFFERS
public static final int MEMINFO_BUFFERS
- See Also:
- Constant Field Values
-
MEMINFO_CACHED
public static final int MEMINFO_CACHED
- See Also:
- Constant Field Values
-
MEMINFO_SHMEM
public static final int MEMINFO_SHMEM
- See Also:
- Constant Field Values
-
MEMINFO_SLAB
public static final int MEMINFO_SLAB
- See Also:
- Constant Field Values
-
MEMINFO_SWAP_TOTAL
public static final int MEMINFO_SWAP_TOTAL
- See Also:
- Constant Field Values
-
MEMINFO_SWAP_FREE
public static final int MEMINFO_SWAP_FREE
- See Also:
- Constant Field Values
-
MEMINFO_ZRAM_TOTAL
public static final int MEMINFO_ZRAM_TOTAL
- See Also:
- Constant Field Values
-
MEMINFO_MAPPED
public static final int MEMINFO_MAPPED
- See Also:
- Constant Field Values
-
MEMINFO_VM_ALLOC_USED
public static final int MEMINFO_VM_ALLOC_USED
- See Also:
- Constant Field Values
-
MEMINFO_PAGE_TABLES
public static final int MEMINFO_PAGE_TABLES
- See Also:
- Constant Field Values
-
MEMINFO_KERNEL_STACK
public static final int MEMINFO_KERNEL_STACK
- See Also:
- Constant Field Values
-
MEMINFO_COUNT
public static final int MEMINFO_COUNT
- See Also:
- Constant Field Values
-
-
Method Detail
-
waitForDebugger
public static void waitForDebugger()
Wait until a debugger attaches. As soon as the debugger attaches, this returns, so you will need to place a breakpoint after the waitForDebugger() call if you want to start tracing immediately.
-
waitingForDebugger
public static boolean waitingForDebugger()
Returns "true" if one or more threads is waiting for a debugger to attach.
-
isDebuggerConnected
public static boolean isDebuggerConnected()
Determine if a debugger is currently attached.
-
getVmFeatureList
public static String[] getVmFeatureList()
Returns an array of strings that identify VM features. This is used by DDMS to determine what sorts of operations the VM can perform.
-
changeDebugPort
@Deprecated public static void changeDebugPort(int port)
Deprecated.no longer needed or usefulChange the JDWP port.
-
startNativeTracing
public static void startNativeTracing()
Enable qemu tracing. For this to work requires running everything inside the qemu emulator; otherwise, this method will have no effect. The trace file is specified on the command line when the emulator is started. For example, the following command line
emulator -trace foo
will start running the emulator and create a trace file named "foo". This method simply enables writing the trace records to the trace file.The main differences between this and
startMethodTracing()are that tracing in the qemu emulator traces every cpu instruction of every process, including kernel code, so we have more complete information, including all context switches. We can also get more detailed information such as cache misses. The sequence of calls is determined by post-processing the instruction trace. The qemu tracing is also done without modifying the application or perturbing the timing of calls because no instrumentation is added to the application being traced.One limitation of using this method compared to using
startMethodTracing()on the real device is that the emulator does not model all of the real hardware effects such as memory and bus contention. The emulator also has a simple cache model and cannot capture all the complexities of a real cache.
-
stopNativeTracing
public static void stopNativeTracing()
Stop qemu tracing. SeestartNativeTracing()to start tracing.Tracing can be started and stopped as many times as desired. When the qemu emulator itself is stopped then the buffered trace records are flushed and written to the trace file. In fact, it is not necessary to call this method at all; simply killing qemu is sufficient. But starting and stopping a trace is useful for examining a specific region of code.
-
enableEmulatorTraceOutput
public static void enableEmulatorTraceOutput()
Enable "emulator traces", in which information about the current method is made available to the "emulator -trace" feature. There is no corresponding "disable" call -- this is intended for use by the framework when tracing should be turned on and left that way, so that traces captured with F9/F10 will include the necessary data. This puts the VM into "profile" mode, which has performance consequences. To temporarily enable tracing, usestartNativeTracing().
-
startMethodTracing
public static void startMethodTracing()
Start method tracing with default log name and buffer size. See Traceview: A Graphical Log Viewer for information about reading these files. Call stopMethodTracing() to stop tracing.
-
startMethodTracing
public static void startMethodTracing(String traceName)
Start method tracing, specifying the trace log file name. The trace file will be put under "/sdcard" unless an absolute path is given. See Traceview: A Graphical Log Viewer for information about reading trace files.- Parameters:
traceName- Name for the trace log file to create. IftraceNameis null, this value defaults to "/sdcard/dmtrace.trace". If the files already exist, they will be truncated. If the trace file given does not end in ".trace", it will be appended for you.
-
startMethodTracing
public static void startMethodTracing(String traceName, int bufferSize)
Start method tracing, specifying the trace log file name and the buffer size. The trace files will be put under "/sdcard" unless an absolute path is given. See Traceview: A Graphical Log Viewer for information about reading trace files.- Parameters:
traceName- Name for the trace log file to create. IftraceNameis null, this value defaults to "/sdcard/dmtrace.trace". If the files already exist, they will be truncated. If the trace file given does not end in ".trace", it will be appended for you.bufferSize- The maximum amount of trace data we gather. If not given, it defaults to 8MB.
-
startMethodTracing
public static void startMethodTracing(String traceName, int bufferSize, int flags)
Start method tracing, specifying the trace log file name and the buffer size. The trace files will be put under "/sdcard" unless an absolute path is given. See Traceview: A Graphical Log Viewer for information about reading trace files.When method tracing is enabled, the VM will run more slowly than usual, so the timings from the trace files should only be considered in relative terms (e.g. was run #1 faster than run #2). The times for native methods will not change, so don't try to use this to compare the performance of interpreted and native implementations of the same method. As an alternative, consider using sampling-based method tracing via
startMethodTracingSampling(String, int, int)or "native" tracing in the emulator viastartNativeTracing().- Parameters:
traceName- Name for the trace log file to create. IftraceNameis null, this value defaults to "/sdcard/dmtrace.trace". If the files already exist, they will be truncated. If the trace file given does not end in ".trace", it will be appended for you.bufferSize- The maximum amount of trace data we gather. If not given, it defaults to 8MB.flags- Flags to control method tracing. The only one that is currently defined isTRACE_COUNT_ALLOCS.
-
startMethodTracingSampling
public static void startMethodTracingSampling(String traceName, int bufferSize, int intervalUs)
Start sampling-based method tracing, specifying the trace log file name, the buffer size, and the sampling interval. The trace files will be put under "/sdcard" unless an absolute path is given. See Traceview: A Graphical Log Viewer for information about reading trace files.- Parameters:
traceName- Name for the trace log file to create. IftraceNameis null, this value defaults to "/sdcard/dmtrace.trace". If the files already exist, they will be truncated. If the trace file given does not end in ".trace", it will be appended for you.bufferSize- The maximum amount of trace data we gather. If not given, it defaults to 8MB.intervalUs- The amount of time between each sample in microseconds.
-
startMethodTracing
public static void startMethodTracing(String traceName, FileDescriptor fd, int bufferSize, int flags)
Like startMethodTracing(String, int, int), but taking an already-opened FileDescriptor in which the trace is written. The file name is also supplied simply for logging. Makes a dup of the file descriptor. Not exposed in the SDK unless we are really comfortable with supporting this and find it would be useful.
-
startMethodTracingDdms
public static void startMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Starts method tracing without a backing file. When stopMethodTracing is called, the result is sent directly to DDMS. (If DDMS is not attached when tracing ends, the profiling data will be discarded.)
-
getMethodTracingMode
public static int getMethodTracingMode()
Determine whether method tracing is currently active and what type is active.
-
stopMethodTracing
public static void stopMethodTracing()
Stop method tracing.
-
threadCpuTimeNanos
public static long threadCpuTimeNanos()
Get an indication of thread CPU usage. The value returned indicates the amount of time that the current thread has spent executing code or waiting for certain types of I/O. The time is expressed in nanoseconds, and is only meaningful when compared to the result from an earlier call. Note that nanosecond resolution does not imply nanosecond accuracy. On system which don't support this operation, the call returns -1.
-
startAllocCounting
@Deprecated public static void startAllocCounting()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Start counting the number and aggregate size of memory allocations.The
startmethod resets the counts and enables counting. Thestopmethod disables the counting so that the analysis code doesn't cause additional allocations. The variousgetmethods return the specified value. And the variousresetmethods reset the specified count.Counts are kept for the system as a whole (global) and for each thread. The per-thread counts for threads other than the current thread are not cleared by the "reset" or "start" calls.
-
stopAllocCounting
@Deprecated public static void stopAllocCounting()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Stop counting the number and aggregate size of memory allocations.
-
getGlobalAllocCount
@Deprecated public static int getGlobalAllocCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalAllocCount
@Deprecated public static void resetGlobalAllocCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the global count of objects allocated.- See Also:
getGlobalAllocCount()
-
getGlobalAllocSize
@Deprecated public static int getGlobalAllocSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalAllocSize
@Deprecated public static void resetGlobalAllocSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the global size of objects allocated.- See Also:
getGlobalAllocSize()
-
getGlobalFreedCount
@Deprecated public static int getGlobalFreedCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalFreedCount
@Deprecated public static void resetGlobalFreedCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the global count of objects freed.- See Also:
getGlobalFreedCount()
-
getGlobalFreedSize
@Deprecated public static int getGlobalFreedSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalFreedSize
@Deprecated public static void resetGlobalFreedSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the global size of objects freed.- See Also:
getGlobalFreedSize()
-
getGlobalGcInvocationCount
@Deprecated public static int getGlobalGcInvocationCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalGcInvocationCount
@Deprecated public static void resetGlobalGcInvocationCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the count of non-concurrent GC invocations.- See Also:
getGlobalGcInvocationCount()
-
getGlobalClassInitCount
@Deprecated public static int getGlobalClassInitCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalClassInitCount
@Deprecated public static void resetGlobalClassInitCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the count of classes initialized.- See Also:
getGlobalClassInitCount()
-
getGlobalClassInitTime
@Deprecated public static int getGlobalClassInitTime()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetGlobalClassInitTime
@Deprecated public static void resetGlobalClassInitTime()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the count of time spent initializing classes.- See Also:
getGlobalClassInitTime()
-
getGlobalExternalAllocCount
@Deprecated public static int getGlobalExternalAllocCount()
Deprecated.This method is now obsolete.This method exists for compatibility and always returns 0.
-
resetGlobalExternalAllocSize
@Deprecated public static void resetGlobalExternalAllocSize()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
resetGlobalExternalAllocCount
@Deprecated public static void resetGlobalExternalAllocCount()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
getGlobalExternalAllocSize
@Deprecated public static int getGlobalExternalAllocSize()
Deprecated.This method is now obsolete.This method exists for compatibility and always returns 0.
-
getGlobalExternalFreedCount
@Deprecated public static int getGlobalExternalFreedCount()
Deprecated.This method is now obsolete.This method exists for compatibility and always returns 0.
-
resetGlobalExternalFreedCount
@Deprecated public static void resetGlobalExternalFreedCount()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
getGlobalExternalFreedSize
@Deprecated public static int getGlobalExternalFreedSize()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
resetGlobalExternalFreedSize
@Deprecated public static void resetGlobalExternalFreedSize()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
getThreadAllocCount
@Deprecated public static int getThreadAllocCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetThreadAllocCount
@Deprecated public static void resetThreadAllocCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the thread-local count of objects allocated.- See Also:
getThreadAllocCount()
-
getThreadAllocSize
@Deprecated public static int getThreadAllocSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.- Returns:
- The allocated size in bytes.
-
resetThreadAllocSize
@Deprecated public static void resetThreadAllocSize()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the thread-local count of objects allocated.- See Also:
getThreadAllocSize()
-
getThreadExternalAllocCount
@Deprecated public static int getThreadExternalAllocCount()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
resetThreadExternalAllocCount
@Deprecated public static void resetThreadExternalAllocCount()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
getThreadExternalAllocSize
@Deprecated public static int getThreadExternalAllocSize()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
resetThreadExternalAllocSize
@Deprecated public static void resetThreadExternalAllocSize()
Deprecated.This method is now obsolete.This method exists for compatibility and has no effect.
-
getThreadGcInvocationCount
@Deprecated public static int getThreadGcInvocationCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.
-
resetThreadGcInvocationCount
@Deprecated public static void resetThreadGcInvocationCount()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears the thread-local count of non-concurrent GC invocations.- See Also:
getThreadGcInvocationCount()
-
resetAllCounts
@Deprecated public static void resetAllCounts()
Deprecated.Accurate counting is a burden on the runtime and may be removed.Clears all the global and thread-local memory allocation counters.- See Also:
startAllocCounting()
-
getRuntimeStat
public static String getRuntimeStat(String statName)
Returns the value of a particular runtime statistic ornullif no such runtime statistic exists.The following table lists the runtime statistics that the runtime supports. Note runtime statistics may be added or removed in a future API level.
Runtime statistic name Meaning Example Supported (API Levels) art.gc.gc-count The number of garbage collection runs. 16423 art.gc.gc-time The total duration of garbage collection runs in ms. 6236423 art.gc.bytes-allocated The total number of bytes that the application allocated. 146394840823 art.gc.bytes-freed The total number of bytes that garbage collection reclaimed. 131349308423 art.gc.blocking-gc-count The number of blocking garbage collection runs. 223 art.gc.blocking-gc-time The total duration of blocking garbage collection runs in ms. 80423 art.gc.gc-count-rate-histogram Every 10 seconds, the gc-count-rate is computed as the number of garbage collection runs that have occurred over the last 10 seconds. art.gc.gc-count-rate-histogram is a histogram of the gc-count-rate samples taken since the process began. The histogram can be used to identify instances of high rates of garbage collection runs. For example, a histogram of "0:34503,1:45350,2:11281,3:8088,4:43,5:8" shows that most of the time there are between 0 and 2 garbage collection runs every 10 seconds, but there were 8 distinct 10-second intervals in which 5 garbage collection runs occurred. 0:34503,1:45350,2:11281,3:8088,4:43,5:823 art.gc.blocking-gc-count-rate-histogram Every 10 seconds, the blocking-gc-count-rate is computed as the number of blocking garbage collection runs that have occurred over the last 10 seconds. art.gc.blocking-gc-count-rate-histogram is a histogram of the blocking-gc-count-rate samples taken since the process began. The histogram can be used to identify instances of high rates of blocking garbage collection runs. For example, a histogram of "0:99269,1:1,2:1" shows that most of the time there are zero blocking garbage collection runs every 10 seconds, but there was one 10-second interval in which one blocking garbage collection run occurred, and there was one interval in which two blocking garbage collection runs occurred. 0:99269,1:1,2:123 - Parameters:
statName- the name of the runtime statistic to look up.- Returns:
- the value of the specified runtime statistic or
nullif the runtime statistic doesn't exist.
-
getRuntimeStats
public static Map<String,String> getRuntimeStats()
Returns a map of the names/values of the runtime statistics thatgetRuntimeStat(String)supports.- Returns:
- a map of the names/values of the supported runtime statistics.
-
getNativeHeapSize
public static long getNativeHeapSize()
Returns the size of the native heap.- Returns:
- The size of the native heap in bytes.
-
getNativeHeapAllocatedSize
public static long getNativeHeapAllocatedSize()
Returns the amount of allocated memory in the native heap.- Returns:
- The allocated size in bytes.
-
getNativeHeapFreeSize
public static long getNativeHeapFreeSize()
Returns the amount of free memory in the native heap.- Returns:
- The freed size in bytes.
-
getMemoryInfo
public static void getMemoryInfo(Debug.MemoryInfo memoryInfo)
Retrieves information about this processes memory usages. This information is broken down by how much is in use by dalivk, the native heap, and everything else.
-
getMemoryInfo
public static void getMemoryInfo(int pid, Debug.MemoryInfo memoryInfo)Note: currently only works when the requested pid has the same UID as the caller.
-
getPss
public static long getPss()
Retrieves the PSS memory used by the process as given by the smaps.
-
getPss
public static long getPss(int pid, long[] outUss, long[] outMemtrack)Retrieves the PSS memory used by the process as given by the smaps. Optionally supply a long array of 1 entry to also receive the uss of the process, and another array to also retrieve the separate memtrack size. @hide
-
getMemInfo
public static void getMemInfo(long[] outSizes)
Retrieves /proc/meminfo. outSizes is filled with fields as defined by MEMINFO_* offsets.
-
setAllocationLimit
@Deprecated public static int setAllocationLimit(int limit)
Deprecated.This method is now obsolete.Establish an object allocation limit in the current thread. This feature was never enabled in release builds. The allocation limits feature was removed in Honeycomb. This method exists for compatibility and always returns -1 and has no effect.
-
setGlobalAllocationLimit
@Deprecated public static int setGlobalAllocationLimit(int limit)
Deprecated.This method is now obsolete.Establish a global object allocation limit. This feature was never enabled in release builds. The allocation limits feature was removed in Honeycomb. This method exists for compatibility and always returns -1 and has no effect.
-
printLoadedClasses
public static void printLoadedClasses(int flags)
Dump a list of all currently loaded class to the log file.- Parameters:
flags- See constants above.
-
getLoadedClassCount
public static int getLoadedClassCount()
Get the number of loaded classes.- Returns:
- the number of loaded classes.
-
dumpHprofData
public static void dumpHprofData(String fileName) throws IOException
Dump "hprof" data to the specified file. This may cause a GC.- Parameters:
fileName- Full pathname of output file (e.g. "/sdcard/dump.hprof").- Throws:
UnsupportedOperationException- if the VM was built without HPROF support.IOException- if an error occurs while opening or writing files.
-
dumpHprofData
public static void dumpHprofData(String fileName, FileDescriptor fd) throws IOException
Like dumpHprofData(String), but takes an already-opened FileDescriptor to which the trace is written. The file name is also supplied simply for logging. Makes a dup of the file descriptor. Primarily for use by the "am" shell command.- Throws:
IOException
-
dumpHprofDataDdms
public static void dumpHprofDataDdms()
Collect "hprof" and send it to DDMS. This may cause a GC.- Throws:
UnsupportedOperationException- if the VM was built without HPROF support.
-
dumpNativeHeap
public static void dumpNativeHeap(FileDescriptor fd)
Writes native heap data to the specified file descriptor.
-
countInstancesOfClass
public static long countInstancesOfClass(Class cls)
Returns a count of the extant instances of a class.
-
getBinderSentTransactions
public static int getBinderSentTransactions()
Returns the number of sent transactions from this process.- Returns:
- The number of sent transactions or -1 if it could not read t.
-
getBinderReceivedTransactions
public static int getBinderReceivedTransactions()
Returns the number of received transactions from the binder driver.- Returns:
- The number of received transactions or -1 if it could not read the stats.
-
getBinderLocalObjectCount
public static final int getBinderLocalObjectCount()
Returns the number of active local Binder objects that exist in the current process.
-
getBinderProxyObjectCount
public static final int getBinderProxyObjectCount()
Returns the number of references to remote proxy Binder objects that exist in the current process.
-
getBinderDeathObjectCount
public static final int getBinderDeathObjectCount()
Returns the number of death notification links to Binder objects that exist in the current process.
-
cacheRegisterMap
public static final boolean cacheRegisterMap(String classAndMethodDesc)
Primes the register map cache. Only works for classes in the bootstrap class loader. Does not cause classes to be loaded if they're not already present. The classAndMethodDesc argument is a concatentation of the VM-internal class descriptor, method name, and method descriptor. Examples: Landroid/os/Looper;.loop:()V Landroid/app/ActivityThread;.main:([Ljava/lang/String;)V- Parameters:
classAndMethodDesc- the method to prepare
-
dumpReferenceTables
public static final void dumpReferenceTables()
Dumps the contents of VM reference tables (e.g. JNI locals and globals) to the log file.
-
setFieldsOn
public static void setFieldsOn(Class<?> cl)
Equivalent tosetFieldsOn(cl, false).- See Also:
setFieldsOn(Class, boolean)
-
setFieldsOn
public static void setFieldsOn(Class<?> cl, boolean partial)
Reflectively sets static fields of a class based on internal debugging properties. This method is a no-op if false is false.NOTE TO APPLICATION DEVELOPERS: false will always be false in release builds. This API is typically only useful for platform developers.
Class setup: define a class whose only fields are non-final, static primitive types (except for "char") or Strings. In a static block after the field definitions/initializations, pass the class to this method, Debug.setFieldsOn(). Example:package com.example; import android.os.Debug; public class MyDebugVars { public static String s = "a string"; public static String s2 = "second string"; public static String ns = null; public static boolean b = false; public static int i = 5;- Parameters:
cl- The class to (possibly) modifypartial- If false, sets all static fields, otherwise, only set fields with theDebug.DebugPropertyannotation- Throws:
IllegalArgumentException- if any fields are final or non-static, or if the type of the field does not match the type of the internal debugging property value.
-
dumpService
public static boolean dumpService(String name, FileDescriptor fd, String[] args)
Get a debugging dump of a system service by name.Most services require the caller to hold android.permission.DUMP.
- Parameters:
name- of the service to dumpfd- to write dump output to (usually an output log file)args- to pass to the service's dump method, may be null- Returns:
- true if the service was dumped successfully, false if the service could not be found or had an error while dumping
-
dumpNativeBacktraceToFile
public static void dumpNativeBacktraceToFile(int pid, String file)Have the stack traces of the given native process dumped to the specified file. Will be appended to the file.
-
getCallers
public static String getCallers(int depth)
Return a string consisting of methods and locations at multiple call stack levels.- Parameters:
depth- the number of levels to return, starting with the immediate caller.- Returns:
- a string describing the call stack.
-
getCallers
public static String getCallers(int start, int depth)
Return a string consisting of methods and locations at multiple call stack levels.- Parameters:
depth- the number of levels to return, starting with the immediate caller.- Returns:
- a string describing the call stack.
-
getCallers
public static String getCallers(int depth, String linePrefix)
LikegetCallers(int), but each location is append to the string as a new line with linePrefix in front of it.- Parameters:
depth- the number of levels to return, starting with the immediate caller.linePrefix- prefix to put in front of each location.- Returns:
- a string describing the call stack.
-
getCaller
public static String getCaller()
- Returns:
- a String describing the immediate caller of the calling method.
-
-