diff --git a/src/main/java/com/odiga/fiesta/common/aop/A.java b/src/main/java/com/odiga/fiesta/common/aop/A.java deleted file mode 100644 index c4c638f5..00000000 --- a/src/main/java/com/odiga/fiesta/common/aop/A.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.odiga.fiesta.common.aop; - -public class A { -} diff --git a/src/main/java/com/odiga/fiesta/common/aop/ExeTimer.java b/src/main/java/com/odiga/fiesta/common/aop/ExeTimer.java new file mode 100644 index 00000000..89952fd1 --- /dev/null +++ b/src/main/java/com/odiga/fiesta/common/aop/ExeTimer.java @@ -0,0 +1,12 @@ +package com.odiga.fiesta.common.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +// https://medium.com/mo-zza/performance-test-4-aop-timer-d40b99fa5b7c +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExeTimer { +} diff --git a/src/main/java/com/odiga/fiesta/common/aop/ExpTimerImpl.java b/src/main/java/com/odiga/fiesta/common/aop/ExpTimerImpl.java new file mode 100644 index 00000000..69300635 --- /dev/null +++ b/src/main/java/com/odiga/fiesta/common/aop/ExpTimerImpl.java @@ -0,0 +1,36 @@ +package com.odiga.fiesta.common.aop; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; +import org.springframework.util.StopWatch; + +import lombok.extern.slf4j.Slf4j; + +// https://medium.com/mo-zza/performance-test-4-aop-timer-d40b99fa5b7c +@Aspect +@Component +@Slf4j +public class ExpTimerImpl { + + @Pointcut("@annotation(com.odiga.fiesta.common.aop.ExeTimer)") + private void timer() { + } + + @Around("timer()") + public Object AssumeExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + Object result = joinPoint.proceed(); + stopWatch.stop(); + long totalTimeMillis = stopWatch.getTotalTimeMillis(); + MethodSignature signature = (MethodSignature)joinPoint.getSignature(); + String methodName = signature.getMethod().getName(); + log.info("메서드 이름 : " + methodName); + log.info("수행 시간 : " + totalTimeMillis + "ms"); + return result; + } +}