Skip to content

Commit 19d6e56

Browse files
committed
added method parameters to dynamic callgraph/calltrace output
1 parent da81eeb commit 19d6e56

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ java -jar javacg-0.1-SNAPSHOT-static.jar lib1.jar lib2.jar...
4040
###### For methods
4141

4242
```
43-
M:class1:<method1>(arg_types) (typeofcall)class2:<method2>(arg_types)
43+
M:class1:<method1>(arg_types1) (typeofcall)class2:<method2>(arg_types2)
4444
```
4545

46-
The line means that `method1` of `class1` called `method2` of `class2`.
46+
The line means that `method1` of `class1` with arguments `arg_types1` called `method2` of `class2` with arguments `arg_types2`.
47+
`arg_types` are (potentially empty) comma-separated (no space after comma) lists of method arguments, where each argument is a fully-qualified class name.
4748
The type of call can have one of the following values (refer to
4849
the [JVM specification](http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html)
4950
for the meaning of the calls):
@@ -102,20 +103,19 @@ java
102103
writes method call pairs as shown below:
103104

104105
```
105-
class1:method1 class2:method2 numcalls
106+
class1:method1(arg_types1) class2:method2(arg_types2) numcalls
106107
```
107108

108109
It also produces a file named `calltrace.txt` in which it writes the entry
109110
and exit timestamps for methods, thereby turning `javacg-dynamic` into
110111
a poor man's profiler. The format is the following:
111112

112113
```
113-
<>[stack_depth][thread_id]fqdn.class:method=timestamp_nanos
114+
<>[stack_depth][thread_id]fqdn.class:method(arg_types)=timestamp_nanos
114115
```
115116

116117
The output line starts with a `<` or `>` depending on whether it is a method
117-
entry or exit. It then writes the stack depth, thread id and the class and
118-
method name, followed by a timestamp. The provided `process_trace.rb`
118+
entry or exit. It then writes the stack depth; thread id; and the class, method name, and method arguments; followed by a timestamp. The provided `process_trace.rb`
119119
script processes the callgraph output to generate total time per method
120120
information.
121121

src/main/java/gr/gousiosg/javacg/dyn/Instrumenter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,23 @@ private void enhanceMethod(CtBehavior method, String className)
166166
throws NotFoundException, CannotCompileException {
167167
String name = className.substring(className.lastIndexOf('.') + 1, className.length());
168168
String methodName = method.getName();
169+
StringBuilder params = new StringBuilder();
170+
boolean first = true;
171+
for (CtClass p : method.getParameterTypes()) {
172+
if (!first) {
173+
params.append(",");
174+
} else {
175+
first = false;
176+
}
177+
params.append(p.getName());
178+
}
169179

170180
if (method.getName().equals(name))
171181
methodName = "<init>";
172182

173-
method.insertBefore("gr.gousiosg.javacg.dyn.MethodStack.push(\"" + className
174-
+ ":" + methodName + "\");");
183+
String signature = className + ":" + methodName + "(" + params.toString() + ")";
184+
185+
method.insertBefore("gr.gousiosg.javacg.dyn.MethodStack.push(\"" + signature + "\");");
175186
method.insertAfter("gr.gousiosg.javacg.dyn.MethodStack.pop();");
176187
}
177188

0 commit comments

Comments
 (0)