Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method parameters to dynamic callgraph/calltrace output #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ java -jar javacg-0.1-SNAPSHOT-static.jar lib1.jar lib2.jar...
###### For methods

```
M:class1:<method1>(arg_types) (typeofcall)class2:<method2>(arg_types)
M:class1:<method1>(arg_types1) (typeofcall)class2:<method2>(arg_types2)
```

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

```
class1:method1 class2:method2 numcalls
class1:method1(arg_types1) class2:method2(arg_types2) numcalls
```

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

```
<>[stack_depth][thread_id]fqdn.class:method=timestamp_nanos
<>[stack_depth][thread_id]fqdn.class:method(arg_types)=timestamp_nanos
```

The output line starts with a `<` or `>` depending on whether it is a method
entry or exit. It then writes the stack depth, thread id and the class and
method name, followed by a timestamp. The provided `process_trace.rb`
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`
script processes the callgraph output to generate total time per method
information.

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/gr/gousiosg/javacg/dyn/Instrumenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,23 @@ private void enhanceMethod(CtBehavior method, String className)
throws NotFoundException, CannotCompileException {
String name = className.substring(className.lastIndexOf('.') + 1, className.length());
String methodName = method.getName();
StringBuilder params = new StringBuilder();
boolean first = true;
for (CtClass p : method.getParameterTypes()) {
if (!first) {
params.append(",");
} else {
first = false;
}
params.append(p.getName());
}

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

method.insertBefore("gr.gousiosg.javacg.dyn.MethodStack.push(\"" + className
+ ":" + methodName + "\");");
String signature = className + ":" + methodName + "(" + params.toString() + ")";

method.insertBefore("gr.gousiosg.javacg.dyn.MethodStack.push(\"" + signature + "\");");
method.insertAfter("gr.gousiosg.javacg.dyn.MethodStack.pop();");
}

Expand Down