01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.aop.interceptor;
18:
19: import org.aopalliance.intercept.MethodInvocation;
20: import org.apache.commons.logging.Log;
21:
22: import org.springframework.util.StopWatch;
23:
24: /**
25: * Simple AOP Alliance <code>MethodInterceptor</code> for performance monitoring.
26: * This interceptor has no effect on the intercepted method call.
27: *
28: * <p>Uses a <code>StopWatch</code> for the actual performance measuring.
29: *
30: * @author Rod Johnson
31: * @author Dmitriy Kopylenko
32: * @author Rob Harrop
33: * @see org.springframework.util.StopWatch
34: * @see JamonPerformanceMonitorInterceptor
35: */
36: public class PerformanceMonitorInterceptor extends
37: AbstractMonitoringInterceptor {
38:
39: /**
40: * Create a new PerformanceMonitorInterceptor with a static logger.
41: */
42: public PerformanceMonitorInterceptor() {
43: }
44:
45: /**
46: * Create a new PerformanceMonitorInterceptor with a dynamic or static logger,
47: * according to the given flag.
48: * @param useDynamicLogger whether to use a dynamic logger or a static logger
49: * @see #setUseDynamicLogger
50: */
51: public PerformanceMonitorInterceptor(boolean useDynamicLogger) {
52: setUseDynamicLogger(useDynamicLogger);
53: }
54:
55: protected Object invokeUnderTrace(MethodInvocation invocation,
56: Log logger) throws Throwable {
57: String name = createInvocationTraceName(invocation);
58: StopWatch stopWatch = new StopWatch(name);
59: stopWatch.start(name);
60: try {
61: return invocation.proceed();
62: } finally {
63: stopWatch.stop();
64: logger.trace(stopWatch.shortSummary());
65: }
66: }
67:
68: }
|