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 portlet performance with hprof
  1. 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
  2. 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.
  3. 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.
  4. 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"
The important points: Call System.exit at the end and use Sun's JRE 1.4.
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.
Additional notes
I've also tried Eclipse 3.2 and its profiling tool (TPTP). For a simple java application it displayed no output untill I changed the default options, setting polling frequency to 1sec (default: auto). I had also some problems trying to run it with JRE 5.0 but 1.4 was ok. So perhaps the RAD's profiling would display soem results if set correctly.


Tags: java performance


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob