public final class Debug extends Object
This interface enables the debug mode for applications to obtain information such as the memory use and CPU time.
Example code for starting the trace of a specified service flow by using the default trace flags:
long start = Debug.getCpuTime();
......
int pss = Debug.getProcessPssSum();
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
Debug.HeapInfo |
Provides the static native heap memory used by the current process of your application.
|
static class |
Debug.IpcType |
Enumerates IPC object types.
|
static class |
Debug.MemType |
Enumerates memory types.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
SHOW_CLASSLOADER |
Indicates the flag for
dumpLoadClasses(int) with information about classLoader included. |
static int |
SHOW_FULL_DETAIL |
Indicates the flag for
dumpLoadClasses(int) with details of loaded classes included. |
static int |
SHOW_INITIALIZED |
Indicates the flag for
dumpLoadClasses(int) with information about initialization statues included. |
static int |
TRACE_COUNT_ALLOCS |
Indicates the flag for starting the tracing of method logs.
|
| 构造器 | 说明 |
|---|---|
Debug() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static void |
attachAgent(String library,
String options,
ClassLoader classLoader) |
Attaches a library as the Java Virtual Machine Tool Interface (JVMTI) agent to the current runtime
based on the given
classLoader. |
static void |
connectToDebugger() |
Connects this process to the debugger for entering the debug mode.
|
static void |
dumpHeapFile(String fileName) |
Dumps a heap file into the specified file.
|
static void |
dumpLoadClasses(int flags) |
Dumps a list of classes with a specific flag that are loaded by this process into a log file.
|
static void |
emulatorTraceBegin() |
Starts tracing emulator logs.
|
static void |
emulatorTraceEnable() |
Enables log tracing for the emulator.
|
static void |
emulatorTraceEnd() |
Stops tracing emulator logs.
|
static void |
functionTraceBegin() |
Starts tracing function logs based on the default log file name (dmtrace.trace) and buffer size.
|
static void |
functionTraceBegin(String traceName) |
Starts tracing function logs based on the specified log file name and the default buffer size (8 MB).
|
static void |
functionTraceBegin(String traceName,
int bufferSize) |
Starts tracing function logs based on the specified log file name and buffer size.
|
static void |
functionTraceBegin(String traceName,
int bufferSize,
int flags) |
Starts tracing function logs based on the specified log name, buffer size, and flag.
|
static void |
functionTraceEnd() |
Stops tracing function logs.
|
static void |
functionTraceSamplingBegin(String traceName,
int bufferSize,
int intervalUs) |
Starts tracing function logs in sampling mode based on the specified log file name, buffer size,
and sampling interval.
|
static int |
getCountofLoadClasses() |
Obtains the number of classes loaded by this process.
|
static long |
getCpuTime() |
Obtains the amount of time that the current process has occupied CPU.
|
static boolean |
getDebuggerConnectStatus() |
Obtains whether this process has been connected to the debugger.
|
static int |
getIpcCount(Debug.IpcType ipcType) |
Obtains the number of IPC objects of the specified IPC type for this process.
|
static int |
getIpcReceivedCount() |
Obtains the number of IPC objects received by this process.
|
static int |
getIpcSentCount() |
Obtains the number of IPC objects sent by this process.
|
static String |
getMemoryStatistic(String statisticName) |
Obtains statistics about the memory of a specified name.
|
static Map<String,String> |
getMemoryStatistics() |
Obtains the statistics about all memory used by this process.
|
static void |
getNativeHeapInfo(Debug.HeapInfo heapInfo) |
Obtains statistics about the memory used by processes in the native heap.
|
static int |
getProcessPrivateClean(Debug.MemType memType) |
Obtains the size of private clean pages of the specified memory type for this process.
|
static int |
getProcessPrivateCleanSum() |
Obtains the total size of private clean pages for this process.
|
static int |
getProcessPrivateDirty(Debug.MemType memType) |
Obtains the information about private dirty pages used by this process.
|
static int |
getProcessPrivateDirtySum() |
Obtains the total amount of private dirty pages used by the current process.
|
static int |
getProcessPss(Debug.MemType memType) |
Obtains the proportional set size (PSS) memory used by the current process.
|
static int |
getProcessPssSum() |
Obtains the total amount of proportional set size (PSS) memory in use.
|
static int |
getProcessRss(Debug.MemType memType) |
Obtains the resident set size (RSS) of the specified memory type for this process.
|
static int |
getProcessRssSum() |
Obtains the total RSS for this process.
|
static int |
getProcessSharedClean(Debug.MemType memType) |
Obtains the size of shared clean pages of the specified memory type for this process.
|
static int |
getProcessSharedCleanSum() |
Obtains the total size of shard clean pages for this process.
|
static int |
getProcessSharedDirty(Debug.MemType memType) |
Obtains the size of shared dirty pages of the specified memory type for this process.
|
static int |
getProcessSharedDirtySum() |
Obtains the total size of shared dirty pages for this process.
|
static int |
getProcessSwappablePss(Debug.MemType memType) |
Obtains the swappable proportional set size (PSS) of the specified memory type for this process.
|
static int |
getProcessSwappablePssSum() |
Obtains the total swappable PSS for this process.
|
static int |
getProcessSwappedOut(Debug.MemType memType) |
Obtains the size of swapped-out dirty pages of the specified memory type for this process.
|
static int |
getProcessSwappedOutPss(Debug.MemType memType) |
Obtains the size of swapped-out PSS of the specified memory type for this process.
|
static int |
getProcessSwappedOutPssSum() |
Obtains the total size of swapped-out PSS for this process.
|
static int |
getProcessSwappedOutSum() |
Obtains the total size of swapped-out dirty pages for this process.
|
static String |
getRuntimeStatistic(String statisticName) |
Obtains the statistical information about the runtime of a specified name.
|
static Map<String,String> |
getRuntimeStatistics() |
Obtains the statistical information about all runtime used by this process.
|
static boolean |
isConnectingToDebugger() |
Checks whether multiple processes are waiting to connect to the debugger.
|
public static final int SHOW_CLASSLOADER
dumpLoadClasses(int) with information about classLoader included.
Value: 0010
When this flag is set, the list of loaded classes you obtained contains only classLoader information.
public static final int SHOW_FULL_DETAIL
dumpLoadClasses(int) with details of loaded classes included.
Value: 0001
When this flag is set, the list of loaded classes you obtained contains all information
about loaded classes: class names, classLoader, and class initialization statuses.
public static final int SHOW_INITIALIZED
dumpLoadClasses(int) with information about initialization statues included.
Value: 0100
When this flag is set, the list of loaded classes you obtained contains only initialization statues.
public static final int TRACE_COUNT_ALLOCS
Value: 0x0001
When this flag is set, the memory allocations count is added to the trace file.
public static int getProcessPss(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessPrivateDirtySum()
public static int getProcessPssSum()
public static void getNativeHeapInfo(Debug.HeapInfo heapInfo)
heapInfo - Indicates the statistics about the memory in the native heap, including the amount of total,
allocated, and free memory.public static long getCpuTime()
public static int getProcessSwappablePss(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSwappablePssSum()
public static int getProcessRss(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessRssSum()
public static int getProcessPrivateDirty(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSharedDirty(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSharedDirtySum()
public static int getProcessPrivateClean(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessPrivateCleanSum()
public static int getProcessSharedClean(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSharedCleanSum()
public static int getProcessSwappedOut(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSwappedOutSum()
public static int getProcessSwappedOutPss(Debug.MemType memType)
memType - Indicates the memory type, which is enumerated in MemType.public static int getProcessSwappedOutPssSum()
public static int getIpcCount(Debug.IpcType ipcType)
ipcType - Indicates the IPC type, as enumerated in IpcType.public static int getIpcSentCount()
-1 if the operation fails.public static int getIpcReceivedCount()
-1 if the operation fails.public static String getMemoryStatistic(String statisticName)
statisticName - Indicates the name of the memory. The following memory names are supported:
summary.java-heap
summary.native-heap
summary.code
summary.graphics
summary.private-other
summary.system
summary.total-pss
summary.total-swap
null if no memory is obtained.public static Map<String,String> getMemoryStatistics()
getMemoryStatistic(java.lang.String).public static void functionTraceBegin()
public static void functionTraceBegin(String traceName)
traceName - Indicates the log file name. If this parameter is null,
the default file name dmtrace.trace will be used.public static void functionTraceBegin(String traceName, int bufferSize)
traceName - Indicates the log file name. If this parameter is null,
the default file name dmtrace.trace will be used.bufferSize - Indicates the buffer size in KB.public static void functionTraceBegin(String traceName, int bufferSize, int flags)
traceName - Indicates the log file name. If this parameter is null,
the default file name dmtrace.trace will be used.bufferSize - Indicates the buffer size in KB.flags - Indicates the trace flag. Currently, only TRACE_COUNT_ALLOCS is supported.public static void functionTraceSamplingBegin(String traceName, int bufferSize, int intervalUs)
traceName - Indicates the log file name. If this parameter is null,
the default file name dmtrace.trace will be used.bufferSize - Indicates the buffer size in KB.intervalUs - Indicates the sampling interval, in microseconds.public static void functionTraceEnd()
public static void dumpHeapFile(String fileName) throws IOException
fileName - Indicates the file name, including the file path, for example, /sdcard/dump.hprof.IOException - if the heap file cannot be dumped.public static String getRuntimeStatistic(String statisticName)
statisticName - Indicates the name of the runtime. The following runtime names are supported.
gc.gc-count
gc.gc-time
gc.bytes-allocated
gc.bytes-freed
gc.blocking-gc-count
gc.blocking-gc-time
gc.gc-count-rate-histogram
gc.blocking-gc-count-rate-histogram
null if the statistics cannot be obtained.public static Map<String,String> getRuntimeStatistics()
getRuntimeStatistic(java.lang.String).public static void connectToDebugger()
public static boolean getDebuggerConnectStatus()
true if this process has been connected to the debugger; returns false otherwise.public static boolean isConnectingToDebugger()
true if multiple processes are waiting to connect to the debugger;
returns false otherwise.public static int getCountofLoadClasses()
public static void dumpLoadClasses(int flags)
flags - Indicates the flag of the loaded classes. The flag can be SHOW_FULL_DETAIL,
SHOW_CLASSLOADER, or SHOW_INITIALIZED.public static void emulatorTraceBegin()
public static void emulatorTraceEnd()
public static void emulatorTraceEnable()
emulatorTraceBegin().public static void attachAgent(String library, String options, ClassLoader classLoader) throws IOException
classLoader.library - Indicates the path of the library to be attached.options - Indicates the options to be passed to the agent.classLoader - Indicates the class loader, which determines the library search path.IOException - Throws this exception if the agent cannot be connected.