FileDocCategorySizeDatePackage
Timings.javaAPI DocGlassfish v2 API5966Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

Timings

public final class Timings extends Object
Central registry of timing values.

Fields Summary
private static final Timings
INSTANCE
private static final Map
sInstances
private final List
mCheckpointNames
private final List
mCheckpointTimes
private final String
mName
private static final String
NEWLINE
Constructors Summary
public Timings(String name)

        mName   = name;
        mCheckpointNames    = new ArrayList<String>();
        mCheckpointTimes    = new ArrayList<Long>();
    
Methods Summary
public voidadd(java.lang.String checkpointName, long nanoseconds)

param
checkpoint the name of the checkpoint
param
nanoseconds the nanoseconds ascribed to this checkpoint

        synchronized( mCheckpointNames )
        {
            mCheckpointNames.add( checkpointName );
            mCheckpointTimes.add( nanoseconds );
        }
    
public voidadd(java.lang.String checkpointName, TimingDelta delta)
Convenience--same as add( checkpoint, delta.elapsed() );

param
checkpoint the name of the checkpoint
param
delta a TimingDelta

        add( checkpointName, delta.elapsed() );
    
public voidclear()
Remove all timings.

        synchronized( mCheckpointNames )
        {
            mCheckpointNames.clear();
        }
    
public static com.sun.appserv.management.util.misc.TimingsgetInstance()
Get the default Timings object. No synchronization happens or is needed; fast.

    
                            
          
    
    
        return INSTANCE;
    
public static com.sun.appserv.management.util.misc.TimingsgetInstance(java.lang.String name)
Get a named Timings object. Synchronization happens in this call, to access a Map.

        Timings   timings   = null;
        synchronized( sInstances )
        {
            timings = sInstances.get( name );
            if ( timings == null )
            {
                timings = newInstance( name );
                sInstances.put( name, timings );
            }
        }
        return timings;
    
public java.lang.StringgetName()

        return mName;
    
public static com.sun.appserv.management.util.misc.TimingsnewInstance(java.lang.String name)
Create a Timings object. It is not retained in the list of Timings instances.

        return new Timings( name );
    
public static voidremoveInstance(java.lang.String name)

   
        synchronized( sInstances )
        {
            sInstances.remove( name );
        }
    
public java.lang.StringtoString()

        final StringBuffer buf  = new StringBuffer();
        
        buf.append( "Timing Log " );
        buf.append( StringUtil.quote( getName() ) );
        buf.append( NEWLINE );

        final List<String>    names = new ArrayList<String>();
        final List<Long>      times = new ArrayList<Long>();
        
        synchronized( mCheckpointNames )
        {
            names.addAll( mCheckpointNames );
            times.addAll( mCheckpointTimes );
        }
        
        for( int i = 0; i < names.size(); ++i )
        {
            final String name = names.get(i);
            final long   nanos = times.get(i);
            
            buf.append( name );
            buf.append( " = " );
            buf.append( StringUtil.getMillisString( nanos ) );
            buf.append( NEWLINE );
        }

        return buf.toString();