zoukankan      html  css  js  c++  java
  • perf4j+spring+aop 配置 注解方式

    今天将perf4j基于spring aop方式进入了接入,接入方法还是比较简单。具体配置如下:

    logback.xml

    <!--perf4j配置-->
        <appender name="statistics" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <Encoding>UTF-8</Encoding>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!--日志文件输出的文件名 -->
                <FileNamePattern>logs/statistics.%d{yyyy-MM-dd}.log</FileNamePattern>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%msg%n</pattern>
            </layout>
        </appender>
    
        <appender name="coalescingStatistics" class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
            <timeSlice>10000</timeSlice>
            <appender-ref ref="statistics"/>
        </appender>
    
        <logger name="org.perf4j.TimingLogger" level="info" additivity="false">
            <appender-ref ref="coalescingStatistics" />
        </logger>
        <!--perf4j配置结束-->

    aop.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
        <aop:config>
            <aop:aspect id="aspect" ref="timingAspect">
                <aop:pointcut id="timingCut" expression="execution(* com.xxx..*.*(..)) and @annotation(profiled))"/>
                <aop:around pointcut-ref="timingCut" method="doPerfLogging"/>
            </aop:aspect>
        </aop:config>
        <bean id="timingAspect" class="org.perf4j.slf4j.aop.TimingAspect" />
    </beans>

    当然还有更方便的配置方式

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
        <aop:aspectj-autoproxy />
    
        <bean id="timingAspect" class="org.perf4j.slf4j.aop.TimingAspect" />
    </beans>

    OK!

    现在就可以在需要监控的方法上添加@Profiled了。

  • 相关阅读:
    洛谷 P2144 [FJOI2007]轮状病毒
    矩阵树定理学习笔记
    洛谷 P3990 [SHOI2013]超级跳马 解题报告
    【模板】exBSGS/Spoj3105 Mod
    【bzoj4804】欧拉心算 解题报告
    洛谷 P3235 [HNOI2014]江南乐 解题报告
    洛谷 P4706 取石子 解题报告
    一些我不会证又记不住的结论...
    【BZOJ2281】【Sdoi2011】黑白棋 解题报告
    洛谷 P4279 [SHOI2008]小约翰的游戏 解题报告
  • 原文地址:https://www.cnblogs.com/maoxiaolv/p/5577022.html
Copyright © 2011-2022 走看看