Total method time in Java VisualVM

In Java VisualVM, is there a way to display the total time of a method, rather than the "time itself"? (The latter is not particularly useful since it does not say anything about how much time is actually taken to complete it.)

If not, is there a separate standalone Java profiler that calculates the total method time?

+45
java profiling visualvm
Dec 12 '09 at 2:22
source share
7 answers

Looking at the trace data in the snapshot view, you can see both the total and the proper time.

Click the snapshot button that appears in the results table. This will create a new tab containing the Call Tree view, which breaks down the number of “I” and the total time. The combined view also provides this information, but shares the screen space with the Hotspots view, which is similar to a standard profiling profile.

Snapshots can be taken from standard Profiler or Sampler data. However, “Profiler” snapshots can only be created before the application is closed, while “Sampler” can be created at any time.

(the above information is based on VisualVM 1.3.1)

+47
Dec 13 '10 at 21:29
source share

Just take a picture of the profiling results. You will receive a wall clock time, as well as from time to time.

+7
Dec 14 '09 at 8:20
source share

There is an easy way to get the total runtime of a program as a percentage of the runtime of a wall clock (rather than a millisecond). Just use ctrl-break to get a bunch of stackshots while you wait. Their share containing a routine is% of the time. Accuracy depends on the number of shots. If you are just looking for where the problems are, you do not need an accurate time measurement. Here is a brief description of how this works.

+1
Dec 12 '09 at 4:14
source share

I think you want to know how long it takes to execute each method. You want to use JETM to control performance. This will give you entry time, exit time and time difference for each method. You will find out which method takes how long.

If you use Spring, then it becomes easy to integrate JETM http://jetm.void.fm/howto/spring_2_x_integration.html

0
Nov 09 2018-11-11T00:
source share

you can use jprofiler or some javaagent tools to track the method execution time for you. There are some open source tools on github, such as simpleAPM.

0
Sep 21 '15 at 14:21
source share

JavaAssist is a class library for managing your Java bytecode without touching the source. Consider an example of measuring the time taken to complete a method.

public class Subject { /** * Timetaken for start & end of the method * * @throws InterruptedException */ public void method2() throws InterruptedException { // Some business logic :) Thread.sleep(2000); } } 

To measure the runtime of subject.method2() , you can improve Subject.methods() by adding the beginning and end of the method code as shown.

 public class JavaAssist { public static void main(String[] args) { timeTaken(); } public static void timeTaken() { try { ClassPool p = ClassPool.getDefault(); CtClass cc = p.get("Subject"); CtMethod meth2 = cc.getDeclaredMethod("method2"); meth2.insertBefore("System.out.println(\" Start : \"+new java.util.Date());"); meth2.insertAfter("System.out.println(\" End : \"+new java.util.Date());"); // cc.writeFile("."); Class c = cc.toClass(); Subject s = (Subject) c.newInstance(); s.method2(); cc.detach(); } catch (Exception e) { // suppressed } } } 

Conclusion: Start: cf. May 26 17:24:18 EDT 2010 End: Wed May 26 17:24:20 EDT 2010

Link http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html#read

http://www.csg.is.titech.ac.jp/~chiba/javassist/html/

Origin Posted by: http://www.senthilb.com/2010/05/javaassist-byte-code-enhancement.html

-one
Jun 27 '10 at 22:37
source share

you can use

  long startTime = System.currentTimeMillis(); 

at the beginning

and

  long endTime = System.currentTimeMillis(); 

and finally get the result

  long result = endTime - startTime; //Note, part might be backwards, I don't //Remember 
-3
Dec 12 '09 at 2:56
source share



All Articles