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

feat: 메소드 실행 시간을 구하기 위한 aop 구현 #136

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/com/odiga/fiesta/common/aop/A.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/com/odiga/fiesta/common/aop/ExeTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.odiga.fiesta.common.aop;

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

// https://medium.com/mo-zza/performance-test-4-aop-timer-d40b99fa5b7c
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ExeTimer {
}
36 changes: 36 additions & 0 deletions src/main/java/com/odiga/fiesta/common/aop/ExpTimerImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.odiga.fiesta.common.aop;

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;

import lombok.extern.slf4j.Slf4j;

// https://medium.com/mo-zza/performance-test-4-aop-timer-d40b99fa5b7c
@Aspect
@Component
@Slf4j
public class ExpTimerImpl {

@Pointcut("@annotation(com.odiga.fiesta.common.aop.ExeTimer)")
private void timer() {
}

@Around("timer()")
public Object AssumeExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Object result = joinPoint.proceed();
stopWatch.stop();
long totalTimeMillis = stopWatch.getTotalTimeMillis();
MethodSignature signature = (MethodSignature)joinPoint.getSignature();
String methodName = signature.getMethod().getName();
log.info("메서드 이름 : " + methodName);
log.info("수행 시간 : " + totalTimeMillis + "ms");
return result;
}
}
Loading