Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발자 되버리기

Springboot (AOP) 메소드별 실행시간 구하기 본문

개발/Spring_Boot

Springboot (AOP) 메소드별 실행시간 구하기

구본익 2021. 1. 4. 18:28

만약 메소드 단위별로 시간을 측정하고싶다면 (혹은 그 외의 무언가 특수한 공통적인 목적이 있을경우) 해당코드를 응용하면 좋을 것 같다.

 

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeTraceAop {

    @Around("execution(* com.mydirectory..*(..))")
    public Object execute(ProceedingJoinPoint joinPoint) throws Throwable{
        long start = System.currentTimeMillis();
        System.out.println("START: " + joinPoint.toString());
        try{
            return joinPoint.proceed();
        } finally {
            long finish = System.currentTimeMillis();
            long timeMs = finish - start;
            System.out.println("END: " + joinPoint.toString() + " " + timeMs+"ms");
        }
    }
}

 

어딘가 병목현상이 일어났을 경우 쉽고 효율적으로 찾을 수 있다.

 

Comments