I want to measure execution time of a method which is present in a client library. My application is a spring boot app and I am calling a method present in a class coming from some library. I tried running below code but it does not working. In my case, client class object is not managed by spring container which could be a reason but is there any way to get hold of that method.
@Aspect
@Component
public class LoggingAspect {
public static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
@Around("execution(public * Invokers.ApiClient.execute(..))") //okhttp3.Call,
public Object methodTimeLogger(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
// Get intercepted method details
String className = methodSignature.getDeclaringType().getSimpleName();
String methodName = methodSignature.getName();
// Measure method execution time
StopWatch stopWatch = new StopWatch(className + "->" + methodName);
stopWatch.start(methodName);
Object result = proceedingJoinPoint.proceed();
stopWatch.stop();
System.out.println("----------Start----------");
// Log method execution time
if (logger.isInfoEnabled()) {
logger.info(stopWatch.prettyPrint());
}
System.out.println("----------End----------");
return result;
}
}