try btrace before I proceed to work on dacapo.

来源:互联网 发布:推荐算法 数据集 编辑:程序博客网 时间:2024/04/28 11:49

Btrace provides annotations to allow users to specify probes and actions easily.

For example, with the annotation, we can specify the control stops at the thread.start(), and carry out the action of printing several words to console.

Seems, BTrace is well designed to include versatile probes (annotations), including the synchronization operations.

I would give it a try before developing my own agents. If it is competent in my task,  I will directly use it.

Otherwise, I might handle the refections (as in tamiflex) and develop my own agents.

Anyway, have a try on btrace first.


==============================

after trying the Btrace, I find it works badly, at least for my case.

Let us see their running example in the webpage: printing the message when a thread is started.

First, the annotation file:

// import all BTrace annotationsimport com.sun.btrace.annotations.*;// import statics from BTraceUtils classimport static com.sun.btrace.BTraceUtils.*; // @BTrace annotation tells that this is a BTrace program@BTracepublic class HelloWorld {      // @OnMethod annotation tells where to probe.    // In this example, we are interested in entry    // into the Thread.start() method.    @OnMethod(        clazz="java.lang.Thread",        method="start"    )    public static void func() {        // println is defined in BTraceUtils        // you can only call the static methods of BTraceUtils        println("about to start a thread!");    }}

Then, the program being instrumented:

public class Simple {static int sharedV= 0;static int sharedM =0;    public static void main (String [] args)     {        System.out.println(Thread.currentThread().hashCode());    System.out.println("to start");Thread t1 = new Thread(){public void run(){    System.out.println("started");//System.out.println(Thread.currentThread().hashCode());  synchronized ("ss") {      sharedV =1;  sharedM =2;       sharedV =3;  sharedM =4;    }}};Thread t2 = new Thread(){public void run(){    sharedM =10; sharedV =20; }};                      t1.start();               t2.start ();       try {t1.join();t2.join();} catch (InterruptedException e) {e.printStackTrace();}    }}

Now, we ollow their instruction to compile and run the instrumentation code.

1 btracec HelloWorld.java
2 btracer HelloWorld.class Simple

No output is printed.
I open the debug mode, and find that, the instrumentation inappropriately happens after the thread.start() statements.


From the trace information (in the following), the instrumentation happens after the thread.start() is executed, therefore, the instrumentation does not affect the thread.start() at all. To conclude, the agent fails to finish its task: instrumenting the thread.start() and printing information. The underlying reason is that, it does not provide a timely update. I have to develop my own agents... disappointed with Btrace.
Finally, I understand why there are so few information about Btrace on the internet.

btrace DEBUG: debugMode is truebtrace DEBUG: unsafeMode is truebtrace DEBUG: dumpClasses is falsebtrace DEBUG: stdout is truebtrace DEBUG: probe descriptor path is .btrace DEBUG: initial script is HelloWorld.classbtrace DEBUG: verifying BTrace classbtrace DEBUG: verified 'HelloWorld' successfullybtrace DEBUG: created class filterbtrace DEBUG: preprocessing BTrace class HelloWorldbtrace DEBUG: preprocessed BTrace class HelloWorldbtrace DEBUG: creating BTraceRuntime instance for HelloWorldbtrace DEBUG: created BTraceRuntime instance for HelloWorldbtrace DEBUG: removing @OnMethod, @OnProbe methodsbtrace DEBUG: removed @OnMethod, @OnProbe methodsbtrace DEBUG: sending Okay commandbtrace DEBUG: client HelloWorld: got com.sun.btrace.comm.OkayCommandlpxz@15ee671btrace DEBUG: about to defineClass HelloWorldbtrace DEBUG: defineClass succeeded for HelloWorldbtrace DEBUG: parsed command line argumentsbtrace DEBUG: noServer is true, server not startedbtrace DEBUG: new Client created com.sun.btrace.agent.FileClientlpxz@6d084bbtrace DEBUG: filtering loaded classesbtrace DEBUG: client HelloWorld: skipping transform for java/util/Collections$EmptySet$1btrace DEBUG: client HelloWorld: skipping transform for java/util/HashMap$EntrySetbtrace DEBUG: client HelloWorld: skipping transform for java/util/HashMap$EntryIteratorbtrace DEBUG: candidate class java.lang.Thread added // why add it as a candidate? give me a timely update!!!btrace DEBUG: client HelloWorld: skipping transform for sun/misc/URLClassPath$FileLoader$1btrace DEBUG: client HelloWorld: skipping transform for Simplebtrace DEBUG: client HelloWorld: skipping transform for Simple$1btrace DEBUG: client HelloWorld: skipping transform for Simple$215582114 to startbtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/parser/SignatureParserbtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/TypeArgumentbtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/TypeTreebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/Treebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/SimpleClassTypeSignaturebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/FieldTypeSignaturebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/BaseTypebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/TypeSignaturebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/ReturnTypebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/tree/ClassTypeSignaturebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/scope/ClassScopebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/scope/Scopebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/scope/AbstractScopebtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/factory/CoreReflectionFactorybtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/factory/GenericsFactorybtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/visitor/Reifierbtrace DEBUG: skipping transform for BTrace class sun/reflect/generics/visitor/TypeTreeVisitorstarted // where is the agent? why does not it work?btrace DEBUG: client HelloWorld: skipping transform for java/lang/reflect/GenericArrayTypebtrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/RetentionPolicybtrace DEBUG: skipping transform for BTrace class sun/reflect/annotation/AnnotationType$1btrace DEBUG: skipping transform for BTrace class sun/reflect/annotation/ExceptionProxybtrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/Retentionbtrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/Inheritedbtrace DEBUG: client HelloWorld: skipping transform for java/lang/Class$4btrace DEBUG: skipping transform for BTrace class sun/reflect/annotation/AnnotationTypeMismatchExceptionProxybtrace DEBUG: skipping transform for BTrace class sun/reflect/annotation/AnnotationInvocationHandlerbtrace DEBUG: client HelloWorld: skipping transform for java/lang/reflect/InvocationHandlerbtrace DEBUG: client HelloWorld: skipping transform for java/lang/reflect/Proxybtrace DEBUG: client HelloWorld: skipping transform for java/util/WeakHashMapbtrace DEBUG: client HelloWorld: skipping transform for java/util/WeakHashMap$Entrybtrace DEBUG: client HelloWorld: skipping transform for java/util/Arrays$ArrayListbtrace DEBUG: client HelloWorld: skipping transform for java/util/IdentityHashMap$KeySetbtrace DEBUG: client HelloWorld: skipping transform for java/util/IdentityHashMap$KeyIteratorbtrace DEBUG: client HelloWorld: skipping transform for java/util/IdentityHashMap$IdentityHashMapIteratorbtrace DEBUG: client HelloWorld: skipping transform for java/io/DeleteOnExitHookbtrace DEBUG: client HelloWorld: skipping transform for java/util/LinkedHashSetbtrace DEBUG: client HelloWorld: skipping transform for java/util/LinkedHashMap$KeyIteratorbtrace DEBUG: client HelloWorld: skipping transform for java/util/LinkedHashMap$LinkedHashIteratorbtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGeneratorbtrace DEBUG: skipping transform for BTrace class sun/security/action/GetBooleanActionbtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ConstantPoolbtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ProxyMethodbtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$MethodInfobtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ConstantPool$ValueEntrybtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ConstantPool$Entrybtrace DEBUG: client HelloWorld: skipping transform for java/io/DataOutputStreambtrace DEBUG: client HelloWorld: skipping transform for java/io/DataOutputbtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ConstantPool$IndirectEntrybtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$FieldInfobtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$PrimitiveTypeInfobtrace DEBUG: client HelloWorld: skipping transform for sun/misc/ProxyGenerator$ExceptionTableEntrybtrace DEBUG: client HelloWorld: skipping transform for $Proxy0btrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/Targetbtrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/ElementTypebtrace DEBUG: client HelloWorld: skipping transform for java/lang/annotation/Documentedbtrace DEBUG: client HelloWorld: skipping transform for $Proxy1btrace DEBUG: client HelloWorld: skipping transform for $Proxy2btrace DEBUG: client HelloWorld: skipping transform for $Proxy3btrace DEBUG: client HelloWorld: skipping transform for java/util/LinkedHashMap$EntryIteratorbtrace DEBUG: added as ClassFileTransformerbtrace DEBUG: client HelloWorld: got com.sun.btrace.comm.RetransformationStartNotificationlpxz@152513abtrace DEBUG: calling retransformClasses (1 classes to be retransformed)btrace DEBUG: client HelloWorld: instrumenting java/lang/Thread  It is too late to instrument the Thread.class