Skip to content

Instantly share code, notes, and snippets.

@matthewmccullough
Forked from rhyolight/gist:142054
Created July 8, 2009 06:46
Show Gist options
  • Save matthewmccullough/142635 to your computer and use it in GitHub Desktop.
Save matthewmccullough/142635 to your computer and use it in GitHub Desktop.
import java.util.Map;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
@BTrace
public class ManyMethodTimerTemplate {
@TLS private static Map<String, Long> startTimes = newHashMap();
<% targetClasses.eachWithIndex { className, classData, classIndex -> %>
<% classData.targetMethods.eachWithIndex { targetMethod, methodIndex -> %>
@OnMethod(clazz = "$className", method = "$targetMethod")
public static void start_${classIndex}_${methodIndex}() {
put(startTimes, "$className", timeMillis());
println(strcat(strcat(strcat(strcat(strcat("entered|", name(probeClass())), "|"), probeMethod()), "|"),
str(get(startTimes, "$className"))));
}
@OnMethod(clazz = "$className", method = "$targetMethod", location = @Location(where = Where.BEFORE, value = Kind.RETURN))
public static void end_${classIndex}_${methodIndex}() {
long endtime = timeMillis();
String duration = str(endtime - get(startTimes, "$className"));
println(strcat(strcat(strcat(strcat(strcat(strcat(strcat(strcat("completed|", name(probeClass())), "|"), probeMethod()),
"|"), str(endtime)), "|"), duration), "|"));
}
<% } %>
<% } %>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment