Class Trace
Traces the execution of a target program.
See http://fpl.cs.depaul.edu/jriely/visualization/
Command-line usage: java Trace [OptionalJvmArguments] fullyQualifiedClassName
Starts a new JVM (java virtual machine) running the main program in fullyQualifiedClassName, then traces it's behavior. The OptionalJvmArguments are passed to this underlying JVM.
Example usages:
java Trace MyClass java Trace mypackage.MyClass java Trace -cp ".:/pathTo/Library.jar" mypackage.MyClass // mac/linux java Trace -cp ".;/pathTo/Library.jar" mypackage.MyClass // windows
Two types of display are support: console and graphviz In order to use graphziv, you must install http://www.graphviz.org/ and perhaps call graphvizAddPossibleDotLocation to include the location of the "dot" executable.
You can either draw the state at each step --- drawSteps()
--- or
you can draw states selectively by calling Trace.draw()
from the program
you are tracing. See the example in ZTraceExample.java
.
Classnames that end in "Node" are drawn using rounded rectangles by default. This does not work until the class is loaded; thus, null references may show up as inline fields for a while, until the class is loaded.
- Author:
- James Riely, jriely@cs.depaul.edu, 2014-2015
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addDrawingIncludePattern
(String value) Add an include pattern for drawing.static void
addExcludePattern
(String value) Add an exclude pattern.static void
addGraphvizIgnoredFields
(String value) Do not display any fields with this name (default includes only "$assertionsDisabled").static void
addPossibleBinLocation
(String value) Possible location of binary class files.static void
addPossibleSrcLocation
(String value) Possible location of java source files.static void
addPrefixOptionsForVm
(String value) Prefix options for the debugger VM.static void
consoleMaxArrayElementsObject
(int value) The maximum number of displayed elements when printing an object array on the console (default==8).static void
consoleMaxArrayElementsPrimitive
(int value) The maximum number of displayed elements when printing a primitive array on the console (default==15).static void
consoleMaxFields
(int value) The maximum number of displayed fields when printing an object on the console (default==8).static void
consoleShow
(boolean value) Show events on the console (default==false).static void
consoleShowNestedArrayIds
(boolean value) Show object ids inside multidimensional arrays (default==false).static void
consoleShowTypeInObjectName
(boolean value) Show the object type in addition to its id (default==false).static void
consoleShowVerbose
(boolean value) Show events on the console, including code (default==false).static void
debug
(boolean value) Turn on debugging information (default==false).static void
draw()
Draw all stack frames and static variables, as well as all reachable objects.static void
drawAll()
Draw all stack frames and static variables, as well as all reachable objects, overriding showStaticClasses() if it is false.static void
drawObject
(Object object) Draw the given object.static void
drawObjects
(Object... objects) Draw the given objects.static void
drawObjectsWithNames
(Object... namesAndObjects) Draw the given objects, labeling them with the given names.static void
drawObjectWithName
(String name, Object object) Draw the given object, labeling it with the given name.static void
Start drawing steps.static void
Stop drawing steps.static void
drawStepsOfMethod
(String methodName) Create a new graphviz drawing for every step of the named method.static void
drawStepsOfMethods
(String... methodName) Create a new graphviz drawing for every step of the named methods.static void
Draw the current frame, as well as all reachable objects.static void
graphvizAddNodeClass
(String value) Add classname to be drawn as a simple oval, with null as a dot.static void
Add a filesystem location to search for the dot executable that comes with graphviz.static void
Graphviz style for an arrow from an array to an Object.static void
graphvizArrayBoxAttributes
(String value) Graphviz style for an array.static void
graphvizFrameBoxAttributes
(String value) Graphviz style for a frame.static void
Graphviz style for an arrow from an exception to a frame.static void
Graphviz style for an arrow from a frame to another frame.static void
Graphviz style for an arrow from a frame to an Object.static void
Graphviz style for an arrow from a return value to a frame.static void
Graphviz style for arrow labels.static void
graphvizLabelBoxAttributes
(String value) Graphviz style for box labels.static void
Extra Graphviz style for an arrow from an non-node to a node object.static void
graphvizNodeBoxAttributes
(String value) Graphviz style for a wrapper object (in simple form).static void
Graphviz style for an arrow from an object to an object.static void
Graphviz style for an object (non-array).static void
graphvizOutputFormat
(String value) The graphviz format -- see http://www.graphviz.org/doc/info/output.html .static void
graphvizPutLineNumberInFilename
(boolean value) Include line number in graphviz filename (default==true).static void
graphvizRemoveGvFiles
(boolean value) Remove graphviz files for which graphic files have been successfully generated.static void
graphvizRemoveNodeClass
(String value) Remove a node class.static void
graphvizRunGraphviz
(boolean value) Run graphviz "dot" program to produce an output file (default==true).static void
graphvizSetFieldAttribute
(String field, String attrib) Set the graphviz attributes for all fields with the given name.static void
graphvizSetFrameAttribute
(Class<?> cz, String attrib) Set the graphviz attributes for frames of the given class.static void
graphvizSetObjectAttribute
(Class<?> cz, String attrib) Set the graphviz attributes for objects of the given class.static void
graphvizSetStaticClassAttribute
(Class<?> cz, String attrib) Set the graphviz attributes for objects of the given class.static void
Graphviz style for an arrow from a static class to an object.static void
Graphviz style for a static class.static void
Graphviz style for a wrapper object (in simple form).static void
The debugger can be invoked from the command line using this method.static void
Remove an include pattern.static void
removeExcludePattern
(String value) Remove an exclude pattern.static void
run()
Run the debugger on the current class.static void
Run the debugger on the given class.static void
Run the debugger on the given class.static void
Run the debugger on the given class.static void
static void
Run the debugger on the given class.static void
runWithArgs
(Class<?> mainClass, String... args) Run the debugger on the given class.static void
runWithArgs
(String mainClassName, String... args) Run the debugger on the given class.static void
Sets the console output to the default (the terminal).static void
setConsoleFilename
(String filename) Sets the console output to the given filename.static void
Sets the console output to the given filename.static void
setGraphizOutputDir
(String dirName) Sets the graphviz output directory.static void
showBuiltInObjects
(boolean value) Show String, Integer, Double, etc as simplified objects (default==false).static void
showBuiltInObjectsVerbose
(boolean value) Show String, Integer, Double, etc as regular objects (default==false).static void
showFieldNamesInLabels
(boolean value) In graphviz, show field name in the label of an object (default==true).static void
showFieldNamesInNodeArrows
(boolean value) In graphviz, show field name on the arrow of a node object (default==true).static void
showFieldNamesInNodeLabels
(boolean value) In graphviz, show field name in the label of a node object (default==false).static void
showFilenamesOnConsole
(boolean value) Show file names on the console (default==false).static void
showFrameNumbers
(boolean value) In graphviz, show stack frame numbers (default==true).static void
Remove all node classes.static void
showNullFields
(boolean value) In graphviz, show null fields (default==true).static void
showNullVariables
(boolean value) In graphviz, show null variables (default==true).static void
showObjectIds
(boolean value) In graphviz, show object ids (default==false).static void
showObjectIdsRedundantly
(boolean value) In graphviz, show object ids and redundant variables for arrows (default==false).static void
showOnlyTopFrame
(boolean value) Run graphviz "dot" program to produce an output file (default==true).static void
showOuterClassInClassName
(boolean value) Include fully qualified class names (default==false).static void
showPackageInClassName
(boolean value) Show fully qualified class names (default==false).static void
showStaticClasses
(boolean value) Show static classes (default==true).static void
showSyntheticFields
(boolean value) Show fields introduced by the compiler (default==true);static void
showSyntheticMethods
(boolean value) Show methods introduced by the compiler (default==true);
-
Method Details
-
drawObject
Draw the given object. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawObjectWithName
Draw the given object, labeling it with the given name. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawObjects
Draw the given objects. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawObjectsWithNames
Draw the given objects, labeling them with the given names. The array of namesAndObjects must alternate between names and objects, as in Trace.drawObjects("x", x, "y" y). This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawThisFrame
Draw the current frame, as well as all reachable objects. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawStepsEnd
Stop drawing steps. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger. -
drawSteps
Start drawing steps. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger. -
draw
Draw all stack frames and static variables, as well as all reachable objects. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
drawAll
Draw all stack frames and static variables, as well as all reachable objects, overriding showStaticClasses() if it is false. This is a stub method, which is trapped by the debugger. It only has an effect if a variant of Trace.run() has been called to start the debugger and Trace.drawSteps() is false. -
graphvizRunGraphviz
Run graphviz "dot" program to produce an output file (default==true). If false, a graphviz source file is created, but no graphic file is generated. -
graphvizOutputFormat
The graphviz format -- see http://www.graphviz.org/doc/info/output.html . (default=="png"). -
setGraphizOutputDir
Sets the graphviz output directory. Creates the directory if necessary. Relative pathnames are interpreted with respect to the user's "Desktop" directory. Default is "GraphvizOutput". -
setConsoleFilenameRelativeToUserDesktop
Sets the console output to the given filename. Console output will be written to:(user home directory)/(filename)
-
setConsoleFilename
Sets the console output to the given filename. -
setConsoleFilename
Sets the console output to the default (the terminal). -
showOnlyTopFrame
Run graphviz "dot" program to produce an output file (default==true). If false, a graphviz source file is created, but no graphic file is generated. -
drawStepsOfMethod
Create a new graphviz drawing for every step of the named method. The methodName does not include parameters. In order to show a constructor, use the method name<init>
. -
drawStepsOfMethods
Create a new graphviz drawing for every step of the named methods. The methodName does not include parameters. In order to show a constructor, use the method name<init>
. -
consoleShow
Show events on the console (default==false). -
consoleShowVerbose
Show events on the console, including code (default==false). -
showBuiltInObjects
Show String, Integer, Double, etc as simplified objects (default==false). -
showBuiltInObjectsVerbose
Show String, Integer, Double, etc as regular objects (default==false). -
run
Run the debugger on the current class. Execution of the current program ends and a new JVM is started under the debugger. The debugger will execute the main method of the class that calls run. The main method is run with no arguments. -
run
-
run
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with no arguments. -
run
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with no arguments. -
run
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with the given arguments. -
run
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with the given arguments. -
runWithArgs
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with the given arguments. -
runWithArgs
Run the debugger on the given class. The current program will continue to execute after this call to run has completed. The main method of the given class is called with the given arguments. -
main
The debugger can be invoked from the command line using this method. The first argument must be the fully qualified name of the class to be debugged. Addition arguments are passed to the main method of the class to be debugged. -
addPossibleSrcLocation
Possible location of java source files. By default this includes "src" (for eclipse) and "src/main/java" (for maven). -
addPossibleBinLocation
Possible location of binary class files. By default this includes the system classpath, "./bin" (for eclipse), "./target/classes" (for maven), and ".". -
addPrefixOptionsForVm
Prefix options for the debugger VM. By default, the classpath is set to the current classpath. Other options can be provided here. -
debug
Turn on debugging information (default==false). Intended for developers. -
addExcludePattern
Add an exclude pattern. Classes whose fully qualified name matches an exclude pattern are ignored by the debugger. Regular expressions are limited to exact matches and patterns that begin with '*' or end with '*'; for example, "*.Foo" or "java.*". This limitation is inherited fromcom.sun.jdi.request.WatchpointRequest
. The default exclude patterns include:"*$$Lambda$*" "java.*" "jdk.*" "sun.*" "com.*" "org.*" "javax.*" "apple.*" "Jama.*" "qs.*" "stdlib.A*" "stdlib.B*" "stdlib.C*" "stdlib.D*" "stdlib.E*" "stdlib.F*" "stdlib.G*" "stdlib.H*" "stdlib.I*" "stdlib.J*" "stdlib.K*" "stdlib.L*" "stdlib.M*" "stdlib.N*" "stdlib.O*" "stdlib.P*" "stdlib.Q*" "stdlib.R*" "stdlib.S*" "stdlib.U*" "stdlib.V*" "stdlib.W*" "stdlib.X*" "stdlib.Y*"
The JDI excludes classes, but does not allow exceptions. This is the reason for the unusual number of excludes forstdlib
. It is important thatstdlib.Trace
not be excluded --- if it were, then callBacks toTrace.draw
would not function. As a result, all classes instdlib
that start with a letter other thanT
are excluded. Be careful when adding classes tostdlib
. Exclude patterns must include"*$$Lambda$*" "java.*" "jdk.*" "sun.*"
otherwise the Trace code itself will fail to run. -
removeExcludePattern
Remove an exclude pattern.- See Also:
-
addDrawingIncludePattern
Add an include pattern for drawing. These are classes that should be shown in drawing and console logs, which would otherwise be excluded. The default is:"java.util.*"
-
removeDrawingIncludePattern
Remove an include pattern.- See Also:
-
graphvizArrayBoxAttributes
Graphviz style for an array. -
graphvizArrayArrowAttributes
Graphviz style for an arrow from an array to an Object. -
graphvizFrameBoxAttributes
Graphviz style for a frame. -
graphvizFrameObjectArrowAttributes
Graphviz style for an arrow from a frame to an Object. -
graphvizFrameReturnAttributes
Graphviz style for an arrow from a return value to a frame. -
graphvizFrameExceptionAttributes
Graphviz style for an arrow from an exception to a frame. -
graphvizFrameFrameArrowAttributes
Graphviz style for an arrow from a frame to another frame. -
graphvizObjectBoxAttributes
Graphviz style for an object (non-array). -
graphvizWrapperBoxAttributes
Graphviz style for a wrapper object (in simple form). -
graphvizNodeBoxAttributes
Graphviz style for a wrapper object (in simple form). -
graphvizObjectArrowAttributes
Graphviz style for an arrow from an object to an object. -
graphvizNodeArrowAttributes
Extra Graphviz style for an arrow from an non-node to a node object. -
graphvizStaticClassBoxAttributes
Graphviz style for a static class. -
graphvizStaticClassArrowAttributes
Graphviz style for an arrow from a static class to an object. -
graphvizLabelBoxAttributes
Graphviz style for box labels. -
graphvizLabelArrowAttributes
Graphviz style for arrow labels. -
graphvizAddPossibleDotLocation
Add a filesystem location to search for the dot executable that comes with graphviz. The default is system dependent. -
graphvizRemoveGvFiles
Remove graphviz files for which graphic files have been successfully generated. -
graphvizAddNodeClass
Add classname to be drawn as a simple oval, with null as a dot. Any classname with value as a suffix will be treated as a Node. Default value includes "Node". -
graphvizRemoveNodeClass
Remove a node class.- See Also:
-
showNodesAsRegularObjects
Remove all node classes.- See Also:
-
showPackageInClassName
Show fully qualified class names (default==false). If showPackageInClassName is true, then showOuterClassInClassName is ignored (taken to be true). -
showStaticClasses
Show static classes (default==true). -
showOuterClassInClassName
Include fully qualified class names (default==false). -
consoleShowTypeInObjectName
Show the object type in addition to its id (default==false). -
consoleMaxFields
The maximum number of displayed fields when printing an object on the console (default==8). -
consoleMaxArrayElementsPrimitive
The maximum number of displayed elements when printing a primitive array on the console (default==15). -
consoleMaxArrayElementsObject
The maximum number of displayed elements when printing an object array on the console (default==8). -
consoleShowNestedArrayIds
Show object ids inside multidimensional arrays (default==false). -
showSyntheticFields
Show fields introduced by the compiler (default==true); -
showSyntheticMethods
Show methods introduced by the compiler (default==true); -
showFilenamesOnConsole
Show file names on the console (default==false). -
showFieldNamesInLabels
In graphviz, show field name in the label of an object (default==true). -
showFieldNamesInNodeLabels
In graphviz, show field name in the label of a node object (default==false). -
showFieldNamesInNodeArrows
In graphviz, show field name on the arrow of a node object (default==true). -
showObjectIds
In graphviz, show object ids (default==false). -
showObjectIdsRedundantly
In graphviz, show object ids and redundant variables for arrows (default==false). This also sets showBuiltInObjects to value. -
showFrameNumbers
In graphviz, show stack frame numbers (default==true). -
showNullFields
In graphviz, show null fields (default==true). -
showNullVariables
In graphviz, show null variables (default==true). -
graphvizPutLineNumberInFilename
Include line number in graphviz filename (default==true). -
addGraphvizIgnoredFields
Do not display any fields with this name (default includes only "$assertionsDisabled"). -
graphvizSetObjectAttribute
Set the graphviz attributes for objects of the given class. -
graphvizSetStaticClassAttribute
Set the graphviz attributes for objects of the given class. -
graphvizSetFrameAttribute
Set the graphviz attributes for frames of the given class. -
graphvizSetFieldAttribute
Set the graphviz attributes for all fields with the given name.
-