You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/08/20 22:43:22 UTC

svn commit: r806346 [1/3] - in /cocoon/cocoon3/trunk: cocoon-profiling/ cocoon-profiling/src/main/java/org/ cocoon-profiling/src/main/java/org/apache/ cocoon-profiling/src/main/java/org/apache/cocoon/ cocoon-profiling/src/main/java/org/apache/cocoon/pr...

Author: reinhard
Date: Thu Aug 20 20:43:20 2009
New Revision: 806346

URL: http://svn.apache.org/viewvc?rev=806346&view=rev
Log:
COCOON3-40 Cocoon Profiling Block

Added:
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/cocoon/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/cocoon/spring/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/cocoon/spring/cocoon-profiling-component.xml   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/cocoon/spring/cocoon-profiling-servlet-service.xml   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/ehcache/
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/META-INF/ehcache/cocoon-profiling-ehcache.xml   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/output.xsd   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/java/org/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/java/org/apache/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/java/org/apache/cocoon/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/java/org/apache/cocoon/profiling/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/java/org/apache/cocoon/profiling/TestServletProfiler.java   (with props)
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/resources/org/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/resources/org/apache/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/resources/org/apache/cocoon/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/resources/org/apache/cocoon/profiling/
    cocoon/cocoon3/trunk/cocoon-profiling/src/test/resources/org/apache/cocoon/profiling/simple.xml   (with props)
    cocoon/cocoon3/trunk/cocoon-sample-webapp/src/test/java/org/apache/cocoon/it/ProfilingTest.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/MockHttpServletRequest.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/MockHttpServletResponse.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/MockXMLSitemapServlet.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/ProfilingIntegrationTest.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/profiling/SitemapServlet.java   (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-profiling-test-component.xml   (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-profiling/pom.xml
    cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap
    cocoon/cocoon3/trunk/parent/pom.xml

Modified: cocoon/cocoon3/trunk/cocoon-profiling/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/pom.xml?rev=806346&r1=806345&r2=806346&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-profiling/pom.xml Thu Aug 20 20:43:20 2009
@@ -17,7 +17,6 @@
   specific language governing permissions and limitations
   under the License.
  -->
-<!-- $Id$ -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -39,10 +38,27 @@
 
   <dependencies>
     <dependency>
+      <groupId>org.apache.cocoon.pipeline</groupId>
+      <artifactId>cocoon-pipeline</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon.sitemap</groupId>
+      <artifactId>cocoon-sitemap</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon.rest</groupId>
+      <artifactId>cocoon-rest</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-aop</artifactId>
     </dependency>
-    <dependency>
+	<dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+	</dependency> 
+	<dependency>
       <groupId>org.aspectj</groupId>
       <artifactId>aspectjrt</artifactId>
     </dependency>
@@ -50,16 +66,13 @@
       <groupId>org.aspectj</groupId>
       <artifactId>aspectjweaver</artifactId>
     </dependency>
+     
     <dependency>
-      <groupId>org.apache.cocoon.pipeline</groupId>
-      <artifactId>cocoon-pipeline</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.cocoon.sitemap</groupId>
-      <artifactId>cocoon-sitemap</artifactId>
-    </dependency>
+      <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache</artifactId>
+	</dependency> 
     <dependency>
-      <groupId>commons-logging</groupId>
+      <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId>
       <exclusions>
         <exclusion>
@@ -73,20 +86,37 @@
       </exclusions>
     </dependency>
     
-    <!-- test dependencies -->
+    <!--  dependencies for tests -->
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <scope>provided</scope>
     </dependency>
-  <dependency>
+    <dependency>
       <groupId>org.apache.cocoon.servlet</groupId>
       <artifactId>cocoon-servlet</artifactId>
     </dependency>
+
+    <!-- test dependencies -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ProfileMethod {
+
+    static String DEFAULT_NAME = "*";
+
+    String name() default DEFAULT_NAME;
+
+    ProfileMethodType type() default ProfileMethodType.BEFORE_INVOCATION;
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethod.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,21 @@
+/*
+ * 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;
+
+public enum ProfileMethodType {
+    BEFORE_INVOCATION, AFTER_INVOCATION, ON_EXCEPTION;
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/ProfileMethodType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,108 @@
+/*
+ * 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.aspects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.profiling.profiler.Profiler;
+import org.apache.cocoon.profiling.spring.AutomaticProfilerInstaller;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.aspectj.lang.ProceedingJoinPoint;
+
+/**
+ * <p>
+ * The dispatcher gets invoked by a profiling aspect. Based on the class of the component that is
+ * invoked a specific {@link Profiler} is used to fill a {@link ProfilingData} object.
+ * </p>
+ * 
+ * <p>
+ * New profilers can be installed with installProfiler(Profiler). More specific profilers will be
+ * chosen first automatically. The recommended way to install a Profiler is to declare it as a
+ * 
+ * spring-managed bean. The {@link AutomaticProfilerInstaller} will install the Profiler
+ * automatically on the correct InvocationDispatcher.
+ * </p>
+ */
+public class InvocationDispatcher {
+
+    protected final Log logger = LogFactory.getLog(this.getClass());
+
+    private List<Profiler<?>> profilers = new LinkedList<Profiler<?>>();
+
+    /**
+     * Creates a new ProfilingData object and routes this invocation to a {@link Profiler}.
+     *
+     * @param pjp the joinpoint
+     * @return return value of {@link ProceedingJoinPoint#proceed()}
+     * @throws Throwable throwable from {@link ProceedingJoinPoint#proceed()}
+     */
+    public Object dispatch(ProceedingJoinPoint pjp) throws Throwable {
+        Object target = pjp.getTarget();
+        ProfilingData data = new ProfilingData();
+
+        Profiler<?> profiler = this.getProfiler(target);
+        String method = pjp.getSignature().getName();
+
+        try {
+            profiler.before(data, target, method, pjp.getArgs());
+            Object returnValue = pjp.proceed(pjp.getArgs());
+            profiler.after(data, method, returnValue);
+            return returnValue;
+        } catch (Exception e) {
+            profiler.exception(data, method, e);
+            throw e;
+        }
+    }
+
+    /**
+     * Installs a new profiler.
+     *
+     * @param profiler the profiler to install
+     */
+    public void installProfiler(Profiler<?> profiler) {
+        Class<?> class1 = profiler.getTargetClass();
+
+        // insertion position determined by type hierarchy
+        for (int i = 0; i < this.profilers.size(); i++) {
+            Class<?> class2 = this.profilers.get(i).getTargetClass();
+
+            if (class2.isAssignableFrom(class1)) {
+                if (class1.equals(class2)) {
+                    throw new RuntimeException(String.format("You are trying to install a profiler for '%s' "
+                            + "but for this class there is already a profiler registered: '%s'", class1.getName(),
+                            this.profilers.get(i).getClass().getName()));
+                }
+                this.profilers.add(i, profiler);
+                return;
+            }
+        }
+
+        this.profilers.add(profiler);
+    }
+
+    private Profiler<?> getProfiler(Object target) {
+        for (Profiler<?> profiler : this.profilers) {
+            if (profiler.getTargetClass().isInstance(target)) {
+                return profiler;
+            }
+        }
+        throw new RuntimeException("No profiler found for " + target.getClass() + ".");
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/InvocationDispatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.aspects;
+
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+import org.apache.cocoon.profiling.jmx.ProfilingManagement;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+/**
+ * Aspect to intercept calls to all classes implementing {@link PipelineComponent}. Can be disabled
+ * via JMX {@link ProfilingManagement}.
+ */
+@Aspect
+public class PipelineComponentProfilingAspect {
+
+    private InvocationDispatcher invocationDispatcher;
+
+    private ProfilingManagement profilingManagement;
+
+    @Around("execution(* *(..)) && target(org.apache.cocoon.pipeline.component.PipelineComponent)")
+    public Object handleInvocation(ProceedingJoinPoint pjp) throws Throwable {
+        if (!this.profilingManagement.isEnabled()) {
+            return pjp.proceed(pjp.getArgs());
+        }
+        return this.invocationDispatcher.dispatch(pjp);
+    }
+
+    public void setInvocationDispatcher(InvocationDispatcher invocationDispatcher) {
+        this.invocationDispatcher = invocationDispatcher;
+    }
+
+    public void setProfilingManagement(ProfilingManagement profilingManagement) {
+        this.profilingManagement = profilingManagement;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineComponentProfilingAspect.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.aspects;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.profiling.jmx.ProfilingManagement;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+/**
+ * Aspect to intercept calls to all classes implementing {@link Pipeline}. Can be disabled via JMX
+ * {@link ProfilingManagement}.
+ */
+@Aspect
+public class PipelineProfilingAspect {
+
+    private InvocationDispatcher invocationDispatcher;
+
+    private ProfilingManagement profilingManagement;
+
+    @Around("execution(* *(..)) && target(org.apache.cocoon.pipeline.Pipeline)")
+    public Object handleInvocation(ProceedingJoinPoint pjp) throws Throwable {
+        if (!this.profilingManagement.isEnabled()) {
+            return pjp.proceed(pjp.getArgs());
+        }
+        return this.invocationDispatcher.dispatch(pjp);
+    }
+
+    public void setInvocationDispatcher(InvocationDispatcher invocationDispatcher) {
+        this.invocationDispatcher = invocationDispatcher;
+    }
+
+    public void setProfilingManagement(ProfilingManagement profilingManagement) {
+        this.profilingManagement = profilingManagement;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/PipelineProfilingAspect.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.aspects;
+
+import javax.servlet.Servlet;
+
+import org.apache.cocoon.profiling.jmx.ProfilingManagement;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.core.annotation.Order;
+
+/**
+ * Aspect to intercept calls to all classes implementing {@link Servlet}. Can be disabled via JMX
+ * {@link ProfilingManagement}. Classes starting with "$Proxy" are ignored.
+ */
+@Aspect
+@Order(Integer.MAX_VALUE)
+public class ServletProfilingAspect {
+
+    private InvocationDispatcher invocationDispatcher;
+
+    private ProfilingManagement profilingManagement;
+
+    @Around("execution(* service(..)) && target(javax.servlet.Servlet)")
+    public Object handleInvocation(ProceedingJoinPoint pjp) throws Throwable {
+        if (!this.profilingManagement.isEnabled()) {
+            return pjp.proceed(pjp.getArgs());
+        }
+        if (pjp.getTarget().getClass().getName().startsWith("$Proxy")) {
+            // ignore dynamic proxies
+            return pjp.proceed(pjp.getArgs());
+        }
+        return this.invocationDispatcher.dispatch(pjp);
+    }
+
+    public void setInvocationDispatcher(InvocationDispatcher invocationDispatcher) {
+        this.invocationDispatcher = invocationDispatcher;
+    }
+
+    public void setProfilingManagement(ProfilingManagement profilingManagement) {
+        this.profilingManagement = profilingManagement;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/ServletProfilingAspect.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.aspects;
+
+import org.apache.cocoon.profiling.jmx.ProfilingManagement;
+import org.apache.cocoon.sitemap.node.SitemapNode;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.core.annotation.Order;
+
+/**
+ * Aspect to intercept calls to all classes implementing {@link SitemapNode}. Can be disabled via
+ * JMX {@link ProfilingManagement}.
+ */
+@Aspect
+@Order(Integer.MAX_VALUE)
+public class SitemapNodeProfilingAspect {
+
+    private InvocationDispatcher invocationDispatcher;
+
+    private ProfilingManagement profilingManagement;
+
+    @Around("execution(* *(..)) && !execution(* getType(..)) && target(org.apache.cocoon.sitemap.node.SitemapNode)")
+    public Object handleInvocation(ProceedingJoinPoint pjp) throws Throwable {
+        if (!this.profilingManagement.isEnabled()) {
+            return pjp.proceed(pjp.getArgs());
+        }
+        return this.invocationDispatcher.dispatch(pjp);
+    }
+
+    public void setInvocationDispatcher(InvocationDispatcher invocationDispatcher) {
+        this.invocationDispatcher = invocationDispatcher;
+    }
+
+    public void setProfilingManagement(ProfilingManagement profilingManagement) {
+        this.profilingManagement = profilingManagement;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/SitemapNodeProfilingAspect.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * Contains classes that use the Spring AOP mechanism to intercept invocations on Cocoon components.
+ * 
+ * <p>
+ * Every instance of an aspect uses an {@link org.apache.cocoon.profiling.aspects.InvocationDispatcher} to provide the
+ * information to the {@link org.apache.cocoon.profiling.profiler.Profiler}.
+ * </p>
+ *  
+ */
+package org.apache.cocoon.profiling.aspects;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/aspects/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,401 @@
+/*
+ * 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.component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
+import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+import org.apache.cocoon.profiling.data.InstanceRepresentation;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.profiling.data.ProfilingDataHolder;
+import org.apache.cocoon.sax.AbstractSAXGenerator;
+import org.apache.cocoon.sax.SAXConsumer;
+import org.apache.cocoon.sitemap.node.InvocationResult;
+import org.apache.cocoon.sitemap.node.MatchNode;
+import org.apache.cocoon.sitemap.node.SitemapNode;
+import org.apache.cocoon.xml.sax.AttributesImpl;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * A cocoon pipeline component to generate an XML representation of a {@link ProfilingData}.
+ */
+public class ProfilingGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
+
+    private ProfilingDataHolder dataHolder;
+
+    private ProfilingData profilingData;
+
+    private String id;
+
+    private SAXConsumer consumer;
+
+    private List<String> elements = new LinkedList<String>();
+
+    private Map<String, ComponentTreeElement> treeElements = new HashMap<String, ComponentTreeElement>();
+
+    private boolean showSitemap = true;
+
+    private boolean showAllMatchers = true;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setup(Map<String, Object> parameters) {
+        HttpServletRequest req = (HttpServletRequest) parameters.get("javax.servlet.http.HttpServletRequest");
+        if (req != null) {
+            String sitemap = req.getParameter("sitemap");
+            if (sitemap != null) {
+                this.showSitemap = Boolean.valueOf(sitemap);
+            }
+
+            String matcher = req.getParameter("matcher");
+            if (matcher != null) {
+                this.showAllMatchers = Boolean.valueOf(matcher);
+            }
+        }
+    }
+
+    public CacheKey constructCacheKey() {
+        ParameterCacheKey cacheKey = new ParameterCacheKey("id", this.id);
+        cacheKey.addParameter("showSitemap", this.showSitemap);
+        cacheKey.addParameter("showAllMatchers", this.showAllMatchers);
+
+        return cacheKey;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        super.setConfiguration(configuration);
+
+        this.id = (String) configuration.get("id");
+        this.profilingData = this.dataHolder.get(this.id);
+
+        if (this.profilingData == null) {
+            throw new SetupException(String.format("Profiling information for id '%s' not found", this.id));
+        }
+    }
+
+    /**
+     * Creates XML events for the given {@link ProfilingData}.
+     */
+    public void execute() {
+        this.consumer = this.getSAXConsumer();
+        try {
+            this.consumer.startDocument();
+
+            AttributesImpl attr = new AttributesImpl();
+            this.addStringAttribute(attr, "id", this.id);
+
+            this.startElement("cocoon-profiling", attr);
+            ComponentTreeElement root = this.buildComponentTree(this.profilingData);
+            this.handleTreeElement(root);
+            this.endElement();
+
+            this.consumer.endDocument();
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void setProfilingDataHolder(ProfilingDataHolder dataHolder) {
+        this.dataHolder = dataHolder;
+    }
+
+    private void handleTreeElement(ComponentTreeElement treeElement) throws SAXException {
+        Class<?> target = treeElement.getTargetClass();
+
+        String element = null;
+
+        if (Servlet.class.isAssignableFrom(target)) {
+            element = "servlet";
+        } else if (SitemapNode.class.isAssignableFrom(target)) {
+            element = "node";
+        } else if (PipelineComponent.class.isAssignableFrom(target)) {
+            element = "component";
+        } else if (Pipeline.class.isAssignableFrom(target)) {
+            element = "pipeline";
+        }
+
+        if (element == null) {
+            throw new RuntimeException("ProfilingGenerator can't create element for " + target.getName());
+        }
+
+        if (this.showElement(treeElement)) {
+            AttributesImpl attr = new AttributesImpl();
+            this.addStringAttribute(attr, "name", treeElement.getDisplayName());
+            this.addStringAttribute(attr, "executionTime", this.milliString(treeElement.getExecutionMillis()));
+
+            this.startElement(element, attr);
+
+            AttributesImpl attr2 = new AttributesImpl();
+            this.addStringAttribute(attr2, "class", treeElement.getProfiler());
+            this.addSimple("profiler", attr2);
+
+            this.startElement("invocations");
+            for (ProfilingData data : treeElement.getInvocations()) {
+                this.handleInvocation(data);
+            }
+            this.endElement();
+
+            this.handleChildren(treeElement);
+
+            this.endElement();
+        } else {
+            this.handleChildren(treeElement);
+        }
+    }
+
+    private String milliString(double executionTime) {
+        return String.format(Locale.US, "%.3fms", executionTime);
+    }
+
+    private void handleInvocation(ProfilingData data) throws SAXException {
+        AttributesImpl attr = new AttributesImpl();
+        this.addStringAttribute(attr, "method", data.getMethod());
+        this.addStringAttribute(attr, "executionTime", this.milliString(data.getExecutionMillis()));
+
+        this.startElement("invocation", attr);
+
+        this.startElement("properties");
+        for (Entry<String, String> entry : data.getData().entrySet()) {
+            AttributesImpl attr2 = new AttributesImpl();
+            this.addStringAttribute(attr2, "id", entry.getKey());
+
+            this.startElement("property", attr2);
+            this.addData(entry.getValue());
+            this.endElement();
+        }
+        this.endElement();
+
+        this.startElement("arguments");
+        for (InstanceRepresentation arg : data.getArguments()) {
+            this.addArgument(arg);
+        }
+        this.endElement();
+
+        this.startElement("result");
+        if (data.getException() != null) {
+            AttributesImpl attr2 = new AttributesImpl();
+            this.addStringAttribute(attr2, "class", data.getException().getClass().getName());
+            this.addStringAttribute(attr2, "message", data.getException().getMessage());
+            this.addSimple("exception", attr2);
+        } else {
+            String classname;
+
+            if (data.getReturnValue().getRepresentedClass() == null) {
+                classname = "";
+            } else {
+                classname = data.getReturnValue().getRepresentedClass().getName();
+            }
+
+            AttributesImpl attr3 = new AttributesImpl();
+            this.addStringAttribute(attr3, "class", classname);
+            this.startElement("return-value", attr3);
+            this.addSimple("value", data.getReturnValue().getStringRepresentation());
+            this.endElement();
+        }
+        this.endElement();
+
+        this.endElement();
+    }
+
+    private void handleChildren(ComponentTreeElement treeElement) throws SAXException {
+        for (ComponentTreeElement te : treeElement.getChildren()) {
+            this.handleTreeElement(te);
+        }
+    }
+
+    private boolean showElement(ComponentTreeElement element) {
+        Class<?> targetClass = element.getTargetClass();
+        if (SitemapNode.class.isAssignableFrom(targetClass)) {
+            if (!this.showSitemap) {
+                return false;
+            }
+
+            if (MatchNode.class.isAssignableFrom(targetClass)) {
+                return this.showMatchNode(element);
+            }
+        }
+
+        return true;
+    }
+
+    private boolean showMatchNode(ComponentTreeElement element) {
+        if (this.showAllMatchers) {
+            return true;
+        }
+
+        for (ProfilingData invocation : element.getInvocations()) {
+            if (invocation.getMethod().equals("invoke")) {
+                InstanceRepresentation returnValue = invocation.getReturnValue();
+                InvocationResult result = InvocationResult.valueOf(returnValue.getStringRepresentation());
+                return result == InvocationResult.COMPLETED || result == InvocationResult.CONTINUE;
+            }
+        }
+
+        return true;
+    }
+
+    private void addSimple(String name, String data) throws SAXException {
+        this.startElement(name);
+        this.addData(data);
+        this.endElement();
+    }
+
+    private void addSimple(String name, AttributesImpl attr) throws SAXException {
+        this.startElement(name, attr);
+        this.endElement();
+    }
+
+    private void addArgument(InstanceRepresentation data) throws SAXException {
+        AttributesImpl attr = new AttributesImpl();
+
+        Class<?> clazz = data.getRepresentedClass();
+        String value = data.getStringRepresentation();
+
+        this.addStringAttribute(attr, "class", clazz.getName());
+        this.startElement("argument", attr);
+        this.addData(value);
+        this.endElement();
+    }
+
+    private void addStringAttribute(AttributesImpl attr, String key, String value) {
+        attr.addAttribute("", key, key, "xsd:string", value == null ? "" : value);
+    }
+
+    private void startElement(String name) throws SAXException {
+        this.startElement(name, (Attributes) null);
+    }
+
+    private void startElement(String name, Attributes attributes) throws SAXException {
+        this.consumer.startElement("", name, name, attributes);
+        this.elements.add(0, name);
+    }
+
+    private void endElement() throws SAXException {
+        String name = this.elements.remove(0);
+        this.consumer.endElement("", name, name);
+    }
+
+    private void addData(String data) throws SAXException {
+        this.consumer.characters(data.toCharArray(), 0, data.length());
+    }
+
+    private ComponentTreeElement buildComponentTree(ProfilingData data) {
+        ComponentTreeElement root = new ComponentTreeElement(data);
+        this.treeElements.put(data.getId(), root);
+
+        for (ProfilingData child : data.getChildren()) {
+            this.continueComponentTree(root, data, child);
+        }
+
+        return root;
+    }
+
+    private void continueComponentTree(ComponentTreeElement parentTreeElement, ProfilingData parent, ProfilingData data) {
+        ComponentTreeElement treeElement = this.treeElements.get(data.getId());
+
+        if (treeElement == null) {
+            treeElement = new ComponentTreeElement(data);
+            parentTreeElement.addChild(treeElement);
+            this.treeElements.put(data.getId(), treeElement);
+        } else {
+            treeElement.addInvocation(data);
+        }
+
+        for (ProfilingData child : data.getChildren()) {
+            this.continueComponentTree(treeElement, data, child);
+        }
+    }
+
+    private class ComponentTreeElement {
+
+        private List<ComponentTreeElement> children;
+
+        private List<ProfilingData> invocations;
+
+        public ComponentTreeElement(ProfilingData data) {
+            this.children = new ArrayList<ComponentTreeElement>();
+            this.invocations = new ArrayList<ProfilingData>();
+            this.invocations.add(data);
+        }
+
+        public Class<?> getTargetClass() {
+            InstanceRepresentation target = this.invocations.get(0).getTarget();
+            return target == null ? null : target.getRepresentedClass();
+        }
+
+        public String getDisplayName() {
+            String displayName = this.invocations.get(0).getDisplayName();
+            for (ProfilingData pd : this.invocations) {
+                if (pd.isDisplayNameSet()) {
+                    displayName = pd.getDisplayName();
+                    break;
+                }
+            }
+            return displayName;
+        }
+
+        public double getExecutionMillis() {
+            double t = 0;
+            for (ProfilingData data : this.invocations) {
+                t += data.getExecutionMillis();
+            }
+            return t;
+        }
+
+        public String getProfiler() {
+            return this.invocations.get(0).getProfiler();
+        }
+
+        public void addChild(ComponentTreeElement child) {
+            this.children.add(child);
+        }
+
+        public void addInvocation(ProfilingData profilingData) {
+            this.invocations.add(profilingData);
+        }
+
+        public List<ComponentTreeElement> getChildren() {
+            return Collections.unmodifiableList(this.children);
+        }
+
+        public List<ProfilingData> getInvocations() {
+            return Collections.unmodifiableList(this.invocations);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,370 @@
+/*
+ * 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.component;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
+import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.component.Finisher;
+import org.apache.cocoon.pipeline.component.Starter;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.profiling.data.ProfilingDataComparator;
+import org.apache.cocoon.profiling.data.ProfilingDataHolder;
+
+/**
+ * A cocoon pipeline component that generates and serializes a png image that visualizes profiling
+ * information.
+ */
+public class ProfilingPngSerializer implements Starter, Finisher, CachingPipelineComponent {
+
+    private String id;
+
+    private ProfilingData profilingData;
+
+    private ProfilingDataHolder dataHolder;
+
+    private OutputStream outputStream;
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setOutputStream(OutputStream outputStream) {
+        this.outputStream = outputStream;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getContentType() {
+        return "image/png";
+    }
+
+    /**
+     * Writes the image data to the output stream.
+     */
+    public void finish() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.id = (String) configuration.get("id");
+        this.profilingData = this.dataHolder.get(this.id);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute() {
+        if (this.profilingData == null) {
+            new ErrorMessageDrawer().writeImage(this.outputStream);
+        } else {
+            new ProfilingDrawer(this.profilingData).writeImage(this.outputStream);
+        }
+    }
+
+    public void setProfilingDataHolder(ProfilingDataHolder dataHolder) {
+        this.dataHolder = dataHolder;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setup(Map<String, Object> parameters) {
+    }
+
+    private class ProfilingDrawer {
+
+        private static final int BAR_WIDTH = 520;
+
+        private Map<String, Integer> lineNumberMap = new HashMap<String, Integer>();
+
+        private List<List<ProfilingData>> lineNumber2profilingData = new ArrayList<List<ProfilingData>>();
+
+        private long startTime;
+        private long endTime;
+
+        private final int LINE_HEIGHT = 20;
+        private final int Y_OFFSET = 10;
+        private final int X_OFFSET = 0;
+        private final int MAX_STRING_WIDTH = 350;
+
+        private int maxStringWidth = 0;
+
+        private ProfilingData profilingData;
+
+        public ProfilingDrawer(ProfilingData profilingData) {
+            this.profilingData = profilingData;
+
+            List<ProfilingData> data = this.transformTreeToList();
+
+            this.startTime = data.get(0).getInvocationStartTime();
+            this.endTime = data.get(0).getInvocationEndTime();
+
+            for (ProfilingData pd : data) {
+                if (this.getLineNumber(pd) == null) {
+                    this.lineNumberMap.put(pd.getId(), this.lineNumberMap.size());
+                }
+            }
+
+            for (ProfilingData pd : data) {
+                Integer lineNumber = this.getLineNumber(pd);
+
+                List<ProfilingData> pds;
+
+                if (this.lineNumber2profilingData.size() <= lineNumber) {
+                    pds = new ArrayList<ProfilingData>();
+                    pds.add(pd);
+                    this.lineNumber2profilingData.add(pds);
+                } else {
+                    this.lineNumber2profilingData.get(lineNumber).add(pd);
+                }
+            }
+        }
+
+        private List<ProfilingData> transformTreeToList() {
+            ArrayList<ProfilingData> list = new ArrayList<ProfilingData>();
+            this.traverse(this.profilingData, list);
+            Collections.sort(list, new ProfilingDataComparator());
+
+            return list;
+        }
+
+        private void traverse(ProfilingData profilingData2, ArrayList<ProfilingData> list) {
+            list.add(profilingData2);
+
+            for (ProfilingData pd : profilingData2.getChildren()) {
+                this.traverse(pd, list);
+            }
+        }
+
+        private float factor(long x) {
+            long executionTime = this.endTime - this.startTime;
+            long t = x - this.startTime;
+
+            return t / (float) executionTime;
+        }
+
+        private Integer getLineNumber(ProfilingData pd) {
+            return this.lineNumberMap.get(pd.getId());
+        }
+
+        private int getY(ProfilingData pd) {
+            return this.getLineNumber(pd) * this.LINE_HEIGHT + this.Y_OFFSET;
+        }
+
+        public void writeImage(OutputStream os) {
+            int height = this.X_OFFSET + this.lineNumber2profilingData.size() * this.LINE_HEIGHT;
+
+            BufferedImage bufferedImage = new BufferedImage(1000, height, BufferedImage.TYPE_INT_ARGB);
+            Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
+            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            g.setBackground(Color.WHITE);
+
+            FontMetrics metrics = g.getFontMetrics();
+
+            this.drawDisplayNameStrings(g, metrics);
+
+            final int xOffset = this.X_OFFSET + this.maxStringWidth + 10;
+            final int yOffset = -10;
+
+            this.drawExecutionTimeStrings(g, xOffset);
+
+            this.drawGrayBars(g, xOffset, yOffset);
+            this.drawGreenBars(g, xOffset, yOffset);
+            this.drawOrangeBars(g, xOffset, yOffset);
+            this.drawCallerLines(g, xOffset, yOffset);
+
+            g.dispose();
+
+            try {
+                ImageIO.write(bufferedImage, "png", os);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        private void drawDisplayNameStrings(Graphics2D g, FontMetrics metrics) {
+            g.setColor(Color.BLACK);
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                String displayName = pds.get(0).getDisplayName();
+                for (ProfilingData pd : pds) {
+                    if (pd.isDisplayNameSet()) {
+                        displayName = pd.getDisplayName();
+                        break;
+                    }
+                }
+
+                displayName = this.adaptToMaxWidth(metrics, displayName);
+                int stringWidth = metrics.stringWidth(displayName);
+
+                g.drawString(displayName, this.X_OFFSET, this.getY(pds.get(0)));
+
+                this.maxStringWidth = Math.max(this.maxStringWidth, stringWidth);
+            }
+        }
+
+        private void drawGrayBars(Graphics2D g, final int xOffset, final int yOffset) {
+            g.setColor(new Color(235, 235, 235));
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                g.fillRect(xOffset, this.getY(pds.get(0)) + yOffset, BAR_WIDTH, 15);
+            }
+        }
+
+        private void drawGreenBars(Graphics2D g, final int xOffset, final int yOffset) {
+            g.setColor(Color.GREEN.darker().darker());
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                int y = this.getY(pds.get(0)) + yOffset;
+                for (ProfilingData pd : pds) {
+                    int x = (int) (BAR_WIDTH * this.factor(pd.getInvocationStartTime()));
+                    int width = (int) (BAR_WIDTH * this.factor(pd.getInvocationEndTime()) - x);
+
+                    g.fillRect(xOffset + x, y, width, 15);
+                }
+            }
+        }
+
+        private void drawOrangeBars(Graphics2D g, final int xOffset, final int yOffset) {
+            g.setColor(Color.ORANGE);
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                int y = this.getY(pds.get(0)) + yOffset;
+
+                for (ProfilingData pd : pds) {
+                    this.drawInactive(g, xOffset, y, pd.getChildren());
+                }
+            }
+        }
+
+        private void drawCallerLines(Graphics2D g, final int xOffset, final int yOffset) {
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                for (ProfilingData pd : pds) {
+                    ProfilingData parent = pd.getParent();
+
+                    if (parent == null) {
+                        continue;
+                    }
+
+                    int thisLine = this.getY(pd) + yOffset + 7;
+                    int parentLine = this.getY(parent) + yOffset + 7;
+
+                    int startX = (int) (BAR_WIDTH * this.factor(pd.getInvocationStartTime()));
+                    int endX = (int) (BAR_WIDTH * this.factor(pd.getInvocationEndTime()));
+
+                    g.setColor(Color.DARK_GRAY);
+                    g.drawLine(startX + xOffset, thisLine, startX + xOffset, parentLine);
+
+                    g.setColor(Color.RED.darker());
+                    g.drawLine(endX + xOffset, thisLine, endX + xOffset, parentLine);
+                }
+            }
+        }
+
+        private void drawExecutionTimeStrings(Graphics2D g, final int xOffset) {
+            g.setColor(Color.BLACK);
+            for (List<ProfilingData> pds : this.lineNumber2profilingData) {
+                double executionTime = 0;
+                for (ProfilingData pd : pds) {
+                    executionTime += pd.getExecutionMillis();
+                }
+
+                String et = String.format(Locale.US, "%.3fms", executionTime);
+                g.drawString(et, xOffset + BAR_WIDTH + 20, this.getY(pds.get(0)));
+            }
+        }
+
+        private String adaptToMaxWidth(FontMetrics metrics, String displayName) {
+            String s = displayName;
+            while (metrics.stringWidth(s) > this.MAX_STRING_WIDTH) {
+                int length = s.length();
+                String start = s.substring(0, length / 2 - 1);
+                String end = s.substring(length / 2 + 1, length);
+                s = start + end;
+            }
+
+            if (!s.equals(displayName)) {
+                int length = s.length();
+                String start = s.substring(0, length / 2);
+                String end = s.substring(length / 2, length);
+                s = start + "..." + end;
+            }
+
+            return s;
+        }
+
+        private void drawInactive(Graphics g, int xOffset, int y, List<ProfilingData> children) {
+            for (ProfilingData pd : children) {
+                int x = (int) (BAR_WIDTH * this.factor(pd.getInvocationStartTime()));
+                int width = (int) (BAR_WIDTH * this.factor(pd.getInvocationEndTime()) - x);
+
+                g.fillRect(xOffset + x, y, width, 15);
+            }
+        }
+    }
+
+    private class ErrorMessageDrawer {
+
+        public void writeImage(OutputStream os) {
+            BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+            Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
+            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+            String errormsg = String.format("Profiling Data for id '%s' couldn't be found.",
+                    ProfilingPngSerializer.this.id);
+
+            FontMetrics metrics = g.getFontMetrics();
+            int stringWidth = metrics.stringWidth(errormsg);
+
+            bufferedImage = new BufferedImage(stringWidth + 2, 20, BufferedImage.TYPE_INT_ARGB);
+            g = (Graphics2D) bufferedImage.getGraphics();
+            g.setBackground(Color.WHITE);
+            g.setColor(Color.BLACK);
+            g.drawString(errormsg, 1, 15);
+            g.dispose();
+
+            try {
+                ImageIO.write(bufferedImage, "png", os);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public CacheKey constructCacheKey() {
+        return new ParameterCacheKey("id", this.id);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/ProfilingPngSerializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ * Provides cocoon-profiling pipeline components.
+ *  
+ */
+package org.apache.cocoon.profiling.component;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/component/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,75 @@
+/*
+ * 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.data;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.management.ManagementService;
+
+public class EhCacheProfilingDataHolder implements ProfilingDataHolder {
+
+    private Cache profilingCache;
+    private CacheManager cacheManager;
+    private String cacheName;
+
+    /**
+     * Get the cache from ehcache cache manager and register MBeans.
+     */
+    public void setupCache() {
+        this.profilingCache = this.cacheManager.getCache(this.cacheName);
+        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+        boolean registerCacheManager = false;
+        boolean registerCaches = true;
+        boolean registerCacheConfigurations = true;
+        boolean registerCacheStatistics = true;
+        ManagementService.registerMBeans(this.cacheManager, mBeanServer, registerCacheManager, registerCaches,
+                registerCacheConfigurations, registerCacheStatistics);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.profiling.data.ProfilingDataHolder#get(java.lang.String)
+     */
+    public ProfilingData get(String id) {
+        Element e = this.profilingCache.get(id);
+        return e == null ? null : (ProfilingData) e.getObjectValue();
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.cocoon.profiling.data.ProfilingDataHolder#store(java.lang.String,
+     *      org.apache.cocoon.profiling.data.ProfilingData)
+     */
+    public void store(String id, ProfilingData data) {
+        this.profilingCache.put(new Element(id, data));
+    }
+
+    public void setCacheManager(CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
+    }
+
+    public void setCacheName(String cacheName) {
+        this.cacheName = cacheName;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/EhCacheProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java Thu Aug 20 20:43:20 2009
@@ -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.data;
+
+import java.io.Serializable;
+
+/**
+ * A data class to store the necessary information used for profiling of an object instance.
+ */
+public class InstanceRepresentation implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    private final Class<?> clazz;
+    private final String value;
+
+    public InstanceRepresentation(Object o) {
+        this.value = o == null ? "(null)" : o.toString();
+        this.clazz = o == null ? null : o.getClass();
+    }
+
+    public Class<?> getRepresentedClass() {
+        return this.clazz;
+    }
+
+    public String getStringRepresentation() {
+        return this.value;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/InstanceRepresentation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,302 @@
+/*
+ * 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.data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Class used to store the gathered profiling information for one intercepted method invocation.
+ */
+public class ProfilingData implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private List<InstanceRepresentation> arguments = new ArrayList<InstanceRepresentation>();
+
+    private long callFrameIdentity;
+
+    private List<ProfilingData> children = new ArrayList<ProfilingData>();
+
+    private Map<String, String> data = new HashMap<String, String>();
+
+    private String displayName;
+
+    private Exception exception;
+
+    private transient String id;
+
+    private int invocationDepth;
+
+    private Long invocationEndTime;
+
+    private Long invocationStartTime;
+
+    private String method;
+
+    private ProfilingData parent;
+
+    private String profiler;
+
+    private String profilingId;
+
+    private InstanceRepresentation returnValue;
+
+    private boolean root;
+
+    private InstanceRepresentation target;
+
+    private long targetIdentity;
+
+    /**
+     * Add the given {@link ProfilingData} as child and make this object its parent.
+     * 
+     * @param data
+     */
+    public void addChild(ProfilingData data) {
+        this.children.add(data);
+        data.setParent(this);
+    }
+
+    /**
+     * Add the given list of children and make this object their parent.
+     * 
+     * @param children
+     */
+    public void addChildren(List<ProfilingData> children) {
+        this.children.addAll(children);
+        for (ProfilingData d : children) {
+            d.setParent(this);
+        }
+    }
+
+    public void addData(String key, String value) {
+        this.data.put(key, value);
+    }
+
+    public List<InstanceRepresentation> getArguments() {
+        return this.arguments;
+    }
+
+    public ProfilingData getChild(int index) {
+        return this.children.get(index);
+    }
+
+    public int getChildCount() {
+        return this.children.size();
+    }
+
+    public List<ProfilingData> getChildren() {
+        return Collections.unmodifiableList(this.children);
+    }
+
+    public Map<String, String> getData() {
+        return Collections.unmodifiableMap(this.data);
+    }
+
+    public String getData(String key) {
+        return this.data.get(key);
+    }
+
+    /**
+     * @return the display name or the simple name of the target object's class if the displayName
+     *         is null, or the String representation of this object, if both the displayName and the
+     *         target happen to be null.
+     */
+    public String getDisplayName() {
+        if (this.displayName != null) {
+            return this.displayName;
+        }
+        if (this.target != null) {
+            return this.target.getRepresentedClass().getSimpleName();
+        }
+        return this.toString();
+    }
+
+    public Exception getException() {
+        return this.exception;
+    }
+
+    public double getExecutionMillis() {
+        return (this.invocationEndTime - this.invocationStartTime) / 1000000.0;
+    }
+
+    /**
+     * @return the id, which is built combining the object id of the target and of the callFrame.
+     */
+    public String getId() {
+        if (this.id == null) {
+            this.id = String.valueOf(this.targetIdentity << 32 + this.callFrameIdentity);
+        }
+        return this.id;
+    }
+
+    public int getInvocationDepth() {
+        return this.invocationDepth;
+    }
+
+    /**
+     * 
+     * @return the invocation end time in nanoseconds
+     */
+    public Long getInvocationEndTime() {
+        return this.invocationEndTime;
+    }
+
+    /**
+     * 
+     * @return the invocation start time in nanoseconds
+     */
+    public Long getInvocationStartTime() {
+        return this.invocationStartTime;
+    }
+
+    public String getMethod() {
+        return this.method;
+    }
+
+    public ProfilingData getParent() {
+        return this.parent;
+    }
+
+    public String getProfiler() {
+        return this.profiler;
+    }
+
+    public String getProfilingId() {
+        return this.profilingId;
+    }
+
+    public InstanceRepresentation getReturnValue() {
+        return this.returnValue;
+    }
+
+    public InstanceRepresentation getTarget() {
+        return this.target;
+    }
+
+    public boolean hasChildren() {
+        return !this.children.isEmpty();
+    }
+
+    public boolean isDisplayNameSet() {
+        return this.displayName != null;
+    }
+
+    public boolean isRoot() {
+        return this.root;
+    }
+
+    /**
+     * Remove all children and set their parent <code>null</code>.
+     */
+    public void removeAllChildren() {
+        for (ProfilingData d : this.children) {
+            d.setParent(null);
+        }
+        this.children.clear();
+    }
+
+    /**
+     * Remove the given {@link ProfilingData} child and set its parent to <code>null</code> if
+     * removal was successful.
+     * 
+     * @param data
+     */
+    public boolean removeChild(ProfilingData data) {
+        boolean success = this.children.remove(data);
+        if (success) {
+            data.setParent(null);
+        }
+        return success;
+    }
+
+    public void setArguments(Object[] arguments) {
+        this.arguments.clear();
+        for (Object o : arguments) {
+            this.arguments.add(new InstanceRepresentation(o));
+        }
+    }
+
+    public void setCallFrameId(int callFrameId) {
+        this.id = null;
+        this.callFrameIdentity = callFrameId;
+    }
+
+    public void setDisplayName(String displayName) {
+        this.displayName = displayName;
+    }
+
+    public void setException(Exception exception) {
+        this.exception = exception;
+    }
+
+    public void setInvocationDepth(int depth) {
+        this.invocationDepth = depth;
+    }
+
+    /**
+     * @param invocationEndTime
+     *            the invocation end time in nanoseconds
+     */
+    public void setInvocationEndTime(Long invocationEndTime) {
+        this.invocationEndTime = invocationEndTime;
+    }
+
+    /**
+     * 
+     * @param invocationStartTime
+     *            the invocation start time in nanoseconds
+     */
+    public void setInvocationStartTime(Long invocationStartTime) {
+        this.invocationStartTime = invocationStartTime;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public void setProfiler(String profiler) {
+        this.profiler = profiler;
+    }
+
+    public void setProfilingId(String profilingId) {
+        this.profilingId = profilingId;
+    }
+
+    public void setReturnValue(Object obj) {
+        this.returnValue = new InstanceRepresentation(obj);
+    }
+
+    public void setRoot(boolean root) {
+        this.root = root;
+    }
+
+    public void setTarget(Object target) {
+        this.id = null;
+        this.targetIdentity = System.identityHashCode(target);
+        this.target = new InstanceRepresentation(target);
+    }
+
+    private void setParent(ProfilingData parent) {
+        this.parent = parent;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain