avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler AbstractProfileSample.java DefaultProfilerManager.java ProfilableProxy.java ProfilePointProxy.java ProfileSample.java
Date Wed, 06 Mar 2002 06:45:04 GMT
leif        02/03/05 22:45:04

  Modified:    src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler
                        AbstractProfileSample.java
                        DefaultProfilerManager.java ProfilableProxy.java
                        ProfilePointProxy.java ProfileSample.java
  Log:
  Add support for compact profiler state files.
  
  Revision  Changes    Path
  1.4       +67 -11    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/AbstractProfileSample.java
  
  Index: AbstractProfileSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/AbstractProfileSample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractProfileSample.java	5 Mar 2002 12:34:32 -0000	1.3
  +++ AbstractProfileSample.java	6 Mar 2002 06:45:04 -0000	1.4
  @@ -9,6 +9,7 @@
   
   import java.util.ArrayList;
   import java.util.Arrays;
  +import java.util.StringTokenizer;
   
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -20,7 +21,7 @@
    *  ProfileSamples.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2002/03/05 12:34:32 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/03/06 06:45:04 $
    * @since 4.1
    */
   abstract class AbstractProfileSample
  @@ -369,9 +370,12 @@
       /**
        * Saves the current state into a Configuration.
        *
  +     * @param useCompactSamples Flag for whether or not ProfileSample data
  +     *                          should be saved in compact format or not.
  +     *
        * @return The state as a Configuration.
        */
  -    public final Configuration saveState()
  +    public final Configuration saveState( boolean useCompactSamples )
       {
           synchronized(this)
           {
  @@ -382,11 +386,28 @@
               // Save the history samples so that the newest is first.
               DefaultConfiguration samples = new DefaultConfiguration( "history", "-" );
               int[] history = getHistorySnapshot();
  -            for ( int i = history.length - 1; i >= 0; i-- )
  +            if ( useCompactSamples )
  +            {
  +                StringBuffer sb = new StringBuffer();
  +                
  +                // Store the first value outside the loop to simplify the loop.
  +                sb.append( history[ history.length - 1 ] );
  +                for ( int i = history.length - 2; i >= 0; i-- )
  +                {
  +                    sb.append( ',' );
  +                    sb.append( history[ i ] );
  +                }
  +                
  +                samples.setValue( sb.toString() );
  +            }
  +            else
               {
  -                DefaultConfiguration sample = new DefaultConfiguration( "sample", "-" );
  -                sample.setValue( Integer.toString( history[i] ) );
  -                samples.addChild( sample );
  +                for ( int i = history.length - 1; i >= 0; i-- )
  +                {
  +                    DefaultConfiguration sample = new DefaultConfiguration( "sample", "-"
);
  +                    sample.setValue( Integer.toString( history[i] ) );
  +                    samples.addChild( sample );
  +                }
               }
               state.addChild( samples );
               
  @@ -418,20 +439,55 @@
               //  First sample is the current value, following sames go back in
               //   time from newest to oldest.
               Configuration history = state.getChild( "history" );
  -            Configuration samples[] = history.getChildren( "sample" );
               
  +            Configuration samples[] = history.getChildren( "sample" );
  +            int[] sampleValues;
  +            if ( samples.length == 0 )
  +            {
  +                // No sample children.  The data may be stored in compact form
  +                String compactSamples = history.getValue();
  +                
  +                // Sample values are stored in newest to oldest order.
  +                StringTokenizer st = new StringTokenizer( compactSamples, "," );
  +                sampleValues = new int[st.countTokens()];
  +                
  +                for ( int i = 0; i < sampleValues.length; i++ )
  +                {
  +                    try
  +                    {
  +                        sampleValues[i] = Integer.parseInt( st.nextToken() );
  +                    }
  +                    catch ( NumberFormatException e )
  +                    {
  +                        throw new ConfigurationException( "The compact sample data could
not be " +
  +                            "loaded, because of a number format problem, for ProfileSample:
" +
  +                            m_name ); 
  +                    }
  +                }
  +            }
  +            else
  +            {
  +                // Sample data stored as individual elements
  +                sampleValues = new int[ samples.length ];
  +                
  +                // Sample values are stored in newest to oldest order.
  +                for ( int i = 0; i < samples.length; i++ )
  +                {
  +                    sampleValues[i] = samples[ i ].getValueAsInteger();
  +                }
  +            }
               
               // Get the current value
               int value;
  -            if ( samples.length > 0 )
  +            if ( sampleValues.length > 0 )
               {
  -                value = samples[0].getValueAsInteger();
  +                value = sampleValues[0];
                   
                   for ( int i = 0; i < m_size - 1; i++ )
                   {
  -                    if ( i < samples.length - 1 )
  +                    if ( i < sampleValues.length - 1 )
                       {
  -                        m_historyOld[ m_size - 2 - i ] = samples[ i + 1 ].getValueAsInteger();
  +                        m_historyOld[ m_size - 2 - i ] = sampleValues[ i + 1 ];
                       }
                       else
                       {
  
  
  
  1.6       +8 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/DefaultProfilerManager.java
  
  Index: DefaultProfilerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/DefaultProfilerManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultProfilerManager.java	5 Mar 2002 16:35:59 -0000	1.5
  +++ DefaultProfilerManager.java	6 Mar 2002 06:45:04 -0000	1.6
  @@ -36,7 +36,7 @@
   /**
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2002/03/05 16:35:59 $
  + * @version CVS $Revision: 1.6 $ $Date: 2002/03/06 06:45:04 $
    * @since 4.1
    */
   public class DefaultProfilerManager
  @@ -56,6 +56,9 @@
       /** Save state interval. */
       private long m_stateInterval;
       
  +    /** Use a compact format when saving profile sample data. */
  +    private boolean m_stateCompactSamples;
  +    
       /** Last time that the state was saved. */
       private long m_lastStateSave;
       
  @@ -138,6 +141,9 @@
               // Configure the state file.
               Configuration stateFileConf = configuration.getChild( "state-file" );
               m_stateInterval = stateFileConf.getAttributeAsLong( "interval", 60000 );
  +            m_stateCompactSamples = 
  +                stateFileConf.getAttributeAsBoolean( "use-compact-samples", true );
  +            
               String stateFile = stateFileConf.getValue( null );
               if ( stateFile != null )
               {
  @@ -404,7 +410,7 @@
               //  that will contain profile samples.
               if ( profilableProxies[i].isConfigured() )
               {
  -                state.addChild( profilableProxies[i].saveState() );
  +                state.addChild( profilableProxies[i].saveState( m_stateCompactSamples )
);
               }
           }
           
  
  
  
  1.5       +6 -3      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfilableProxy.java
  
  Index: ProfilableProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfilableProxy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProfilableProxy.java	5 Mar 2002 16:35:59 -0000	1.4
  +++ ProfilableProxy.java	6 Mar 2002 06:45:04 -0000	1.5
  @@ -22,7 +22,7 @@
    * Not Synchronized.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/03/05 16:35:59 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/03/06 06:45:04 $
    * @since 4.1
    */
   class ProfilableProxy
  @@ -308,9 +308,12 @@
       /**
        * Saves the current state into a Configuration.
        *
  +     * @param useCompactSamples Flag for whether or not ProfileSample data
  +     *                          should be saved in compact format or not.
  +     *
        * @return The state as a Configuration.
        */
  -    Configuration saveState()
  +    Configuration saveState( boolean useCompactSamples )
       {
           DefaultConfiguration state = new DefaultConfiguration( "profilable", "-" );
           state.addAttribute( "name", m_name );
  @@ -322,7 +325,7 @@
               //  that will contain profile samples.
               if ( proxies[i].isConfigured() )
               {
  -                state.addChild( proxies[i].saveState() );
  +                state.addChild( proxies[i].saveState( useCompactSamples ) );
               }
           }
           
  
  
  
  1.4       +6 -3      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfilePointProxy.java
  
  Index: ProfilePointProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfilePointProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProfilePointProxy.java	5 Mar 2002 12:34:32 -0000	1.3
  +++ ProfilePointProxy.java	6 Mar 2002 06:45:04 -0000	1.4
  @@ -29,7 +29,7 @@
    *  It is resolved when the Profilable actually registers the ProfilePoint.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2002/03/05 12:34:32 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/03/06 06:45:04 $
    * @since 4.1
    */
   public class ProfilePointProxy
  @@ -708,9 +708,12 @@
       /**
        * Saves the current state into a Configuration.
        *
  +     * @param useCompactSamples Flag for whether or not ProfileSample data
  +     *                          should be saved in compact format or not.
  +     *
        * @return The state as a Configuration.
        */
  -    Configuration saveState()
  +    Configuration saveState( boolean useCompactSamples )
       {
           DefaultConfiguration state = new DefaultConfiguration( "profile-point", "-" );
           state.addAttribute( "name", m_name );
  @@ -718,7 +721,7 @@
           ProfileSample[] samples = getProfileSamples();
           for ( int i = 0; i < samples.length; i++ )
           {
  -            state.addChild( samples[i].saveState() );
  +            state.addChild( samples[i].saveState( useCompactSamples ) );
           }
           
           return state;
  
  
  
  1.3       +5 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfileSample.java
  
  Index: ProfileSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/ProfileSample.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProfileSample.java	5 Mar 2002 12:34:32 -0000	1.2
  +++ ProfileSample.java	6 Mar 2002 06:45:04 -0000	1.3
  @@ -16,7 +16,7 @@
    * Access to ProfileSamples are synchronized through the ProfileDataSet.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2002/03/05 12:34:32 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/03/06 06:45:04 $
    * @since 4.1
    */
   public interface ProfileSample
  @@ -110,9 +110,12 @@
       /**
        * Saves the current state into a Configuration.
        *
  +     * @param useCompactSamples Flag for whether or not ProfileSample data
  +     *                          should be saved in compact format or not.
  +     *
        * @return The state as a Configuration.
        */
  -    Configuration saveState();
  +    Configuration saveState( boolean useCompactSamples );
       
       /**
        * Loads the state into the ProfileSample.
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message