DTrace Scripts
From Siwiki
A community maintained library of DTrace scripts
The Solaris Internals DTrace repository can be found here. Scripts may be added via the upload tool.
Please upload and describe your DTrace example scripts in alphabetical order.
Also, scripts can be found in the DTraceToolkit. The primary location is on the OpenSolaris website at [1]
Contents |
[edit] fsflush.d
Shows the dynamic operation of the fsflush daemon.
# fsflush.d
SCANNED EXAMINED LOCKED MODIFIED COALESCE RELEASES TIME(ns)
8392 8393 35 24 0 0 1049420
8392 8393 198 25 0 0 1167158
8392 8393 1131 18 0 0 1341590
8392 8393 1023 31 0 0 1341769
8392 8393 319 5 0 0 1152183
8392 6347 315 72 0 0 931490
8392 8393 328 60 0 0 1186559
[edit] intr.d
Measure usr/sys/intr/idle on a system in per thousand of a CPU
# intr.d BUSY USR SYS INTR IDLE TOTAL =================================================== 5 2 3 0 994 999 BUSY USR SYS INTR IDLE TOTAL =================================================== 102 58 41 3 898 1000 BUSY USR SYS INTR IDLE TOTAL =================================================== 431 332 89 10 569 1000
[edit] hotuser (Dtrace Toolkit)
The following are demonstrations of the hotuser DTrace program.
Here, hotuser is run on a test program called "dofuncs", which is hard coded
to spend half its time in delta(), a third in beta() and a sixth in alpha().
# ./hotuser -c ./dofuncs Sampling... Hit Ctrl-C to end. ^C FUNCTION COUNT PCNT dofuncs`alpha 511 16.5% dofuncs`beta 1029 33.3% dofuncs`delta 1552 50.2%
hotuser has accurately sampled which user-level functions are on the CPU, producing a report of the expected breakdown. The hottest user-level function is delta(), which was sampled 1552 times - 50.2% of the total samples.
Now hotuser is run on gunzip, to find which functions are most often on the CPU,
# ./hotuser -c 'gunzip contents.gz' Sampling... Hit Ctrl-C to end. FUNCTION COUNT PCNT libc.so.1`_free_unlocked 1 0.1% gunzip`unzip 1 0.1% ld.so.1`strcmp 1 0.1% gunzip`inflate_dynamic 1 0.1% libc.so.1`_write 1 0.1% gunzip`write_buf 1 0.1% gunzip`0x2d990 2 0.3% libc.so.1`write 2 0.3% gunzip`0x2d994 2 0.3% ld.so.1`rtld_db_preinit 3 0.4% gunzip`0x2d98c 7 0.9% gunzip`huft_build 9 1.2% libc_psr.so.1`memcpy 138 18.5% gunzip`inflate_codes 233 31.2% gunzip`updcrc 344 46.1%
This shows that updcrc() was sampled 344 times, and 46.1% of the total samples.
A -l option will provide a breakdown on libraries only. hotuser is run on gzip to show library usage only,
# ./hotuser -lc 'gzip contents' Sampling... Hit Ctrl-C to end. LIBRARY COUNT PCNT libc.so.1 2 0.0% libc_psr.so.1 37 0.9% gzip 4113 99.1%
This shows that code in the gzip binary itself was on the CPU 99.1% of the sample times, with libc_psr.so.1 code on the CPU 0.9% of the time.
The following shows library usage of mozilla. The pgrep command is used to match the most recent PID of mozilla-bin.
# ./hotuser -lp `pgrep -n mozilla-bin` Sampling... Hit Ctrl-C to end. ^C LIBRARY COUNT PCNT libplds4.so 1 0.1% libappcomps.so 1 0.1% libi18n.so 1 0.1% libuconv.so 1 0.1% libpref.so 1 0.1% libblueprint.so 1 0.1% libz.so.1 2 0.2% libcaps.so 2 0.2% libXrender.so.1 2 0.2% libimglib2.so 2 0.2% libXft.so.2 3 0.3% libCrun.so.1 3 0.3% libdocshell.so 3 0.3% libplc4.so 4 0.4% libgtk-x11-2.0.so.0.400.9 5 0.5% libjsd.so 5 0.5% libX11.so.4 5 0.5% libnecko.so 8 0.9% libwidget_gtk2.so 9 1.0% libgkgfx.so 13 1.4% libglib-2.0.so.0.400.1 14 1.5% libgfx_gtk.so 18 2.0% libnspr4.so 20 2.2% libxpconnect.so 22 2.4% libgdk-x11-2.0.so.0.400.9 23 2.5% libgobject-2.0.so.0.400.1 25 2.7% libhtmlpars.so 27 3.0% libfontconfig.so.1 41 4.5% libxpcom.so 49 5.4% mozilla-bin 55 6.0% libmozjs.so 80 8.8% libc.so.1 115 12.6% libgklayout.so 352 38.6%
This shows that 352 samples found code from libgklayout.so running, which was 38.6% of the samples.
[edit] iosnoop
iosnoop examples
The following are extended examples of iosnoop, a Solaris 10 DTrace program to snoop disk I/O activity live.
Default Output contains most of the useful information - PID, SIZE, COMM and PATHNAME.
# iosnoop UID PID D BLOCK SIZE COMM PATHNAME 100 15795 R 3808 8192 tar /usr/bin/eject 100 15795 R 35904 6144 tar /usr/bin/eject 100 15795 R 39828 6144 tar /usr/bin/env 100 15795 R 3872 8192 tar /usr/bin/expr 100 15795 R 21120 7168 tar /usr/bin/expr 100 15795 R 43680 6144 tar /usr/bin/false 100 15795 R 44176 6144 tar /usr/bin/fdetach 100 15795 R 3920 8192 tar /usr/bin/fdformat 100 15795 R 3936 8192 tar /usr/bin/fdformat 100 15795 R 4080 8192 tar /usr/bin/fdformat 100 15795 R 9680 3072 tar /usr/bin/fdformat 100 15795 R 4096 8192 tar /usr/bin/fgrep 100 15795 R 46896 6144 tar /usr/bin/fgrep 100 15795 R 4112 8192 tar /usr/bin/file [...]
Usage the following is the usage message from ver 0.95.
# iosnoop -h
USAGE: iosnoop [-a|-A|-Degstv] [-d device] [-f filename]
[-m mount_point]
iosnoop # default output
-a # print all data
-A # dump all data, space delimited
-D # include time delta, us
-e # include device name
-g # include command arguments
-s # include start time, us
-t # include completion time, us
-v # include completion time, string
-d device # instance name to snoop
-f filename # snoop this file only
-m mount_point # this FS only
Timestamp Output using the -v switch displays timestamps in a human readable format.
# iosnoop -v STRTIME UID PID D BLOCK SIZE COMM PATHNAME 2005 Jan 6 19:33:31 0 7471 R 57136 8192 bash /usr/sbin/df 2005 Jan 6 19:33:31 0 7471 R 57152 8192 bash /usr/sbin/df 2005 Jan 6 19:33:40 0 7472 R 23544 4096 uptime /usr/bin/sparcv9/uptime 2005 Jan 6 19:33:40 0 7472 R 4618080 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:40 0 7472 R 4618144 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:40 0 7472 R 4618160 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:40 0 7472 R 4618096 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:41 0 7472 R 4617456 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:41 0 7472 R 4618624 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:41 0 7472 R 4617408 8192 uptime /lib/sparcv9/libc.so.1 2005 Jan 6 19:33:49 0 7473 R 23544 4096 uptime /usr/bin/sparcv9/uptime 2005 Jan 6 19:33:53 0 3 W 8305 2560 fsflush <none> [...]
[edit] whoq.d
Shows the processes on the run queue at sampled intervals
# whoq.d Run queue of length 1: Run queue of length 2: 9196/1 (sshd) 9440/1 (dtrace) Run queue of length 3: 0/0 (sched) 3/1 (fsflush) 9/19 (svc.configd) Run queue of length 5: 0/0 (sched) 706/6 (svc.configd) 1530/4 (inetd) 702/3 (svc.startd) 7/3 (svc.startd) Run queue of length 6: 0/0 (sched) 1042/24 (nscd) 1322/4 (inetd) 1095/24 (nscd) 1092/24 (nscd) 3012/1 (snmpdx)
