Call trace in java

前端 未结 8 2160
野趣味
野趣味 2020-12-05 11:38

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.

相关标签:
8条回答
  • 2020-12-05 11:51

    If you want to trace the execution of your Java code you can use a tool called InTrace.

    NOTE: InTrace is a free and open source tool which I have written.

    0 讨论(0)
  • 2020-12-05 11:51

    Runtime.traceMethodCalls(), which prints a line for each method call of all objects in all threads

    0 讨论(0)
  • 2020-12-05 11:54

    There is btrace, that can be used for this kind of action.

    0 讨论(0)
  • 2020-12-05 11:55

    The more easier way than Btrace is using HouseMD, you can get the from here

    0 讨论(0)
  • 2020-12-05 11:58

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

    0 讨论(0)
  • 2020-12-05 11:58

    We could create a new Throwable object which will have the call trace. And using some string manipulations, we can get the call stack.

    Throwable t = new Throwable();
    System.out.println(t.getStackTrace()[1].toString());
    

    I'm not sure retrieving the info this way , is a good practice or not. :)

    0 讨论(0)
提交回复
热议问题