We have web application (servlets), need to find how much time took for execution of methods for user action, code is written without coding standards, without adding explicitly logger statement for each method; want to know time took for method execution. Please let me know how I can achieve.
1) Record starting time.
2) Execute method.
3) Record ending time.
4) Display ending time minus starting time.
Joined: Jul 24, 2011
I have user action, it calls many method, i don't want to modify the code to add logger statement to display execution time, i am looking is there any framework i can use to get execution time for methods in user action.
Java profiling tools allow you to do what you described (among a lot of other things). You should note, however, that monitoring the JVM in this way will make it run a lot slower, so the timings you can achieve this way are not absolute values. You can, however, find out which methods require which fraction of the overall execution time, which in most cases is just as good.
A (imho very good) commercial tool with a lot of profiling options is JProfiler. A free alternative with less functions is the JVisualVM that is supplied with the Java SDK (in the bin/ subfolder).
The only way to get exact timings for your methods without writing extra code is through the use of java agents - this is, however, a fairly complicated topic and i guess the profiler option is better suited to your needs...