Create execution time measurement aspect
This commit is contained in:
@@ -76,6 +76,7 @@ dependencies {
|
|||||||
|
|
||||||
// Spring
|
// Spring
|
||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-aop'
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
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.gc.Cleanable;
|
||||||
import com.bartlomiejpluta.base.core.logic.Updatable;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ dependencies {
|
|||||||
|
|
||||||
// Spring
|
// Spring
|
||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-aop'
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ app:
|
|||||||
core:
|
core:
|
||||||
targetUps: 50 # Updates per second
|
targetUps: 50 # Updates per second
|
||||||
|
|
||||||
|
profiling:
|
||||||
|
aspects: false
|
||||||
|
|
||||||
sprite:
|
sprite:
|
||||||
entity:
|
entity:
|
||||||
dimension:
|
dimension:
|
||||||
@@ -20,3 +23,8 @@ app:
|
|||||||
left: 1
|
left: 1
|
||||||
right: 2
|
right: 2
|
||||||
up: 3
|
up: 3
|
||||||
|
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.bartlomiejpluta.base.core.profiling.time.aspect.ExecutionTimeAspect: DEBUG
|
||||||
Reference in New Issue
Block a user