Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dump execution - java?

Tags:

java

debugging

Is it possible to dump the complete program execution in java? I have to go through a complete process flow for a execution for a specific input values. Using step over, step into is a bit time consuming and I wanted to find out if any java command dumps the execution?

like image 809
name_masked Avatar asked Jun 07 '11 18:06

name_masked


2 Answers

  1. Maybe you want to have a look at the Chronon Time Travel Debugger.

    I haven't tried it out yet, after a long beta period it seems to be now officially available and may satisfy your demands. It's a commercial product, but offers a free time trial.

  2. Another alternative may be the use of debugging to a core file using the jsadebugd utility provided with the JDK. (you can't step forwards and backwards, but you can examine the stack/monitors of all threads which might help you already out)

  3. If you only need the method calls, as stated in a comment, maybe a profiler which uses instrumentation like jprofiler or yourkit will also be helpful.

  4. Or you want to have a look at btrace, a dtrace-like tool.

  5. If you're able to modify/build the application, also some sort of a small AOP method interceptor will do the job.

like image 198
MRalwasser Avatar answered Sep 30 '22 11:09

MRalwasser


If I understand correctly, you want something like a view of all the method calls that happen when your program processes some set of inputs. You can often get this kind of information out of a profiler, such as JProbe:

http://www.quest.com/jprobe/

You can run the program under JProbe, and then it will present a visual call graph of all of the method calls or a list of all method calls along with their frequency of execution.

Somewhat related are static analysis tools, such as Understand:

http://www.scitools.com/

Static analysis tools tend to focus on figuring out overall code structure rather than what happens with a specific set of inputs though.

Of course, you can always change code, but it's probably too much work to change every method in a large system to print a debugging string. Aspect-oriented programming tends to be a good approach for this kind of problem, because it's a cross-cutting concern across the codebase. There are a few different Java AOP solutions. I've used Spring AOP with dynamic proxies, which isn't enough to cover all method executions, but it is good enough for covering any method execution defined on an interface for a bean managed in a Spring container:

http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/aop.html

For example, I've written a TimingAspect that wraps the execution of a method and logs its execution time after it completes. When I want to use it, I update my Spring applicationContext.xml to specify pointcuts for the methods I want to measure. You could define a similar TracingAspect to print a debugging message at the start of each method execution. Just remember to leave this off for production deployment.

For all of these approaches, measuring every single method call is probably going to cause information overload. You'll probably want to selectively measure just a few important pieces of your own codebase, filtering out core JDK methods and third-party libraries.

like image 34
Chris Nauroth Avatar answered Sep 30 '22 11:09

Chris Nauroth