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

5 comments:

Unknown said...

What do I insert in web.xml? This?


infrared
net.sf.infrared.aspects.servlet.InfraREDServletFilter


infrared
/*


net.sf.infrared.agent.setup.InfraREDServletContextListener

Sid said...

my web.xml contained following configs:

[filter]
[filter-name>infrared[/filter-name>]
[filter-class]
net.sf.infrared.aspects.servlet.InfraREDServletFilter
[/filter-class]
[/filter]
[filter-mapping]
[filter-name]infrared[/filter-name]
[url-pattern]/*[/url-pattern]
[/filter-mapping]

[listener]
[listener-class]
net.sf.infrared.agent.setup.InfraREDServletContextListener
[/listener-class]
[/listener]

Anonymous said...

Hi Sid, please help me. getting below error.

<2014-10-28 11:47:30,701 WARN Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Detected problem with connection
java.net.SocketException: socket write error: Connection reset by peer.
at jrockit.net.SocketNativeIO.writeBytesPinned(Native Method)
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)
at java.net.SocketOutputStream.socketWrite0(SocketOutputStream.java)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1257)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1211)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1395)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333)
at net.sf.infrared.agent.transport.impl.SocketWriter.writeToStream(SocketWriter.java:143)
at net.sf.infrared.agent.transport.impl.SocketWriter.write(SocketWriter.java:99)
at net.sf.infrared.agent.transport.impl.SocketForwarder.forward(SocketForwarder.java:55)
at net.sf.infrared.agent.transport.impl.BufferedAggregator.flush(BufferedAggregator.java:88)
at net.sf.infrared.agent.transport.impl.PeriodicFlushPolicy$1.run(PeriodicFlushPolicy.java:61)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)>
<2014-10-28 11:47:30,706 INFO Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Started connector thread>

Anonymous said...

Please check my startup parameters and also the error.

starting weblogic 11gR1 with Java version:
Listening for transport dt_socket at address: 8453
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Oracle JRockit(R) (build R28.2.7-7-155314-1.6.0_45-20130329-0646-windows-x86_64, compiled mode)



<2014-10-28 11:50:59,633 INFO [ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' net.sf.infrared.agent.transport.impl.SocketWriter - Started connector thread>
<***************************************************************
* InfraRED version ${ver}
*
* Configured logging system from null. No debug messages would be logged as -Dinfrared.debug=true JVM PARAM is not set.

<2014-10-28 11:47:30,701 WARN Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Detected problem with connection
java.net.SocketException: socket write error: Connection reset by peer.
at jrockit.net.SocketNativeIO.writeBytesPinned(Native Method)
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)
at java.net.SocketOutputStream.socketWrite0(SocketOutputStream.java)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1257)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1211)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1395)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333)
at net.sf.infrared.agent.transport.impl.SocketWriter.writeToStream(SocketWriter.java:143)
at net.sf.infrared.agent.transport.impl.SocketWriter.write(SocketWriter.java:99)
at net.sf.infrared.agent.transport.impl.SocketForwarder.forward(SocketForwarder.java:55)
at net.sf.infrared.agent.transport.impl.BufferedAggregator.flush(BufferedAggregator.java:88)
at net.sf.infrared.agent.transport.impl.PeriodicFlushPolicy$1.run(PeriodicFlushPolicy.java:61)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)>
<2014-10-28 11:47:30,706 INFO Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Started connector thread>

October 28, 2014 at 8:48 AM

Kaybee said...

<2014-10-28 11:47:30,701 WARN Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Detected problem with connection
java.net.SocketException: socket write error: Connection reset by peer.
at jrockit.net.SocketNativeIO.writeBytesPinned(Native Method)
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)
at java.net.SocketOutputStream.socketWrite0(SocketOutputStream.java)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1257)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1211)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1395)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333)
at net.sf.infrared.agent.transport.impl.SocketWriter.writeToStream(SocketWriter.java:143)
at net.sf.infrared.agent.transport.impl.SocketWriter.write(SocketWriter.java:99)
at net.sf.infrared.agent.transport.impl.SocketForwarder.forward(SocketForwarder.java:55)
at net.sf.infrared.agent.transport.impl.BufferedAggregator.flush(BufferedAggregator.java:88)
at net.sf.infrared.agent.transport.impl.PeriodicFlushPolicy$1.run(PeriodicFlushPolicy.java:61)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)>
<2014-10-28 11:47:30,706 INFO Timer-3 net.sf.infrared.agent.transport.impl.SocketWriter - Started connector thread>

October 28, 2014 at 8:48 AM