I'm looking for a way to list all the methods called (a call tree) by another method, during java runtime.
I'm looking for an api or an output that could allow me to use the data with a script.
Any ideas?
Thx
Coverage and profiling tools mostly employ two techniques : polling periodically the JVM for the state of various threads or instrumenting application bytecode to push out of the JVM relevant data.
There is no direct API support in the java language itself, however there are many tools you can exploit :
Solution 3 is by far easier, clean and versatile.
To print, at runtime, whatever method is called as a consequence of the execution of a method is a simple tracing aspect, something similar to :
public aspect TraceCalls {
pointcut aCall : call(* *(..));
pointcut inside : cflow(execution(public MyClass.MyMethod(..)));
before() : aCall() && inside() {
System.out.println(thisJoinPoint);
}
}
Obviously, you can access much more data, print them in a file, format it etc...
(Please note that I wrote this code here, so it could be full of syntax errors)
Well...it's a good question in the first place...I highly doubt if there is any such utility available in the market...however, there are ways to get around this...like using a debugger tool in one of your favorite IDEs like Eclipse and Netbeans...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With