Create execution time measurement aspect
This commit is contained in:
@@ -76,6 +76,7 @@ dependencies {
|
||||
|
||||
// Spring
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-aop'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.core.stat;
|
||||
package com.bartlomiejpluta.base.core.profiling.fps;
|
||||
|
||||
import com.bartlomiejpluta.base.core.gc.Cleanable;
|
||||
import com.bartlomiejpluta.base.core.logic.Updatable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.core.stat;
|
||||
package com.bartlomiejpluta.base.core.profiling.fps;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.bartlomiejpluta.base.core.profiling.time.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface MeasureExecutionTime {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.bartlomiejpluta.base.core.profiling.time.aspect;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
@ConditionalOnExpression("${app.profiling.aspects:false}")
|
||||
public class ExecutionTimeAspect {
|
||||
|
||||
@Around("@annotation(com.bartlomiejpluta.base.core.stat.metrics.annotation.MeasureExecutionTime)")
|
||||
public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
long start = 0;
|
||||
long end = 0;
|
||||
long elapsed;
|
||||
Object result;
|
||||
try {
|
||||
start = System.nanoTime();
|
||||
result = joinPoint.proceed();
|
||||
} finally {
|
||||
end = System.nanoTime();
|
||||
}
|
||||
|
||||
elapsed = end - start;
|
||||
log.debug("[{}.{}] = [{}s] [{}ms] [{}ns]",
|
||||
joinPoint.getTarget().getClass().getSimpleName(),
|
||||
joinPoint.getSignature().getName(),
|
||||
elapsed / 1000000.0, elapsed / 1000.0, elapsed
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user