Last active
September 29, 2017 19:23
-
-
Save adam-hert/ae36a5fb0b945a88f6903e9559a206ba to your computer and use it in GitHub Desktop.
Java partition + method profile
This file contains 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
javac -cp *:. hello-trace.java |
This file contains 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
/** | |
* 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"); | |
} | |
} |
This file contains 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
java -javaagent:/usr/local/tracelytics/tracelyticsagent.jar -cp *:. HelloTrace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment