Giriş
Şu satırı dahil ederiz
import org.springframework.aop.interceptor.PerformanceMonitorInterceptor;
Açıklaması şöyle
When you enable the “PerformanceMonitorInterceptor,” it quietly observes your code and collects essential information, such as the execution time of different methods. It keeps a record of how much time is spent in each method, which is incredibly helpful in identifying bottlenecks or areas where your code might be slowing down.Having access to this information allows you to analyze and optimize your code to make it faster and more efficient. For example, if you discover that a particular method is taking too much time to execute, you can focus on optimizing that specific part of your code to improve overall performance.Moreover, the “PerformanceMonitorInterceptor” enables you to measure the performance of your code across multiple requests or interactions. This broader perspective helps you understand how your application is performing over time, rather than relying on isolated measurements.
Maven
Şu satırı dahil ederiz
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
AbstractMonitoringInterceptor sınıfından kalıtır. Loglama ayarları için şöyle yaparız
logging.level.dev.knowledgecafe=TRACE logging.level.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE
Örnek
Şöyle yaparız
@Configuration@EnableAspectJAutoProxypublic class AopConfiguration {@Pointcut("execution(public String foo.EmployeeService.getFullName(..)))")public void monitor() { }@Beanpublic PerformanceMonitorInterceptor performanceMonitorInterceptor() {return new PerformanceMonitorInterceptor(true);}@Beanpublic Advisor performanceMonitorAdvisor() {AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();pointcut.setExpression("dev.knowledgecafe.performance_trace.AopConfiguration.monitor()");return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor());}}
Hiç yorum yok:
Yorum Gönder