Tuesday, July 31, 2012

Configuring InfraRED 2.6-rc1 in your java web project

InfraRED is a Java profiler [1].

There is a good post here [2], that compares all different available open source profilers, include infraRED.

There is an installation guide [3], that is last available document for infraRED version 2.4.1-BETA, You could follow that installation guide and check my guide here to see the differences in version 2.6-rc1.
Note: I was not able to find any document for version 2.6-rc1.

Step1: download the infraRED 2.6-rc1 from SourceForge [4].

Step2: preparing the application

1. Include infrared-agent.properties to your WEB-INF/classes directory of your web project.
2. Include infrared jar file to your WEB-INF/lib directory of your web project.

3. Add infraRED application startup listener and filter to your web.xml

Step 3: install web GUI of InfraRED

Find infrared-web-2.6-rc1.war file and copy it to your application server (e.g tomcat/webapps).

Step 4 (optional): customizing application layers using Aspectj
Note: this step worked for me with exact following configuration

1. Add aspectjrt.jar to your project classpath
Note: If you are using Eclipse and Aspectj plugin then right-click in your project -> Configure -> Convert to Aspectj project

2. Create a java class file like this one, WebLayerAspect.java:

  package infraredprofiler;

  import net.sf.infrared.aspects.aj.AbstractApiAspect;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Pointcut;

  @Aspect
  public class WebLayerAspect extends AbstractApiAspect {
  
    // Pointcut for all classes and all methods
    @Pointcut(value= "call(* *(..) )")
    public void apiExecution() {}
  
    public String getLayer() {
      return "Layer_name_e_g_001";
    }
  }

3. Create aop.xml under META-INF directory, by following content:

Sorry this blogger.com it didn't make it easy for me to past XML content!!
It's been a while that I am not happy with blogger.com anymore..
So I start my own blogging software in following address:
https://github.com/smoradi/flogger
and my own example of using this software is available in
http://sidmorad.herokuapp.com/
Want to know why I am not happy with blogger ? read following page
http://sidmorad.herokuapp.com/app/file?name=startMyBlog.xml
http://sidmorad.herokuapp.com/data/startMyBlog.xml

Oh about aop.xml, just see another aop.xml of InfraRED examples, it should be easy to figure out.

4. Make sure your code compiled with Aspectj compiler (In my case I had aspectj-maven-plugin from org.codehaus.mojo version 1.3).

That's all, you should be able to browse your app and open infraRED GUI and see the statistics.



Note: for some reason adding second layer didn't worked for me, I had only one layer and only one pointcut to work with!

[1] http://infrared.sourceforge.net
[2] sorry I was not able to find that post in Google search engine again! and I am using duckduckgo.com right now! ;-)
[3] http://infrared.sourceforge.net/versions/latest/installation.html
[4] http://sourceforge.net/project/showfiles.php?group_id=92904