Permalink
Browse files

Merge pull request #12 from javabrett/PERFFORJ-61-56

PERFFORJ-61 and PERFFORJ-56
  • Loading branch information...
2 parents ba33634 + 66e462c commit 8143b6b2412142ad9327adaa1fb35c50d6a57044 @xuhuisheng xuhuisheng committed Jun 13, 2012
Showing with 997 additions and 38 deletions.
  1. +35 −4 pom.xml
  2. +4 −14 src/main/java/org/perf4j/aop/AbstractTimingAspect.java
  3. +41 −4 src/main/java/org/perf4j/aop/AgnosticTimingAspect.java
  4. +44 −0 src/main/java/org/perf4j/aop/ProfiledTimingAspect.java
  5. +34 −0 src/main/java/org/perf4j/aop/ScopedTimingAspect.java
  6. +36 −0 src/main/java/org/perf4j/commonslog/aop/ScopedTimingAspect.java
  7. +4 −2 src/main/java/org/perf4j/commonslog/aop/TimingAspect.java
  8. +77 −0 src/main/java/org/perf4j/helpers/PackageParentProperties.java
  9. +50 −0 src/main/java/org/perf4j/helpers/Perf4jProperties.java
  10. +38 −0 src/main/java/org/perf4j/javalog/aop/ScopedTimingAspect.java
  11. +7 −4 src/main/java/org/perf4j/javalog/aop/TimingAspect.java
  12. +36 −0 src/main/java/org/perf4j/log4j/aop/ScopedTimingAspect.java
  13. +4 −2 src/main/java/org/perf4j/log4j/aop/TimingAspect.java
  14. +35 −0 src/main/java/org/perf4j/slf4j/aop/ScopedTimingAspect.java
  15. +4 −2 src/main/java/org/perf4j/slf4j/aop/TimingAspect.java
  16. +23 −1 src/test/java/org/perf4j/aop/AopTest.java
  17. +12 −0 src/test/java/org/perf4j/aop/EjbAopTest.java
  18. +27 −0 src/test/java/org/perf4j/aop/EjbProfiledObject.java
  19. +5 −0 src/test/java/org/perf4j/aop/EjbProfiledObjectInterface.java
  20. +1 −1 src/test/java/org/perf4j/aop/InMemoryTimingAspect.java
  21. +35 −1 src/test/java/org/perf4j/aop/ProfiledObject.java
  22. +44 −0 src/test/java/org/perf4j/aop/ScopedInMemoryTimingAspect.java
  23. +64 −0 src/test/java/org/perf4j/helpers/PackageParentPropertiesTest.java
  24. +53 −0 src/test/java/org/perf4j/javalog/aop/AopTest.java
  25. +51 −0 src/test/java/org/perf4j/javalog/aop/ListHandler.java
  26. +56 −0 src/test/java/org/perf4j/log4j/AopTest.java
  27. +58 −0 src/test/java/org/perf4j/log4j/ListAppender.java
  28. +67 −0 src/test/java/org/perf4j/logback/AopTest.java
  29. +2 −3 src/test/java/org/perf4j/logback/AppenderTest.java
  30. +21 −0 src/test/resources/META-INF/aop.xml
  31. +3 −0 src/test/resources/org/perf4j/log4j/log4j.xml
  32. +7 −0 src/test/resources/org/perf4j/logback/logback.xml
  33. +19 −0 src/test/resources/perf4j.properties
View
39 pom.xml
@@ -196,6 +196,7 @@
<currentProductionVersion>0.9.16</currentProductionVersion>
<currentSnapshotVersion>0.9.17-SNAPSHOT</currentSnapshotVersion>
<git.executable>git</git.executable>
+ <aspectjVersion>1.6.11</aspectjVersion>
</properties>
<profiles>
@@ -210,9 +211,39 @@
<git.executable>git.cmd</git.executable>
</properties>
</profile>
+ <profile>
+ <id>ajc</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>aspectj-maven-plugin</artifactId>
+ <version>1.4</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjtools</artifactId>
+ <version>${aspectjVersion}</version>
+ </dependency>
+ </dependencies>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal> <!-- use this goal to weave all your main classes -->
+ <goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
-
<dependencies>
<!-- if you use the log4j implementation of perf4j, you must also include this dependency -->
<dependency>
@@ -262,15 +293,15 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
- <version>1.6.1</version>
+ <version>${aspectjVersion}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
- <version>1.6.1</version>
+ <version>${aspectjVersion}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@@ -582,7 +613,7 @@
<includes>
<include>**/*Test.java</include>
</includes>
- <argLine>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.6.1/aspectjweaver-1.6.1.jar</argLine>
+ <argLine>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectjVersion}/aspectjweaver-${aspectjVersion}.jar</argLine>
<systemProperties>
<property>
<name>log4j.debug</name>
@@ -16,7 +16,6 @@
package org.perf4j.aop;
import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.perf4j.LoggingStopWatch;
@@ -30,17 +29,8 @@
*/
@Aspect
public abstract class AbstractTimingAspect extends AgnosticTimingAspect {
- /**
- * This advice is used to add the StopWatch logging statements around method executions that have been tagged
- * with the Profiled annotation.
- *
- * @param pjp The ProceedingJoinPoint encapulates the method around which this aspect advice runs.
- * @param profiled The profiled annotation that was attached to the method.
- * @return The return value from the method that was executed.
- * @throws Throwable Any exceptions thrown by the underlying method.
- */
- @Around(value = "execution(* *(..)) && @annotation(profiled)", argNames = "pjp,profiled")
- public Object doPerfLogging(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
+
+ protected Object runProfiledMethod(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
//We just delegate to the super class, wrapping the AspectJ-specific ProceedingJoinPoint as an AbstractJoinPoint
return runProfiledMethod(
new AbstractJoinPoint() {
@@ -51,12 +41,12 @@ public Object doPerfLogging(final ProceedingJoinPoint pjp, Profiled profiled) th
public Object[] getParameters() { return pjp.getArgs(); }
public String getMethodName() { return pjp.getSignature().getName(); }
-
+
public Class<?> getDeclaringClass() { return pjp.getSignature().getDeclaringType(); }
},
profiled,
newStopWatch(profiled.logger() + "", profiled.level())
- );
+ );
}
/**
@@ -5,6 +5,7 @@
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.context.HashMapContext;
import org.perf4j.LoggingStopWatch;
+import org.perf4j.helpers.Perf4jProperties;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -82,9 +83,24 @@ protected String getStopWatchTag(Profiled profiled,
Throwable exceptionThrown) {
String tag;
if (Profiled.DEFAULT_TAG_NAME.equals(profiled.tag())) {
+ // look for properties-based default
// if the tag name is not explicitly set on the Profiled annotation,
- // use the name of the method being annotated.
- tag = joinPoint.getMethodName();
+ final StringBuilder sb = new StringBuilder("tag.").append(joinPoint.getDeclaringClass().getName())
+ .append('.').append(joinPoint.getMethodName());
+ tag = Perf4jProperties.INSTANCE.getProperty(sb.toString());
+
+ if (tag == null) {
+ // fall back to using the name of the method being annotated.
+ tag = joinPoint.getMethodName();
+ } else if (tag.indexOf("{") >= 0) {
+ tag = evaluateJexl(tag,
+ joinPoint.getMethodName(),
+ joinPoint.getParameters(),
+ joinPoint.getExecutingObject(),
+ joinPoint.getDeclaringClass(),
+ returnValue,
+ exceptionThrown);
+ }
} else if (profiled.el() && profiled.tag().indexOf("{") >= 0) {
tag = evaluateJexl(profiled.tag(),
joinPoint.getMethodName(),
@@ -116,7 +132,28 @@ protected String getStopWatchMessage(Profiled profiled,
Object returnValue,
Throwable exceptionThrown) {
String message;
- if (profiled.el() && profiled.message().indexOf("{") >= 0) {
+ if (profiled.message().length() == 0) {
+ // look for properties-based default
+ // if the message name is not explicitly set on the Profiled annotation,
+ final StringBuilder sb = new StringBuilder("message.").append(joinPoint.getDeclaringClass().getName())
+ .append('.').append(joinPoint.getMethodName());
+ message = Perf4jProperties.INSTANCE.getProperty(sb.toString());
+
+ if (message == null) {
+ // may be null, that's OK
+ return message;
+ } else {
+ if (message.indexOf("{") >= 0) {
+ message = evaluateJexl(message,
+ joinPoint.getMethodName(),
+ joinPoint.getParameters(),
+ joinPoint.getExecutingObject(),
+ joinPoint.getDeclaringClass(),
+ returnValue,
+ exceptionThrown);
+ }
+ }
+ } else if (profiled.el() && profiled.message().indexOf("{") >= 0) {
message = evaluateJexl(profiled.message(),
joinPoint.getMethodName(),
joinPoint.getParameters(),
@@ -128,7 +165,7 @@ protected String getStopWatchMessage(Profiled profiled,
message = null;
}
} else {
- message = "".equals(profiled.message()) ? null : profiled.message();
+ message = profiled.message();
}
return message;
}
@@ -0,0 +1,44 @@
+/* Copyright (c) 2008-2009 HomeAway, Inc.
+ * All rights reserved. http://www.perf4j.org
+ *
+ * Licensed 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.perf4j.aop;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public abstract class ProfiledTimingAspect extends AbstractTimingAspect {
+
+ /**
+ * This advice is used to add the StopWatch logging statements around method executions that have been tagged
+ * with the Profiled annotation.
+ *
+ * @param pjp The ProceedingJoinPoint encapulates the method around which this aspect advice runs.
+ * @param profiled The profiled annotation that was attached to the method.
+ * @return The return value from the method that was executed.
+ * @throws Throwable Any exceptions thrown by the underlying method.
+ */
+ @Around("execution(* *(..)) && @annotation(profiled)")
+ public Object doPerfLogging(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
+
+ if (profiled == null) {
+ profiled = DefaultProfiled.INSTANCE;
+ }
+
+ return runProfiledMethod(pjp, profiled);
+ }
+
+}
@@ -0,0 +1,34 @@
+/* Copyright (c) 2008-2009 HomeAway, Inc.
+ * All rights reserved. http://www.perf4j.org
+ *
+ * Licensed 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.perf4j.aop;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect
+public abstract class ScopedTimingAspect extends AbstractTimingAspect {
+
+ @Pointcut
+ public abstract void scope();
+
+ @Around("scope()")
+ public Object doPerfLoggingNotProfiled(final ProceedingJoinPoint pjp) throws Throwable {
+ return runProfiledMethod(pjp, DefaultProfiled.INSTANCE);
+ }
+
+}
@@ -0,0 +1,36 @@
+/* Copyright (c) 2011 Brett Randall.
+ * All rights reserved. http://www.perf4j.org
+ *
+ * Licensed 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.perf4j.commonslog.aop;
+
+import org.apache.commons.logging.LogFactory;
+import org.aspectj.lang.annotation.Aspect;
+import org.perf4j.commonslog.CommonsLogStopWatch;
+
+/**
+ *
+ * @author Brett Randall
+ *
+ */
+
+@Aspect
+public abstract class ScopedTimingAspect extends org.perf4j.aop.ScopedTimingAspect {
+
+ protected CommonsLogStopWatch newStopWatch(String loggerName, String levelName) {
+ int levelInt = CommonsLogStopWatch.mapLevelName(levelName);
+ return new CommonsLogStopWatch(LogFactory.getLog(loggerName), levelInt, levelInt);
+ }
+
+}
@@ -17,7 +17,7 @@
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.annotation.Aspect;
-import org.perf4j.aop.AbstractTimingAspect;
+import org.perf4j.aop.ProfiledTimingAspect;
import org.perf4j.commonslog.CommonsLogStopWatch;
/**
@@ -26,9 +26,11 @@
* @author Alex Devine
*/
@Aspect
-public class TimingAspect extends AbstractTimingAspect {
+public class TimingAspect extends ProfiledTimingAspect {
+
protected CommonsLogStopWatch newStopWatch(String loggerName, String levelName) {
int levelInt = CommonsLogStopWatch.mapLevelName(levelName);
return new CommonsLogStopWatch(LogFactory.getLog(loggerName), levelInt, levelInt);
}
+
}
Oops, something went wrong.

0 comments on commit 8143b6b

Please sign in to comment.