DTrace helps you understand a software system by enabling you to dynamically modify the operating system kernel and user processes to record additional data that you specify at locations of interest, called probes. A probe is a location or activity to which DTrace can bind a request to perform a set of actions, like recording a stack trace, a timestamp, or the argument to a function. Probes are like programmable sensors scattered all over your Solaris system in interesting places. If you want to figure out what's going on, you use DTrace to program the appropriate sensors to record the information that is of interest to you. Then, as each probe fires, DTrace gathers the data from your probes and reports it back to you. If you don't specify any actions for a probe, DTrace will just take note of each time the probe fires.
Every probe in DTrace has two names: a unique integer ID and a human-readable string name. We're going to start learning DTrace by building some very simple requests using the probe named BEGIN, which fires once each time you start a new tracing request. You can use the dtrace(1M) utility's -n option to enable a probe using its string name. Type the following command:
# dtrace -n BEGIN
After a brief pause, you will see DTrace tell you that one probe was
enabled and you will see a line of output indicating that the BEGIN probe fired. Once you see this output, dtrace
remains paused waiting for other probes to fire. Since you haven't enabled
any other probes and BEGIN only fires once, press Control-C
in your shell to exit dtrace and return to your shell prompt:
# dtrace -n BEGIN -n END
dtrace: description 'BEGIN' matched 1 probe
dtrace: description 'END' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN
^C
0 2 :END
#
As you can see, pressing Control-C to exit dtrace
triggers the END probe. dtrace reports
this probe firing before exiting.
Now that you understand a little bit about naming and enabling probes,
you're ready to write the DTrace version of everyone's first program, “Hello,
World.” In addition to constructing DTrace experiments on the command
line, you can also write them in text files using the D programming language.
In a text editor, create a new file called hello.d and
type in your first D program:
Example 1–1 hello.d: Hello, World from the D Programming Language
BEGIN
{
trace("hello, world");
exit(0);
}
After you have saved your program, you can run it using the dtrace -s option.
Type the following command:
# dtrace -s hello.d
dtrace: script 'hello.d' matched 1 probe
CPU ID FUNCTION:NAME
0 1 :BEGIN hello, world
#
1 comments:
is this dtrace for D programming only?
or can we use it with other programming languages as well?
And, is dtrace a D programming tool OR sun os tool?
Post a Comment