java profiling
Are there any easy way of profiling a java code.
Other than doing like this...
Run the java prof:
java -prof:Proffile1.prof MyClass
Then examine the generated code(Proffile1.prof ) line by line
According count,callee,caller,time
What are the ways of improving the profiling techniques...
[330 byte] By [
jugpa] at [2008-1-9]

Hi!
There's a product from Sun called "Sun Studio", which is a complete development environment. Version 11 of Sun Studio is available for free.
Sun Studio also has profiling capabilities (collect to gather a runtime profile of a process and er_print/collect for evaluation of this profile). The tools are not Java-specific but also able to profile C/C++ code and some more, but they work very well for Java. We use them with great success to find expensive methods in our Java code. The tools are easy to use and are stable even under heavy load.
There are some other tools, too, e.g. Borland OptimizeIt. We've tried it but were not so happy with it.
For Sun Studio profiling, take a look at:
http://developers.sun.com/prodtech/cc/analyzer_index.html
Nick.
Besides HPROF and using -Xrunhprof:cpu=samples (the JDK 5 HPROF manual is at http://blogs.sun.com/roller/resources/kto/manual.html) which is as you describe, "look at the output and your source". The JDK itself doesn't provide much more. The JDK 6 release at http://download.java.net/jdk6/binaries/ also contains the jhat tool which can be used to browse a heap dump, but that's not a cpu performance help.
You might take a look at the NetBeans Profiler at http://www.netbeans.org/products/profiler/.
But for getting down to the hardware, the collector/analyzer in Sun Studio 11 is hard to beat, but that's for Solaris (and Linux too now? see http://developers.sun.com/prodtech/cc/linux_index.html), it provides mappings back into Java code and some pretty extreme details on the performance of the app.
See http://developers.sun.com/prodtech/cc/analyzer_index.html for details.
-kto
If you have an interface then jamon 2.2 can easily monitor it.For example the following code will work for ANY interface
import com.jamonapi.proxy.*;
MyInterface myObj = MonProxyFactory.monitor(new MyImplementation());
myObj.myMethod();// all method calls and exceptions thrown are now monitored i.e. hits/avg times/min times/max times and more
JAMon also allows you to monitor all SQL issued and JDBC methods called with the JAMon jdbc driver, and the JAMon servlet filter allows you to monitor all servlets/jsps. Both with no code changes required in your application. So with minimal effort jamon gives you a lot of monitoring power. you could be monitoring with it in minutes. jamon is also open source so it costs you nothing.
You can read more at http://www.jamonapi.com and see a live demo that has the servlet filter and jdbc monitoring at http://www.ssouza.com/jamon
steve - www.jamonapi.com