Created
July 7, 2009 12:46
-
-
Save rhyolight/142054 to your computer and use it in GitHub Desktop.
A groovy template for SimpleTemplateEngine that creates a btrace Java source file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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