From 5fbc66bc3dc9cd720d01fce32f69693188de10b0 Mon Sep 17 00:00:00 2001 From: juno-junho Date: Tue, 14 May 2024 17:15:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=20=EC=B8=A1=EC=A0=95=EC=9D=84=20=EC=9C=84=ED=95=9C=20StopWatch?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/spaceclub/global/timer/StopWatch.java | 14 ++++++++ .../global/timer/StopWatchExecutor.java | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/com/spaceclub/global/timer/StopWatch.java create mode 100644 src/main/java/com/spaceclub/global/timer/StopWatchExecutor.java diff --git a/src/main/java/com/spaceclub/global/timer/StopWatch.java b/src/main/java/com/spaceclub/global/timer/StopWatch.java new file mode 100644 index 00000000..7cb5b5f7 --- /dev/null +++ b/src/main/java/com/spaceclub/global/timer/StopWatch.java @@ -0,0 +1,14 @@ +package com.spaceclub.global.timer; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.RUNTIME) +public @interface StopWatch { + +} diff --git a/src/main/java/com/spaceclub/global/timer/StopWatchExecutor.java b/src/main/java/com/spaceclub/global/timer/StopWatchExecutor.java new file mode 100644 index 00000000..3b993719 --- /dev/null +++ b/src/main/java/com/spaceclub/global/timer/StopWatchExecutor.java @@ -0,0 +1,34 @@ +package com.spaceclub.global.timer; + +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.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.util.StopWatch; + +@Slf4j +@Aspect +@Component +@Profile("local") +public class StopWatchExecutor { + + @Pointcut("@annotation(com.spaceclub.global.timer.StopWatch)") + private void stopWatch() { + } + + @Around("stopWatch()") + public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { + StopWatch stopWatch = new StopWatch(); + try { + stopWatch.start(joinPoint.toShortString() + "Timer started"); + return joinPoint.proceed(); + } finally { + stopWatch.stop(); + log.info(stopWatch.prettyPrint()); + } + } + +}