stephan 2002/09/03 00:44:32 Modified: src/java/org/apache/cocoon/components/profiler Profiler.java ProfilerData.java ProfilerResult.java ProfilingCachingProcessingPipeline.java ProfilingNonCachingProcessingPipeline.java ProfilingXMLPipe.java profiler.xconf profiler.xroles Added: src/java/org/apache/cocoon/components/profiler EnvironmentInfo.java ProfilerImpl.java Removed: src/java/org/apache/cocoon/components/profiler ProfilingSAXBufferConnector.java ProfilingSAXConnector.java SimpleProfiler.java Log: Extend the profiler components to store intermediate SAX fragments, and also the some informations about the environment, thanks to Bruno Dumon. Revision Changes Path 1.7 +16 -8 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/Profiler.java Index: Profiler.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/Profiler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Profiler.java 20 Aug 2002 16:15:27 -0000 1.6 +++ Profiler.java 3 Sep 2002 07:44:31 -0000 1.7 @@ -58,6 +58,7 @@ * Profiler component interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> * @version CVS $Id$ */ public interface Profiler extends Component @@ -70,32 +71,39 @@ void clearResults(); /** - * Remove the specified result. + * Remove a specified result. + * + * @param key Key of the result. */ void clearResult(Object key); /** - * + * Add a result for a request. + * + * @param uri URI of the request + * @param data Result of the profiling */ void addResult(String uri, ProfilerData data); /** + * Returns a collection of all keys * + * @return Keys of all results. */ Collection getResultKeys(); /** + * Returns a collection of the results. * + * @return Collection of results. */ Collection getResults(); /** + * Returns a result of a specifed key. * + * @param key Key of the result. + * @return Result. */ ProfilerResult getResult(Object key); - - /** - * Create a XMLPipe component to profile the request. - */ - public ProfilingXMLPipe createConnector(); } 1.9 +92 -36 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ProfilerData.java 21 Aug 2002 15:37:58 -0000 1.8 +++ ProfilerData.java 3 Sep 2002 07:44:31 -0000 1.9 @@ -58,67 +58,137 @@ * Request-time profiler information. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> * @version CVS $Id$ */ public class ProfilerData { - class Entry + /** + * Entry, which stores the role and source of a component from a pipeline. + */ + public class Entry { - Object component; - String role; - String source; - long time; - - Entry(Object c, String r, String s) - { - component = c; - role = r; - source = s; + public String role; + public String source; + public long time; + public Object fragment; + + private Entry(String role, String source) { + this.role = role; + this.source = source; } } - private ArrayList a = null; + // List of all entries + private ArrayList entries = null; + + // Environment information + private EnvironmentInfo environmentinfo; + // Measured total time private long totaltime = 0; public ProfilerData() { - a = new ArrayList(); + entries = new ArrayList(); } /** * Add new component from the pipeling, which should be measured. + * + * @param component Component of the pipeline. + * @param role Role of the component. + * @param source Source attribute of the component. */ public void addComponent(Object component, String role, String source) { - a.add(new Entry(component, role, source)); + entries.add(new Entry(role!=null?role:component.getClass().getName(), source)); + } + + /** + * Set the environment information. + * + * @param environmentinfo Environment information. + */ + public void setEnvironmentInfo(EnvironmentInfo environmentinfo) { + this.environmentinfo = environmentinfo; + } + + /** + * Returns the environment information. + * + * @return Environment information. + */ + public EnvironmentInfo getEnvironmentInfo() { + return this.environmentinfo; + } + + /** + * Set measured time of precessing from the pipeline. + * + * @param time Total time of all components. + */ + public void setTotalTime(long time) { + this.totaltime = time; + } + + /** + * Return measured time of precessing from the pipeline. + * + * @return Total time of all components. + */ + public long getTotalTime() { + return this.totaltime; } /** * Set measured time of the i-th component of the pipeline. + * + * @param index Index of the component. + * @param time Measured time of the component. */ - public void setTime(int i, long time) { - ((Entry)a.get(i)).time = time; + public void setTime(int index, long time) { + ((Entry)entries.get(index)).time = time; } /** * Get measured time of the i-th component of the pipeline. + * + * @return Measured time of the component. + */ + public long getTime(int index) { + return ((Entry)entries.get(index)).time; + } + + /** + * Set the SAX fragment for the i-th component of the pipeline. + * + * @param index Index of the component. + * @param fragment SAX fragment of the component. */ - public long setTime(int i) { - return ((Entry)a.get(i)).time; + public void setSAXFragment(int index, Object fragment) + { + ((Entry)entries.get(index)).fragment = fragment; } /** * Returns all measured times. + * + * @return Array of all entries. */ public Entry[] getEntries() { - return (Entry[])a.toArray(new Entry[a.size()]); + return (Entry[])entries.toArray(new Entry[entries.size()]); } + /** + * Generate a key for a given URI for this pipeline + * + * @return Hash key. + */ public long getKey(String uri) { StringBuffer key = new StringBuffer(uri); - for(int i=0; i<a.size(); i++){ - Entry entry = (Entry)a.get(i); + for(int i=0; i<entries.size(); i++){ + Entry entry = (Entry)entries.get(i); key.append(':'); key.append(entry.role); @@ -126,20 +196,6 @@ key.append(entry.source); } return HashUtil.hash(key); - } - - /** - * Set measured time of precessing from the pipeline. - */ - public void setTotalTime(long time) { - this.totaltime = time; - } - - /** - * Return measured time of precessing from the pipeline. - */ - public long getTotalTime() { - return this.totaltime; } /* 1.6 +59 -37 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerResult.java Index: ProfilerResult.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerResult.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProfilerResult.java 20 Aug 2002 16:15:27 -0000 1.5 +++ ProfilerResult.java 3 Sep 2002 07:44:31 -0000 1.6 @@ -53,13 +53,17 @@ import java.util.Arrays; /** - * Represents data collected about one pipeline. + * A ProfilerResult stores a collection of the lastest n ProfilerDatas + * for one pipeline. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a> * @version CVS $Id$ */ -public class ProfilerResult -{ +public class ProfilerResult { + + // URI of the request private String uri; // Roles of the sitemap components @@ -71,107 +75,125 @@ // Count of the ProfilerData entries private int count = 0; + // Environment information of each request. + private EnvironmentInfo[] latestEnvironmentInfo; + // Total times of each request private long[] totalTime; // Times of each component of the latest n-requests private long[][] latestTimes; - // Which row of 'latestTimes' are lastest - private int latestCurrent = 0; + // SAX fragments of eac component of the latest n-requests + private Object[][] latestFragments; - public ProfilerResult(String uri, int latestResultsCount) - { + public ProfilerResult(String uri, int latestResultsCount) { this.uri = uri; + this.latestEnvironmentInfo = new EnvironmentInfo[(latestResultsCount>0)?latestResultsCount:5]; this.latestTimes = new long[(latestResultsCount>0)?latestResultsCount:5][]; this.totalTime = new long[(latestResultsCount>0)?latestResultsCount:5]; + this.latestFragments = new Object[(latestResultsCount>0)?latestResultsCount:5][]; + this.count = 0; } /** * Add a new profiler data from a request to the result. */ - public void addData(ProfilerData data) - { + public void addData(ProfilerData data) { ProfilerData.Entry[] entries = data.getEntries(); synchronized(this){ if(roles == null || roles.length != entries.length){ - // Reinitialize arrays + // Reinitialize arrays about the pipeline roles = new String[entries.length]; sources = new String[entries.length]; for(int i=0; i<entries.length; i++){ roles[i] = entries[i].role; - if(roles[i] == null) - roles[i] = entries[i].component.getClass().getName(); sources[i] = entries[i].source; } // Clear counter - count = 0; + this.count = 0; } - long[] latest = new long[entries.length]; - for(int i=0; i<entries.length; i++) - latest[i] = entries[i].time; - - if(latestTimes != null){ - latestTimes[latestCurrent] = latest; - totalTime[latestCurrent++] = data.getTotalTime(); - if(latestCurrent >= latestTimes.length) latestCurrent = 0; - } + if (latestTimes != null) { + // move the current data + for (int i = latestTimes.length - 1; i > 0; i--) { + latestEnvironmentInfo[i] = latestEnvironmentInfo[i - 1]; + totalTime[i] = totalTime[i - 1]; + latestTimes[i] = latestTimes[i - 1]; + latestFragments[i] = latestFragments[i - 1]; + } + latestEnvironmentInfo[0] = data.getEnvironmentInfo(); + totalTime[0] = data.getTotalTime(); + latestTimes[0] = new long[entries.length]; + for(int i=0; i<entries.length; i++) + this.latestTimes[0][i] = entries[i].time; + latestFragments[0] = new Object[entries.length]; + for(int i=0; i<entries.length; i++) + latestFragments[0][i] = entries[i].fragment; - if (count<latestTimes.length) - count++; + if (count<latestTimes.length) + count++; + } } } /** * The URI of the request. */ - public String getURI() - { + public String getURI() { return uri; } /** * Roles of the sitemap components. */ - public String[] getRoles() - { + public String[] getRoles() { return roles; } /** * Sources of the sitemap components. */ - public String[] getSources() - { + public String[] getSources() { return sources; } /** * Count of the ProfilerData entries */ - public int getCount() - { + public int getCount() { return count; } /** + * Environment infomation of the latest n-requests + */ + public EnvironmentInfo[] getLatestEnvironmentInfos() { + return latestEnvironmentInfo; + } + + /** * Total times of each request. */ - public long[] getTotalTime() - { + public long[] getTotalTime() { return totalTime; } /** * Times of each component of the latest n-requests */ - public long[][] getLastTimes() - { + public long[][] getLastTimes() { return latestTimes; } + /** + * SAX fragment of each component of the latest n-requests + */ + public Object[][] getLatestSAXFragments() { + return latestFragments; + } + /* public void report() { System.err.println("-------------------------------------------------------------------------------"); 1.6 +8 -4 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProfilingCachingProcessingPipeline.java 21 Aug 2002 15:37:58 -0000 1.5 +++ ProfilingCachingProcessingPipeline.java 3 Sep 2002 07:44:31 -0000 1.6 @@ -65,6 +65,7 @@ /** * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a> * @version CVS $Id$ */ public class ProfilingCachingProcessingPipeline @@ -90,7 +91,7 @@ * Disposable */ public void dispose() { - if(this.profiler != null){ + if (this.profiler != null){ this.manager.release(this.profiler); this.profiler = null; } @@ -186,13 +187,16 @@ this.index = 0; if (this.data != null) { + // Capture environment info + this.data.setEnvironmentInfo(new EnvironmentInfo(environment)); + // Execute pipeline long time = System.currentTimeMillis(); boolean result = super.process(environment); this.data.setTotalTime(System.currentTimeMillis() - time); // Report - profiler.addResult(environment.getURI(), data); + profiler.addResult(environment.getURI(), this.data); return result; } else { @@ -208,7 +212,7 @@ XMLProducer producer, XMLConsumer consumer) throws ProcessingException { - ProfilingXMLPipe connector = this.profiler.createConnector(); + ProfilingXMLPipe connector = new ProfilingXMLPipe(); connector.setup(this.index, this.data); this.index++; super.connect(environment, producer, connector); 1.6 +11 -3 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProfilingNonCachingProcessingPipeline.java 21 Aug 2002 15:37:58 -0000 1.5 +++ ProfilingNonCachingProcessingPipeline.java 3 Sep 2002 07:44:31 -0000 1.6 @@ -63,8 +63,13 @@ import org.apache.cocoon.xml.XMLProducer; /** + * Special version of the NonCachingProcessingPipeline that supports capturing + * the SAX-events that go through it and stores the result in the + * ProfilerData. + * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a> * @version CVS $Id$ */ public class ProfilingNonCachingProcessingPipeline @@ -186,13 +191,16 @@ this.index = 0; if (this.data != null) { + // Capture environment info + this.data.setEnvironmentInfo(new EnvironmentInfo(environment)); + // Execute pipeline long time = System.currentTimeMillis(); boolean result = super.process(environment); this.data.setTotalTime(System.currentTimeMillis() - time); // Report - profiler.addResult(environment.getURI(), data); + profiler.addResult(environment.getURI(), this.data); return result; } else { @@ -208,7 +216,7 @@ XMLProducer producer, XMLConsumer consumer) throws ProcessingException { - ProfilingXMLPipe connector = this.profiler.createConnector(); + ProfilingXMLPipe connector = new ProfilingXMLPipe(); connector.setup(this.index, this.data); this.index++; super.connect(environment, producer, connector); 1.2 +137 -5 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java Index: ProfilingXMLPipe.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProfilingXMLPipe.java 20 Aug 2002 16:15:27 -0000 1.1 +++ ProfilingXMLPipe.java 3 Sep 2002 07:44:31 -0000 1.2 @@ -50,19 +50,151 @@ */ package org.apache.cocoon.components.profiler; +import org.apache.cocoon.components.sax.XMLDeserializer; +import org.apache.cocoon.components.sax.XMLByteStreamCompiler; +import org.apache.cocoon.components.sax.XMLByteStreamInterpreter; +import org.apache.cocoon.components.sax.XMLSerializer; +import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLPipe; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; /** - * This interface glues together an XML producer and consumer to create a - * SAX pipe. This class make possible to profile. + * This SAX connector measures time taken by each Sitemap component. This + * class use the XMLSerializer/Interpreter to buffer the output, and to + * seperate the measurement of the time. The SAX fragments were also stored + * into the ProfilerData. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a> * @version CVS $Id$ */ -public interface ProfilingXMLPipe extends XMLPipe { +public class ProfilingXMLPipe implements XMLPipe { + + private XMLConsumer consumer; + + // Data of the profile + private ProfilerData data; + + // Index of the component + private int index; + + // Start time + private long time; + + // Time difference + private long total; + + private XMLDeserializer deserializer; + private XMLSerializer serializer; /** - * Setup this SAXPipe for profiling. + * Setup this XMLPipe. + * + * @param index Index of the component. + * @param data Data of the profile. */ - public void setup(int index, ProfilerData data); + public void setup(int index, ProfilerData data) { + this.index = index; + this.data = data; + + // FIXME Retrieve components from the CM + this.deserializer = new XMLByteStreamInterpreter(); + this.serializer = new XMLByteStreamCompiler(); + } + + /** + * Set the <code>XMLConsumer</code> that will receive XML data. + */ + public void setConsumer(XMLConsumer consumer) { + this.consumer = consumer; + } + + public void startDocument() throws SAXException { + this.time = System.currentTimeMillis(); // Startup time + + this.serializer.startDocument(); + } + + public void endDocument() throws SAXException { + this.total = System.currentTimeMillis() - this.time; + + this.serializer.endDocument(); + if (this.index != -1) + this.data.setTime(this.index, this.total); + + // push the content of the buffer through the next component + Object fragment = this.serializer.getSAXFragment(); + + if (this.index != -1) + this.data.setSAXFragment(this.index, fragment); + + this.deserializer.setConsumer(this.consumer); + this.deserializer.deserialize(fragment); + } + + public void setDocumentLocator(Locator locator) { + this.serializer.setDocumentLocator(locator); + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + this.serializer.startPrefixMapping(prefix, uri); + } + + public void endPrefixMapping(String prefix) throws SAXException { + this.serializer.endPrefixMapping(prefix); + } + + public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { + this.serializer.startElement(uri, loc, raw, a); + } + + public void endElement(String uri, String loc, String raw) throws SAXException { + this.serializer.endElement(uri, loc, raw); + } + + public void characters(char c[], int start, int len) throws SAXException { + this.serializer.characters(c, start, len); + } + + public void ignorableWhitespace(char c[], int start, int len) throws SAXException { + this.serializer.ignorableWhitespace(c, start, len); + } + + public void processingInstruction(String target, String data) throws SAXException { + this.serializer.processingInstruction(target, data); + } + + public void skippedEntity(String name) throws SAXException { + this.serializer.skippedEntity(name); + } + + public void startDTD(String name, String publicId, String systemId) throws SAXException { + this.serializer.startDTD(name, publicId, systemId); + } + + public void endDTD() throws SAXException { + this.serializer.endDTD(); + } + + public void startEntity(String name) throws SAXException { + this.serializer.startEntity(name); + } + + public void endEntity(String name) throws SAXException { + this.serializer.endEntity(name); + } + + public void startCDATA() throws SAXException { + this.serializer.startCDATA(); + } + + public void endCDATA() throws SAXException { + this.serializer.endCDATA(); + } + + public void comment(char ch[], int start, int len) throws SAXException { + this.serializer.comment(ch, start, len); + } } 1.2 +1 -3 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/profiler.xconf Index: profiler.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/profiler.xconf,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- profiler.xconf 21 Aug 2002 06:15:31 -0000 1.1 +++ profiler.xconf 3 Sep 2002 07:44:31 -0000 1.2 @@ -8,7 +8,5 @@ which are used to generate the profile report. You need to enable all of these components to use profiler. --> - <profiler results="10"> - <connector class="org.apache.cocoon.components.profiler.ProfilingSAXBufferConnector"/> - </profiler> + <profiler results="10"/> </xconf> 1.2 +1 -1 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/profiler.xroles Index: profiler.xroles =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/profiler/profiler.xroles,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- profiler.xroles 21 Aug 2002 06:15:31 -0000 1.1 +++ profiler.xroles 3 Sep 2002 07:44:31 -0000 1.2 @@ -3,5 +3,5 @@ <role name="org.apache.cocoon.components.profiler.Profiler" shorthand="profiler" - default-class="org.apache.cocoon.components.profiler.SimpleProfiler"/> + default-class="org.apache.cocoon.components.profiler.ProfilerImpl"/> </xroles> 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java Index: EnvironmentInfo.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.profiler; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Session; import java.util.HashMap; import java.util.Map; import java.util.Enumeration; /** * Holds information about the environment (such as request * parameters and session attributes) to be stored in the ProfilerData. * * @author <a href="mailto:[EMAIL PROTECTED]">Bruno Dumon</a>, * @version CVS $Id: EnvironmentInfo.java,v 1.1 2002/09/03 07:44:31 stephan Exp $ */ public class EnvironmentInfo { HashMap requestParameters = new HashMap(); HashMap sessionAttributes = new HashMap(); String uri; String uriPrefix; public EnvironmentInfo(Environment environment) { Map objectModel = environment.getObjectModel(); Request request = ObjectModelHelper.getRequest(objectModel); // make a copy of the request parameters Enumeration requestParameterNames = request.getParameterNames(); while (requestParameterNames.hasMoreElements()) { String paramName = (String)requestParameterNames.nextElement(); String rawValue = request.getParameter(paramName); String value = rawValue != null ? rawValue : "null"; requestParameters.put(paramName, value); } // make a copy of the session contents Session session = request.getSession(false); if (session != null) { Enumeration sessionAttributeNames = session.getAttributeNames(); while (sessionAttributeNames.hasMoreElements()) { String attrName = (String)sessionAttributeNames.nextElement(); Object rawValue = session.getAttribute(attrName); String value = rawValue != null ? rawValue.toString() : "null"; sessionAttributes.put(attrName, value); } } uri = environment.getURI(); uriPrefix = environment.getURIPrefix(); } public String getURI() { return uri; } public Map getRequestParameters() { return requestParameters; } public Map getSessionAttributes() { return sessionAttributes; } } 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/profiler/ProfilerImpl.java Index: ProfilerImpl.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.profiler; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.xml.XMLPipe; import java.util.Collection; import java.util.HashMap; import java.util.Map; /** * Profiler component implementation. Stores profiler data for * all pipelines. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> * @version CVS $Id: ProfilerImpl.java,v 1.1 2002/09/03 07:44:31 stephan Exp $ */ public class ProfilerImpl extends AbstractLogEnabled implements Profiler, ThreadSafe, Configurable { // Maximal count of entries, which should be stored. private int results_count = 10; private Map results; public ProfilerImpl() { results = new HashMap(); } /** * Pass the Configuration to the Configurable class. This method must * always be called after the constructor and before any other method. * * @param configuration the class configurations. */ public void configure(Configuration configuration) throws ConfigurationException { this.results_count = configuration.getAttributeAsInteger("results", 10); } /** * Clear the results. */ public void clearResults() { results.clear(); } /** * Remove the specified result. */ public void clearResult(Object key) { results.remove(key); } /** * Returns a collection of all keys * * @return Keys of all results. */ public Collection getResultKeys() { return results.keySet(); } /** * Returns a collection of the results. * * @return Collection of results. */ public Collection getResults() { return results.values(); } /** * Returns a result of a specifed key. * * @param key Key of the result. * @return Result of the profiling */ public ProfilerResult getResult(Object key) { return (ProfilerResult)results.get(key); } /** * Add a result for a request. * * @param uri URI of the request * @param data Result of the profiling */ public void addResult(String uri, ProfilerData data) { Long key = new Long(data.getKey(uri)); ProfilerResult result = (ProfilerResult)results.get(key); if(result == null){ synchronized(results){ if((result = (ProfilerResult)results.get(key)) == null) results.put(key, result = new ProfilerResult(uri, results_count)); } } result.addData(data); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]