-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/gdsc/cau/puangbe/common/annotation/ExeTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package gdsc.cau.puangbe.common.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExeTimer { | ||
} | ||
37 changes: 37 additions & 0 deletions
37
src/main/java/gdsc/cau/puangbe/common/util/ExecutionTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gdsc.cau.puangbe.common.util; | ||
|
||
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.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StopWatch; | ||
|
||
@Slf4j | ||
@Aspect | ||
@Component | ||
public class ExecutionTimer { | ||
// 조인포인트를 어노테이션으로 설정 | ||
@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); | ||
} | ||
Comment on lines
+16
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 범용성 있게 쓸 수 있겠네요. |
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
에 대해 적용하고 싶은 경우가 생길까봐 추가했습니다!