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 voidaddDrawingIncludePattern(String value) Add an include pattern for drawing.static voidaddExcludePattern(String value) Add an exclude pattern.static voidaddGraphvizIgnoredFields(String value) Do not display any fields with this name (default includes only "$assertionsDisabled").static voidaddPossibleBinLocation(String value) Possible location of binary class files.static voidaddPossibleSrcLocation(String value) Possible location of java source files.static voidaddPrefixOptionsForVm(String value) Prefix options for the debugger VM.static voidconsoleMaxArrayElementsObject(int value) The maximum number of displayed elements when printing an object array on the console (default==8).static voidconsoleMaxArrayElementsPrimitive(int value) The maximum number of displayed elements when printing a primitive array on the console (default==15).static voidconsoleMaxFields(int value) The maximum number of displayed fields when printing an object on the console (default==8).static voidconsoleShow(boolean value) Show events on the console (default==false).static voidconsoleShowNestedArrayIds(boolean value) Show object ids inside multidimensional arrays (default==false).static voidconsoleShowTypeInObjectName(boolean value) Show the object type in addition to its id (default==false).static voidconsoleShowVerbose(boolean value) Show events on the console, including code (default==false).static voiddebug(boolean value) Turn on debugging information (default==false).static voiddraw()Draw all stack frames and static variables, as well as all reachable objects.static voiddrawAll()Draw all stack frames and static variables, as well as all reachable objects, overriding showStaticClasses() if it is false.static voiddrawObject(Object object) Draw the given object.static voiddrawObjects(Object... objects) Draw the given objects.static voiddrawObjectsWithNames(Object... namesAndObjects) Draw the given objects, labeling them with the given names.static voiddrawObjectWithName(String name, Object object) Draw the given object, labeling it with the given name.static voidStart drawing steps.static voidStop drawing steps.static voiddrawStepsOfMethod(String methodName) Create a new graphviz drawing for every step of the named method.static voiddrawStepsOfMethods(String... methodName) Create a new graphviz drawing for every step of the named methods.static voidDraw the current frame, as well as all reachable objects.static voidgraphvizAddNodeClass(String value) Add classname to be drawn as a simple oval, with null as a dot.static voidAdd a filesystem location to search for the dot executable that comes with graphviz.static voidGraphviz style for an arrow from an array to an Object.static voidgraphvizArrayBoxAttributes(String value) Graphviz style for an array.static voidgraphvizFrameBoxAttributes(String value) Graphviz style for a frame.static voidGraphviz style for an arrow from an exception to a frame.static voidGraphviz style for an arrow from a frame to another frame.static voidGraphviz style for an arrow from a frame to an Object.static voidGraphviz style for an arrow from a return value to a frame.static voidGraphviz style for arrow labels.static voidgraphvizLabelBoxAttributes(String value) Graphviz style for box labels.static voidExtra Graphviz style for an arrow from an non-node to a node object.static voidgraphvizNodeBoxAttributes(String value) Graphviz style for a wrapper object (in simple form).static voidGraphviz style for an arrow from an object to an object.static voidGraphviz style for an object (non-array).static voidgraphvizOutputFormat(String value) The graphviz format -- see http://www.graphviz.org/doc/info/output.html .static voidgraphvizPutLineNumberInFilename(boolean value) Include line number in graphviz filename (default==true).static voidgraphvizRemoveGvFiles(boolean value) Remove graphviz files for which graphic files have been successfully generated.static voidgraphvizRemoveNodeClass(String value) Remove a node class.static voidgraphvizRunGraphviz(boolean value) Run graphviz "dot" program to produce an output file (default==true).static voidgraphvizSetFieldAttribute(String field, String attrib) Set the graphviz attributes for all fields with the given name.static voidgraphvizSetFrameAttribute(Class<?> cz, String attrib) Set the graphviz attributes for frames of the given class.static voidgraphvizSetObjectAttribute(Class<?> cz, String attrib) Set the graphviz attributes for objects of the given class.static voidgraphvizSetStaticClassAttribute(Class<?> cz, String attrib) Set the graphviz attributes for objects of the given class.static voidGraphviz style for an arrow from a static class to an object.static voidGraphviz style for a static class.static voidGraphviz style for a wrapper object (in simple form).static voidThe debugger can be invoked from the command line using this method.static voidRemove an include pattern.static voidremoveExcludePattern(String value) Remove an exclude pattern.static voidrun()Run the debugger on the current class.static voidRun the debugger on the given class.static voidRun the debugger on the given class.static voidRun the debugger on the given class.static voidstatic voidRun the debugger on the given class.static voidrunWithArgs(Class<?> mainClass, String... args) Run the debugger on the given class.static voidrunWithArgs(String mainClassName, String... args) Run the debugger on the given class.static voidSets the console output to the default (the terminal).static voidsetConsoleFilename(String filename) Sets the console output to the given filename.static voidSets the console output to the given filename.static voidsetGraphizOutputDir(String dirName) Sets the graphviz output directory.static voidshowBuiltInObjects(boolean value) Show String, Integer, Double, etc as simplified objects (default==false).static voidshowBuiltInObjectsVerbose(boolean value) Show String, Integer, Double, etc as regular objects (default==false).static voidshowFieldNamesInLabels(boolean value) In graphviz, show field name in the label of an object (default==true).static voidshowFieldNamesInNodeArrows(boolean value) In graphviz, show field name on the arrow of a node object (default==true).static voidshowFieldNamesInNodeLabels(boolean value) In graphviz, show field name in the label of a node object (default==false).static voidshowFilenamesOnConsole(boolean value) Show file names on the console (default==false).static voidshowFrameNumbers(boolean value) In graphviz, show stack frame numbers (default==true).static voidRemove all node classes.static voidshowNullFields(boolean value) In graphviz, show null fields (default==true).static voidshowNullVariables(boolean value) In graphviz, show null variables (default==true).static voidshowObjectIds(boolean value) In graphviz, show object ids (default==false).static voidshowObjectIdsRedundantly(boolean value) In graphviz, show object ids and redundant variables for arrows (default==false).static voidshowOnlyTopFrame(boolean value) Run graphviz "dot" program to produce an output file (default==true).static voidshowOuterClassInClassName(boolean value) Include fully qualified class names (default==false).static voidshowPackageInClassName(boolean value) Show fully qualified class names (default==false).static voidshowStaticClasses(boolean value) Show static classes (default==true).static voidshowSyntheticFields(boolean value) Show fields introduced by the compiler (default==true);static voidshowSyntheticMethods(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.Tracenot be excluded --- if it were, then callBacks toTrace.drawwould not function. As a result, all classes instdlibthat start with a letter other thanTare 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.
-