-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
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); | ||
} | ||
} |