1 Reply Latest reply on Oct 25, 2010 9:29 AM by adinn

    traceStackMatching

    mazz

      just wanted to post a kudos for the new features in byteman.. I'm using "traceStackMatching" to help track down a problem in my code and its helping me pinpoint where in the code I should begin looking at. Its a very helpful feature.

       

      Essentially I have two very simple rules that end up dumping to stdout a filtered stack trace only when a particular timing crosses a threshold (e.g. dump filtered stack when it takes longer than N milliseconds to invoke method A). Its even more helpful because I have dynamic proxies involved here and I was able to use $ notation (e.g. $1) to dump the actual name of the interface method being invoked (as opposed to just seeing the $Proxy class name)).

        • 1. Re: traceStackMatching
          adinn

          Hi John,

           

          Glad you like the feature.

           

          It's rather nice that Java lets you see the call stack. I used the same capability to implement the callerEquals() and callerMatchers() built-ins. I don't know if you have seen these yet but they are really useful in rule condiitons when you want to be very specifci about which calls you are interested in e.g.

           

            RULE fire when foo called from bar
            CLASS MyClass
            METHOD foo()
            AT ENTRY
            IF callerEquals("MyClass.bar", true)
            DO traceln("MyClass.foo() called from MyClass.bar()",
               traceStack()
            ENDRULE
          

           

          This means that the rule only gets fired when you are in a call to MyClass.foo() which was made from MyClass.bar(). Calls from any other method will trigger the rule but the condition will be false so it won't fire. n.b. parameter true says include the class name when checking the caller method.

           

          There is also a variant built-in callerMatches() which takes a regular expression rather than a direct method name.

           

          As with the traceStack() and traceStackMatching() calls there are all sorts of optional parameters including a start frame and frame count which means you can be very specific about call paths

           

            RULE fire when foo called from bar called from some other class

            CLASS MyClass

            METHOD foo()

            AT ENTRY

            IF callerEquals("MyClass.bar", true, 1, 1) &&

               !callerMatches("MyClass\..*", true, 2, 1)

            DO traceln("MyClass.foo() called from MyClass.bar() called from some other class",

               traceStack()

            ENDRULE

           

          Enjoy!

           

          regards,

           

           

          Andrew Dinn