-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
fa2379d
commit 27c6efc
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/com/spaceclub/global/timer/ExecutionStopWatch.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 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 ExecutionStopWatch { | ||
|
||
@Pointcut("@annotation(com.spaceclub.global.timer.StopWatch)") | ||
private void stopWatch() { | ||
} | ||
|
||
@Around("stopWatch()") | ||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { | ||
StopWatch stopWatch = new StopWatch(); | ||
Object result = null; | ||
try { | ||
stopWatch.start(joinPoint.toShortString() + "Timer started"); | ||
result = joinPoint.proceed(); | ||
} finally { | ||
stopWatch.stop(); | ||
log.info(stopWatch.prettyPrint()); | ||
log.info("Execution time of " + joinPoint.getSignature() + " : " + stopWatch.getTotalTimeMillis() + " ms"); | ||
} | ||
return result; | ||
} | ||
|
||
} |
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,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 { | ||
|
||
} |