Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call trace in java

Tags:

java

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.

like image 279
JavaRocky Avatar asked Jun 22 '09 06:06

JavaRocky


People also ask

What is a trace in Java?

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.

What is a call stack trace?

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.

How do you get a StackTrace?

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.

How can I get the current stack trace in Java?

You can use Thread. currentThread(). getStackTrace() . That returns an array of StackTraceElement s that represent the current stack trace of a program.


1 Answers

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 :) )

like image 168
Thorbjørn Ravn Andersen Avatar answered Oct 23 '22 08:10

Thorbjørn Ravn Andersen