public
final
class
Debug
extends Object
java.lang.Object | |
↳ | android.os.Debug |
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 classes | |||
---|---|---|---|
class |
Debug.InstructionCount
This class was deprecated in API level 23. Instruction counting is no longer supported. |
||
class |
Debug.MemoryInfo
This class is used to retrieved various statistics about the memory mappings for this process. |
Constants | |
---|---|
int |
SHOW_CLASSLOADER
|
int |
SHOW_FULL_DETAIL
Flags for printLoadedClasses(). |
int |
SHOW_INITIALIZED
|
int |
TRACE_COUNT_ALLOCS
This constant was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
Public methods | |
---|---|
static
void
|
changeDebugPort(int port)
This method was deprecated in API level 3. no longer needed or useful |
static
void
|
dumpHprofData(String fileName)
Dump "hprof" data to the specified file. |
static
boolean
|
dumpService(String name, FileDescriptor fd, String[] args)
Get a debugging dump of a system service by name. |
static
void
|
enableEmulatorTraceOutput()
Enable "emulator traces", in which information about the current method is made available to the "emulator -trace" feature. |
static
final
int
|
getBinderDeathObjectCount()
Returns the number of death notification links to Binder objects that exist in the current process. |
static
final
int
|
getBinderLocalObjectCount()
Returns the number of active local Binder objects that exist in the current process. |
static
final
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()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalAllocSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalClassInitCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalClassInitTime()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalExternalAllocCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getGlobalExternalAllocSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getGlobalExternalFreedCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getGlobalExternalFreedSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getGlobalFreedCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalFreedSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getGlobalGcInvocationCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
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
long
|
getPss()
Retrieves the PSS memory used by the process as given by the smaps. |
static
String
|
getRuntimeStat(String statName)
Returns the value of a particular runtime statistic or |
static
Map<String, String>
|
getRuntimeStats()
Returns a map of the names/values of the runtime statistics
that |
static
int
|
getThreadAllocCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getThreadAllocSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
getThreadExternalAllocCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getThreadExternalAllocSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
getThreadGcInvocationCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
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()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalAllocCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalAllocSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalClassInitCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalClassInitTime()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalExternalAllocCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetGlobalExternalAllocSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetGlobalExternalFreedCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetGlobalExternalFreedSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetGlobalFreedCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalFreedSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetGlobalGcInvocationCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetThreadAllocCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetThreadAllocSize()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
resetThreadExternalAllocCount()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetThreadExternalAllocSize()
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
resetThreadGcInvocationCount()
This method was deprecated in API level 23. Accurate counting is a burden on the runtime and may be removed. |
static
int
|
setAllocationLimit(int limit)
This method was deprecated in API level 11. This method is now obsolete. |
static
int
|
setGlobalAllocationLimit(int limit)
This method was deprecated in API level 11. This method is now obsolete. |
static
void
|
startAllocCounting()
This method was deprecated in API level 18. Accurate counting is a burden on the runtime and may be removed. |
static
void
|
startMethodTracing()
Start method tracing with default log name and buffer size. |
static
void
|
startMethodTracing(String tracePath, int bufferSize, int flags)
Start method tracing, specifying the trace log file name, the buffer size, and flags. |
static
void
|
startMethodTracing(String tracePath)
Start method tracing, specifying the trace log file path. |
static
void
|
startMethodTracing(String tracePath, int bufferSize)
Start method tracing, specifying the trace log file name and the buffer size. |
static
void
|
startMethodTracingSampling(String tracePath, int bufferSize, int intervalUs)
Start sampling-based method tracing, specifying the trace log file name, the buffer size, and the sampling interval. |
static
void
|
startNativeTracing()
Enable qemu tracing. |
static
void
|
stopAllocCounting()
This method was deprecated in API level 18. Accurate counting is a burden on the runtime and may be removed. |
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. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
int SHOW_FULL_DETAIL
Flags for printLoadedClasses(). Default behavior is to only show the class name.
Constant Value: 1 (0x00000001)
int TRACE_COUNT_ALLOCS
This constant was deprecated
in API level 23.
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.
Constant Value: 1 (0x00000001)
void changeDebugPort (int port)
This method was deprecated
in API level 3.
no longer needed or useful
Change the JDWP port.
Parameters | |
---|---|
port |
int
|
void dumpHprofData (String fileName)
Dump "hprof" data to the specified file. This may cause a GC.
Parameters | |
---|---|
fileName |
String :
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. |
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 |
String :
of the service to dump |
fd |
FileDescriptor :
to write dump output to (usually an output log file) |
args |
String :
to pass to the service's dump method, may be null |
Returns | |
---|---|
boolean |
true if the service was dumped successfully, false if the service could not be found or had an error while dumping |
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, use startNativeTracing()
.
int getBinderDeathObjectCount ()
Returns the number of death notification links to Binder objects that exist in the current process.
Returns | |
---|---|
int |
int getBinderLocalObjectCount ()
Returns the number of active local Binder objects that exist in the current process.
Returns | |
---|---|
int |
int getBinderProxyObjectCount ()
Returns the number of references to remote proxy Binder objects that exist in the current process.
Returns | |
---|---|
int |
int getBinderReceivedTransactions ()
Returns the number of received transactions from the binder driver.
Returns | |
---|---|
int |
The number of received transactions or -1 if it could not read the stats. |
int getBinderSentTransactions ()
Returns the number of sent transactions from this process.
Returns | |
---|---|
int |
The number of sent transactions or -1 if it could not read t. |
int getGlobalAllocCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the global count of objects allocated by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
int getGlobalAllocSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the global size, in bytes, of objects allocated by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
int getGlobalClassInitCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the number of classes successfully initialized (ie those that executed without
throwing an exception) between a start
and
stop
.
Returns | |
---|---|
int |
int getGlobalClassInitTime ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the time spent successfully initializing classes between a
start
and stop
.
Returns | |
---|---|
int |
int getGlobalExternalAllocCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and always returns 0.
Returns | |
---|---|
int |
int getGlobalExternalAllocSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and always returns 0.
Returns | |
---|---|
int |
int getGlobalExternalFreedCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and always returns 0.
Returns | |
---|---|
int |
int getGlobalExternalFreedSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
Returns | |
---|---|
int |
int getGlobalFreedCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the global count of objects freed by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
int getGlobalFreedSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the global size, in bytes, of objects freed by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
int getGlobalGcInvocationCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the number of non-concurrent GC invocations between a
start
and stop
.
Returns | |
---|---|
int |
int getLoadedClassCount ()
Get the number of loaded classes.
Returns | |
---|---|
int |
the number of loaded classes. |
void getMemoryInfo (Debug.MemoryInfo memoryInfo)
Retrieves information about this processes memory usages. This information is broken down by how much is in use by dalvik, the native heap, and everything else.
Note: this method directly retrieves memory information for the give process
from low-level data available to it. It may not be able to retrieve information about
some protected allocations, such as graphics. If you want to be sure you can see
all information about allocations by the process, use instead
getProcessMemoryInfo(int[])
.
Parameters | |
---|---|
memoryInfo |
Debug.MemoryInfo
|
long getNativeHeapAllocatedSize ()
Returns the amount of allocated memory in the native heap.
Returns | |
---|---|
long |
The allocated size in bytes. |
long getNativeHeapFreeSize ()
Returns the amount of free memory in the native heap.
Returns | |
---|---|
long |
The freed size in bytes. |
long getNativeHeapSize ()
Returns the size of the native heap.
Returns | |
---|---|
long |
The size of the native heap in bytes. |
long getPss ()
Retrieves the PSS memory used by the process as given by the smaps.
Returns | |
---|---|
long |
String getRuntimeStat (String statName)
Returns the value of a particular runtime statistic or null
if 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. | 164 |
23 |
art.gc.gc-time | The total duration of garbage collection runs in ms. | 62364 |
23 |
art.gc.bytes-allocated | The total number of bytes that the application allocated. | 1463948408 |
23 |
art.gc.bytes-freed | The total number of bytes that garbage collection reclaimed. | 1313493084 |
23 |
art.gc.blocking-gc-count | The number of blocking garbage collection runs. | 2 |
23 |
art.gc.blocking-gc-time | The total duration of blocking garbage collection runs in ms. | 804 |
23 |
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:8 |
23 |
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:1 |
23 |
Parameters | |
---|---|
statName |
String :
the name of the runtime statistic to look up. |
Returns | |
---|---|
String |
the value of the specified runtime statistic or null if the
runtime statistic doesn't exist.
|
Map<String, String> getRuntimeStats ()
Returns a map of the names/values of the runtime statistics
that getRuntimeStat(String)
supports.
Returns | |
---|---|
Map<String, String> |
a map of the names/values of the supported runtime statistics. |
int getThreadAllocCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the thread-local count of objects allocated by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
int getThreadAllocSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the thread-local size of objects allocated by the runtime between a
start
and stop
.
Returns | |
---|---|
int |
The allocated size in bytes. |
int getThreadExternalAllocCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
Returns | |
---|---|
int |
int getThreadExternalAllocSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
Returns | |
---|---|
int |
int getThreadGcInvocationCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Returns the number of thread-local non-concurrent GC invocations between a
start
and stop
.
Returns | |
---|---|
int |
boolean isDebuggerConnected ()
Determine if a debugger is currently attached.
Returns | |
---|---|
boolean |
void printLoadedClasses (int flags)
Dump a list of all currently loaded class to the log file.
Parameters | |
---|---|
flags |
int :
See constants above.
|
void resetAllCounts ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears all the global and thread-local memory allocation counters.
See also:
void resetGlobalAllocCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the global count of objects allocated.
See also:
void resetGlobalAllocSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the global size of objects allocated.
See also:
void resetGlobalClassInitCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the count of classes initialized.
See also:
void resetGlobalClassInitTime ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the count of time spent initializing classes.
See also:
void resetGlobalExternalAllocCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetGlobalExternalAllocSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetGlobalExternalFreedCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetGlobalExternalFreedSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetGlobalFreedCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the global count of objects freed.
See also:
void resetGlobalFreedSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the global size of objects freed.
See also:
void resetGlobalGcInvocationCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the count of non-concurrent GC invocations.
See also:
void resetThreadAllocCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the thread-local count of objects allocated.
See also:
void resetThreadAllocSize ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the thread-local count of objects allocated.
See also:
void resetThreadExternalAllocCount ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetThreadExternalAllocSize ()
This method was deprecated
in API level 11.
This method is now obsolete.
This method exists for compatibility and has no effect.
void resetThreadGcInvocationCount ()
This method was deprecated
in API level 23.
Accurate counting is a burden on the runtime and may be removed.
Clears the thread-local count of non-concurrent GC invocations.
See also:
int setAllocationLimit (int limit)
This method was deprecated
in API level 11.
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.
Parameters | |
---|---|
limit |
int
|
Returns | |
---|---|
int |
int setGlobalAllocationLimit (int limit)
This method was deprecated
in API level 11.
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.
Parameters | |
---|---|
limit |
int
|
Returns | |
---|---|
int |
void startAllocCounting ()
This method was deprecated
in API level 18.
Accurate counting is a burden on the runtime and may be removed.
Start counting the number and aggregate size of memory allocations.
The start
method resets the counts and enables counting.
The stop
method disables the counting so that the analysis
code doesn't cause additional allocations. The various get
methods return
the specified value. And the various reset
methods 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.
void startMethodTracing ()
Start method tracing with default log name and buffer size.
By default, the trace file is called "dmtrace.trace" and it's placed
under your package-specific directory on primary shared/external storage,
as returned by getExternalFilesDir(String)
.
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 via startNativeTracing()
.
void startMethodTracing (String tracePath, int bufferSize, int flags)
Start method tracing, specifying the trace log file name, the buffer size, and flags.
When a relative file path is given, the trace file will be placed under
your package-specific directory on primary shared/external storage, as
returned by getExternalFilesDir(String)
.
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 via startNativeTracing()
.
Parameters | |
---|---|
tracePath |
String :
Path to the trace log file to create. If null ,
this will default to "dmtrace.trace". If the file already
exists, it will be truncated. If the path given does not end
in ".trace", it will be appended for you. |
bufferSize |
int :
The maximum amount of trace data we gather. If not
given, it defaults to 8MB. |
flags |
int :
Flags to control method tracing. The only one that is
currently defined is TRACE_COUNT_ALLOCS .
|
void startMethodTracing (String tracePath)
Start method tracing, specifying the trace log file path.
When a relative file path is given, the trace file will be placed under
your package-specific directory on primary shared/external storage, as
returned by getExternalFilesDir(String)
.
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 via startNativeTracing()
.
Parameters | |
---|---|
tracePath |
String :
Path to the trace log file to create. If null ,
this will default to "dmtrace.trace". If the file already
exists, it will be truncated. If the path given does not end
in ".trace", it will be appended for you.
|
void startMethodTracing (String tracePath, int bufferSize)
Start method tracing, specifying the trace log file name and the buffer size.
When a relative file path is given, the trace file will be placed under
your package-specific directory on primary shared/external storage, as
returned by getExternalFilesDir(String)
.
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 via startNativeTracing()
.
Parameters | |
---|---|
tracePath |
String :
Path to the trace log file to create. If null ,
this will default to "dmtrace.trace". If the file already
exists, it will be truncated. If the path given does not end
in ".trace", it will be appended for you. |
bufferSize |
int :
The maximum amount of trace data we gather. If not
given, it defaults to 8MB.
|
void startMethodTracingSampling (String tracePath, int bufferSize, int intervalUs)
Start sampling-based method tracing, specifying the trace log file name, the buffer size, and the sampling interval.
When a relative file path is given, the trace file will be placed under
your package-specific directory on primary shared/external storage, as
returned by getExternalFilesDir(String)
.
See Traceview: A Graphical Log Viewer for information about reading trace files.
Parameters | |
---|---|
tracePath |
String :
Path to the trace log file to create. If null ,
this will default to "dmtrace.trace". If the file already
exists, it will be truncated. If the path given does not end
in ".trace", it will be appended for you. |
bufferSize |
int :
The maximum amount of trace data we gather. If not
given, it defaults to 8MB. |
intervalUs |
int :
The amount of time between each sample in microseconds.
|
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.
void stopAllocCounting ()
This method was deprecated
in API level 18.
Accurate counting is a burden on the runtime and may be removed.
Stop counting the number and aggregate size of memory allocations.
void stopNativeTracing ()
Stop qemu tracing. See startNativeTracing()
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.
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.
Returns | |
---|---|
long |
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.
boolean waitingForDebugger ()
Returns "true" if one or more threads is waiting for a debugger to attach.
Returns | |
---|---|
boolean |