I am trying to implement an aspect to time method execution for NIO.
Basically, I need to get the time when a method is initially called and then when a callback is triggered (the callback is always either a failed() or succeeded() call - so I need to associate the initial method call with the appropriate callback.
I have the following implementation but it will not work unless calls are made serially which of course will not be the case.
Any help would be great
public aspect TimerAJ {
private long timer = 0;
private String methodName;
private static Logger logger = LoggerFactory.getLogger(TimerAJ.class);
//the call to the call back method
pointcut timerCall1() : target(io.vertx.core.AsyncResult) && (call( * io.vertx.core.AsyncResult.failed(..)) || call( * io.vertx.core.AsyncResult.succeeded(..)));
//the call to the method itself
pointcut timerCall2() : execution(@Timer * *(..));
before() : timerCall2() {
timer = System.currentTimeMillis();
methodName = methodSignature.getName();
}
after() : timerCall1() {
logger.info(methodName + " " + String.format("%s took %d ms", thisEnclosingJoinPointStaticPart.getSourceLocation().getWithinType().getName(), (System.currentTimeMillis() - timer)));
}
}