Skip to content

Instantly share code, notes, and snippets.

@matthewmccullough
Forked from rhyolight/gist:142054
Created July 8, 2009 06:46

Revisions

  1. @rhyolight rhyolight created this gist Jul 7, 2009.
    30 changes: 30 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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), "|"));
    }

    <% } %>
    <% } %>

    }