Package dalvik.system
Class VMDebug
- java.lang.Object
-
- dalvik.system.VMDebug
-
public final class VMDebug extends Object
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 classandroid.os.Debug.
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleancacheRegisterMap(String classAndMethodDesc)Primes the register map cache.static longcountInstancesOfClass(Class klass, boolean assignable)Counts the instances of a class.static long[]countInstancesOfClasses(Class[] classes, boolean assignable)Counts the instances of classes.static voidcrash()Crashes the VM.static voiddumpHprofData(String filename)Dumps "hprof" data to the specified file.static voiddumpHprofData(String fileName, FileDescriptor fd)Dumps "hprof" heap data to a file, by name or descriptor.static voiddumpHprofDataDdms()Collects "hprof" heap data and sends it to DDMS.static voiddumpReferenceTables()Dumps the contents of the VM reference tables (e.g.static intgetAllocCount(int kind)static voidgetHeapSpaceStats(long[] data)Export the heap per-space stats for dumpsys meminfo.static voidgetInstructionCount(int[] counts)static intgetLoadedClassCount()Gets the number of loaded classes.static intgetMethodTracingMode()Determine whether method tracing is currently active and what type is active.static StringgetRuntimeStat(String statName)Returns the value of a particular runtime statistic ornullif no such runtime statistic exists.static Map<String,String>getRuntimeStats()Returns a map of the names/values of the runtime statistics that#getRuntimeStat()supports.static String[]getVmFeatureList()Returns an array of strings that identify VM features.static voidinfopoint(int id)Together with gdb, provide a handy way to stop the VM at user-tagged locations.static booleanisDebuggerConnected()Determines if a debugger is currently attached.static booleanisDebuggingEnabled()Determines if debugging is enabled in this VM.static longlastDebuggerActivity()Returns the time since the last known debugger activity.static voidprintLoadedClasses(int flags)Dumps a list of loaded class to the log file.static voidresetAllocCount(int kinds)static voidresetInstructionCount()static intsetAllocationLimit(int limit)Deprecated.static intsetGlobalAllocationLimit(int limit)Deprecated.static voidstartAllocCounting()Count the number and aggregate size of memory allocations between two points.static voidstartEmulatorTracing()Starts sending Dalvik method trace info to the emulator.static voidstartInstructionCounting()Count the number of instructions executed between two points.static voidstartMethodTracing()Deprecated.Not used, not needed.static voidstartMethodTracing(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Start method tracing, specifying a file name as well as a default buffer size.static voidstartMethodTracing(String traceFileName, FileDescriptor fd, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Like startMethodTracing(String, int, int), but taking an already-opened FileDescriptor in which the trace is written.static voidstartMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Starts method tracing without a backing file.static voidstopAllocCounting()static voidstopEmulatorTracing()Stops sending Dalvik method trace info to the emulator.static voidstopInstructionCounting()static voidstopMethodTracing()Stops method tracing.static longthreadCpuTimeNanos()Get an indication of thread CPU usage.
-
-
-
Field Detail
-
TRACE_COUNT_ALLOCS
public static final int TRACE_COUNT_ALLOCS
flag for startMethodTracing(), which adds the results from startAllocCounting to the trace key file.- See Also:
- Constant Field Values
-
KIND_GLOBAL_ALLOCATED_OBJECTS
public static final int KIND_GLOBAL_ALLOCATED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_GLOBAL_ALLOCATED_BYTES
public static final int KIND_GLOBAL_ALLOCATED_BYTES
- See Also:
- Constant Field Values
-
KIND_GLOBAL_FREED_OBJECTS
public static final int KIND_GLOBAL_FREED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_GLOBAL_FREED_BYTES
public static final int KIND_GLOBAL_FREED_BYTES
- See Also:
- Constant Field Values
-
KIND_GLOBAL_GC_INVOCATIONS
public static final int KIND_GLOBAL_GC_INVOCATIONS
- See Also:
- Constant Field Values
-
KIND_GLOBAL_CLASS_INIT_COUNT
public static final int KIND_GLOBAL_CLASS_INIT_COUNT
- See Also:
- Constant Field Values
-
KIND_GLOBAL_CLASS_INIT_TIME
public static final int KIND_GLOBAL_CLASS_INIT_TIME
- See Also:
- Constant Field Values
-
KIND_GLOBAL_EXT_ALLOCATED_OBJECTS
public static final int KIND_GLOBAL_EXT_ALLOCATED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_GLOBAL_EXT_ALLOCATED_BYTES
public static final int KIND_GLOBAL_EXT_ALLOCATED_BYTES
- See Also:
- Constant Field Values
-
KIND_GLOBAL_EXT_FREED_OBJECTS
public static final int KIND_GLOBAL_EXT_FREED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_GLOBAL_EXT_FREED_BYTES
public static final int KIND_GLOBAL_EXT_FREED_BYTES
- See Also:
- Constant Field Values
-
KIND_THREAD_ALLOCATED_OBJECTS
public static final int KIND_THREAD_ALLOCATED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_THREAD_ALLOCATED_BYTES
public static final int KIND_THREAD_ALLOCATED_BYTES
- See Also:
- Constant Field Values
-
KIND_THREAD_FREED_OBJECTS
public static final int KIND_THREAD_FREED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_THREAD_FREED_BYTES
public static final int KIND_THREAD_FREED_BYTES
- See Also:
- Constant Field Values
-
KIND_THREAD_GC_INVOCATIONS
public static final int KIND_THREAD_GC_INVOCATIONS
- See Also:
- Constant Field Values
-
KIND_THREAD_CLASS_INIT_COUNT
public static final int KIND_THREAD_CLASS_INIT_COUNT
- See Also:
- Constant Field Values
-
KIND_THREAD_CLASS_INIT_TIME
public static final int KIND_THREAD_CLASS_INIT_TIME
- See Also:
- Constant Field Values
-
KIND_THREAD_EXT_ALLOCATED_OBJECTS
public static final int KIND_THREAD_EXT_ALLOCATED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_THREAD_EXT_ALLOCATED_BYTES
public static final int KIND_THREAD_EXT_ALLOCATED_BYTES
- See Also:
- Constant Field Values
-
KIND_THREAD_EXT_FREED_OBJECTS
public static final int KIND_THREAD_EXT_FREED_OBJECTS
- See Also:
- Constant Field Values
-
KIND_THREAD_EXT_FREED_BYTES
public static final int KIND_THREAD_EXT_FREED_BYTES
- See Also:
- Constant Field Values
-
KIND_ALL_COUNTS
public static final int KIND_ALL_COUNTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
lastDebuggerActivity
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
-
isDebuggingEnabled
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
-
isDebuggerConnected
public static boolean isDebuggerConnected()
Determines if a debugger is currently attached.- Returns:
- true if (and only if) a debugger is connected
-
getVmFeatureList
public static String[] getVmFeatureList()
Returns an array of strings that identify VM features. This is used by DDMS to determine what sorts of operations the VM can perform.
-
startMethodTracing
@Deprecated public static void startMethodTracing()
Deprecated.Not used, not needed.Start method tracing with default name, size, and with0flags.
-
startMethodTracing
public static void startMethodTracing(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)
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 filebufferSize- the maximum size of both files combined. If passed as0, it defaults to 8MB.flags- flags to control method tracing. The only one that is currently defined isTRACE_COUNT_ALLOCS.samplingEnabled- if true, sample profiling is enabled. Otherwise, method instrumentation is used.intervalUs- the time between samples in microseconds when sampling is enabled.
-
startMethodTracing
public static void startMethodTracing(String traceFileName, FileDescriptor fd, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)
Like startMethodTracing(String, int, int), but taking an already-opened FileDescriptor in which the trace is written. The file name is also supplied simply for logging. Makes a dup of the file descriptor.
-
startMethodTracingDdms
public static void startMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)Starts method tracing without a backing file. When stopMethodTracing is called, the result is sent directly to DDMS. (If DDMS is not attached when tracing ends, the profiling data will be discarded.)
-
getMethodTracingMode
public static int getMethodTracingMode()
Determine whether method tracing is currently active and what type is active.
-
stopMethodTracing
public static void stopMethodTracing()
Stops method tracing.
-
startEmulatorTracing
public static void startEmulatorTracing()
Starts sending Dalvik method trace info to the emulator.
-
stopEmulatorTracing
public static void stopEmulatorTracing()
Stops sending Dalvik method trace info to the emulator.
-
threadCpuTimeNanos
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.
-
startAllocCounting
public static void startAllocCounting()
Count the number and aggregate size of memory allocations between two points.
-
stopAllocCounting
public static void stopAllocCounting()
-
getAllocCount
public static int getAllocCount(int kind)
-
resetAllocCount
public static void resetAllocCount(int kinds)
-
setAllocationLimit
@Deprecated public static int setAllocationLimit(int limit)
Deprecated.This method exists for binary compatibility. It was part of the allocation limits API which was removed in Android 3.0 (Honeycomb).
-
setGlobalAllocationLimit
@Deprecated public static int setGlobalAllocationLimit(int limit)
Deprecated.This method exists for binary compatibility. It was part of the allocation limits API which was removed in Android 3.0 (Honeycomb).
-
startInstructionCounting
public static void startInstructionCounting()
Count the number of instructions executed between two points.
-
stopInstructionCounting
public static void stopInstructionCounting()
-
getInstructionCount
public static void getInstructionCount(int[] counts)
-
resetInstructionCount
public static void resetInstructionCount()
-
printLoadedClasses
public static void printLoadedClasses(int flags)
Dumps a list of loaded class to the log file.
-
getLoadedClassCount
public static int getLoadedClassCount()
Gets the number of loaded classes.- Returns:
- the number of loaded classes
-
dumpHprofData
public static void dumpHprofData(String filename) throws IOException
Dumps "hprof" data to the specified file. This may 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.
-
dumpHprofDataDdms
public static void dumpHprofDataDdms()
Collects "hprof" heap data and sends it to DDMS. This may cause a GC.- Throws:
UnsupportedOperationException- if the VM was built without HPROF support.
-
dumpHprofData
public static void dumpHprofData(String fileName, FileDescriptor fd) throws IOException
Dumps "hprof" heap data to a file, by name or descriptor.- Parameters:
fileName- Name of output file. If fd is non-null, the file name is only used in log messages (and may be null).fd- Descriptor of open file that will receive the output. If this is null, the fileName is used instead.- Throws:
IOException
-
cacheRegisterMap
public static boolean cacheRegisterMap(String classAndMethodDesc)
Primes the register map cache.
-
dumpReferenceTables
public static void dumpReferenceTables()
Dumps the contents of the VM reference tables (e.g. JNI locals and globals) to the log file.
-
crash
public static void crash()
Crashes the VM. Seriously. Dumps the interpreter stack trace for the current thread and then aborts the VM so you can see the native stack trace. Useful for figuring out how you got somewhere when lots of native code is involved.
-
infopoint
public static void infopoint(int id)
Together with gdb, provide a handy way to stop the VM at user-tagged locations.
-
countInstancesOfClass
public static long countInstancesOfClass(Class klass, boolean assignable)
Counts the instances of a class. It is the caller's responsibility to do GC if they don't want unreachable objects to get counted.- Parameters:
klass- the class to be counted.assignable- if false, direct instances of klass are counted. If true, instances that are assignable to klass, as defined byClass.isAssignableFrom(java.lang.Class<?>)are counted.- Returns:
- the number of matching instances.
-
countInstancesOfClasses
public static long[] countInstancesOfClasses(Class[] classes, boolean assignable)
Counts the instances of classes. It is the caller's responsibility to do GC if they don't want unreachable objects to get counted.- Parameters:
classes- the classes to be counted.assignable- if false, direct instances of klass are counted. If true, instances that are assignable to klass, as defined byClass.isAssignableFrom(java.lang.Class<?>)are counted.- Returns:
- an array containing the number of matching instances. The value for an index is the number of instances of the class at that index in number classes.
-
getHeapSpaceStats
public static void getHeapSpaceStats(long[] data)
Export the heap per-space stats for dumpsys meminfo. The content of the array is:data[0] : the application heap space size data[1] : the application heap space allocated bytes data[2] : the application heap space free bytes data[3] : the zygote heap space size data[4] : the zygote heap space allocated size data[5] : the zygote heap space free size data[6] : the large object space size data[7] : the large object space allocated bytes data[8] : the large object space free bytes
- Parameters:
data- the array into which the stats are written.
-
getRuntimeStat
public static String getRuntimeStat(String statName)
Returns the value of a particular runtime statistic ornullif no such runtime statistic exists.- Parameters:
statName- the name of the runtime statistic to look up.- Returns:
- the value of the runtime statistic.
-
-