Tracing an application timing for a single thread

  3 posts   Feedicon  
Replies: 2 - Last Post: February 14, 2011 14:15
by: m_hess
showing 1 - 3 of 3
 
Posted: February 12, 2011 19:10 by Santosh_Bhushan
I am new to BTrace, does anyone has sample to use BTrace for the following.

There is one thread who loops and invokes 50 methods. and keep repeating it all the time.

Now i want to use BTrace to know how much time it takes in each method ? Do anyone has sample code.
 
Posted: February 14, 2011 12:47 by Jaroslav Bachorik
Try using this with BTrace v1.2. Customize the parameters to fit your needs.


package onethread;

import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;

@BTrace(name="OneThreadTracker")
class OneThreadTracker {
    private Profiler p = Profiling.newProfiler();
    
    // replace values for clazz and method with desired class and method names

    @OnMethod(clazz="/java2d\\..*/", method="/.*/")
    void onEnter(@ProbeMethodName(fqn=true) String methodFqn) {
        // replace AWT-EventQueue-0 with the name of the thread you want to monitor
        if (strcmp(Threads.name(Threads.currentThread()), "AWT-EventQueue-0") == 0) {
            Profiling.recordEntry(p, methodFqn);
        }
    }
    
    @OnMethod(clazz="/java2d\\..*/", method="/.*/", location=@Location(value=Kind.RETURN))
    void onExit(@Duration long dur, @ProbeMethodName(fqn=true) String methodFqn) {
        // replace AWT-EventQueue-0 with the name of the thread you want to monitor
        if (strcmp(Threads.name(Threads.currentThread()), "AWT-EventQueue-0") == 0) {
            Profiling.recordExit(p, methodFqn, dur);
        }
    }
    
    @OnEvent()
    void showData() {
        Profiling.printSnapshot("My Data", p);
    }
}


-JB-
 
Posted: February 14, 2011 14:15 by m_hess
Just a quick thought: Maybe "Profiler p" could also be fetched from a ThreadLocal? That way the String comparison could be saved, and each Thread would automatically pick it's "correct" Profiler....
Replies: 2 - Last Post: February 14, 2011 14:15
by: m_hess
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close