SunSPOT API V4.0


com.sun.squawk
Class VM.Stats

java.lang.Object
  extended by com.sun.squawk.VM.Stats
Enclosing class:
VM

public static class VM.Stats
extends Object

Virtual machine statistics.

Note that these statistics are simple counters that may wrap to negative values. Negative values can simply be treated as unsigned values.

The expeceted usage of these counters is to be polled periodically, so the absolute value is not as important as the difference between different readings. You will need to be prepared to handle a counter wrapping during two readings, but if samples are frequent, you shouldn't have to worry about the counters wrapping more than once.

 EXAMPLE 1 (Perf meter):

      totalTimeDiff = totalTime[n]  - totalTime[n-1];
      gcTimeDiff    =  gcTime[n] - gcTime[n-1];
      sysTimeDiff   = sysTime[n] - sysTime[n-1];
      userTimeDiff  = totalTime[n] - (gcTime[n] + sysTime[n]);
      System.out.println("User time: " + (userTimeDiff * 100) / totalTimeDiff + "%");
      System.out.println("GC time: " + (gcTimeDiff * 100) / totalTimeDiff + "%");
      System.out.println("System/Idle time: " + (sysTimeDiff * 100) / totalTimeDiff + "%");
 


Field Summary
static int NUM_STAT_VALUES
           
static int STAT_BRANCH_COUNT
           
static int STAT_BYTES_LAST_FREED
           
static int STAT_BYTES_TOTAL_ALLOCATED
           
static int STAT_BYTES_TOTAL_FREED
           
static int STAT_CONTENDED_MONITOR_COUNT
           
static int STAT_FIRST_COUNT_STAT
           
static int STAT_FULL_GC_COUNT
           
static int STAT_FULL_GC_TIME
           
static int STAT_GC_TIME
           
static int STAT_HEAP_FREE
           
static int STAT_HEAP_TOTAL
           
static int STAT_LAST_GC_TIME
           
static int STAT_MAX_FULLGC_TIME
           
static int STAT_MAX_PARTGC_TIME
           
static int STAT_MAX_STACK_SIZE
           
static int STAT_MONITORS_ALLOCATED
           
static int STAT_OBJECTS_TOTAL_ALLOCATED
           
static int STAT_PARTIAL_GC_COUNT
           
static int STAT_PARTIAL_GC_TIME
           
static int STAT_STACKS_ALLOCATED
           
static int STAT_THREAD_SWITCH_COUNT
           
static int STAT_THREADS_ALLOCATED
           
static int STAT_THROW_COUNT
           
static int STAT_WAIT_TIME
           
static int STAT_WALL_TIME
          tag for data sent by sendStatData()
 
Constructor Summary
VM.Stats()
          Create a new Stats object, This is primarily used when calling sendStatData(java.io.DataOutputStream).
 
Method Summary
static long getBytesAllocatedTotal()
          Get the number of bytes allocated since reboot.
static long getBytesFreedTotal()
          Get the number of bytes freed since reboot.
static long getBytesLastFreed()
          Get the number of bytes freed in the last collection.
static int getContendedMontorEnterCount()
          Return the number of times that a thread was blocked trying to synchronize on an object.
static int getFullGCCount()
          Get the total number of full garbage collections since reboot.
static long getLastGCTime()
          Get the time taken by the last garbage collection.
static long getMaxFullGCTime()
          Get the time taken by the slowest full garbage collection.
static long getMaxGCTime()
          Get the time taken by the slowest garbage collection.
static long getMaxPartialGCTime()
          Get the time taken by the slowest partial garbage collection.
static int getMaxStackSize()
          Return size of the largest stack ever allocated.
static int getMonitorsAllocatedCount()
          Return the number of monitors allocated.
static int getObjectsAllocatedTotal()
          Get the number of objects allocated since reboot.
static int getPartialGCCount()
          Get the total number of partial garbage collections since reboot.
static int getStacksAllocatedCount()
          Return the number of stacks allocated.
static int getThreadsAllocatedCount()
          Get the number of Thread objects allocated since reboot.
static int getThreadSwitchCount()
          Return count of thread context switching since reboot.
static int getThrowCount()
          Return number of exceptions thrown.
static long getTotalFullGCTime()
          Get the total time taken by all full garbage collections.
static long getTotalGCTime()
          Get the total time taken by all garbage collections.
static long getTotalPartialGCTime()
          Get the total time taken by all partial garbage collections.
static long getTotalWaitTime()
          Get the total time the VM was idle.
static void initHeapStats()
          Pre-create all data structures used in heap stats, so heap walking won't allocate more memory.
static void printHeapStats(Object startObj, boolean printInstances)
          Do heap walk from start object (or whole heap is startObj is null).
static void readAllValues(long[] values)
          Take a sample of all data and store into values.
 void sendStatData(DataOutputStream dos)
          Take a sample of all statics and send to output stream dos.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_STAT_VALUES

public static final int NUM_STAT_VALUES
See Also:
Constant Field Values

STAT_BRANCH_COUNT

public static final int STAT_BRANCH_COUNT
See Also:
Constant Field Values

STAT_BYTES_LAST_FREED

public static final int STAT_BYTES_LAST_FREED
See Also:
Constant Field Values

STAT_BYTES_TOTAL_ALLOCATED

public static final int STAT_BYTES_TOTAL_ALLOCATED
See Also:
Constant Field Values

STAT_BYTES_TOTAL_FREED

public static final int STAT_BYTES_TOTAL_FREED
See Also:
Constant Field Values

STAT_CONTENDED_MONITOR_COUNT

public static final int STAT_CONTENDED_MONITOR_COUNT
See Also:
Constant Field Values

STAT_FIRST_COUNT_STAT

public static final int STAT_FIRST_COUNT_STAT
See Also:
Constant Field Values

STAT_FULL_GC_COUNT

public static final int STAT_FULL_GC_COUNT
See Also:
Constant Field Values

STAT_FULL_GC_TIME

public static final int STAT_FULL_GC_TIME
See Also:
Constant Field Values

STAT_GC_TIME

public static final int STAT_GC_TIME
See Also:
Constant Field Values

STAT_HEAP_FREE

public static final int STAT_HEAP_FREE
See Also:
Constant Field Values

STAT_HEAP_TOTAL

public static final int STAT_HEAP_TOTAL
See Also:
Constant Field Values

STAT_LAST_GC_TIME

public static final int STAT_LAST_GC_TIME
See Also:
Constant Field Values

STAT_MAX_FULLGC_TIME

public static final int STAT_MAX_FULLGC_TIME
See Also:
Constant Field Values

STAT_MAX_PARTGC_TIME

public static final int STAT_MAX_PARTGC_TIME
See Also:
Constant Field Values

STAT_MAX_STACK_SIZE

public static final int STAT_MAX_STACK_SIZE
See Also:
Constant Field Values

STAT_MONITORS_ALLOCATED

public static final int STAT_MONITORS_ALLOCATED
See Also:
Constant Field Values

STAT_OBJECTS_TOTAL_ALLOCATED

public static final int STAT_OBJECTS_TOTAL_ALLOCATED
See Also:
Constant Field Values

STAT_PARTIAL_GC_COUNT

public static final int STAT_PARTIAL_GC_COUNT
See Also:
Constant Field Values

STAT_PARTIAL_GC_TIME

public static final int STAT_PARTIAL_GC_TIME
See Also:
Constant Field Values

STAT_STACKS_ALLOCATED

public static final int STAT_STACKS_ALLOCATED
See Also:
Constant Field Values

STAT_THREADS_ALLOCATED

public static final int STAT_THREADS_ALLOCATED
See Also:
Constant Field Values

STAT_THREAD_SWITCH_COUNT

public static final int STAT_THREAD_SWITCH_COUNT
See Also:
Constant Field Values

STAT_THROW_COUNT

public static final int STAT_THROW_COUNT
See Also:
Constant Field Values

STAT_WAIT_TIME

public static final int STAT_WAIT_TIME
See Also:
Constant Field Values

STAT_WALL_TIME

public static final int STAT_WALL_TIME
tag for data sent by sendStatData()

See Also:
Constant Field Values
Constructor Detail

VM.Stats

public VM.Stats()
Create a new Stats object, This is primarily used when calling sendStatData(java.io.DataOutputStream).

Method Detail

getBytesAllocatedTotal

public static long getBytesAllocatedTotal()
Get the number of bytes allocated since reboot.

Watch out for overflow.

Returns:
total bytes allocated

getBytesFreedTotal

public static long getBytesFreedTotal()
Get the number of bytes freed since reboot.

Watch out for overflow.

Returns:
total bytes freed

getBytesLastFreed

public static long getBytesLastFreed()
Get the number of bytes freed in the last collection.

Returns:
bytes freed

getContendedMontorEnterCount

public static int getContendedMontorEnterCount()
Return the number of times that a thread was blocked trying to synchronize on an object.

Note that this counts the initial contention. A thread may be released to aquire the lock, but another thread (potentially higher priority) runs first, and actually acquires the lock. The first thread will then have to wait again.

Returns:
contended enters

getFullGCCount

public static int getFullGCCount()
Get the total number of full garbage collections since reboot.

Returns:
full gc count

getLastGCTime

public static long getLastGCTime()
Get the time taken by the last garbage collection.

Returns:
the last GC time in milliseconds

getMaxFullGCTime

public static long getMaxFullGCTime()
Get the time taken by the slowest full garbage collection.

Returns:
the longest full GC time in milliseconds

getMaxGCTime

public static long getMaxGCTime()
Get the time taken by the slowest garbage collection.

Returns:
the longest GC time in milliseconds

getMaxPartialGCTime

public static long getMaxPartialGCTime()
Get the time taken by the slowest partial garbage collection.

Returns:
the longest partial GC time in milliseconds

getMaxStackSize

public static int getMaxStackSize()
Return size of the largest stack ever allocated.

Returns:
largest stack size, in words

getMonitorsAllocatedCount

public static int getMonitorsAllocatedCount()
Return the number of monitors allocated.

Often, uncontended locking is handled by the interpreter in the pendingMonitors cache. But if the cache is full, or there is contention, or Object.wait() is used, or a threadd is switched out while holding a virtual monitor, then a real monitor has to be allocated for an object. It is possible for the monitor for an object to come and go, so there is the possibility of "monitor object thrashing".

Returns:
total monitors allocated

getObjectsAllocatedTotal

public static int getObjectsAllocatedTotal()
Get the number of objects allocated since reboot. Watch out for overflow.

Returns:
total objects allocated

getPartialGCCount

public static int getPartialGCCount()
Get the total number of partial garbage collections since reboot.

Returns:
partial gc count

getStacksAllocatedCount

public static int getStacksAllocatedCount()
Return the number of stacks allocated.

Stacks are allocated for each thread, and as more frames are needed, new stacks are created to replace the original stacks (typically at 2x the size of the original stack). The default stack size is about 160 words.

Returns:
total stacks allocated

getThreadSwitchCount

public static int getThreadSwitchCount()
Return count of thread context switching since reboot.

This does not include system-level switches that occur for GC, exception throwing, etc.

Returns:
switch count

getThreadsAllocatedCount

public static int getThreadsAllocatedCount()
Get the number of Thread objects allocated since reboot.

Returns:
threads allocated

getThrowCount

public static int getThrowCount()
Return number of exceptions thrown.

Returns:
exceptions thrown

getTotalFullGCTime

public static long getTotalFullGCTime()
Get the total time taken by all full garbage collections.

Returns:
the full GC time in milliseconds

getTotalGCTime

public static long getTotalGCTime()
Get the total time taken by all garbage collections.

Returns:
the total GC time in milliseconds

getTotalPartialGCTime

public static long getTotalPartialGCTime()
Get the total time taken by all partial garbage collections.

Returns:
the partial GC time in milliseconds

getTotalWaitTime

public static long getTotalWaitTime()
Get the total time the VM was idle.

This typically means waiting for timeouts or IO.

Returns:
wait time in milliseconds

initHeapStats

public static void initHeapStats()
Pre-create all data structures used in heap stats, so heap walking won't allocate more memory.


printHeapStats

public static void printHeapStats(Object startObj,
                                  boolean printInstances)
Do heap walk from start object (or whole heap is startObj is null). Count how many instances, and how many bytes are used, by all objects that are the same age or youngre than startObj. Print out statistics of each class that has at least one instance in the set found in the heap walk. Statistics are NOT sorted.

Parameters:
startObj - the object to start walking from , or null
printInstances -

readAllValues

public static void readAllValues(long[] values)
Take a sample of all data and store into values.

This is simply a convenience method.

Parameters:
values - must have length of at least NUM_STAT_VALUES.

sendStatData

public void sendStatData(DataOutputStream dos)
Take a sample of all statics and send to output stream dos.

The format of the data is:

     byte tag     = 0
     long value
     byte tag     = 1
     long value
        ...
     byte tag     = NUM_STAT_VALUES - 1
     long value
The data can be read by a DataInputStream.

Parameters:
dos - output stream to send values.

SunSPOT API V4.0


Copyright © 2006-2008 Sun Microsystems, Inc. All Rights Reserved.