You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2001/07/05 17:03:28 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/components/profiler Profiler.java ProfilerData.java ProfilerGenerator.java ProfilerResult.java ProfilingCachingEventPipeline.java ProfilingNonCachingEventPipeline.java ProfilingSAXConnector.java SimpleProfiler.java
vgritsenko 01/07/05 08:03:28
Added: src/org/apache/cocoon/components/profiler Profiler.java
ProfilerData.java ProfilerGenerator.java
ProfilerResult.java
ProfilingCachingEventPipeline.java
ProfilingNonCachingEventPipeline.java
ProfilingSAXConnector.java SimpleProfiler.java
Log:
First cut to implement profiler. A lot more must be done...
Revision Changes Path
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.util.Collection;
import org.xml.sax.ContentHandler;
import org.apache.avalon.framework.component.Component;
import org.apache.cocoon.environment.Request;
/**
* Profiler component interface.
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public interface Profiler extends Component
{
public void clearResults();
public void clearResult(Object key);
public void addResult(String uri, ProfilerData data);
public Collection getResultKeys();
public Collection getResults();
public ProfilerResult getResult(Object key);
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilerData.java
Index: ProfilerData.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.util.HashUtil;
/**
* Request-time profiler information.
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilerData
{
class Entry
{
Object component;
String role;
String source;
long time;
Entry(Object c, String r, String s)
{
component = c;
role = r;
source = s;
}
}
private ArrayList a = null;
public ProfilerData()
{
a = new ArrayList();
a.add(null);
}
public void setGenerator(Object generator, String role, String source)
{
a.set(0, new Entry(generator, role, source));
}
public void addComponent(Object component, String role, String source)
{
a.add(new Entry(component, role, source));
}
public int indexOf(Object component)
{
for(int i=0; i<a.size(); i++){
if(((Entry)a.get(i)).component == component)
return i;
}
return -1;
}
public void setTime(int i, long time)
{
((Entry)a.get(i)).time = time;
}
Entry[] getEntries()
{
return (Entry[])a.toArray(new Entry[a.size()]);
}
public long getKey(String uri)
{
StringBuffer key = new StringBuffer(uri);
for(int i=0; i<a.size(); i++){
Entry entry = (Entry)a.get(i);
key.append(':');
key.append(entry.role);
key.append(':');
key.append(entry.source);
}
return HashUtil.hash(key);
}
/*
public void report(String uri)
{
System.err.println("-------------------------------------------------------------------------------");
System.err.println("PROFILER DATA FOR: " + uri);
Entry[] entries = getEntries();
for(int i=0; i<entries.length; i++){
long time = entries[i].time;
if(i < entries.length - 1)
time -= entries[i+1].time;
if(entries[i].role == null || entries[i].role.length() == 0)
System.err.println("PROFILER DATA: " + time
+ "\tFOR " + entries[i].component);
else
System.err.println("PROFILER DATA: " + time
+ "\tFOR " + entries[i].role + "\t" + entries[i].source);
}
System.err.println("PROFILER DATA: " + entries[0].time + " TOTAL");
}
*/
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilerGenerator.java
Index: ProfilerGenerator.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Collection;
import java.util.Iterator;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.activity.Disposable;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.apache.cocoon.generation.ComposerGenerator;
/**
* Generates an XML representation of the current status of Profiler.
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilerGenerator extends ComposerGenerator
implements Recyclable, Composable, Disposable {
/**
* The XML namespace for the output document.
*/
protected static final String namespace = "http://apache.org/cocoon/profiler/1.0";
private Profiler profiler;
public void compose(ComponentManager manager) throws ComponentException
{
super.compose(manager);
try{
this.profiler = (Profiler)super.manager.lookup("org.apache.cocoon.components.profiler.Profiler");
}catch(Exception e){
e.printStackTrace();
}
}
public void dispose()
{
if(this.profiler != null){
super.manager.release(this.profiler);
this.profiler = null;
}
}
/**
* Generate the status information in XML format.
* @throws SAXException
* when there is a problem creating the output SAX events.
*/
public void generate() throws SAXException {
// Start the document and set the namespace.
this.contentHandler.startDocument();
this.contentHandler.startPrefixMapping("", namespace);
generate(this.contentHandler);
// End the document.
this.contentHandler.endPrefixMapping("");
this.contentHandler.endDocument();
}
/** Generate the main status document. */
private void generate(ContentHandler ch) throws SAXException {
// Root element.
// The current date and time.
String dateTime = DateFormat.getDateTimeInstance().format(new Date());
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(namespace, "date", "date", "CDATA", dateTime);
ch.startElement(namespace, "profilerinfo", "profilerinfo", atts);
Collection results = profiler.getResults();
for(Iterator i = results.iterator(); i.hasNext();)
generateResult(ch, (ProfilerResult)i.next());
// End root element.
ch.endElement(namespace, "profilerinfo", "profilerinfo");
}
private void generateResult(ContentHandler ch, ProfilerResult result) throws SAXException {
AttributesImpl atts = new AttributesImpl();
int count = result.getCount();
String[] roles = result.getRoles();
String[] source = result.getSources();
long[] avgTime = result.getTotalTime();
long avgTotal = 0;
for(int i=0; i < avgTime.length; i++)
avgTotal += avgTime[i];
atts.addAttribute(namespace, "uri", "uri", "CDATA", result.getURI());
atts.addAttribute(namespace, "count", "count", "CDATA", Integer.toString(result.getCount()));
atts.addAttribute(namespace, "time", "time", "CDATA", Long.toString(avgTotal));
ch.startElement(namespace, "pipeline", "pipeline", atts);
atts.clear();
if(count > 0){
atts.addAttribute(namespace, "time", "time", "CDATA", Long.toString(avgTotal / count));
ch.startElement(namespace, "average", "average", atts);
atts.clear();
for(int i=0; i<roles.length; i++){
if(roles[i] != null)
atts.addAttribute(namespace, "role", "role", "CDATA", roles[i]);
if(source[i] != null)
atts.addAttribute(namespace, "source", "source", "CDATA", source[i]);
atts.addAttribute(namespace, "time", "time", "CDATA", Long.toString(avgTime[i] / count));
ch.startElement(namespace, "element", "element", atts);
atts.clear();
ch.endElement(namespace, "element", "element");
}
ch.endElement(namespace, "average", "average");
long[][] last = result.getLastTimes();
for(int j=0; j<last.length; j++){
if(last[j] != null){
long[] curTime = last[j];
long curTotal = 0;
for(int i=0; i < curTime.length; i++)
curTotal += curTime[i];
atts.addAttribute(namespace, "time", "time", "CDATA", Long.toString(curTotal));
ch.startElement(namespace, "result", "result", atts);
atts.clear();
for(int i=0; i<roles.length; i++){
if(roles[i] != null)
atts.addAttribute(namespace, "role", "role", "CDATA", roles[i]);
if(source[i] != null)
atts.addAttribute(namespace, "source", "source", "CDATA", source[i]);
atts.addAttribute(namespace, "time", "time", "CDATA", Long.toString(curTime[i]));
ch.startElement(namespace, "element", "element", atts);
atts.clear();
ch.endElement(namespace, "element", "element");
}
ch.endElement(namespace, "result", "result");
}
}
}
ch.endElement(namespace, "pipeline", "pipeline");
}
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilerResult.java
Index: ProfilerResult.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Arrays;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Environment;
/**
* Represents data collected about one pipeline.
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilerResult
{
private String uri;
private String[] roles;
private String[] sources;
private int count;
private long[] totalTime;
private long[][] latestTimes;
private int latestCurrent;
public ProfilerResult(String uri, int latestResultsCount)
{
this.uri = uri;
if(latestResultsCount > 0)
this.latestTimes = new long[latestResultsCount][];
}
public void addData(ProfilerData data)
{
ProfilerData.Entry[] entries = data.getEntries();
synchronized(this){
if(totalTime == null || totalTime.length != entries.length){
// Reinitialize arrays
totalTime = new long[entries.length];
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 latest times
if(latestTimes != null)
Arrays.fill(latestTimes, 0, latestTimes.length, null);
latestCurrent = 0;
// Clear counter
count = 0;
}
// Adjust time. It's cumulative towards 0 index in data object
for(int i=0; i<entries.length-1; i++)
entries[i].time -= entries[i+1].time;
long[] latest = new long[entries.length];
for(int i=0; i<entries.length; i++)
totalTime[i] += latest[i] = entries[i].time;
if(latestTimes != null){
latestTimes[latestCurrent++] = latest;
if(latestCurrent >= latestTimes.length) latestCurrent = 0;
}
count++;
}
}
public String getURI()
{
return uri;
}
public String[] getRoles()
{
return roles;
}
public String[] getSources()
{
return sources;
}
public int getCount()
{
return count;
}
public long[] getTotalTime()
{
return totalTime;
}
public long[][] getLastTimes()
{
return latestTimes;
}
/*
public void report()
{
System.err.println("-------------------------------------------------------------------------------");
System.err.println("PROFILER TOTALS FOR: " + uri);
if(totalTime != null){
long time = 0;
for(int i=0; i<totalTime.length; i++){
System.err.println("PROFILER TOTALS: " + totalTime[i] + "\tFOR " + roles[i] + "\t" + sources[i]);
time += totalTime[i];
}
System.err.println("PROFILER TOTALS: " + time + " TIMES");
System.err.println("PROFILER TOTALS: " + count + " REQUESTS");
}
}
*/
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilingCachingEventPipeline.java
Index: ProfilingCachingEventPipeline.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.sitemap.ErrorNotifier;
import org.apache.cocoon.transformation.Transformer;
import org.apache.cocoon.xml.AbstractXMLProducer;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.xml.XMLProducer;
import org.apache.cocoon.components.pipeline.CachingEventPipeline;
import org.xml.sax.SAXException;
/**
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilingCachingEventPipeline extends CachingEventPipeline
implements Recyclable, Composable, Disposable {
private ComponentManager manager;
private Profiler profiler;
private ProfilerData data = null;
public void compose(ComponentManager manager) throws ComponentException
{
super.compose(manager);
try{
this.manager = manager;
this.profiler = (Profiler)manager.lookup("org.apache.cocoon.components.profiler.Profiler");
}catch(Exception e){
e.printStackTrace();
}
}
public void dispose()
{
super.dispose();
if(this.profiler != null){
this.manager.release(this.profiler);
this.profiler = null;
}
this.manager = null;
}
public void setGenerator (String role, String source, Parameters param, Exception e)
throws Exception {
super.setGenerator(role, source, param, e);
if(this.data == null)
this.data = new ProfilerData();
this.data.setGenerator(super.generator, role, source);
}
public void setGenerator (String role, String source, Parameters param)
throws Exception {
super.setGenerator(role, source, param);
if(this.data == null)
this.data = new ProfilerData();
this.data.setGenerator(super.generator, role, source);
}
public void addTransformer (String role, String source, Parameters param)
throws Exception {
super.addTransformer(role, source, param);
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 Exception {
this.data.addComponent(super.xmlConsumer, null, null);
environment.getObjectModel().put("profiler", data);
// Execute pipeline
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();
}
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilingNonCachingEventPipeline.java
Index: ProfilingNonCachingEventPipeline.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.sitemap.ErrorNotifier;
import org.apache.cocoon.transformation.Transformer;
import org.apache.cocoon.xml.AbstractXMLProducer;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.xml.XMLProducer;
import org.apache.cocoon.components.pipeline.NonCachingEventPipeline;
import org.xml.sax.SAXException;
/**
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilingNonCachingEventPipeline extends NonCachingEventPipeline
implements Recyclable, Composable, Disposable {
private ComponentManager manager;
private Profiler profiler;
private ProfilerData data = null;
public void compose(ComponentManager manager) throws ComponentException
{
super.compose(manager);
try{
this.manager = manager;
this.profiler = (Profiler)manager.lookup("org.apache.cocoon.components.profiler.Profiler");
}catch(Exception e){
e.printStackTrace();
}
}
public void dispose()
{
super.dispose();
if(this.profiler != null){
this.manager.release(this.profiler);
this.profiler = null;
}
this.manager = null;
}
public void setGenerator (String role, String source, Parameters param, Exception e)
throws Exception {
super.setGenerator(role, source, param, e);
if(this.data == null)
this.data = new ProfilerData();
this.data.setGenerator(super.generator, role, source);
}
public void setGenerator (String role, String source, Parameters param)
throws Exception {
super.setGenerator(role, source, param);
if(this.data == null)
this.data = new ProfilerData();
this.data.setGenerator(super.generator, role, source);
}
public void addTransformer (String role, String source, Parameters param)
throws Exception {
super.addTransformer(role, source, param);
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 Exception {
this.data.addComponent(super.xmlConsumer, null, null);
environment.getObjectModel().put("profiler", data);
// Execute pipeline
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();
}
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/ProfilingSAXConnector.java
Index: ProfilingSAXConnector.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.io.IOException;
import java.util.Map;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.sitemap.Sitemap;
import org.apache.cocoon.xml.AbstractXMLPipe;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.components.saxconnector.SAXConnector;
/**
* This SAX connector measures time taken by the following SAX handler.
* @author <a href="vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class ProfilingSAXConnector extends AbstractXMLPipe
implements Recyclable, SAXConnector
{
private ProfilerData data;
private int index;
private long time;
private long total;
/**
* 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 startDocument() throws SAXException
{
time = System.currentTimeMillis();
super.startDocument();
total += System.currentTimeMillis() - time;
}
public void endDocument() throws SAXException
{
time = System.currentTimeMillis();
super.endDocument();
total += System.currentTimeMillis() - time;
if(index != -1)
data.setTime(index, total);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException
{
time = System.currentTimeMillis();
super.startPrefixMapping(prefix, uri);
total += System.currentTimeMillis() - time;
}
public void endPrefixMapping(String prefix) throws SAXException
{
time = System.currentTimeMillis();
super.endPrefixMapping(prefix);
total += System.currentTimeMillis() - time;
}
public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException
{
time = System.currentTimeMillis();
super.startElement(uri, loc, raw, a);
total += System.currentTimeMillis() - time;
}
public void endElement(String uri, String loc, String raw) throws SAXException
{
time = System.currentTimeMillis();
super.endElement(uri, loc, raw);
total += System.currentTimeMillis() - time;
}
public void characters(char c[], int start, int len) throws SAXException
{
time = System.currentTimeMillis();
super.characters(c, start, len);
total += System.currentTimeMillis() - time;
}
public void ignorableWhitespace(char c[], int start, int len) throws SAXException
{
time = System.currentTimeMillis();
super.ignorableWhitespace(c, start, len);
total += System.currentTimeMillis() - time;
}
public void processingInstruction(String target, String data) throws SAXException
{
time = System.currentTimeMillis();
super.processingInstruction(target, data);
total += System.currentTimeMillis() - time;
}
public void skippedEntity(String name) throws SAXException
{
time = System.currentTimeMillis();
super.skippedEntity(name);
total += System.currentTimeMillis() - time;
}
public void startDTD(String name, String publicId, String systemId) throws SAXException
{
time = System.currentTimeMillis();
super.startDTD(name, publicId, systemId);
total += System.currentTimeMillis() - time;
}
public void endDTD() throws SAXException
{
time = System.currentTimeMillis();
super.endDTD();
total += System.currentTimeMillis() - time;
}
public void startEntity(String name) throws SAXException
{
time = System.currentTimeMillis();
super.startEntity(name);
total += System.currentTimeMillis() - time;
}
public void endEntity(String name) throws SAXException
{
time = System.currentTimeMillis();
super.endEntity(name);
total += System.currentTimeMillis() - time;
}
public void startCDATA() throws SAXException
{
time = System.currentTimeMillis();
super.startCDATA();
total += System.currentTimeMillis() - time;
}
public void endCDATA() throws SAXException
{
time = System.currentTimeMillis();
super.endCDATA();
total += System.currentTimeMillis() - time;
}
public void comment(char ch[], int start, int len) throws SAXException
{
time = System.currentTimeMillis();
super.comment(ch, start, len);
total += System.currentTimeMillis() - time;
}
}
1.1 xml-cocoon2/src/org/apache/cocoon/components/profiler/SimpleProfiler.java
Index: SimpleProfiler.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 file. *
*****************************************************************************/
package org.apache.cocoon.components.profiler;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import org.xml.sax.ContentHandler;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.serialization.Serializer;
/**
* Profiler component implementation. Stores profiler data for
* all pipelines.
*
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/07/05 15:03:28 $
*/
public class SimpleProfiler extends AbstractLoggable
implements Profiler, ThreadSafe //, Composable, Configurable, Disposable
{
private static final int RESULTS_COUNT = 10;
private Map results;
public SimpleProfiler()
{
results = new HashMap();
}
public void clearResults()
{
results.clear();
}
public void clearResult(Object key)
{
results.remove(key);
}
public Collection getResultKeys()
{
return results.keySet();
}
public Collection getResults()
{
return results.values();
}
public ProfilerResult getResult(Object key)
{
return (ProfilerResult)results.get(key);
}
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);
// result.report();
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org