Perf4j - Release 0.9.9 available

Markus Eisele
I was playing around with perf4j recently. Quite impressive, how simple you can generate performance statistics for your application.
Even without using any of the delivered aspects you can simply write your own interceptor and use an appropriate stoppwatch, wherever needed.
In my sample case, I wrote a simple interceptor. This is the slightes way ever. I skipped essential things like handling exceptions and so on. But this should be enough to demonstrate the basics ;)

public class PerformanceLoggingInterceptor implements MethodInterceptor {

public Object invoke(MethodInvocation invocation) throws Throwable {
//new Log4JstopWatch with your own tag
StopWatch stopWatch = new Log4JStopWatch("myperftag", logger);

Object retVal = invocation.proceed();
stopWatch.stop(cls + "." + methodName);
return retVal;

Now you need to configure the intercepter and setup perf4j within your application.
1) Use the right dependency with maven


2) Change your to an xml style version and add the needed appenders. The documentation on the perf4j website is a good place to start with the basic configuration.
Remember to change the tags, that should be logged appropriate, e.g.:

<param name="TagNamesToGraph"
value="doStart,myTag,test2" />

3) If you like to expose the statistics within your webapp you have to configure the delivered servlet within your web.xml. An example is provided on the perf4j website.

If this is finished, you can take a look at the working system and get a chart generated from google, which looks like this:

Since the 0.9.8 release a bug with non english locales was fixed. In addition you can now use a csv enabled logfile parser, that generates csv output.

Post a Comment


Post a Comment (0)