You can use the dtrace command to create executable interpreter files. The file must have execute permission. The initial line of the file must be #!/usr/sbin/dtrace -s. You can specify other options to the dtrace command on this line. You must specify the options with only one dash (-). List the s option last, as in the following example.
#!/usr/sbin/dtrace -qvs |
You can specify options for the dtrace command by using #pragma lines in the D script, as in the following D fragment:
# cat -n mem2.d
1 #!/usr/sbin/dtrace -s
2
3 #pragma D option quiet
4 #pragma D option verbose
5
6 vminfo:::
...
|
The following table lists the option names that you can use in #pragma lines.
Table 3–1 DTrace Consumer Options|
Option Name |
Value |
dtrace Alias |
Description |
|---|---|---|---|
|
aggrate |
time |
Rate of aggregation reading |
|
|
aggsize |
size |
Aggregation buffer size |
|
|
bufresize |
auto or manual |
Buffer resizing policy |
|
|
bufsize |
size |
-b |
Principal buffer size |
|
cleanrate |
time |
Cleaning rate |
|
|
cpu |
scalar |
-c |
CPU on which to enable tracing |
|
defaultargs |
— |
Allow references to unspecified macro arguments |
|
|
destructive |
— |
-w |
Allow destructive actions |
|
dynvarsize |
size |
Dynamic variable space size |
|
|
flowindent |
— |
-F |
Indent function entry and prefix with ->; unindent function return and prefix with <- |
|
grabanon |
— |
-a |
Claim anonymous state |
|
jstackframes |
scalar |
Number of default stack frames jstack() |
|
|
jstackstrsize |
scalar |
Default string space size for jstack() |
|
|
nspec |
scalar |
Number of speculations |
|
|
quiet |
— |
-q |
Output only explicitly traced data |
|
specsize |
size |
Speculation buffer size |
|
|
strsize |
size |
String size |
|
|
stackframes |
scalar |
Number of stack frames |
|
|
stackindent |
scalar |
Number of whitespace characters to use when indenting stack() and ustack() output |
|
|
statusrate |
time |
Rate of status checking |
|
|
switchrate |
time |
Rate of buffer switching |
|
|
ustackframes |
scalar |
Number of user stack frames |
A D script can refer to a set of built in macro variables. These macro variables are defined by the D compiler.
Macro arguments
Effective group-ID
Effective user-ID
Real group-ID
Process ID
Process group ID
Parent process ID
Project ID
Session ID
Target process ID
Task ID
Real user-ID
This example passes the PID of a running vi process to the syscalls2.d D script. The D script terminates when the vi command exits.
# cat -n syscalls2.d
1 #!/usr/sbin/dtrace -qs
2
3 syscall:::entry
4 /pid == $1/
5 {
6 @[probefunc] = count();
7 }
8 syscall::rexit:entry
9 {
10 exit(0);
11 }
# pgrep vi
2208
# ./syscalls2.d 2208
rexit 1
setpgrp 1
creat 1
getpid 1
open 1
lstat64 1
stat64 1
fdsync 1
unlink 1
close 1
alarm 1
lseek 1
sigaction 1
ioctl 1
read 1
write 1
|