• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time took for execution of methods

 
vittal mareddy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 5807
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Record starting time.
2) Execute method.
3) Record ending time.
4) Display ending time minus starting time.
 
vittal mareddy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to use a profile to do what you are asking. I've never used one, so i couldn't say.
 
Alexander Kober
Ranch Hand
Posts: 32
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic