cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r485649 - in /cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl: ./ src/main/java/org/apache/cocoon/profiling/ src/main/java/org/apache/cocoon/profiling/generation/ src/main/java/org/apache/cocoon/profiling/statistics/
Date Mon, 11 Dec 2006 12:55:42 GMT
Author: cziegeler
Date: Mon Dec 11 04:55:40 2006
New Revision: 485649

URL: http://svn.apache.org/viewvc?view=rev&rev=485649
Log:
Add statistics component.

Added:
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
  (with props)
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/pom.xml

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/pom.xml?view=diff&rev=485649&r1=485648&r2=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/pom.xml (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/pom.xml Mon Dec 11 04:55:40 2006
@@ -40,5 +40,10 @@
       <artifactId>cocoon-core</artifactId>
       <version>2.2.0-M3-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-auth-impl</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.generation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.cocoon.profiling.statistics.Collector;
+import org.apache.cocoon.profiling.statistics.PageReport;
+import org.apache.cocoon.profiling.statistics.Report;
+import org.apache.cocoon.profiling.statistics.Statistics;
+import org.apache.cocoon.xml.AttributesImpl;
+import org.apache.cocoon.xml.XMLUtils;
+import org.xml.sax.SAXException;
+
+/**
+ * Statistic-Generator.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class StatisticsGenerator
+    extends ServiceableGenerator {
+
+    protected Collector collector;
+
+    /**
+     * @see org.apache.cocoon.generation.AbstractGenerator#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, par);
+        final Request req = ObjectModelHelper.getRequest(objectModel);
+        if ( req.getParameter("clear") != null ) {
+            this.collector.clear();
+        }
+        if ( req.getParameter("enable") != null ) {
+            this.collector.setCollectingStatistics(true);
+        }
+        if ( req.getParameter("disable") != null ) {
+            this.collector.setCollectingStatistics(false);
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.generation.Generator#generate()
+     */
+    public void generate() throws IOException, SAXException, ProcessingException {
+        this.xmlConsumer.startDocument();
+        XMLUtils.startElement(this.xmlConsumer, "statistics");
+
+        if ( this.collector.isCollectingStatistics() ) {
+            XMLUtils.startElement(this.xmlConsumer, "reports");
+            boolean found = false;
+            List entries = new ArrayList(this.collector.getStatistics());
+            Collections.sort(entries, new ReportComparator());
+            final Iterator i = entries.iterator();
+            while ( i.hasNext() ) {
+                found = true;
+                final Report report = (Report)i.next();
+                final AttributesImpl attrs = new AttributesImpl();
+                attrs.addCDATAAttribute("name", report.getCategory());
+                XMLUtils.startElement(this.xmlConsumer, "report", attrs);
+                XMLUtils.createElement(this.xmlConsumer, "count", String.valueOf(report.getCount()));
+                XMLUtils.createElement(this.xmlConsumer, "min", this.getTime(report.getMin()));
+                XMLUtils.createElement(this.xmlConsumer, "max", this.getTime(report.getMax()));
+                XMLUtils.createElement(this.xmlConsumer, "last", this.getTime(report.getLast()));
+                XMLUtils.createElement(this.xmlConsumer, "all", report.getAll());
+                XMLUtils.createElement(this.xmlConsumer, "average", this.getTime(report.getAverage()));
+                XMLUtils.endElement(this.xmlConsumer, "report");
+            }
+            if ( !found ) {
+                XMLUtils.data(this.xmlConsumer, "No reports");                
+            }
+            XMLUtils.endElement(this.xmlConsumer, "reports");
+            if ( found ) {
+                XMLUtils.startElement(this.xmlConsumer, "pages");
+                entries = new ArrayList(this.collector.getPageReports());
+                Collections.sort(entries, new PageReportComparator());
+                final Iterator pi = entries.iterator();
+                while ( pi.hasNext() ) {
+                    final PageReport report = (PageReport)pi.next();
+                    final AttributesImpl attrs = new AttributesImpl();
+                    attrs.addCDATAAttribute("id", report.getId());
+                    attrs.addCDATAAttribute("date", report.getDate().toString());
+                    XMLUtils.startElement(this.xmlConsumer, "report", attrs);
+                    final Iterator si = report.getStatistics().iterator();
+                    while ( si.hasNext() ) {
+                        final Statistics stats = (Statistics)si.next();
+                        attrs.clear();
+                        attrs.addCDATAAttribute("name", stats.getCategory());
+                        attrs.addCDATAAttribute("duraration", String.valueOf(stats.getDuration()));
+                        XMLUtils.createElement(this.xmlConsumer, "component", attrs);
+                    }
+                    XMLUtils.endElement(this.xmlConsumer, "report");
+                }
+                XMLUtils.endElement(this.xmlConsumer, "pages");                
+            }
+        } else {
+            XMLUtils.data(this.xmlConsumer, "Turned off");
+        }
+        XMLUtils.endElement(this.xmlConsumer, "statistics");
+        this.xmlConsumer.endDocument();
+    }
+
+    protected String getTime(long msecs) {
+        long secs = msecs / 1000;
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(secs);
+        buffer.append('.');
+        long rest = (msecs - secs * 1000);
+        if ( rest < 100 ) {
+            buffer.append('0');
+        }
+        if ( rest < 10 ) {
+            buffer.append('0');
+        }
+        buffer.append(rest);
+        buffer.append('s');
+        return buffer.toString();
+    }
+
+    /**
+     * @see org.apache.cocoon.generation.ServiceableGenerator#dispose()
+     */
+    public void dispose() {
+        if ( this.manager != null ) {
+            this.manager.release(this.collector);
+            this.collector = null;
+        }
+        super.dispose();
+    }
+
+    /**
+     * @see org.apache.cocoon.generation.ServiceableGenerator#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager aManager) throws ServiceException {
+        super.service(aManager);
+        this.collector = (Collector)this.manager.lookup(Collector.class.getName());
+    }
+
+    public static final class ReportComparator implements Comparator {
+
+        public int compare(Object o1, Object o2) {
+            Report r1 = (Report)o1;
+            Report r2 = (Report)o2;
+            return r1.getCategory().compareTo(r2.getCategory());
+        }
+    }
+
+    public static final class PageReportComparator implements Comparator {
+
+        public int compare(Object o1, Object o2) {
+            PageReport r1 = (PageReport)o1;
+            PageReport r2 = (PageReport)o2;
+            return r1.getId().compareTo(r2.getId());
+        }
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/generation/StatisticsGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+import java.util.Collection;
+
+/**
+ * The collector is the central component collecting various statistics about
+ * the current request.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public interface Collector {
+
+    /**
+     * Add a new statistics object.
+     */
+    void addStatistics(Statistics stats);
+
+    /** 
+     * Collection of {@link Report}s.
+     */
+    Collection getStatistics();
+
+    /**
+     * Collection of {@link PageReport}s.
+     */
+    Collection getPageReports();
+
+    void setCollectingStatistics(boolean value);
+
+    boolean isCollectingStatistics();
+
+    void clear();
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Collector.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.auth.ApplicationUtil;
+import org.apache.cocoon.auth.User;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.excalibur.store.Store;
+import org.apache.excalibur.store.StoreJanitor;
+
+/**
+ * Implementation for the statistics component.
+ * In order to prevent an out of memory exception we implement the Store
+ * interface (dummy implementation) so we can register this component with
+ * the StoreJanitor component which will invoke this component to free
+ * memory in case of low memory.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class CollectorImpl
+    extends AbstractLogEnabled
+    implements Collector, Store, ThreadSafe, Serviceable, Disposable, Contextualizable {
+
+    private static final String COUNT_ATTRIBUTE = CollectorImpl.class.getName();
+
+    /** Are we currently collecting? */
+    protected boolean isCollecting = false;
+
+    /** All reports. */
+    protected Map reports = new HashMap();
+
+    /** All page reports. */
+    protected Map pageReports = new HashMap();
+
+    /** The store janitor for registering ourself. */
+    protected StoreJanitor janitor;
+
+    /** The service manager. */
+    protected ServiceManager manager;
+
+    /** The component context. */
+    protected Context context;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context c) throws ContextException {
+        this.context = c;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager aManager) throws ServiceException {
+        this.manager = aManager;
+        this.janitor = (StoreJanitor)this.manager.lookup(StoreJanitor.ROLE);
+        this.janitor.register(this);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        if ( this.manager != null ) {
+            if ( this.janitor != null ) {
+                this.janitor.unregister(this);
+            }
+            this.manager.release(this.janitor);
+            this.janitor = null;
+            this.manager = null;
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#addStatistics(org.apache.cocoon.profiling.statistics.Statistics)
+     */
+    public void addStatistics(final Statistics stats) {
+        if ( this.isCollecting && stats != null ) {
+            // get report for this category
+            ReportImpl report = (ReportImpl)this.reports.get(stats.getCategory());
+            if ( report == null ) {
+                synchronized (this) {
+                    report = (ReportImpl)this.reports.get(stats.getCategory());
+                    if ( report == null ) {
+                        // create new report
+                        report = new ReportImpl(stats.getCategory());
+                        this.reports.put(stats.getCategory(), report);
+                    }
+                }
+            }
+            synchronized (report) {
+                report.add(stats);
+            }
+            final String pageKey = this.getRequestKey();
+            PageReportImpl pageReport = (PageReportImpl)this.pageReports.get(pageKey);
+            if ( pageReport == null ) {
+                pageReport = new PageReportImpl(pageKey);
+                this.pageReports.put(pageKey, pageReport);
+            }
+            pageReport.addStatistics(stats);
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#getStatistics()
+     */
+    public Collection getStatistics() {
+        return this.reports.values();
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#getPageReports()
+     */
+    public Collection getPageReports() {
+        return this.pageReports.values();
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#isCollectingStatistics()
+     */
+    public boolean isCollectingStatistics() {
+        return this.isCollecting;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#setCollectingStatistics(boolean)
+     */
+    public void setCollectingStatistics(boolean value) {
+        this.isCollecting = value;
+        if ( !this.isCollecting ) {
+            this.reports.clear();
+            this.pageReports.clear();
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Collector#clear()
+     */
+    public void clear() {
+        this.reports.clear();
+        this.pageReports.clear();
+    }
+
+    protected String getRequestKey() {
+        final Map objectModel = ContextHelper.getObjectModel(this.context);
+        final User user = ApplicationUtil.getUser(objectModel);
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        final Session session = request.getSession();
+        Integer counter = (Integer) request.getAttribute(CollectorImpl.COUNT_ATTRIBUTE);
+        if ( counter == null) {
+            counter = (Integer) session.getAttribute(CollectorImpl.COUNT_ATTRIBUTE);
+            if ( counter == null ) {
+                counter = new Integer(0);
+            } else {
+                counter = new Integer(counter.intValue() + 1);
+            }
+            session.setAttribute(CollectorImpl.COUNT_ATTRIBUTE, counter);
+            request.setAttribute(CollectorImpl.COUNT_ATTRIBUTE, counter);
+        }
+        return (user == null ? "anon" : user.getId()) + ':' + session.getId() + '/' + counter;
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#containsKey(java.lang.Object)
+     */
+    public boolean containsKey(Object arg0) {
+        return false;
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#free()
+     */
+    public void free() {
+        // we simply free everything
+        synchronized ( this ) {
+            this.reports.clear();
+            this.pageReports.clear();
+        }
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#get(java.lang.Object)
+     */
+    public Object get(Object arg0) {
+        return null;
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#keys()
+     */
+    public Enumeration keys() {
+        return Collections.enumeration(Collections.EMPTY_LIST);
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#remove(java.lang.Object)
+     */
+    public void remove(Object arg0) {
+        // nothing to do here
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#size()
+     */
+    public int size() {
+        return this.reports.size();
+    }
+
+    /**
+     * @see org.apache.excalibur.store.Store#store(java.lang.Object, java.lang.Object)
+     */
+    public void store(Object arg0, Object arg1) throws IOException {
+        // nothing to do here
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Reports for a specific page.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public interface PageReport {
+
+    String getId();
+
+    Date getDate();
+
+    List getStatistics();
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReport.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class PageReportImpl implements PageReport {
+
+    protected final List statistics = new ArrayList();
+    protected final String id;
+    protected final Date   date = new Date();
+
+    public PageReportImpl(String id) {
+        this.id = id;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.PageReport#getId()
+     */
+    public String getId() {
+        return this.id;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.PageReport#getDate()
+     */
+    public Date getDate() {
+        return this.date;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.PageReport#getStatistics()
+     */
+    public List getStatistics() {
+        return this.statistics;
+    }
+
+    /**
+     * @param stats
+     */
+    public void addStatistics(Statistics stats) {
+        if ( stats != null ) {
+            this.statistics.add(new SimpleStats(stats.getCategory(), stats.getDuration()));
+        }
+    }
+
+    protected final static class SimpleStats implements Statistics {
+
+        protected final String category;
+        protected final long   duration;
+
+        public SimpleStats(String category, long duration) {
+            this.category = category;
+            this.duration = duration;
+        }
+
+        /**
+         * @see org.apache.cocoon.profiling.statistics.Statistics#getCategory()
+         */
+        public String getCategory() {
+            return this.category;
+        }
+
+        /**
+         * @see org.apache.cocoon.profiling.statistics.Statistics#getDuration()
+         */
+        public long getDuration() {
+            return this.duration;
+        }
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/PageReportImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+/**
+ * A report gives information about the invocation of a category.
+ * It collects the information from all {@link Statistics} objects
+ * for the specific category.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public interface Report {
+
+    String getCategory();
+
+    int getCount();
+
+    long getMin();
+
+    long getMax();
+
+    long getAverage();
+
+    long getLast();
+
+    String getAll();
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Report.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+/**
+ * 
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class ReportImpl implements Report {
+
+    protected int count;
+    protected long min = -1;
+    protected long max = 0;
+    protected long accumulated;
+    protected long last;
+    protected String category;
+    protected StringBuffer buffer = new StringBuffer();
+
+    public ReportImpl(String category) {
+        this.category = category;
+    }
+
+    public void add(Statistics stat) {
+        if ( stat != null ) {
+            long duration = stat.getDuration();
+            if ( duration == 0 ) {
+                duration = 1;
+            }
+            this.count++;
+            this.accumulated += duration;
+            if ( this.min == -1 || duration < this.min ) {
+                this.min = duration;
+            }
+            if ( duration > this.max ) {
+                this.max = duration;
+            }
+            this.last = duration;
+            if ( buffer.length() > 0 ) {
+                buffer.append(", ");
+            }
+            buffer.append(this.getTime(duration));
+        }
+    }
+
+    protected String getTime(long msecs) {
+        long secs = msecs / 1000;
+        StringBuffer b = new StringBuffer();
+        b.append(secs);
+        b.append('.');
+        long rest = (msecs - secs * 1000);
+        if ( rest < 100 ) {
+            b.append('0');
+        }
+        if ( rest < 10 ) {
+            b.append('0');
+        }
+        b.append(rest);
+        b.append('s');
+        return b.toString();
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getAverage()
+     */
+    public long getAverage() {
+        if ( count > 0 ) {
+            return accumulated / count;
+        }
+        return 0;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getCategory()
+     */
+    public String getCategory() {
+        return this.category;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getCount()
+     */
+    public int getCount() {
+       return this.count;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getMax()
+     */
+    public long getMax() {
+        return this.max;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getMin()
+     */
+    public long getMin() {
+        return this.min;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getLast()
+     */
+    public long getLast() {
+        return this.last;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Report#getAll()
+     */
+    public String getAll() {
+        return buffer.toString();
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/ReportImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+/**
+ * 
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class SimpleStatistics implements Statistics {
+
+    protected long duration;
+    protected String category;
+
+    public SimpleStatistics(String category, long start) {
+        this.category = category;
+        this.duration = System.currentTimeMillis() - start;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Statistics#getDuration()
+     */
+    public long getDuration() {
+        return this.duration;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Statistics#getCategory()
+     */
+    public String getCategory() {
+        return this.category;
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/SimpleStatistics.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+/**
+ * A simple statistics object.
+ * A statistics object stores the duration for an invocation
+ * of a defined category.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public interface Statistics {
+
+    /**
+     * The duration of the invocation in milliseconds.
+     */
+    long getDuration();
+
+    /**
+     * The category for the invocation.
+     */
+    String getCategory();
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/Statistics.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java?view=auto&rev=485649
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
(added)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
Mon Dec 11 04:55:40 2006
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.profiling.statistics;
+
+/**
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class WSStatistics implements Statistics {
+
+    protected String category;
+    protected long duration;
+    protected String url;
+    protected String method;
+
+    public WSStatistics(String url, String method, long start) {
+        this.duration = System.currentTimeMillis() - start;
+        this.url = url;
+        this.method = method;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Statistics#getDuration()
+     */
+    public long getDuration() {
+        return duration;
+    }
+
+    /**
+     * @see org.apache.cocoon.profiling.statistics.Statistics#getCategory()
+     */
+    public String getCategory() {
+        if ( this.category == null ) {
+            this.category = "WebService " + this.url + "/" + this.method;
+        }
+        return this.category;
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/WSStatistics.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message