0
我有以下問題:我想通過使用perf4j @Profiled註釋和log4j來監視一些低性能方法的執行時間。 問題是監控日誌文件是空的,看起來像這樣:Perf4J @Profiled註解+ log4j不起作用
Performance Statistics 2013-07-17 18:07:50 - 2013-07-17 18:08:00
Tag Avg(ms) Min Max Std Dev Count
Performance Statistics 2013-07-17 18:08:00 - 2013-07-17 18:08:10
Tag Avg(ms) Min Max Std Dev Count
log4j.xml文件包含在projectRoot/conf目錄/ EXP目錄,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="logfile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="./logs/exp-log.txt"/>
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %d{HH:mm:ss.SSS} %c %m%n"/>
</layout>
</appender>
<appender name="CoalescingStatistics"
class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
<param name="TimeSlice" value="10000"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="graphExecutionTimes"/>
<appender-ref ref="graphExecutionTPS"/>
</appender>
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="./logs/perfStats.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<appender name="graphExecutionTimes"
class="org.perf4j.log4j.GraphingStatisticsAppender">
<!-- Possible GraphTypes are Mean, Min, Max, StdDev, Count and TPS -->
<param name="GraphType" value="Mean"/>
<!-- The tags of the timed execution blocks to graph are specified here -->
<param name="TagNamesToGraph" value="firstBlock,secondBlock"/>
<appender-ref ref="graphsFileAppender"/>
</appender>
<appender name="graphExecutionTPS"
class="org.perf4j.log4j.GraphingStatisticsAppender">
<param name="GraphType" value="TPS"/>
<param name="TagNamesToGraph" value="firstBlock,secondBlock"/>
<appender-ref ref="graphsFileAppender"/>
</appender>
<appender name="graphsFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="./logs/perfGraphs.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="org.perf4j.TimingLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="CoalescingStatistics"/>
</logger>
<logger name="sui">
<level value="debug"/>
</logger>
<root>
<priority value="debug"/>
<appender-ref ref="logfile"/>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>
我有在我的消息來源以下注釋:
@Profiled(tag = "exportRecsForAccount")
protected void exportRecsForAccount(NetSuiteAcctInfo acctInfo) {
@Profiled(tag = "exportRecsForEachAccount")
protected boolean exportRecsForEachAccount() throws QueueManagerException, CriticalDBConnectionFailed {
除此之外,我有位於projectRoot /的recources/META-INF的aop.xml文件。其內容如下:
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<aspects>
<aspect name="org.perf4j.log4j.aop.TimingAspect"/>
</aspects>
<weaver options="-verbose -showWeaveInfo">
<include within="comp.sui.ExportService"/>
</weaver>
</aspectj>
其中comp.sui.ExportService是指向源代碼類的鏈接。
所以問題是我做錯了什麼?當我使用StopWatches郵票時,所有內容都是正確的,但使用@Profiled註釋看起來沒什麼用。