RAD: Profiling a portlet
Recently I needed to profile a portlet to find its time performance bottlenecks. Since I developed it in RAD using its WebSphere 5.1 Test Environment, I thought I'd run the server in the Profiling mode and would get the results. The profiler worked very hard, but at the end no results were displayed. I tried to profile a simple (non server) Java app. - again it seemed to do something but no results vere displayed. But finally I've found how to get the data using hprof:
Analyzing the output of hprof
The best is to find a tool that analyzis the output of hprof. If you want to do it yourself, look first at the end of the file - there is a list of the most time consuming methods, each with a trace number. Find a stack trace of the method in the previous part of the file using that number. Note that the stack traces are not ordered w.r.t. the trace number.
Analyzing portlet performance with hprof
- Create a normal Java app. that will call the portlet's code or a JUnit (or e.g. MockObjectTestCase, if you need JNDI and the like set up) test
- Write a main method of the app. and call there the portlet code. If it's a test case, don't forget to call setUp before and tearDown after that.
- At the end of main call System.exit(0) - otherwise it may happen that the thread will not actually finish and thus the output won't be completely generated (usually there will only be a header and names of threads that have started). Killing it via the red square button stops the threads but doesn't generate the output.
- Run the app./test case as a "Java Application" using a Sun JRE 1.4 (IBM JRE would fail) and passing the VM the option "-Xrunhprof:cpu=samples,thread=y,file=cpu_profiling.hprof,depth=32"