@ Around ( "execution(* *(..)) && @annotation(TimerJ)" ) public Object around ( ProceedingJoinPoint point ) throws Throwable { String methodName = MethodSignature . class . cast ( point . getSignature ( ) ) . getMethod ( ) . getName ( ) ; String methodArgs = point . getArgs ( ) . toString ( ) ; MetricRegistry metricRegistry = Metrics . getRegistry ( ) ; Timer timer ; String metricName = "Starting method " + methodName + "at " + System . nanoTime ( ) ; synchronized ( this ) { if ( metricRegistry . getTimers ( ) . containsKey ( methodName ) ) { timer = metricRegistry . getTimers ( ) . get ( metricName ) ; } else { timer = metricRegistry . register ( metricName , new Timer ( ) ) ; } } Timer . Context before = timer . time ( ) ; Object result = point . proceed ( ) ; long timeAfter = before . stop ( ) ; logger . debug ( "Method " + methodName + " with args " + methodArgs + " executed in " + timeAfter + " ns" ) ; return result ; }
Function that register metrics .