Reputation: 479
I'm trying to find an output mode that will show me the execution and order of every method called in the running program. Verbose and debugger output detail don't seem to give me that. Is there any way to get a detailed output like the one I've described here? Thanks!
Upvotes: 1
Views: 535
Reputation: 17849
You can do something like this using the following ways:
One: Put either of these codes in every method in your program:
System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());
Two: Use the dumpStack()
method:
Thread.currentThread().dumpStack();
Three: Use the printStackTrace
of Throwable
new Throwable().printStackTrace();
Four: This is a variation of the first solution
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for(StackTraceElement st : stackTrace){
System.err.println(st);
}
Upvotes: 1