Last active
January 12, 2016 15:40
-
-
Save kofemann/72160021d09ef9cc5b5f to your computer and use it in GitHub Desktop.
btrace script
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 com.sun.btrace.annotations.*; | |
| import com.sun.btrace.aggregation.Aggregation; | |
| import com.sun.btrace.aggregation.AggregationKey; | |
| import com.sun.btrace.aggregation.AggregationFunction; | |
| import static com.sun.btrace.BTraceUtils.*; | |
| /** | |
| * run as: | |
| * $ su dcache -c "/opt/btrace/bin/btrace <pid> NetorkInterfaceFtracer.java" | |
| */ | |
| @BTrace public class NetorkInterfaceFtracer { | |
| private static Aggregation average = Aggregations.newAggregation(AggregationFunction.AVERAGE); | |
| private static Aggregation count = Aggregations.newAggregation(AggregationFunction.COUNT); | |
| @OnMethod( | |
| clazz="java.net.Inet6Address", | |
| method="readObject", | |
| location = @Location(Kind.RETURN) | |
| ) | |
| public static void func(@ProbeClassName String pcm, @ProbeMethodName String pmn, @Duration long duration) { | |
| AggregationKey key = Aggregations.newAggregationKey(Strings.strcat(pcm, Strings.strcat("#", pmn))); | |
| Aggregations.addToAggregation(average, key, duration); | |
| Aggregations.addToAggregation(count, key, 1); | |
| } | |
| @OnEvent | |
| @OnTimer(20000) | |
| public static void onEvent() { | |
| println("---------------------------------------------"); | |
| Aggregations.printAggregation("Average", average); | |
| Aggregations.printAggregation("Count", count); | |
| println("---------------------------------------------"); | |
| Sys.exit(0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment