Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Last active September 29, 2017 19:23
Show Gist options
  • Save adam-hert/ae36a5fb0b945a88f6903e9559a206ba to your computer and use it in GitHub Desktop.
Save adam-hert/ae36a5fb0b945a88f6903e9559a206ba to your computer and use it in GitHub Desktop.
Java partition + method profile
javac -cp *:. hello-trace.java
/**
* The HelloTrace class is an example of how to instrument a non-servlet java application
* Includes an example of adding a partition, and profiling a method
*/
//import the tracelytics-api.jar (/usr/local/tracelytics/tracelytics-api.jar)
import com.tracelytics.api.ext.*;
class HelloTrace {
public static void main(String[] args) {
//Start a trace (In a servlet, we do this automatically at the start of the request)
TraceEvent event = Trace.startTrace("Hello Trace POJO");
event.report();
//Create an info event and add the KV pairs of 'Partition' and whichever string you want to map to the UI
TraceEvent info = Trace.createInfoEvent(null);
info.addInfo("Partition", "My_Partiton");
info.report();
//Do some normal java stuff
System.out.println("Hello Trace!"); // Display the string.
try {
sleep(200);
} catch(InterruptedException ex){
Thread.currentThread().interrupt();
}
//End the Trace
Trace.endTrace("Hello Trace POJO");
}
@ProfileMethod(profileName="sleep", backTrace=true, storeReturn=true)
public static void sleep(long ms) throws InterruptedException {
Thread.sleep(ms);
System.out.println("Slept");
}
}
java -javaagent:/usr/local/tracelytics/tracelyticsagent.jar -cp *:. HelloTrace
@adam-hert
Copy link
Author

partition

@adam-hert
Copy link
Author

method profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment