public final class

VMDebug

extends Object
java.lang.Object
   ↳ dalvik.system.VMDebug

Class Overview

Provides access to some VM-specific debug features. Though this class and many of its members are public, this class is meant to be wrapped in a more friendly way for use by application developers. On the Android platform, the recommended way to access this functionality is through the class android.os.Debug.

Summary

Constants
String DEFAULT_METHOD_TRACE_FILE_NAME Specifies the default method trace data file name.
int KIND_ALL_COUNTS
int KIND_GLOBAL_ALLOCATED_BYTES
int KIND_GLOBAL_ALLOCATED_OBJECTS
int KIND_GLOBAL_EXT_ALLOCATED_BYTES
int KIND_GLOBAL_EXT_ALLOCATED_OBJECTS
int KIND_GLOBAL_EXT_FREED_BYTES
int KIND_GLOBAL_EXT_FREED_OBJECTS
int KIND_GLOBAL_FREED_BYTES
int KIND_GLOBAL_FREED_OBJECTS
int KIND_GLOBAL_GC_INVOCATIONS
int KIND_THREAD_ALLOCATED_BYTES
int KIND_THREAD_ALLOCATED_OBJECTS
int KIND_THREAD_EXT_ALLOCATED_BYTES
int KIND_THREAD_EXT_ALLOCATED_OBJECTS
int KIND_THREAD_EXT_FREED_BYTES
int KIND_THREAD_EXT_FREED_OBJECTS
int KIND_THREAD_FREED_BYTES
int KIND_THREAD_FREED_OBJECTS
int KIND_THREAD_GC_INVOCATIONS
int TRACE_COUNT_ALLOCS flag for startMethodTracing(), which adds the results from startAllocCounting to the trace key file.
Public Methods
static void dumpHprofData(String fileName)
Dump "hprof" data to the specified file.
static int getAllocCount(int kind)
static void getInstructionCount(int[] counts)
static int getLoadedClassCount()
Gets the number of loaded classes.
static boolean isDebuggerConnected()
Determines if a debugger is currently attached.
static boolean isDebuggingEnabled()
Determines if debugging is enabled in this VM.
static long lastDebuggerActivity()
Returns the time since the last known debugger activity.
static void printLoadedClasses(int flags)
Dumps a list of loaded class to the log file.
static void resetAllocCount(int kinds)
static void resetInstructionCount()
static int setAllocationLimit(int limit)
Establishes an object allocation limit in the current thread.
static int setGlobalAllocationLimit(int limit)
Establishes an object allocation limit for the entire VM.
static void startAllocCounting()
Count the number and aggregate size of memory allocations between two points.
static void startEmulatorTracing()
Starts sending Dalvik method trace info to the emulator.
static void startInstructionCounting()
Count the number of instructions executed between two points.
static void startMethodTracing()
Start method tracing with default name, size, and with 0 flags.
static void startMethodTracing(String traceFileName, int bufferSize, int flags)
Start method tracing, specifying a file name as well as a default buffer size.
static void stopAllocCounting()
static void stopEmulatorTracing()
Stops sending Dalvik method trace info to the emulator.
static void stopInstructionCounting()
static void stopMethodTracing()
Stops method tracing.
static long threadCpuTimeNanos()
Get an indication of thread CPU usage.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DEFAULT_METHOD_TRACE_FILE_NAME

Specifies the default method trace data file name.

Constant Value: "/sdcard/dmtrace.trace"

public static final int KIND_ALL_COUNTS

Constant Value: -1 (0xffffffff)

public static final int KIND_GLOBAL_ALLOCATED_BYTES

Constant Value: 2 (0x00000002)

public static final int KIND_GLOBAL_ALLOCATED_OBJECTS

Constant Value: 1 (0x00000001)

public static final int KIND_GLOBAL_EXT_ALLOCATED_BYTES

Constant Value: 8192 (0x00002000)

public static final int KIND_GLOBAL_EXT_ALLOCATED_OBJECTS

Constant Value: 4096 (0x00001000)

public static final int KIND_GLOBAL_EXT_FREED_BYTES

Constant Value: 32768 (0x00008000)

public static final int KIND_GLOBAL_EXT_FREED_OBJECTS

Constant Value: 16384 (0x00004000)

public static final int KIND_GLOBAL_FREED_BYTES

Constant Value: 8 (0x00000008)

public static final int KIND_GLOBAL_FREED_OBJECTS

Constant Value: 4 (0x00000004)

public static final int KIND_GLOBAL_GC_INVOCATIONS

Constant Value: 16 (0x00000010)

public static final int KIND_THREAD_ALLOCATED_BYTES

Constant Value: 131072 (0x00020000)

public static final int KIND_THREAD_ALLOCATED_OBJECTS

Constant Value: 65536 (0x00010000)

public static final int KIND_THREAD_EXT_ALLOCATED_BYTES

Constant Value: 536870912 (0x20000000)

public static final int KIND_THREAD_EXT_ALLOCATED_OBJECTS

Constant Value: 268435456 (0x10000000)

public static final int KIND_THREAD_EXT_FREED_BYTES

Constant Value: -2147483648 (0x80000000)

public static final int KIND_THREAD_EXT_FREED_OBJECTS

Constant Value: 1073741824 (0x40000000)

public static final int KIND_THREAD_FREED_BYTES

Constant Value: 524288 (0x00080000)

public static final int KIND_THREAD_FREED_OBJECTS

Constant Value: 262144 (0x00040000)

public static final int KIND_THREAD_GC_INVOCATIONS

Constant Value: 1048576 (0x00100000)

public static final int TRACE_COUNT_ALLOCS

flag for startMethodTracing(), which adds the results from startAllocCounting to the trace key file.

Constant Value: 1 (0x00000001)

Public Methods

public static void dumpHprofData (String fileName)

Dump "hprof" data to the specified file. This will cause a GC. The VM may create a temporary file in the same directory.

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.

public static int getAllocCount (int kind)

public static void getInstructionCount (int[] counts)

public static int getLoadedClassCount ()

Gets the number of loaded classes.

Returns
  • the number of loaded classes

public static boolean isDebuggerConnected ()

Determines if a debugger is currently attached.

Returns
  • true if (and only if) a debugger is connected

public static boolean isDebuggingEnabled ()

Determines if debugging is enabled in this VM. If debugging is not enabled, a debugger cannot be attached.

Returns
  • true if debugging is enabled

public static long lastDebuggerActivity ()

Returns the time since the last known debugger activity.

Returns
  • the time in milliseconds, or -1 if the debugger is not connected

public static void printLoadedClasses (int flags)

Dumps a list of loaded class to the log file.

public static void resetAllocCount (int kinds)

public static void resetInstructionCount ()

public static int setAllocationLimit (int limit)

Establishes an object allocation limit in the current thread. Useful for catching regressions in code that is expected to operate without causing any allocations. The limit is valid from the return of this method until it is either changed or the thread terminates.

Parameters
limit the new limit. A value of 0 means not a single new object may be allocated. A value of -1 disables the limit.
Returns
  • the previous limit, or -1 if no limit was set

public static int setGlobalAllocationLimit (int limit)

Establishes an object allocation limit for the entire VM. Useful for catching regressions in code that is expected to operate without causing any allocations. The limit is valid from the return of this method until it is either changed or the thread terminates.

Parameters
limit the new limit. A value of 0 means not a single new object may be allocated. A value of -1 disables the limit.
Returns
  • the previous limit, or -1 if no limit was set

public static void startAllocCounting ()

Count the number and aggregate size of memory allocations between two points.

public static void startEmulatorTracing ()

Starts sending Dalvik method trace info to the emulator.

public static void startInstructionCounting ()

Count the number of instructions executed between two points.

public static void startMethodTracing ()

Start method tracing with default name, size, and with 0 flags.

public static void startMethodTracing (String traceFileName, int bufferSize, int flags)

Start method tracing, specifying a file name as well as a default buffer size. See Running the Traceview Debugging Program for information about reading trace files.

You can use either a fully qualified path and name, or just a name. If only a name is specified, the file will be created under the /sdcard/ directory. If a name is not given, the default is /sdcard/dmtrace.trace.

Parameters
traceFileName name to give the trace file
bufferSize the maximum size of both files combined. If passed as 0, it defaults to 8MB.
flags flags to control method tracing. The only one that is currently defined is TRACE_COUNT_ALLOCS.

public static void stopAllocCounting ()

public static void stopEmulatorTracing ()

Stops sending Dalvik method trace info to the emulator.

public static void stopInstructionCounting ()

public static void stopMethodTracing ()

Stops method tracing.

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.

Returns
  • the CPU usage. A value of -1 means the system does not support this feature.