| Author |
Time took for execution of methods
|
vittal mareddy
Greenhorn
Joined: Jul 24, 2011
Posts: 14
|
|
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.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3052
|
|
1) Record starting time.
2) Execute method.
3) Record ending time.
4) Display ending time minus starting time.
|
 |
vittal mareddy
Greenhorn
Joined: Jul 24, 2011
Posts: 14
|
|
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.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9952
|
|
|
You may be able to use a profile to do what you are asking. I've never used one, so i couldn't say.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Alexander Kober
Ranch Hand
Joined: Aug 05, 2011
Posts: 32
|
|
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...
|
 |
 |
|
|
subject: Time took for execution of methods
|
|
|