Methods Summary |
---|
public static void | changeDebugPort(int port)Change the JDWP port.
|
public static void | dumpHprofData(java.lang.String fileName)Dump "hprof" data to the specified file. This will cause a GC.
VMDebug.dumpHprofData(fileName);
|
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, use {@link #startNativeTracing()}.
VMDebug.startEmulatorTracing();
|
public static final native int | getBinderDeathObjectCount()Returns the number of death notification links to Binder objects that
exist in the current process.
|
public static final native int | getBinderLocalObjectCount()Returns the number of active local Binder objects that exist in the
current process.
|
public static final native int | getBinderProxyObjectCount()Returns the number of references to remote proxy Binder objects that
exist in the current process.
|
public static native int | getBinderReceivedTransactions()Returns the number of received transactions from the binder driver.
|
public static native int | getBinderSentTransactions()Returns the number of sent transactions from this process.
|
public static int | getGlobalAllocCount()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS);
|
public static int | getGlobalAllocSize()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES);
|
public static int | getGlobalExternalAllocCount()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_EXT_ALLOCATED_OBJECTS);
|
public static int | getGlobalExternalAllocSize()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_EXT_ALLOCATED_BYTES);
|
public static int | getGlobalExternalFreedCount()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_EXT_FREED_OBJECTS);
|
public static int | getGlobalExternalFreedSize()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_EXT_FREED_BYTES);
|
public static int | getGlobalFreedCount()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS);
|
public static int | getGlobalFreedSize()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES);
|
public static int | getGlobalGcInvocationCount()
return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS);
|
public static int | getLoadedClassCount()Get the number of loaded classes.
return VMDebug.getLoadedClassCount();
|
public static native void | getMemoryInfo(android.os.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.
|
public static native long | getNativeHeapAllocatedSize()Returns the amount of allocated memory in the native heap.
|
public static native long | getNativeHeapFreeSize()Returns the amount of free memory in the native heap.
|
public static native long | getNativeHeapSize()Returns the size of the native heap.
|
public static int | getThreadAllocCount()
return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS);
|
public static int | getThreadAllocSize()
return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES);
|
public static int | getThreadExternalAllocCount()
return VMDebug.getAllocCount(VMDebug.KIND_THREAD_EXT_ALLOCATED_OBJECTS);
|
public static int | getThreadExternalAllocSize()
return VMDebug.getAllocCount(VMDebug.KIND_THREAD_EXT_ALLOCATED_BYTES);
|
public static int | getThreadGcInvocationCount()
return VMDebug.getAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS);
|
public static boolean | isDebuggerConnected()Determine if a debugger is currently attached.
return VMDebug.isDebuggerConnected();
|
public static void | printLoadedClasses(int flags)Dump a list of all currently loaded class to the log file.
VMDebug.printLoadedClasses(flags);
|
public static void | resetAllCounts()
VMDebug.resetAllocCount(VMDebug.KIND_ALL_COUNTS);
|
public static void | resetGlobalAllocCount()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS);
|
public static void | resetGlobalAllocSize()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES);
|
public static void | resetGlobalExternalAllocCount()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_EXT_ALLOCATED_OBJECTS);
|
public static void | resetGlobalExternalAllocSize()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_EXT_ALLOCATED_BYTES);
|
public static void | resetGlobalExternalFreedCount()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_EXT_FREED_OBJECTS);
|
public static void | resetGlobalExternalFreedSize()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_EXT_FREED_BYTES);
|
public static void | resetGlobalFreedCount()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS);
|
public static void | resetGlobalFreedSize()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES);
|
public static void | resetGlobalGcInvocationCount()
VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS);
|
public static void | resetThreadAllocCount()
VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS);
|
public static void | resetThreadAllocSize()
VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES);
|
public static void | resetThreadExternalAllocCount()
VMDebug.resetAllocCount(VMDebug.KIND_THREAD_EXT_ALLOCATED_OBJECTS);
|
public static void | resetThreadExternalAllocSize()
VMDebug.resetAllocCount(VMDebug.KIND_THREAD_EXT_ALLOCATED_BYTES);
|
public static void | resetThreadGcInvocationCount()
VMDebug.resetAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS);
|
public static int | setAllocationLimit(int limit)Establish an object allocation limit in the current thread. Useful
for catching regressions in code that is expected to operate
without causing any allocations.
Pass in the maximum number of allowed allocations. Use -1 to disable
the limit. Returns the previous limit.
The preferred way to use this is:
int prevLimit = -1;
try {
prevLimit = Debug.setAllocationLimit(0);
... do stuff that's not expected to allocate memory ...
} finally {
Debug.setAllocationLimit(prevLimit);
}
This allows limits to be nested. The try/finally ensures that the
limit is reset if something fails.
Exceeding the limit causes a dalvik.system.AllocationLimitError to
be thrown from a memory allocation call. The limit is reset to -1
when this happens.
The feature may be disabled in the VM configuration. If so, this
call has no effect, and always returns -1.
return VMDebug.setAllocationLimit(limit);
|
public static int | setGlobalAllocationLimit(int limit)Establish a global object allocation limit. This is similar to
{@link #setAllocationLimit(int)} but applies to all threads in
the VM. It will coexist peacefully with per-thread limits.
[ The value of "limit" is currently restricted to 0 (no allocations
allowed) or -1 (no global limit). This may be changed in a future
release. ]
if (limit != 0 && limit != -1)
throw new IllegalArgumentException("limit must be 0 or -1");
return VMDebug.setGlobalAllocationLimit(limit);
|
public static void | startAllocCounting()Count the number and aggregate size of memory allocations between
two points.
The "start" function resets the counts and enables counting. The
"stop" function disables the counting so that the analysis code
doesn't cause additional allocations. The "get" function returns
the specified value.
Counts are kept for the system as a whole and for each thread.
The per-thread counts for threads other than the current thread
are not cleared by the "reset" or "start" calls.
VMDebug.startAllocCounting();
|
public static void | startMethodTracing(java.lang.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.
startMethodTracing(traceName, 0, 0);
|
public static void | startMethodTracing(java.lang.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.
startMethodTracing(traceName, bufferSize, 0);
|
public static void | startMethodTracing(java.lang.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 "native" tracing
in the emulator via {@link #startNativeTracing()}.
String pathName = traceName;
if (pathName.charAt(0) != '/")
pathName = DEFAULT_TRACE_PATH_PREFIX + pathName;
if (!pathName.endsWith(DEFAULT_TRACE_EXTENSION))
pathName = pathName + DEFAULT_TRACE_EXTENSION;
VMDebug.startMethodTracing(pathName, bufferSize, flags);
|
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.
VMDebug.startMethodTracing(DEFAULT_TRACE_FILE_PATH, 0, 0);
|
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 {@link #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
{@link #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.
// Open the sysfs file for writing and write "1" to it.
PrintWriter outStream = null;
try {
FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
outStream = new PrintWriter(new OutputStreamWriter(fos));
outStream.println("1");
} catch (Exception e) {
} finally {
if (outStream != null)
outStream.close();
}
VMDebug.startEmulatorTracing();
|
public static void | stopAllocCounting()
VMDebug.stopAllocCounting();
|
public static void | stopMethodTracing()Stop method tracing.
VMDebug.stopMethodTracing();
|
public static void | stopNativeTracing()Stop qemu tracing. See {@link #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.
VMDebug.stopEmulatorTracing();
// Open the sysfs file for writing and write "0" to it.
PrintWriter outStream = null;
try {
FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
outStream = new PrintWriter(new OutputStreamWriter(fos));
outStream.println("0");
} catch (Exception e) {
// We could print an error message here but we probably want
// to quietly ignore errors if we are not running in the emulator.
} finally {
if (outStream != null)
outStream.close();
}
|
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.
return VMDebug.threadCpuTimeNanos();
|
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.
if (!VMDebug.isDebuggingEnabled()) {
//System.out.println("debugging not enabled, not waiting");
return;
}
if (isDebuggerConnected())
return;
// if DDMS is listening, inform them of our plight
System.out.println("Sending WAIT chunk");
byte[] data = new byte[] { 0 }; // 0 == "waiting for debugger"
Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1);
DdmServer.sendChunk(waitChunk);
mWaiting = true;
while (!isDebuggerConnected()) {
try { Thread.sleep(SPIN_DELAY); }
catch (InterruptedException ie) {}
}
mWaiting = false;
System.out.println("Debugger has connected");
/*
* There is no "ready to go" signal from the debugger, and we're
* not allowed to suspend ourselves -- the debugger expects us to
* be running happily, and gets confused if we aren't. We need to
* allow the debugger a chance to set breakpoints before we start
* running again.
*
* Sit and spin until the debugger has been idle for a short while.
*/
while (true) {
long delta = VMDebug.lastDebuggerActivity();
if (delta < 0) {
System.out.println("debugger detached?");
break;
}
if (delta < MIN_DEBUGGER_IDLE) {
System.out.println("waiting for debugger to settle...");
try { Thread.sleep(SPIN_DELAY); }
catch (InterruptedException ie) {}
} else {
System.out.println("debugger has settled (" + delta + ")");
break;
}
}
|
public static boolean | waitingForDebugger()Returns "true" if one or more threads is waiting for a debugger
to attach.
return mWaiting;
|