aspose file tools
The moose likes Java in General and the fly likes Time took for execution of methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Time took for execution of methods" Watch "Time took for execution of methods" New topic

Time took for execution of methods

vittal mareddy

Joined: Jul 24, 2011
Posts: 17

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

Joined: Sep 20, 2010
Posts: 3679

1) Record starting time.
2) Execute method.
3) Record ending time.
4) Display ending time minus starting time.
vittal mareddy

Joined: Jul 24, 2011
Posts: 17
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

Joined: Oct 02, 2003
Posts: 11688

You may be able to use a profile to do what you are asking. I've never used one, so i couldn't say.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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...
wood burning stoves
subject: Time took for execution of methods