maven:
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
<version>0.9.16</version>
</dependency>
xml配置:
<!-- watchDog -->
<appender name="cachePerfAnalysis" class="ch.qos.logback.core.FileAppender">
<file>${LOG_HOME}/${APP_NAME}_cache-pref-analysis.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%m%n</pattern>
</encoder>
</appender>
<appender name="cacheCoalescingStatistics" class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
<!--
TimeSlice配置多少时间间隔去做一次汇总写入文件中
默认值是 30000 ms
-->
<param name="timeSlice" value="10000"/>
<appender-ref ref="cachePerfAnalysis"/>
</appender>
使用:
StopWatch stopWatch = new Slf4JStopWatch();
stopWatch.lap("tag");