| Skip Navigation Links | |
| Exit Print View | |
|
Oracle Solaris 11.1 Dynamic Tracing Guide Oracle Solaris 11.1 Information Library |
The data recording actions comprise the core DTrace actions. Each of these actions records data to the principal buffer by default, but each action may also be used to record data to speculative buffers. See Chapter 5, Buffers and Buffering for more details on the principal buffer. See Chapter 7, Speculative Tracing for more details on speculative buffers. The descriptions in this section refer only to the directed buffer, indicating that data is recorded either to the principal buffer or to a speculative buffer if the action follows a speculate.
void trace(expression)
The most basic action is the trace action, which takes a D expression as its argument and traces the result to the directed buffer. The following statements are examples of trace actions:
trace(execname);
trace(curlwpsinfo->pr_pri);
trace(timestamp / 1000);
trace(`lbolt);
trace("somehow managed to get here");
void tracemem(address, size_t nbytes)
The tracemem action takes a D expression as its first argument, address, and a constant as its second argument, nbytes. tracemem copies the memory from the address specified by address into the directed buffer for the length specified by nbytes.
The output format depends on the data printed. When dtrace decides that the data looks like ascii string, it prints them as text, and output is terminated by first '0'. When dtrace decides that the data is binary, it prints them in hex form
0 342 write:entry
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
0: c0 de 09 c2 4a e8 27 54 dc f8 9f f1 9a 20 4b d1 ....J.'T..... K.
10: 9c 7a 7a 85 1b 03 0a fb 3a 81 8a 1b 25 35 b3 9a .zz.....:...%5..
20: f1 7d e6 2b 66 6d 1c 11 f8 eb 40 7f 65 9a 25 f8 .}.+fm....@.e.%.
30: c8 68 87 b2 6f 48 a2 a5 f3 a2 1f 46 ab 3d f9 d2 .h..oH.....F.=..
40: 3d b8 4c c0 41 3c f7 3c cd 18 ad 0d 0d d3 1a 90 =.L.A<.<........
You can force tracemem to use always binary format by using rawbytes option.
void printf(string format, ...)
Like trace, the printf action traces D expressions. However, printf allows for elaborate printf(3C) -style formatting. Like printf(3C), the parameters consists of a format string followed by a variable number of arguments. By default, the arguments are traced to the directed buffer. The arguments are later formatted for output by dtrace(1M) according to the specified format string. For example, the first two examples of trace from trace could be combined in a single printf:
printf("execname is %s; priority is %d", execname, curlwpsinfo->pr_pri);
For more information on printf, see Chapter 6, Output Formatting.
void printa(aggregation) void printa(string format, aggregation)
The printa action enables you to display and format aggregations. See Chapter 3, Aggregations for more detail on aggregations. If a format is not provided, printa only traces a directive to the DTrace consumer that the specified aggregation should be processed and displayed using the default format. If a format is provided, the aggregation will be formatted as specified. See Chapter 6, Output Formatting for a more detailed description of the printa format string.
printa only traces a directive that the aggregation should be processed by the DTrace consumer. It does not process the aggregation in the kernel. Therefore, the time between the tracing of the printa directive and the actual processing of the directive depends on the factors that affect buffer processing. These factors include the aggregation rate, the buffering policy and, if the buffering policy is switching, the rate at which buffers are switched. See Chapter 3, Aggregations and Chapter 5, Buffers and Buffering for detailed descriptions of these factors.
void stack(int nframes) void stack(void)
The stack action records a kernel stack trace to the directed buffer. The kernel stack will be nframes in depth. If nframes is not provided, the number of stack frames recorded is the number specified by the stackframes option. For example:
# dtrace -n uiomove:entry'{stack()}'
CPU ID FUNCTION:NAME
0 9153 uiomove:entry
genunix`fop_write+0x1b
namefs`nm_write+0x1d
genunix`fop_write+0x1b
genunix`write+0x1f7
0 9153 uiomove:entry
genunix`fop_read+0x1b
genunix`read+0x1d4
0 9153 uiomove:entry
genunix`strread+0x394
specfs`spec_read+0x65
genunix`fop_read+0x1b
genunix`read+0x1d4
...
The stack action is a little different from other actions in that it may also be used as the key to an aggregation:
# dtrace -n kmem_alloc:entry'{@[stack()] = count()}'
dtrace: description 'kmem_alloc:entry' matched 1 probe
^C
rpcmod`endpnt_get+0x47c
rpcmod`clnt_clts_kcallit_addr+0x26f
rpcmod`clnt_clts_kcallit+0x22
nfs`rfscall+0x350
nfs`rfs2call+0x60
nfs`nfs_getattr_otw+0x9e
nfs`nfsgetattr+0x26
nfs`nfs_getattr+0xb8
genunix`fop_getattr+0x18
genunix`cstat64+0x30
genunix`cstatat64+0x4a
genunix`lstat64+0x1c
1
genunix`vfs_rlock_wait+0xc
genunix`lookuppnvp+0x19d
genunix`lookuppnat+0xe7
genunix`lookupnameat+0x87
genunix`lookupname+0x19
genunix`chdir+0x18
1
rpcmod`endpnt_get+0x6b1
rpcmod`clnt_clts_kcallit_addr+0x26f
rpcmod`clnt_clts_kcallit+0x22
nfs`rfscall+0x350
nfs`rfs2call+0x60
nfs`nfs_getattr_otw+0x9e
nfs`nfsgetattr+0x26
nfs`nfs_getattr+0xb8
genunix`fop_getattr+0x18
genunix`cstat64+0x30
genunix`cstatat64+0x4a
genunix`lstat64+0x1c
1
...
void ustack(int nframes, int strsize) void ustack(int nframes) void ustack(void)
The ustack action records a user stack trace to the directed buffer. The user stack will be nframes in depth. If nframes is not provided, the number of stack frames recorded is the number specified by the ustackframes option. While ustack is able to determine the address of the calling frames when the probe fires, the stack frames will not be translated into symbols until the ustack action is processed at user-level by the DTrace consumer. If strsize is specified and non-zero, ustack will allocate the specified amount of string space, and use it to perform address-to-symbol translation directly from the kernel. This direct user symbol translation is currently available only for Java virtual machines, version 1.5 and higher. Java address-to-symbol translation annotates user stacks that contain Java frames with the Java class and method name. If such frames cannot be translated, the frames will appear only as hexadecimal addresses.
The following example traces a stack with no string space, and therefore no Java address-to-symbol translation:
# dtrace -n syscall::write:entry'/pid == $target/{ustack(50, 0);
exit(0)}' -c "java -version"
dtrace: description 'syscall::write:entry' matched 1 probe
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b58, mixed mode)
dtrace: pid 5312 has exited
CPU ID FUNCTION:NAME
0 35 write:entry
libc.so.1`_write+0x15
libjvm.so`__1cDhpiFwrite6FipkvI_I_+0xa8
libjvm.so`JVM_Write+0x2f
d0c5c946
libjava.so`Java_java_io_FileOutputStream_writeBytes+0x2c
cb007fcd
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb002a7b
cb000152
libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_
pnMmethodHandle_pnRJavaCallArguments_
pnGThread__v_+0x187
libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_
pnMmethodHandle_pnRJavaCallArguments_
pnGThread__v2468_v_+0x14
libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_
pnRJavaCallArguments_pnGThread __v_+0x28
libjvm.so`__1cRjni_invoke_static6FpnHJNIEnv__pnJJavaValue_
pnI_jobject_nLJNICallType_pnK_jmethodID_pnSJNI_
ArgumentPusher_pnGThread__v_+0x180
libjvm.so`jni_CallStaticVoidMethod+0x10f
java`main+0x53d
Notice that the C and C++ stack frames from the Java virtual machine are presented symbolically using C++ “mangled” symbol names, and the Java stack frames are presented only as hexadecimal addresses. The following example shows a call to ustack with a non-zero string space:
# dtrace -n syscall::write:entry'/pid == $target/{ustack(50, 500); exit(0)}'
-c "java -version"
dtrace: description 'syscall::write:entry' matched 1 probe
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b58, mixed mode)
dtrace: pid 5308 has exited
CPU ID FUNCTION:NAME
0 35 write:entry
libc.so.1`_write+0x15
libjvm.so`__1cDhpiFwrite6FipkvI_I_+0xa8
libjvm.so`JVM_Write+0x2f
d0c5c946
libjava.so`Java_java_io_FileOutputStream_writeBytes+0x2c
java/io/FileOutputStream.writeBytes
java/io/FileOutputStream.write
java/io/BufferedOutputStream.flushBuffer
java/io/BufferedOutputStream.flush
java/io/PrintStream.write
sun/nio/cs/StreamEncoder$CharsetSE.writeBytes
sun/nio/cs/StreamEncoder$CharsetSE.implFlushBuffer
sun/nio/cs/StreamEncoder.flushBuffer
java/io/OutputStreamWriter.flushBuffer
java/io/PrintStream.write
java/io/PrintStream.print
java/io/PrintStream.println
sun/misc/Version.print
sun/misc/Version.print
StubRoutines (1)
libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_
pnMmethodHandle_pnRJavaCallArguments_pnGThread
__v_+0x187
libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_
pnMmethodHandle_pnRJavaCallArguments_pnGThread
__v2468_v_+0x14
libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle
_pnRJavaCallArguments_pnGThread__v_+0x28
libjvm.so`__1cRjni_invoke_static6FpnHJNIEnv__pnJJavaValue_pnI
_jobject_nLJNICallType_pnK_jmethodID_pnSJNI
_ArgumentPusher_pnGThread__v_+0x180
libjvm.so`jni_CallStaticVoidMethod+0x10f
java`main+0x53d
8051b9a
The above example output demonstrates symbolic stack frame information for Java stack frames. There are still some hexadecimal frames in this output because some functions are static and do not have entries in the application symbol table. Translation is not possible for these frames.
The ustack symbol translation for non-Java frames occurs after the stack data is recorded. Therefore, the corresponding user process might exit before symbol translation can be performed, making stack frame translation impossible. If the user process exits before symbol translation is performed, dtrace will emit a warning message, followed by the hexadecimal stack frames, as shown in the following example:
dtrace: failed to grab process 100941: no such process
c7b834d4
c7bca85d
c7bca1a4
c7bd4374
c7bc2628
8047efc
Techniques for mitigating this problem are described in Chapter 12, User Process Tracing.
Finally, because the postmortem DTrace debugger commands cannot perform the frame translation, using ustack with a ring buffer policy always results in raw ustack data.
The following D program shows an example of ustack that leaves strsize unspecified:
syscall::brk:entry
/execname == $$1/
{
@[ustack(40)] = count();
}
To run this example for the Oracle Solaris prstat command use the following command:
# dtrace -s brk.d prstat
dtrace: script 'brk.d' matched 1 probe
^C
libc.so.1`_brk_unlocked+0xa
libc.so.1`sbrk+0x2c
libc.so.1`_morecore+0x112
libc.so.1`_malloc_unlocked+0x182
libc.so.1`realloc+0x39f
prstat`Realloc+0x21
prstat`Zalloc+0x17
prstat`fd_init+0x2a
prstat`main+0x55
prstat`0x4047dc
1
libc.so.1`_brk_unlocked+0xa
libc.so.1`sbrk+0x2c
libc.so.1`_morecore+0x112
libc.so.1`_malloc_unlocked+0x182
libc.so.1`malloc+0x31
libc.so.1`calloc+0x57
libcurses.so.1`setupterm+0xacc
libcurses.so.1`newscreen+0x87
libcurses.so.1`initscr32+0x53
prstat`curses_on+0x1f
prstat`main+0x7f0
prstat`0x4047dc
1
...
void jstack(int nframes, int strsize) void jstack(int nframes) void jstack(void)
jstack is an alias for ustack that uses the value of the jstackframes option for the number of stack frames and the value of the jstackstrsize option for the string space size. By default, jstacksize defaults to a non-zero value. As a result, use of jstack will result in a stack with in situ Java frame translation.
_usymaddr uaddr(uintptr_t address)
uaddr will prints the symbol for a specified address, including hexadecimal offset. This allows for the same symbol resolution that ustack provides.
# dtrace -c date -n 'pid$target::main:entry{ uaddr(0x8062578); }'
dtrace: description 'pid$target::main:entry' matched 1 probe
Sun Feb 3 20:58:03 PST 2008
dtrace: pid 105537 has exited
CPU ID FUNCTION:NAME
0 59934 main:entry date`clock_val
In the above example, a call to uaddr(0x8062578) causes date`clock_val to be printed.
The example below shows the hexadecimal offsets being printed.
demo$ sudo dtrace -n "pid\$target::main:{uaddr(uregs[R_PC])}" -c date
dtrace: description 'pid$target::main:' matched 203 probes
Saturday, June 9, 2012 07:06:39 AM IST
CPU ID FUNCTION:NAME
0 67146 main:entry date`main
0 67147 main:0 date`main
0 67148 main:1 date`main+0x1
0 67149 main:3 date`main+0x3
0 67151 main:4 date`main+0x4
0 67152 main:5 date`main+0x5
0 67153 main:6 date`main+0x6
0 67154 main:9 date`main+0x9
0 67155 main:c date`main+0xc
0 67156 main:f date`main+0xf
0 67157 main:14 date`main+0x14
0 67158 main:16 date`main+0x16
0 67159 main:18 date`main+0x18
0 67160 main:1a date`main+0x1a
0 67161 main:1f date`main+0x1f
0 67162 main:22 date`main+0x22
0 67163 main:27 date`main+0x27
0 67164 main:2c date`main+0x2c
0 67165 main:2f date`main+0x2f
0 67166 main:34 date`main+0x34
0 67167 main:37 date`main+0x37
0 67168 main:3a date`main+0x3a
0 67169 main:3b date`main+0x3b
0 67170 main:40 date`main+0x40
0 67171 main:43 date`main+0x43
0 67172 main:46 date`main+0x46
0 67210 main:bb date`main+0xbb
0 67211 main:be date`main+0xbe
0 67212 main:c4 date`main+0xc4
0 67213 main:c6 date`main+0xc6
0 67214 main:c9 date`main+0xc9
0 67215 main:cc date`main+0xcc
0 67216 main:cf date`main+0xcf
0 67217 main:d6 date`main+0xd6
0 67221 main:dd date`main+0xdd
0 67222 main:df date`main+0xdf
0 67223 main:e5 date`main+0xe5
0 67224 main:e8 date`main+0xe8
0 67225 main:ed date`main+0xed
0 67226 main:ee date`main+0xee
0 67227 main:f0 date`main+0xf0
0 67228 main:f5 date`main+0xf5
0 67229 main:f8 date`main+0xf8
0 67230 main:fd date`main+0xfd
0 67231 main:102 date`main+0x102
0 67232 main:104 date`main+0x104
0 67233 main:10a date`main+0x10a
0 67234 main:10e date`main+0x10e
0 67258 main:156 date`main+0x156
0 67259 main:159 date`main+0x159
0 67260 main:15b date`main+0x15b
0 67261 main:160 date`main+0x160
0 67262 main:163 date`main+0x163
0 67263 main:165 date`main+0x165
0 67264 main:16c date`main+0x16c
0 67265 main:16e date`main+0x16e
0 67266 main:171 date`main+0x171
0 67267 main:176 date`main+0x176
0 67268 main:17b date`main+0x17b
0 67269 main:17e date`main+0x17e
0 67270 main:180 date`main+0x180
0 67281 main:1a9 date`main+0x1a9
0 67282 main:1ac date`main+0x1ac
0 67283 main:1b1 date`main+0x1b1
0 67284 main:1b2 date`main+0x1b2
0 67285 main:1b7 date`main+0x1b7
0 67286 main:1ba date`main+0x1ba
0 67287 main:1bc date`main+0x1bc
0 67288 main:1bf date`main+0x1bf
0 67289 main:1c0 date`main+0x1c0
0 67290 main:1c1 date`main+0x1c1
0 67291 main:1c6 date`main+0x1c6
0 67292 main:1c9 date`main+0x1c9
0 67293 main:1cc date`main+0x1cc
0 67294 main:1cd date`main+0x1cd
0 67295 main:1d2 date`main+0x1d2
0 67296 main:1d7 date`main+0x1d7
0 67297 main:1dc date`main+0x1dc
0 67298 main:1e1 date`main+0x1e1
0 67299 main:1e4 date`main+0x1e4
0 67300 main:1e9 date`main+0x1e9
0 67301 main:1ee date`main+0x1ee
0 67302 main:1f1 date`main+0x1f1
0 67303 main:1f3 date`main+0x1f3
0 67304 main:1f6 date`main+0x1f6
0 67305 main:1f7 date`main+0x1f7
0 67306 main:1f8 date`main+0x1f8
0 67307 main:1f9 date`main+0x1f9
0 67308 main:1fa date`main+0x1fa
0 2513 main:return date`main+0x1fa
dtrace: pid 2972 has exited
_usymaddr usym(uintptr_t address)
usym will print the symbol for a specified address. This is analogous to how uaddr works, but without the hexadecimal offsets.
uaddr: date`clock_val+0x1
usym: date`clock_val