cziegeler    2002/06/27 03:06:57

  Modified:    .        changes.xml
               src/java/org/apache/cocoon/components/profiler
                        ProfilerData.java ProfilerGenerator.java
                        ProfilingCachingProcessingPipeline.java
                        ProfilingNonCachingProcessingPipeline.java
                        ProfilingSAXConnector.java
               src/webapp/WEB-INF cocoon.xconf
  Log:
  Refactored the profiling code, no need for sax connectors anymore
  
  Revision  Changes    Path
  1.196     +5 -2      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.195
  retrieving revision 1.196
  diff -u -r1.195 -r1.196
  --- changes.xml       24 Jun 2002 20:32:18 -0000      1.195
  +++ changes.xml       27 Jun 2002 10:06:56 -0000      1.196
  @@ -25,6 +25,7 @@
     <person name="Berin Loritsch" email="[EMAIL PROTECTED]" id="BL"/>
     <person name="Stefano Mazzocchi" email="[EMAIL PROTECTED]" id="SM"/>
     <person name="Stephan Michels" email="[EMAIL PROTECTED]" id="SMS"/>
  +  <person name="John Morrison" email="[EMAIL PROTECTED]" id="JM"/>
     <person name="Giacomo Pati" email="[EMAIL PROTECTED]" id="GP"/>
     <person name="Konstantin Piroumian" email="[EMAIL PROTECTED]" id="KP"/>
     <person name="Ovidiu Predescu" email="[EMAIL PROTECTED]" id="OP"/>
  @@ -35,10 +36,12 @@
     <person name="Davanum Srinivas" email="[EMAIL PROTECTED]" id="DM"/>
     <person name="Sylvain Wallez" email="[EMAIL PROTECTED]" id="SW"/>
     <person name="Carsten Ziegeler" email="[EMAIL PROTECTED]" id="CZ"/>
  -  <person name="John Morrison" email="[EMAIL PROTECTED]" id="JM"/>
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="CZ" type="update">
  +   Updated the profiler code, removed the need of SAXConnectors.
  +  </action>
     <action dev="SW" type="add">
      Extend the syntax of sitemap variable substitution : variables can have a prefix 
which
      indicates an InputModule where to get the value from. For example, the expression
  
  
  
  1.6       +1 -12     
xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerData.java
  
  Index: ProfilerData.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerData.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProfilerData.java 26 Jun 2002 14:07:22 -0000      1.5
  +++ ProfilerData.java 27 Jun 2002 10:06:56 -0000      1.6
  @@ -95,17 +95,6 @@
           a.add(new Entry(component, role, source));
       }
   
  -    public int indexOf(Object component)
  -    {
  -        for(int i=0; i<a.size(); i++){
  -            // FIXME - this does not work if caching is used, as
  -            //         a transformer might be compared with an XMLTeePipe
  -            if(((Entry)a.get(i)).component == component)
  -                return i;
  -        }
  -        return -1;
  -    }
  -
       public void setTime(int i, long time)
       {
           ((Entry)a.get(i)).time = time;
  
  
  
  1.6       +14 -18    
xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerGenerator.java
  
  Index: ProfilerGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerGenerator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProfilerGenerator.java    22 Feb 2002 07:00:11 -0000      1.5
  +++ ProfilerGenerator.java    27 Jun 2002 10:06:56 -0000      1.6
  @@ -50,11 +50,8 @@
   */
   package org.apache.cocoon.components.profiler;
   
  -import org.apache.avalon.excalibur.pool.Recyclable;
  -import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
   import org.apache.cocoon.generation.ComposerGenerator;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
  @@ -71,8 +68,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vadim Gritsenko</a>
    * @version CVS $Id$
    */
  -public class ProfilerGenerator extends ComposerGenerator
  -implements Recyclable, Composable, Disposable {
  +public class ProfilerGenerator
  +extends ComposerGenerator {
   
       /**
        * The XML namespace for the output document.
  @@ -81,21 +78,20 @@
   
       private Profiler profiler;
   
  -
  -    public void compose(ComponentManager manager) throws ComponentException
  -    {
  +    /**
  +     * Composable
  +     */
  +    public void compose(ComponentManager manager)
  +    throws ComponentException {
           super.compose(manager);
  -
  -        try{
  -            this.profiler = (Profiler)super.manager.lookup(Profiler.ROLE);
  -        }catch(Exception e){
  -            e.printStackTrace();
  -        }
  +        this.profiler = (Profiler)super.manager.lookup(Profiler.ROLE);
       }
   
  -    public void dispose()
  -    {
  -        if(this.profiler != null){
  +    /**
  +     * Disposable
  +     */
  +    public void dispose() {
  +        if (this.profiler != null){
               super.manager.release(this.profiler);
               this.profiler = null;
           }
  
  
  
  1.3       +40 -13    
xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java
  
  Index: ProfilingCachingProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProfilingCachingProcessingPipeline.java   25 Jun 2002 06:09:01 -0000      1.2
  +++ ProfilingCachingProcessingPipeline.java   27 Jun 2002 10:06:56 -0000      1.3
  @@ -59,6 +59,8 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline;
   import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.xml.XMLConsumer;
  +import org.apache.cocoon.xml.XMLProducer;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vadim Gritsenko</a>
  @@ -67,28 +69,38 @@
   public class ProfilingCachingProcessingPipeline
       extends CachingProcessingPipeline {
   
  -    private ComponentManager manager;
       private Profiler profiler;
   
       private ProfilerData data = null;
   
  +    private int index = 0;
   
  +    /**
  +     * Composable
  +     */
       public void compose(ComponentManager manager)
       throws ComponentException {
           super.compose(manager);
  -
  -        this.manager = manager;
           this.profiler = (Profiler)manager.lookup(Profiler.ROLE);
       }
   
  +    /**
  +     * Disposable
  +     */
       public void dispose() {
  -        super.dispose();
  -
           if(this.profiler != null){
               this.manager.release(this.profiler);
               this.profiler = null;
           }
  -        this.manager = null;
  +        super.dispose();
  +    }
  +
  +    /**
  +     * Recyclable
  +     */
  +    public void recycle() {
  +        this.data = null;
  +        super.recycle();
       }
   
       public void setGenerator (String role, String source, Parameters param)
  @@ -111,10 +123,9 @@
   
       public boolean process(Environment environment)
       throws ProcessingException {
  -        // FIXME - If a reader is used, data is not set
  +        this.index = 0;
           if (this.data != null) {
               this.data.addComponent(super.lastConsumer, null, null);
  -            environment.getObjectModel().put("profiler", data);
   
               // Execute pipeline
               long time = System.currentTimeMillis();
  @@ -125,12 +136,28 @@
               profiler.addResult(environment.getURI(), data);
               return result;
           } else {
  -            return super.process( environment );
  +            this.data = new ProfilerData();
  +            long time = System.currentTimeMillis();
  +            boolean result = super.process( environment );
  +            this.data.setTime(0, System.currentTimeMillis() - time);
  +            // Report
  +            profiler.addResult(environment.getURI(), data);
  +            return result;
           }
       }
   
  -    public void recycle() {
  -        this.data = null;
  -        super.recycle();
  +    /**
  +     * Connect the next component
  +     */
  +    protected void connect(Environment environment,
  +                           XMLProducer producer,
  +                           XMLConsumer consumer)
  +    throws ProcessingException {
  +        ProfilingSAXConnector connector = new ProfilingSAXConnector();
  +        connector.setup(this.index, this.data);
  +        this.index++;
  +        super.connect(environment, producer, connector);
  +        super.connect(environment, connector, consumer);
       }
  +
   }
  
  
  
  1.3       +41 -13    
xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
  
  Index: ProfilingNonCachingProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProfilingNonCachingProcessingPipeline.java        25 Jun 2002 06:09:01 -0000     
 1.2
  +++ ProfilingNonCachingProcessingPipeline.java        27 Jun 2002 10:06:56 -0000     
 1.3
  @@ -59,6 +59,8 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline;
   import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.xml.XMLConsumer;
  +import org.apache.cocoon.xml.XMLProducer;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vadim Gritsenko</a>
  @@ -68,33 +70,44 @@
       extends NonCachingProcessingPipeline
       implements Disposable {
   
  -    private ComponentManager manager;
       private Profiler profiler;
   
       private ProfilerData data = null;
   
  +    private int index = 0;
   
  +    /**
  +     * Composable
  +     */
       public void compose(ComponentManager manager)
       throws ComponentException {
           super.compose(manager);
  -
  -        this.manager = manager;
           this.profiler = (Profiler)manager.lookup(Profiler.ROLE);
       }
   
  +    /**
  +     * Disposable
  +     */
       public void dispose() {
           if (this.profiler != null){
               this.manager.release(this.profiler);
               this.profiler = null;
           }
  -        this.manager = null;
  +    }
  +
  +    /**
  +     * Recyclable
  +     */
  +    public void recycle() {
  +        this.data = null;
  +        super.recycle();
       }
   
       public void setGenerator (String role, String source, Parameters param)
       throws ProcessingException {
           super.setGenerator(role, source, param);
   
  -        if(this.data == null)
  +        if (this.data == null)
               this.data = new ProfilerData();
           this.data.setGenerator(super.generator, role, source);
       }
  @@ -103,17 +116,16 @@
       throws ProcessingException {
           super.addTransformer(role, source, param);
   
  -        if(this.data == null)
  +        if (this.data == null)
               this.data = new ProfilerData();
           this.data.addComponent(super.transformers.get(super.transformers.size()-1), 
role, source);
       }
   
       public boolean process(Environment environment)
       throws ProcessingException {
  -        // FIXME - If a reader is used, data is not set
  +        this.index = 0;
           if (this.data != null) {
               this.data.addComponent(super.lastConsumer, null, null);
  -            environment.getObjectModel().put("profiler", data);
   
               // Execute pipeline
               long time = System.currentTimeMillis();
  @@ -124,12 +136,28 @@
               profiler.addResult(environment.getURI(), data);
               return result;
           } else {
  -            return super.process( environment );
  +            this.data = new ProfilerData();
  +            long time = System.currentTimeMillis();
  +            boolean result = super.process( environment );
  +            this.data.setTime(0, System.currentTimeMillis() - time);
  +            // Report
  +            profiler.addResult(environment.getURI(), data);
  +            return result;
           }
       }
   
  -    public void recycle() {
  -        this.data = null;
  -        super.recycle();
  +    /**
  +     * Connect the next component
  +     */
  +    protected void connect(Environment environment,
  +                           XMLProducer producer,
  +                           XMLConsumer consumer)
  +    throws ProcessingException {
  +        ProfilingSAXConnector connector = new ProfilingSAXConnector();
  +        connector.setup(this.index, this.data);
  +        this.index++;
  +        super.connect(environment, producer, connector);
  +        super.connect(environment, connector, consumer);
       }
  +
   }
  
  
  
  1.6       +9 -44     
xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingSAXConnector.java
  
  Index: ProfilingSAXConnector.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingSAXConnector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProfilingSAXConnector.java        13 May 2002 16:06:52 -0000      1.5
  +++ ProfilingSAXConnector.java        27 Jun 2002 10:06:56 -0000      1.6
  @@ -50,27 +50,16 @@
   */
   package org.apache.cocoon.components.profiler;
   
  -import org.apache.avalon.excalibur.pool.Recyclable;
  -import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.components.saxconnector.SAXConnector;
  -import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.xml.AbstractXMLPipe;
  -import org.apache.cocoon.xml.XMLConsumer;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   
  -import java.io.IOException;
  -import java.util.Map;
  -
   /**
    * This SAX connector measures time taken by the following SAX handler.
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vadim Gritsenko</a>
    * @version CVS $Id$
    */
  -public class ProfilingSAXConnector extends AbstractXMLPipe
  -    implements Recyclable, SAXConnector
  -{
  +public class ProfilingSAXConnector extends AbstractXMLPipe {
       private ProfilerData data;
       private int index;
       private long time;
  @@ -79,42 +68,18 @@
       /**
        * Setup this SAXConnector.
        */
  -    public void setup(SourceResolver resolver, Map objectModel, String src, 
Parameters params)
  -        throws ProcessingException, SAXException, IOException
  -    {
  -        this.data = (ProfilerData)objectModel.get("profiler");
  -    }
  -
  -    /**
  -     * Recycle the SAXConnector
  -     */
  -    public void recycle()
  -    {
  -        this.data = null;
  -        this.time = this.total = 0;
  -        this.index = -1;
  -        super.recycle();
  -    }
  -
  -    public void setConsumer(XMLConsumer consumer)
  -    {
  -        super.setConsumer(consumer);
  -        if(this.data != null)
  -            this.index = this.data.indexOf(consumer);
  -        else
  -            this.index = -1;
  +    public void setup(int index, ProfilerData data) {
  +        this.index = index;
  +        this.data = data;
       }
   
  -
  -    public void startDocument() throws SAXException
  -    {
  +    public void startDocument() throws SAXException {
           time = System.currentTimeMillis();
           super.startDocument();
           total += System.currentTimeMillis() - time;
       }
   
  -    public void endDocument() throws SAXException
  -    {
  +    public void endDocument() throws SAXException {
           time = System.currentTimeMillis();
           super.endDocument();
           total += System.currentTimeMillis() - time;
  @@ -122,8 +87,8 @@
               data.setTime(index, total);
       }
   
  -    public void startPrefixMapping(String prefix, String uri) throws SAXException
  -    {
  +    public void startPrefixMapping(String prefix, String uri)
  +    throws SAXException {
           time = System.currentTimeMillis();
           super.startPrefixMapping(prefix, uri);
           total += System.currentTimeMillis() - time;
  
  
  
  1.25      +1 -3      xml-cocoon2/src/webapp/WEB-INF/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/WEB-INF/cocoon.xconf,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- cocoon.xconf      27 May 2002 14:02:30 -0000      1.24
  +++ cocoon.xconf      27 Jun 2002 10:06:57 -0000      1.25
  @@ -458,16 +458,14 @@
       Connects the various pipeline components.
       LoggingSAXConnector logs SAX events between pipeline components
       into cocoon's log file.
  -    ProfilingSAXConnector gathers timing information.
       Uncomment one of the following lines for using the SAXConnector.
     <sax-connector 
class="org.apache.cocoon.components.saxconnector.LoggingSAXConnector"/>
  -  <sax-connector 
class="org.apache.cocoon.components.profiler.ProfilingSAXConnector"/>
     -->
   
     <!-- Profiler:
       The profiler facilitates the gathering of statistics about timings of
       different steps of pipelines. Profiler consists of several components:
  -     profiling pipeline, profiling SAX connector, and profiler generator
  +     profiling pipeline and profiler generator
       which are used to generate the profile report. You need to enable all of
       these components to use profiler.
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to