Is there a way to output a call trace for a particular thread in java?
I do not want a stack trace. I would like a sequence of calls on each object for tracing.
A Java stack trace is displayed when an error or exception occurs. The stack trace, also called a backtrace, consists of a collection of stack records, which store an application's movement during its execution.
Techopedia Explains Stack Trace A stack trace works on the "call stack," which is a data structure that provides information about the current subroutine of the program being debugged. The call stack is also known simply as the "stack" or the execution stack, runtime stack or machine stack.
You can obtain a stack trace from a thread – by calling the getStackTrace method on that Thread instance. This invocation returns an array of StackTraceElement, from which details about stack frames of the thread can be extracted.
You can use Thread. currentThread(). getStackTrace() . That returns an array of StackTraceElement s that represent the current stack trace of a program.
I think you might find this interesting. It is a java agent which adds entry and exit logging to methods, using the slf4j framework to actually log the output. Then it is a matter of configuring the logging framework to only print out that thread you are interested in.
http://www.slf4j.org/extensions.html#javaagent
(just to be explicit: 1) I wrote it, 2) it works for me :) )
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