Skip to content
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

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

RumosZin
Copy link
Contributor

@RumosZin RumosZin commented Sep 5, 2024

#️⃣ 연관 이슈

📝 작업 내용

메서드 실행 시간 측정 AOP를 구현했습니다. 실행 시간을 측정하고자 하는 메서드에 @Exetimer를 붙여서 사용하면 됩니다.

image image

@RumosZin RumosZin added chore 기능 변동 없는 작업(빌드 및 환경설정, 일부 표현 수정 등) feat 기능 구현 labels Sep 5, 2024
@RumosZin RumosZin self-assigned this Sep 5, 2024
Copy link
Contributor

@win-luck win-luck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AOP까지 쓰실 줄 몰랐네요. 고생 많으셨습니다!

Comment on lines +16 to +36
// 조인포인트를 어노테이션으로 설정
@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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

범용성 있게 쓸 수 있겠네요.

Comment on lines +8 to +11
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface ExeTimer {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ANNOTATION_TYPE이 추가로 붙은 이유가 있을까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드만 넣을까 하다가 @PuangUser에 대해 적용하고 싶은 경우가 생길까봐 추가했습니다!

@win-luck win-luck linked an issue Sep 6, 2024 that may be closed by this pull request
2 tasks
@win-luck win-luck merged commit 5b15e9e into GDSC-CAU:main Sep 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore 기능 변동 없는 작업(빌드 및 환경설정, 일부 표현 수정 등) feat 기능 구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[test] method 실행 시간 측정 AOP 구현
2 participants