すべてのクエリの実行時間を計算し、クエリに時間がかかる場合はログに記録するクエリログプロファイラーを構築しようとしています。AspectJ を使用すると、Wrapper に比べて時間がかかります。なので、性能向上の余地があればバイトバディとか他のライブラリを使いたいです。
これがAspectJを使用した現在の実装です。
@Aspect
public class QueryLoggerProfiler {
private static final Logger LOGGER = Logger.getLogger(QueryLoggerProfiler.class.getName());
public static final String QUERY_LOGGING_POINTCUT = "execution(* com.abc.PreparedStatement.execute*(..))";
@
Pointcut(QUERY_LOGGING_POINTCUT)
private void queryPointcut() {}
@
Around("queryPointcut()")
public Object profile(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
long start = System.currentTimeMillis();
Object output = joinPoint.proceed();
long elapsedTime = System.currentTimeMillis() - start;
if (elapsedTime >= 5) {
LOGGER.info(">>>>>>>>>>>>>>>>>>>... Going to call the method ... " + method.getName());
LOGGER.info(">>>>>>>>>>>>>>>>>>>... With parameter ... " + method.getParameters());
LOGGER.info(">>>>>>>>>>>>>>>>>>>... Method execution time: " + elapsedTime + " milliseconds.");
}
return output;
}
}
パフォーマンスのボトルネックがないだけでなく、ログを記録する方法はありますか?