|
|
@ -0,0 +1,26 @@ |
|
|
|
|
|
package com.inspect.nvr.aop; |
|
|
|
|
|
|
|
|
|
|
|
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.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
@Aspect |
|
|
|
|
|
@Component |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
public class TimeTraceAspect { |
|
|
|
|
|
@Around("@annotation(TimeTrace)") |
|
|
|
|
|
public Object trace(ProceedingJoinPoint joinPoint) throws Throwable { |
|
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
|
try { |
|
|
|
|
|
return joinPoint.proceed(); |
|
|
|
|
|
} finally { |
|
|
|
|
|
long end = System.currentTimeMillis(); |
|
|
|
|
|
long duration = end - start; |
|
|
|
|
|
// 获取方法签名 |
|
|
|
|
|
String methodName = joinPoint.getSignature().toShortString(); |
|
|
|
|
|
log.info("方法 {} 执行耗时: {} ms", methodName, duration); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |