-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[test] 메서드 실행 시간 측정 AOP 구현 #48
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AOP까지 쓰실 줄 몰랐네요. 고생 많으셨습니다!
// 조인포인트를 어노테이션으로 설정 | ||
@Pointcut("@annotation(gdsc.cau.puangbe.common.annotation.ExeTimer)") | ||
private void timer(){}; | ||
|
||
// 메서드 실행 전,후로 시간을 공유해야 하기 때문 | ||
@Around("timer()") | ||
public void AssumeExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { | ||
|
||
StopWatch stopWatch = new StopWatch(); | ||
|
||
stopWatch.start(); | ||
joinPoint.proceed(); // 조인포인트의 메서드 실행 | ||
stopWatch.stop(); | ||
|
||
long totalTimeMillis = stopWatch.getTotalTimeMillis(); | ||
|
||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
String methodName = signature.getMethod().getName(); | ||
|
||
log.info("실행 메서드: {}, 실행시간 = {}ms", methodName, totalTimeMillis); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
범용성 있게 쓸 수 있겠네요.
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExeTimer { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ANNOTATION_TYPE이 추가로 붙은 이유가 있을까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드만 넣을까 하다가 @PuangUser
에 대해 적용하고 싶은 경우가 생길까봐 추가했습니다!
#️⃣ 연관 이슈
📝 작업 내용
메서드 실행 시간 측정 AOP를 구현했습니다. 실행 시간을 측정하고자 하는 메서드에
@Exetimer
를 붙여서 사용하면 됩니다.