I defined the following aspect the measure the time execution of some methods:
@Around("execution(@Metrics * *.*(..))")
public Object metrics(ProceedingJoinPoint pointcut) {
Logger log = LoggerFactory.getLogger(pointcut.getSourceLocation().getWithinType());
long ms = System.currentTimeMillis();
try {
Object result = pointcut.proceed();
ms = System.currentTimeMillis() - ms;
log.info(String.format("Execution of method %s finished in %d ms", pointcut.getSignature().getName(), ms));
return result;
}
catch (Throwable e) {
log.error(String.format("Execution of method %s ended with an error", pointcut.getSignature().getName()), e);
}
return null;
}
The problem comes when I use it in the update method of my daos, which is @Transactional. The results I'm getting do not match the real times. I guess it is only measuring the time execution of the java code, but not the database update performed by Hibernate.
Is it possible to measure the complete execution time?
For more information I am using spring 3.2.9 and hibernate 3.5 in my application.