I would like to be able to visualize the call sequence for a given JVM process (what methods were called on which objects and what parameters where passed). For example a tool that would dump this information to a file.
Is there an existing tool to do this? If not could you give some pointers on how this can be done? What solutions could you advise (besides modifying the bytecodes of the methods)?
I would like to be able to visualize the call sequence for a given
Share
OP says, “Java logging” no good. “Yes but you have to insert manually all the log calls. Not a very viable option for a large project, is it?”.
OK, what you need is a way to insert custom instrumentation automatically into your application.
Our DMS Software Reengineering Toolkit with its Java Front End could be used to do this. DMS provides generic machinery to parse source code, build ASTs and symbol tables, analyze the code (trees) for special cases, and carry out transformations on the code(trees), finally regenerating modified code (from the modified trees). The Java Front end enables DMS to do this for Java; DMS has many other front end language modules.
What you’d want to do is to write a DMS source-to-source transformation to instrument the function entry with logic to dump the parameter list values (e.g., serialize their “toString” equivalents):
What the “instrument_function_entry” rule does is place a call to record the function entry, and to generate a series of calls to record the argument values. The “empty_arguments” rule handles the base case of no-more-arguments to process (including “no arguments at all”). The “more_arguments” rule handle a list of arguments by picking off the last, generating code to dump that argument, and producing a shorter list of remaining argumetns to be processed by the same rule or eventually the “empty_arguments” rule.
What this should produce for the method:
will be
You get to define the “Call” object however you like, to record the results. If you want to place extra filters in there to eliminate data from the wrong thread, or not between some time window or not near some interesting event, you can. This is likely to slow down you application a lot, at least if you let the instrumenter do this to every function call across your application. (More complex transformations can control where they are applied).