Skip to content

Commit

Permalink
feat: 실행 시간 측정을 위한 StopWatch 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho committed May 14, 2024
1 parent fa2379d commit 5fbc66b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/spaceclub/global/timer/StopWatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.spaceclub.global.timer;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
public @interface StopWatch {

}
34 changes: 34 additions & 0 deletions src/main/java/com/spaceclub/global/timer/StopWatchExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.spaceclub.global.timer;

import lombok.extern.slf4j.Slf4j;
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.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Slf4j
@Aspect
@Component
@Profile("local")
public class StopWatchExecutor {

@Pointcut("@annotation(com.spaceclub.global.timer.StopWatch)")
private void stopWatch() {
}

@Around("stopWatch()")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start(joinPoint.toShortString() + "Timer started");
return joinPoint.proceed();
} finally {
stopWatch.stop();
log.info(stopWatch.prettyPrint());
}
}

}

0 comments on commit 5fbc66b

Please sign in to comment.