| Solaris |
|
|
The Java DTrace API is available in Solaris 10 update 4 or later and Solaris Nevada build 35 or later, and you can browse the source online. The javadoc is not yet available to browse online, but if you have the Java DTrace API installed on your system, you can view the javadoc here:
file:///usr/share/lib/java/javadoc/dtrace/api/index.html
The jar is installed at
/usr/share/lib/java/dtrace.jar
Check out the API Diagram and Quick Start Guide in the Related Documentation section of the javadoc package summary. The Quick Start Guide includes program examples. Here's the simplest one: TestApi.java. The significant code block shows how easy it is to use the API:
try {
consumer.open();
consumer.compile(file, macroArgs);
consumer.enable();
consumer.go();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
This gets an open libdtrace handle, compiles the given D program file, enables the compiled probes, and begins tracing in a background thread. You can compile it as follows:
% javac -cp /usr/share/lib/java/dtrace.jar TestAPI.java
Try running it with a simple D program file such as the following:
BEGIN
{
trace("hello, world!");
exit(0);
}
If you save the D program as hello.d you can run it as follows:
% java -cp .:/usr/share/lib/java/dtrace.jar TestAPI hello.d
The output should look like this:
org.opensolaris.os.dtrace.ProbeData[epid = 1, cpu = 1, enabledProbeDescription = dtrace:::BEGIN, flow = null, records = ["hello, world!", 0]]
I wrote a lengthier test program that emulates the dtrace command. It supports many of the dtrace(1M) options, so it's a good example of how to access common DTtrace functionality using the API. You can get the jdtrace source and instructions here.
Terms of Use
|
Privacy
|
Trademarks
|
Copyright Policy
|
Site Guidelines
|
Site Map
|
Help
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Use.
© 2012, Oracle Corporation and/or its affiliates.