Wicket Metrics - Simplified time measurement

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c4ac72e5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c4ac72e5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c4ac72e5

Branch: refs/heads/master
Commit: c4ac72e5eb1861f5249448a8e10414e9ed8cfc2d
Parents: 5f8b9fe
Author: Tobias Soloschenko <[email protected]>
Authored: Thu Mar 10 14:12:21 2016 +0100
Committer: Tobias Soloschenko <[email protected]>
Committed: Wed Mar 16 17:55:10 2016 +0100

----------------------------------------------------------------------
 .../apache/wicket/metrics/WicketMetrics.java    | 30 ++++++++++++++++++--
 .../metrics/aspects/ApplicationAspect.java      | 12 +-------
 2 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c4ac72e5/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java
----------------------------------------------------------------------
diff --git 
a/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java 
b/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java
index 055b07f..9c4eb59 100644
--- a/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java
+++ b/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.metrics;
 
+import org.aspectj.lang.ProceedingJoinPoint;
+
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer.Context;
@@ -56,7 +58,7 @@ public class WicketMetrics
         * @param name
         *            the name of the meter to be marked
         */
-       protected void mark(String name)
+       public void mark(String name)
        {
                if (WicketMetrics.enabled)
                {
@@ -71,7 +73,7 @@ public class WicketMetrics
         *            the name of the timer context
         * @return the timer context
         */
-       protected Context context(String name)
+       public Context context(String name)
        {
                if (WicketMetrics.enabled)
                {
@@ -98,6 +100,30 @@ public class WicketMetrics
        }
 
        /**
+        * Simply measure the time for a {@literal @}around
+        * 
+        * @param name
+        *            the name of the timer context
+        * @param joinPoint
+        *            the joinPoint to be proceed
+        * @return the value of the join point
+        * @throws Throwable
+        *             if there is an exception while execution
+        */
+       public Object measureTime(String name, ProceedingJoinPoint joinPoint) 
throws Throwable
+       {
+               Context context = context(name);
+               try
+               {
+                       return joinPoint.proceed();
+               }
+               finally
+               {
+                       stopQuietly(context);
+               }
+       }
+
+       /**
         * Starts the jmx reporter
         */
        public static void startJmxReporter()

http://git-wip-us.apache.org/repos/asf/wicket/blob/c4ac72e5/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java
----------------------------------------------------------------------
diff --git 
a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java
 
b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java
index 10d51a8..45fe51d 100644
--- 
a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java
+++ 
b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java
@@ -21,8 +21,6 @@ import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 
-import com.codahale.metrics.Timer.Context;
-
 /**
  * Aspect to handle basic web application information
  * 
@@ -46,14 +44,6 @@ public class ApplicationAspect extends WicketMetrics
        @Around("execution(* 
org.apache.wicket.protocol.http.WicketFilter.processRequest(..))")
        public Object aroundRequestProcessed(ProceedingJoinPoint joinPoint) 
throws Throwable
        {
-               Context context = context("core/application/request");
-               try
-               {
-                       return joinPoint.proceed();
-               }
-               finally
-               {
-                       stopQuietly(context);
-               }
+               return measureTime("core/application/request", joinPoint);
        }
 }

Reply via email to