java.lang.Object android.os.Debug
public final class Debug
Provides various debugging functions 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().
嵌套类摘要 | |
---|---|
static class |
Debug.InstructionCount API for gathering and querying instruction counts. |
static class |
Debug.MemoryInfo This class is used to retrieved various statistics about the memory mappings for this process. |
字段摘要 | |
---|---|
static int |
SHOW_CLASSLOADER |
static int |
SHOW_FULL_DETAIL Flags for printLoadedClasses(). |
static int |
SHOW_INITIALIZED |
static int |
TRACE_COUNT_ALLOCS Flags for startMethodTracing(). |
方法摘要 | |
---|---|
static void |
changeDebugPort(int port) 已过时。 no longer needed or useful |
static void |
dumpHprofData(String fileName) Dump "hprof" data to the specified file. |
static void |
enableEmulatorTraceOutput() Enable "emulator traces", in which information about the current method is made available to the "emulator -trace" feature. |
static int |
getBinderDeathObjectCount() Returns the number of death notification links to Binder objects that exist in the current process. |
static int |
getBinderLocalObjectCount() Returns the number of active local Binder objects that exist in the current process. |
static int |
getBinderProxyObjectCount() Returns the number of references to remote proxy Binder objects that exist in the current process. |
static int |
getBinderReceivedTransactions() Returns the number of received transactions from the binder driver. |
static int |
getBinderSentTransactions() Returns the number of sent transactions from this process. |
static int |
getGlobalAllocCount() |
static int |
getGlobalAllocSize() |
static int |
getGlobalExternalAllocCount() |
static int |
getGlobalExternalAllocSize() |
static int |
getGlobalExternalFreedCount() |
static int |
getGlobalExternalFreedSize() |
static int |
getGlobalFreedCount() |
static int |
getGlobalFreedSize() |
static int |
getGlobalGcInvocationCount() |
static int |
getLoadedClassCount() Get the number of loaded classes. |
static void |
getMemoryInfo(Debug.MemoryInfo memoryInfo) Retrieves information about this processes memory usages. |
static long |
getNativeHeapAllocatedSize() Returns the amount of allocated memory in the native heap. |
static long |
getNativeHeapFreeSize() Returns the amount of free memory in the native heap. |
static long |
getNativeHeapSize() Returns the size of the native heap. |
static int |
getThreadAllocCount() |
static int |
getThreadAllocSize() |
static int |
getThreadExternalAllocCount() |
static int |
getThreadExternalAllocSize() |
static int |
getThreadGcInvocationCount() |
static boolean |
isDebuggerConnected() Determine if a debugger is currently attached. |
static void |
printLoadedClasses(int flags) Dump a list of all currently loaded class to the log file. |
static void |
resetAllCounts() |
static void |
resetGlobalAllocCount() |
static void |
resetGlobalAllocSize() |
static void |
resetGlobalExternalAllocCount() |
static void |
resetGlobalExternalAllocSize() |
static void |
resetGlobalExternalFreedCount() |
static void |
resetGlobalExternalFreedSize() |
static void |
resetGlobalFreedCount() |
static void |
resetGlobalFreedSize() |
static void |
resetGlobalGcInvocationCount() |
static void |
resetThreadAllocCount() |
static void |
resetThreadAllocSize() |
static void |
resetThreadExternalAllocCount() |
static void |
resetThreadExternalAllocSize() |
static void |
resetThreadGcInvocationCount() |
static int |
setAllocationLimit(int limit) Establish an object allocation limit in the current thread. |
static int |
setGlobalAllocationLimit(int limit) Establish a global object allocation limit. |
static void |
startAllocCounting() Count the number and aggregate size of memory allocations between two points. |
static void |
startMethodTracing() Start method tracing with default log name and buffer size. |
static void |
startMethodTracing(String traceName) Start method tracing, specifying the trace log file name. |
static void |
startMethodTracing(String traceName, int bufferSize) Start method tracing, specifying the trace log file name and the buffer size. |
static void |
startMethodTracing(String traceName, int bufferSize, int flags) Start method tracing, specifying the trace log file name and the buffer size. |
static void |
startNativeTracing() Enable qemu tracing. |
static void |
stopAllocCounting() |
static void |
stopMethodTracing() Stop method tracing. |
static void |
stopNativeTracing() Stop qemu tracing. |
static long |
threadCpuTimeNanos() Get an indication of thread CPU usage. |
static void |
waitForDebugger() Wait until a debugger attaches. |
static boolean |
waitingForDebugger() Returns "true" if one or more threads is waiting for a debugger to attach. |
从类 java.lang.Object 继承的方法 |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
字段详细信息 |
---|
public static final int TRACE_COUNT_ALLOCS
public static final int SHOW_FULL_DETAIL
public static final int SHOW_CLASSLOADER
public static final int SHOW_INITIALIZED
方法详细信息 |
---|
public static void waitForDebugger()
public static boolean waitingForDebugger()
public static boolean isDebuggerConnected()
@Deprecated
public static void changeDebugPort(int port)
public static void startNativeTracing()
emulator -trace foo
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.
public static void stopNativeTracing()
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.
public static void enableEmulatorTraceOutput()
public static void startMethodTracing()
public static void startMethodTracing(String traceName)
traceName
- Name for the trace log file to create. If no name argument is given, 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.
public static void startMethodTracing(String traceName, int bufferSize)
traceName
- Name for the trace log file to create. If no name argument is given, 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.
public static void startMethodTracing(String traceName, int bufferSize, int flags)
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 "native" tracing in the emulator via startNativeTracing().
traceName
- Name for the trace log file to create. If no name argument is given, 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.
public static void stopMethodTracing()
public static long threadCpuTimeNanos()
public static void startAllocCounting()
public static void stopAllocCounting()
public static int getGlobalAllocCount()
public static int getGlobalAllocSize()
public static int getGlobalFreedCount()
public static int getGlobalFreedSize()
public static int getGlobalExternalAllocCount()
public static int getGlobalExternalAllocSize()
public static int getGlobalExternalFreedCount()
public static int getGlobalExternalFreedSize()
public static int getGlobalGcInvocationCount()
public static int getThreadAllocCount()
public static int getThreadAllocSize()
public static int getThreadExternalAllocCount()
public static int getThreadExternalAllocSize()
public static int getThreadGcInvocationCount()
public static void resetGlobalAllocCount()
public static void resetGlobalAllocSize()
public static void resetGlobalFreedCount()
public static void resetGlobalFreedSize()
public static void resetGlobalExternalAllocCount()
public static void resetGlobalExternalAllocSize()
public static void resetGlobalExternalFreedCount()
public static void resetGlobalExternalFreedSize()
public static void resetGlobalGcInvocationCount()
public static void resetThreadAllocCount()
public static void resetThreadAllocSize()
public static void resetThreadExternalAllocCount()
public static void resetThreadExternalAllocSize()
public static void resetThreadGcInvocationCount()
public static void resetAllCounts()
public static long getNativeHeapSize()
public static long getNativeHeapAllocatedSize()
public static long getNativeHeapFreeSize()
public static void getMemoryInfo(Debug.MemoryInfo memoryInfo)
public static int setAllocationLimit(int limit)
public static int setGlobalAllocationLimit(int limit)
public static void printLoadedClasses(int flags)
flags
- See constants above.
public static int getLoadedClassCount()
public static void dumpHprofData(String fileName) throws IOException
fileName
- Full pathname of output file (e.g. "/sdcard/dump.hprof").
UnsupportedOperationException
- if the VM was built without HPROF support.
IOException
- if an error occurs while opening or writing files.
public static int getBinderSentTransactions()
public static int getBinderReceivedTransactions()
public static final int getBinderLocalObjectCount()
public static final int getBinderProxyObjectCount()
public static final int getBinderDeathObjectCount()Returns the number of death notification links to Binder objects thatexist in the current process.