Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2009 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/241945 to your computer and use it in GitHub Desktop.
Save anonymous/241945 to your computer and use it in GitHub Desktop.
/* BTrace Script Template */
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TracingScript {
private static java.util.Map<String, Integer> myMap = newHashMap();
private static int methodCountTreshold = 200;
@OnMethod(
clazz="/com\\.sowas\\.alphaagent\\..+/",
method="/.*/",
location=@Location(Kind.ENTRY)
)
public static void funcEnter() {
String method = probeMethod();
Integer callCount = 0;
if (containsKey(myMap, method))
callCount = get(myMap, method);
callCount += 1;
put(myMap, method, callCount);
if (callCount > methodCountTreshold)
return;
print(timeMillis());
print(' ');
print("entering ");
print(probeClass());
print('.');
print(method);
print(" (");
print(callCount);
println(")");
}
@OnMethod(
clazz="/com\\.sowas\\.alphaagent\\..+/",
method="/.*/",
location=@Location(Kind.RETURN)
)
public static void funcLeave() {
String method = probeMethod();
Integer callCount = 0;
if (containsKey(myMap, method))
callCount = get(myMap, method);
callCount += 1;
put(myMap, method, callCount);
if (callCount > methodCountTreshold)
return;
print(timeMillis());
print(' ');
print("leaving ");
print(probeClass());
print('.');
print(method);
print(" (");
print(callCount);
println(")");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment