avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile AbstractProfilePoint.java CSVProfiler.java EventsPerSampleProfilePoint.java PeekValueProfilePoint.java Profilable.java ProfilePoint.java Profiler.java ValueProfilePoint.java
Date Thu, 13 Dec 2001 19:36:48 GMT
bloritsch    01/12/13 11:36:48

  Added:       src/scratchpad/org/apache/avalon/excalibur/profile
                        AbstractProfilePoint.java CSVProfiler.java
                        EventsPerSampleProfilePoint.java
                        PeekValueProfilePoint.java Profilable.java
                        ProfilePoint.java Profiler.java
                        ValueProfilePoint.java
  Log:
  add profile to excalibur
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/AbstractProfilePoint.java
  
  Index: AbstractProfilePoint.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The ProfilPoint interface is to mark objects that can be sampled by a
   * Profiler. The interface only has one sampling method to simplify the items
   * that can be sampled.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class AbstractProfilePoint implements ProfilePoint
  {
      private final String m_name;
  
      /**
       * Initializes the ProfilePoint with a name.
       */
      public AbstractProfilePoint( String name )
      {
          m_name = name;
      }
  
      /**
       * Get the ProfilePoint's name.  The Profiler uses this so that the
       * heading for the sample data makes sense.
       */
      public final String getName()
      {
          return m_name;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/CSVProfiler.java
  
  Index: CSVProfiler.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Set;
  import java.util.HashSet;
  
  /**
   * This Profiler is a simple implementation that serializes the values in
   * a Comma Separated Value (CSV) file.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class CSVProfiler implements Profiler, Startable
  {
      private Set m_profilables = new HashSet();
      private Thread m_thread = null;
      /**
       * Adds a target to profile, along with a name for the target.  Good names
       * include what the expected samples are.  For instance "ThreadController:
       * number of threads" or "EventQueue: events processed per second".  The real
       * results come from the Profilable object itself, but the name is so humans
       * have a reference for the values.  NOTE: if the Profilable class does
       * not expose any ProfilePoints, it is excluded from the list of Profilable
       * classes that are notified when the Profiler is active.
       *
       * @parameter  profileSource  The actual source of the samples
       */
      void add( Profilable profileSource );
  
      /**
       * Serializes the results of the profiling to a file.  The actual format
       * depends on the Profiler in use.  It can be simple Comma Separated Values
       * (CSV) with the columns representing a unique Profilable.  Most spreadsheet
       * programs can import this and generate meaningful graphs from it.  Another
       * alternative is to output the information in a tool specific format.  The
       * actual format depends on the Profiler in question, and the Profiler merely
       * needs the reference to the output file.
       *
       * @parameter  outputInfo  The handle of the file the profiler serializes the
       *                         results to.
       *
       * @throws <code>IOException</code> If the file is not valid, or cannot
be
       *         written to.
       */
      void serialize( File outputInfo ) throws IOException;
  }
  
  private class Sampler implements Runnable
  {
      private final Set m_profilables;
      private final File m_outputFile;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/EventsPerSampleProfilePoint.java
  
  Index: EventsPerSampleProfilePoint.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The ProfilPoint interface is to mark objects that can be sampled by a
   * Profiler. The interface only has one sampling method to simplify the items
   * that can be sampled.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class EventsPerSampleProfilePoint extends AbstractProfilePoint
  {
      private       int    m_value = 0;
  
      /**
       * Creates a EventsPerSampleProfilePoint with an initial name.
       */
      public EventsPerSampleProfilePoint( String name )
      {
          super( name );
      }
  
      /**
       * Set the sample value
       */
      public void increment( )
      {
          m_value++;
      }
  
      /**
       * Obtain the sample.  All samples are an integer, so the profiled objects
       * must measure quantity (numbers of items), rate (items/period), time in
       * milliseconds, etc.
       */
      public int getSample()
      {
          final int returnValue = m_value;
          m_value = 0;
  
          return returnValue;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/PeekValueProfilePoint.java
  
  Index: PeekValueProfilePoint.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The ProfilPoint interface is to mark objects that can be sampled by a
   * Profiler. The interface only has one sampling method to simplify the items
   * that can be sampled.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class PeekValueProfilePoint extends AbstractProfilePoint
  {
      private       int    m_value = 0;
  
      /**
       * Creates a PeekValueProfilePoint with an initial name.
       */
      public PeekValueProfilePoint( String name )
      {
          super( name );
      }
  
      /**
       * Set the sample value
       */
      public void setValue( int currentValue )
      {
          if ( currentValue > m_value )
          {
              m_value = currentValue;
          }
      }
  
      /**
       * Obtain the sample.  All samples are an integer, so the profiled objects
       * must measure quantity (numbers of items), rate (items/period), time in
       * milliseconds, etc.
       */
      public int getSample()
      {
          return m_value;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/Profilable.java
  
  Index: Profilable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The Profilable interface is to mark objects that can be sampled by a Profiler.
   * The interface provides a method to initialize the profiler, plus two methods
   * to provide an optimization cue for the object (when it is safe not to track
   * events).
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Profilable
  {
      /**
       * Obtain a reference to all the ProfilePoints that the Profilable
       * object wishes to expose.  All sampling is done directly through
       * the ProfilePoints as opposed to the Profilable interface.
       */
      ProfilePoint[] getProfilePoints();
  
      /**
       * The Profiler will call this method when it begins taking samples.
       * This is an optimization cue to the Profilable class.  It does take
       * resources to hold ProfilePoints and update them.  A class may keep
       * a <code>boolean</code> to flag whether the ProfilePoints are to be
       * maintained.
       */
      void startProfiling();
  
      /**
       * The Profiler will call this method when it no longer is interested
       * in taking samples.  It is an optimization cue to the Profilable
       * class so that it can release resources and stop maintaining the
       * ProfilePoints.
       */
      void stopProfiling();
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/ProfilePoint.java
  
  Index: ProfilePoint.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The ProfilPoint interface is to mark objects that can be sampled by a
   * Profiler. The interface only has one sampling method to simplify the items
   * that can be sampled.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface ProfilePoint
  {
      /**
       * Get the ProfilePoint's name.  The Profiler uses this so that the
       * heading for the sample data makes sense.
       */
      String getName();
  
      /**
       * Obtain the sample.  All samples are an integer, so the profiled objects
       * must measure quantity (numbers of items), rate (items/period), time in
       * milliseconds, etc.
       */
      int getSample();
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/Profiler.java
  
  Index: Profiler.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  import java.io.File;
  import java.io.IOException;
  
  /**
   * The Profiler is used to determine numeric values for specific parts of the
   * Avalon environment.  The idea is to add references to Profilable objects to
   * the Profiler.  The Profiler takes periodic snapshots of the running system
   * so that performance or resource usage can be assertained.  The sample duration
   * is dependant on the Profiler's settings, and should never change during the
   * time the Profiler is running.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Profiler
  {
      /**
       * Adds a target to profile, along with a name for the target.  Good names
       * include what the expected samples are.  For instance "ThreadController:
       * number of threads" or "EventQueue: events processed per second".  The real
       * results come from the Profilable object itself, but the name is so humans
       * have a reference for the values.  NOTE: if the Profilable class does
       * not expose any ProfilePoints, it is excluded from the list of Profilable
       * classes that are notified when the Profiler is active.
       *
       * @parameter  profileSource  The actual source of the samples
       */
      void add( Profilable profileSource );
  
      /**
       * Serializes the results of the profiling to a file.  The actual format
       * depends on the Profiler in use.  It can be simple Comma Separated Values
       * (CSV) with the columns representing a unique Profilable.  Most spreadsheet
       * programs can import this and generate meaningful graphs from it.  Another
       * alternative is to output the information in a tool specific format.  The
       * actual format depends on the Profiler in question, and the Profiler merely
       * needs the reference to the output file.
       *
       * @parameter  outputInfo  The handle of the file the profiler serializes the
       *                         results to.
       *
       * @throws <code>IOException</code> If the file is not valid, or cannot
be
       *         written to.
       */
      void serialize( File outputInfo ) throws IOException;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/profile/ValueProfilePoint.java
  
  Index: ValueProfilePoint.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.framework.profile;
  
  /**
   * The ProfilPoint interface is to mark objects that can be sampled by a
   * Profiler. The interface only has one sampling method to simplify the items
   * that can be sampled.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public class ValueProfilePoint extends AbstractProfilePoint
  {
      private       int    m_value = 0;
  
      /**
       * Creates a ValueProfilePoint with an initial name.
       */
      public ValueProfilePoint( String name )
      {
          super( name );
      }
  
      /**
       * Set the sample value
       */
      public void setValue( int currentValue )
      {
          m_value = currentValue;
      }
  
      /**
       * Obtain the sample.  All samples are an integer, so the profiled objects
       * must measure quantity (numbers of items), rate (items/period), time in
       * milliseconds, etc.
       */
      public int getSample()
      {
          return m_value;
      }
  }
  
  
  

--
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