Tuesday, July 5, 2011

Detail Guide to Use JBoss Profiler

Long time I haven't write new post. Here the guide about remote profiling.

According to wikipedia, software profiling is a process of optimizing source code by analyzing the application running by profiler tools. By using profiler we can know how many times a method or function is invoked and also how long is taken for such invocation.

In the field Java, there so many profiler tools. Most known IDE usually have built in profiler tools. But there is sometime a need to do remote profiling. E.g profiling Java EE application that run in server. If we use JBoss application server then we are blessed by existence of JBoss profiler.

Excerpt from its website JBoss Profiler is a log based profiler using JVMPI and JVMTI. It uses an agent written in C that captures events from the JVM and logs to disk. A web application running on JBoss or another machine can be used to analyze these logs through a web browser.

The process of installing the profiler is very easy. First of course we need to download the newest version of the software from this link . In the time this post written I was using version 2.0 Beta5. Extract the files to some directory. I extract that to /opt directory. So the files will be available at /opt/jboss-profiler-<version>.

After extracting do the following steps exactly.
  1. Copy jboss-profiler.jar to jbossas/bin
  2. Copy jboss-profiler.properties to jbossas/bin
  3. Copy javassist.jar to jbossas/bin
  4. Edit jboss-profiler.properties in jbossas/bin to include the classes to be profiled
  5. Copy jboss-profiler-plugins.jar to jbossas/bin
  6. Edit run.conf (Unix) or run.bat (Windows) in jbossas/bin to include JBoss Profiler in JAVA_OPTS add the following argument: -javaagent:jboss-profiler.jar -Djboss-profiler.properties=jboss-profiler.properties
  7. Copy jboss-profiler.sar to jbossas/server/<conf>/deploy

Note: you don't need to do step number 3 if you use JBoss 5 or JBoss 6 application server.

After finished copying the needed files, open jboss-profiler.properties. The most important key is "includes". Add the java package you wish to profile. After it's done, we are ready to do profiling.

Start the server then run the following command from directory of our extracted jboss-profiler. In my case I extract to /opt/jboss-profiler-<version>. The command is

java -Xmx512m -Djboss-profiler-client.properties=jboss-profiler-client.properties -jar jboss-profiler-client.jar

After running the that there will be a list of availables commands as follow.

startProfiler : Start the profiler
stopProfiler : Stop the profiler
snapshot : Take a snapshot
getSnapshot : Get a snapshot
listSnapshots : List snapshots
clearSnapshots : Clear snapshots
gc : Trigger garbage collection
enable : Enable the profiler
disable : Disable the profiler
load : Load a snapshot
save : Save a snapshot
diff : Compare snapshots
add : Add classes (public|package|protected|private)
remove : Remove classes
list : List classes

The most important command is snapshot. Everytime we run this command the profiler client will produce profiler report in current directory. The report consist html files with detail of method invocation for every classes that we have included in configuration.

Some problem that might appear:
1. Forget copying jboss-profiler.sar to jbossas/server/<conf>/deploy will make jboss-proiler-client.jar won't run
2. Make sure to chmod every jar in /opt/jboss-profiler-<version> directory to be excecuted. Otherwise the profiler client also won't run.

Happy profiling and let's find the thing to optimize let's kill the memory leak.

1 comment:

  1. Hi,

    How to resolved jboss profiler problem .

    J boss version :jboss-5.1.0 GA

    profiler : jboss profiler2.0 beta5

    i have used jboss 5.0.1 GA and jboss profiler2.0 beta5 version.then i was put this command like java -Xmx512m -Djboss-profiler-client.properties=jboss-profile r-client.properties -jar jboss-profiler-client.jar list

    showing error like this,

    2014-04-10 19:20:00,009 ERROR [org.jboss.remoting.transport.socket.SocketClientI

    nvoker] Got marshalling exception, exiting

    java.net.SocketException: end of file

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transpor t(MicroSocketClientInvoker.java:629)

    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientI nvoker.java:122)

    at org.jboss.remoting.Client.invoke(Client.java:1634) at org.jboss.remoting.Client.invoke(Client.java:548)

    at org.jboss.remoting.Client.invoke(Client.java:536)

    at org.jboss.profiler.client.cmd.Client.main(Client.java:318)

    2014-04-10 19:20:00,012 ERROR [org.jboss.profiler.client.cmd.Client] Failed to c ommunicate. Problem during marshalling/unmarshalling; nested exception is:

    java.net.SocketException: end of file

    java.rmi.MarshalException: Failed to communicate. Problem during marshalling/un marshalling; nested exception is:

    java.net.SocketException: end of file

    at org.jboss.remoting.transport.socket.SocketClientInvoker.handleExcepti on(SocketClientInvoker.java:127)

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transpor t(MicroSocketClientInvoker.java:699)

    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientI nvoker.java:122)

    at org.jboss.remoting.Client.invoke(Client.java:1634)

    at org.jboss.remoting.Client.invoke(Client.java:548)

    at org.jboss.remoting.Client.invoke(Client.java:536)

    at org.jboss.profiler.client.cmd.Client.main(Client.java:318)

    Caused by: java.net.SocketException: end of file

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transpor t(MicroSocketClientInvoker.java:629)

    ... 5 more

    Thanks
    senthil

    ReplyDelete