I want to create an annotation for sending timer metrics for my methods. I thought about doing something like that:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Timer {
}
And then I want to use AspectJ for doing the metrics collection logic as follows:
@Aspect
public class TimerAspect {
@Pointcut("@annotation(Timer)")
public void timerPointcut() {}
@Pointcut("execution(* com.mycompany.**.*(..))")
public void methodPointcut() {}
@Before("methodPointcut() && timerPointcut()")
public void startTimer() throws Throwable {
// start timer logic here
}
@After("methodPointcut() && timerPointcut()")
public void sendTimer() throws Throwable {
// stop timer and send metrics logic here
}
}
What I would like to understand, and I'm not sure how to benchmark it, is whether I have a performance penalty here when using this annotation.