@@ -37,15 +37,41 @@ Instructions for running the callgraph generators
3737java -jar javacg-0.1-SNAPSHOT-static.jar lib1.jar lib2.jar...
3838</code >
3939
40+ ` javacg-static ` produces combined output in the following format:
41+
42+ ###### For methods
43+
44+ <code >
45+ M:class1:<method1 > (typeofcall)class2:<method2 >
46+ </code >
47+
48+ The line means that ` method1 ` of ` class1 ` called ` method2 ` of ` class2 ` .
49+ The type of call can have one of the following values (refer to
50+ the [ JVM specification] ( http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html )
51+ for the meaning of the calls):
52+
53+ * ` M ` for ` invokevirtual ` calls
54+ * ` I ` for ` invokeinterface ` calls
55+ * ` O ` for ` invokespecial ` calls
56+ * ` S ` for ` invokestatic ` calls
57+
58+ ###### For classes
59+
60+ <code >
61+ C: class1 class2
62+ </code >
63+
64+ This means that some method(s) in ` class1 ` called some method(s) in ` class2 ` .
65+
4066##### Dynamic
4167
4268` javacg-dynamic ` uses
4369[ javassist] ( http://www.csg.is.titech.ac.jp/~chiba/javassist/ ) to insert probes
4470at method entry and exit points. To be able to analyze a class ` javassist ` must
45- resolve all dependent classes at instrumentation time. To do so, it reads
71+ resolve all dependent classes at instrumentation time. To do so, it reads
4672classes from the JVM's boot classloader. By default, the JVM sets the boot
4773classpath to use Java's default classpath implementation (` rt.jar ` on
48- Win/Linux, ` classes.jar ` on the Mac). The boot classpath can be extended using
74+ Win/Linux, ` classes.jar ` on the Mac). The boot classpath can be extended using
4975the ` -Xbootclasspath ` option, which works the same as the traditional
5076` -classpath ` option. It is advisable for ` javacg-dynamic ` to work as expected,
5177to set the boot classpath to the same, or an appropriate subset, entries as the
@@ -54,21 +80,41 @@ normal application classpath.
5480Moreover, since instrumenting all methods will produce huge callgraphs which
5581are not necessarily helpful (e.g. it will include Java's default classpath
5682entries), ` javacg-dynamic ` includes support for restricting the set of classes
57- to be implemented through include and exclude statements. The options are
83+ to be instrumented through include and exclude statements. The options are
5884appended to the ` -javaagent ` argument and has the following format
5985
6086<code >-javaagent: javacg-dycg-agent .jar="incl=mylib.* ,mylib2.* ,java.nio.* ;excl=java.nio.charset.* "</code >
6187
6288The example above will instrument all classes under the the ` mylib ` , ` mylib2 ` and
6389` java.nio ` namespaces, except those that fall under the ` java.nio.charset ` namespace.
6490
65- < code >
91+ ```
6692java
6793-Xbootclasspath:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:mylib.jar
6894-javaagent:javacg-0.1-SNAPSHOT-dycg-agent.jar="incl=mylib.*;"
6995-classpath mylib.jar mylib.Mainclass
70- </code >
96+ ```
97+
98+ ` javacg-dynamic ` produces two kinds of output. On the standard output, it
99+ writes method call pairs as shown below:
71100
101+ ```
102+ class1:method1 class2:method2 numcalls
103+ ```
104+
105+ It also produces a file named ` calltrace.txt ` in which it writes the entry
106+ and exit timestamps for methods, thereby turning ` javacg-dynamic ` into
107+ a poor man's profiler. The format is the following:
108+
109+ ```
110+ <>[stack_depth][thread_id]fqdn.class:method=timestamp_nanos
111+ ```
112+
113+ The output line starts with a ` < ` or ` > ` depending on whether it is a method
114+ entry or exit. It then writes the stack depth, thread id and the class and
115+ method name, followed by a timestamp. The provided ` process_trace.rb `
116+ script processes the callgraph output to generate total time per method
117+ information.
72118
73119#### Examples
74120
@@ -81,12 +127,13 @@ in the `jar` directory.
81127
82128Running the batik Dacapo benchmark:
83129
84- < code >
130+ ```
85131java -Xbootclasspath:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:jar/batik-all.jar:jar/xml-apis-ext.jar -javaagent:target/javacg-0.1-SNAPSHOT-dycg-agent.jar="incl=org.apache.batik.*,org.w3c.*;" -jar dacapo-9.12-bach.jar batik -s small |tail -n 10
86- </code >
87- <br /><br />
88- <code >
89- [ ...] <br />
132+ ```
133+ <br />
134+
135+ ```
136+ [...]
90137org.apache.batik.dom.AbstractParentNode:appendChild org.apache.batik.dom.AbstractParentNode:fireDOMNodeInsertedEvent 6270<br/>
91138org.apache.batik.dom.AbstractParentNode:fireDOMNodeInsertedEvent org.apache.batik.dom.AbstractDocument:getEventsEnabled 6280<br/>
92139org.apache.batik.dom.AbstractParentNode:checkAndRemove org.apache.batik.dom.AbstractNode:getOwnerDocument 6280<br/>
@@ -95,16 +142,17 @@ org.apache.batik.dom.util.DoublyIndexedTable:put org.apache.batik.dom.util.Doubl
95142org.apache.batik.dom.AbstractElement:invalidateElementsByTagName org.apache.batik.dom.AbstractElement:getNodeType 7198<br/>
96143org.apache.batik.dom.AbstractElement:invalidateElementsByTagName org.apache.batik.dom.AbstractDocument:getElementsByTagName 14396<br/>
97144org.apache.batik.dom.AbstractElement:invalidateElementsByTagName org.apache.batik.dom.AbstractDocument:getElementsByTagNameNS 28792<br/>
98- </ code >
145+ ```
99146
100147Running the lucene Dacapo benchmark:
101148
102- < code >
149+ ```
103150java -Xbootclasspath:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:jar/lucene-core-2.4.jar:jar/luindex.jar -javaagent:target/javacg-0.1-SNAPSHOT-dycg-agent.jar="incl=org.apache.lucene.*;" -jar dacapo-9.12-bach.jar luindex -s small |tail -n 10
104- </ code >
151+ ```
105152<br /><br />
106- <code >
107- [ ...] <br />
153+
154+ ```
155+ [...]
108156org.apache.lucene.analysis.Token:setTermBuffer org.apache.lucene.analysis.Token:growTermBuffer 43449<br/>
109157org.apache.lucene.analysis.CharArraySet:getSlot org.apache.lucene.analysis.CharArraySet:getHashCode 43472<br/>
110158org.apache.lucene.analysis.CharArraySet:getSlot org.apache.lucene.analysis.CharArraySet:equals 46107<br/>
@@ -115,15 +163,16 @@ org.apache.lucene.store.IndexOutput:writeVInt org.apache.lucene.store.BufferedIn
115163org.apache.lucene.index.TermsHashPerField:quickSort org.apache.lucene.index.TermsHashPerField:comparePostings 107343<br/>
116164org.apache.lucene.analysis.Token:termBuffer org.apache.lucene.analysis.Token:initTermBuffer 162115<br/>
117165org.apache.lucene.analysis.Token:termLength org.apache.lucene.analysis.Token:initTermBuffer 205554<br/>
118-
119- </code >
166+ ```
120167
121168#### Known Restrictions
122169
123170* The static call graph generator does not account for methods invoked via
124171 reflection.
125172* The dynamic call graph generator will not work reliably (or at all) for
126173 multithreaded programs
174+ * The dynamic call graph generator does not handle exceptions very well, so some
175+ methods might appear as having never returned
127176
128177#### Author
129178
0 commit comments