For debugging purposes, I need to follow the execution of some piece of code, within a class. I would like to generate a log for all method calls, in XML, like :
<call class='pack.age.MyClass' method='myMethod1'>
<param name='param1'>param1.toString() value</param>
...
<call>Call to other method within myMethod1; you get the idea</call>
</call>
Because the class is long and has lots of methods, I wondered if there is a way to access the parameters generically, maybe using reflection. I am inside of the method, and I want to loop on the parameters given to this call of the method. It would ease my pain and allow me to make a regexp to add the log lines. Is it possible ?
Any other neat way to do it appreciated (but AOP alas not really an option).
Another way is using a dynamic tracer like BTrace (similar to AOP, but outside of your code). Look at BTrace’s wiki for examples. There are even VisualVM Plugins to attach to running process making things easier. With the following BTrace code you get the method calls and its parameters (taken from the examples).
Attaching BTrace to your running program is easy. First get the PID of your process using jps, after this call: