diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/futexes.stp | 36 | ||||
-rw-r--r-- | examples/futexes.txt | 18 | ||||
-rw-r--r-- | examples/helloworld.stp | 1 | ||||
-rw-r--r-- | examples/iostat-scsi.stp | 51 | ||||
-rw-r--r-- | examples/iostat-scsi.txt | 14 | ||||
-rw-r--r-- | examples/nettop.stp | 53 | ||||
-rw-r--r-- | examples/nettop.txt | 20 | ||||
-rw-r--r-- | examples/pf2.stp | 15 | ||||
-rw-r--r-- | examples/pf2.txt | 21 |
9 files changed, 229 insertions, 0 deletions
diff --git a/examples/futexes.stp b/examples/futexes.stp new file mode 100644 index 00000000..608ce0de --- /dev/null +++ b/examples/futexes.stp @@ -0,0 +1,36 @@ +#! stap + +# This script tries to identify contended user-space locks by hooking +# into the futex system call. + +global thread_thislock # short +global thread_blocktime # +global FUTEX_WAIT = 0, FUTEX_WAKE = 1 + +global lock_waits # long-lived stats on (tid,lock) blockage elapsed time +global process_names # long-lived pid-to-execname mapping + +probe syscall.futex { + if (op != FUTEX_WAIT) next # we don't care about originators of WAKE events + t = tid () + process_names[pid()] = execname() + thread_thislock[t] = $uaddr + thread_blocktime[t] = gettimeofday_us() +} + +probe syscall.futex.return { + t = tid() + ts = thread_blocktime[t] + if (ts) { + elapsed = gettimeofday_us() - ts + lock_waits[pid(), thread_thislock[t]] <<< elapsed + delete thread_blocktime[t] + delete thread_thislock[t] + } +} + +probe end { + foreach ([pid+, lock] in lock_waits) + printf ("%s[%d] lock %p contended %d times, %d avg us\n", + process_names[pid], pid, lock, @count(lock_waits[pid,lock]), @avg(lock_waits[pid,lock])) +} diff --git a/examples/futexes.txt b/examples/futexes.txt new file mode 100644 index 00000000..51de4352 --- /dev/null +++ b/examples/futexes.txt @@ -0,0 +1,18 @@ +From: http://sourceware.org/systemtap/wiki/WSFutexContention + +# stap futexes.stp +^C +liferea-bin[3613] lock 0x0a117340 contended 1 times, 71 avg us +java_vm[8155] lock 0x09baa45c contended 9 times, 1004013 avg us +java_vm[8155] lock 0x09d6f9ac contended 186 times, 55964 avg us +xmms[16738] lock 0xbfe29eec contended 777 times, 69 avg us +xmms[16738] lock 0xbfe29ecc contended 119 times, 64 avg us +xmms[16738] lock 0xbfe29ebc contended 111 times, 68 avg us +xmms[16738] lock 0xbfe29ef0 contended 742 times, 91 avg us +xmms[16738] lock 0xbfe29ed0 contended 107 times, 101 avg us +xmms[16738] lock 0xbfe29ec0 contended 107 times, 74 avg us +firefox-bin[21801] lock 0x096d16f4 contended 24 times, 12 avg us +firefox-bin[21801] lock 0x096d1198 contended 2 times, 4 avg us +firefox-bin[21801] lock 0x096d16f8 contended 150 times, 64997 avg us +named[23869] lock 0x41ab0b84 contended 1 times, 131 avg us +named[23869] lock 0x41ab0b50 contended 1 times, 26 avg us diff --git a/examples/helloworld.stp b/examples/helloworld.stp new file mode 100644 index 00000000..82e406af --- /dev/null +++ b/examples/helloworld.stp @@ -0,0 +1 @@ +probe begin { log("hello world") exit () } diff --git a/examples/iostat-scsi.stp b/examples/iostat-scsi.stp new file mode 100644 index 00000000..2fb4acf1 --- /dev/null +++ b/examples/iostat-scsi.stp @@ -0,0 +1,51 @@ +global devices, reads, writes + +/* data collection: SCSI disk */ +probe module("sd_mod").function("sd_init_command") { + device=kernel_string($SCpnt->request->rq_disk->disk_name) + sector_size=$SCpnt->device->sector_size + nr_sectors=$SCpnt->request->nr_sectors + devices[device] = 1 + if ($SCpnt->request->flags /* cmd_flags on some kernels */ & 1) + writes[device] <<< nr_sectors * sector_size + else + reads[device] <<< nr_sectors * sector_size +} +/* data collection: SCSI tape */ +probe module("st").function("st_do_scsi") { + device=kernel_string($STp->disk->disk_name) + devices[device] = 1 + if ($direction) + writes[device] <<< $bytes + else + reads[device] <<< $bytes +} + + +/* reporting */ +global blksize=512 +global hdrcount +probe timer.s($1) { + if ((hdrcount++ % 10) == 0) + printf("%9s %9s %9s %9s %9s %9s\n", + "Device:","tps","blk_read/s","blk_wrtn/s","blk_read","blk_wrtn") + + foreach (dev in devices) { + rdcount=@count(reads[dev]) + wrcount=@count(writes[dev]) + tps=(rdcount+wrcount)*100/$1 + rdblkcount=rdcount ? @sum(reads[dev])/blksize : 0 + wrblkcount=wrcount ? @sum(writes[dev])/blksize : 0 + rdblkrate=rdblkcount*100/$1 + wrblkrate=wrblkcount*100/$1 + printf("%9s %6d.%02d %6d.%02d %6d.%02d %9d %9d\n", + dev, tps/100,tps%100, + rdblkrate/100,rdblkrate%100, + wrblkrate/100,wrblkrate%100, + rdblkcount, wrblkcount) + } + printf ("\n") + delete devices + delete reads + delete writes +} diff --git a/examples/iostat-scsi.txt b/examples/iostat-scsi.txt new file mode 100644 index 00000000..81157b1d --- /dev/null +++ b/examples/iostat-scsi.txt @@ -0,0 +1,14 @@ +From: http://sourceware.org/systemtap/wiki/WSiostatSCSI + +# stap iostat-scsi.stp 10 # seconds between reports + Device: tps blk_read/s blk_wrtn/s blk_read blk_wrtn + sda 1.30 2.40 105.60 24 1056 + + sda 0.30 0.00 4.00 0 40 + + sda 21.30 1.60 428.80 16 4288 + + sda 30.40 2820.80 11.60 28208 116 + + sda 38.10 2816.80 53.60 28168 536 +^C diff --git a/examples/nettop.stp b/examples/nettop.stp new file mode 100644 index 00000000..4004a03d --- /dev/null +++ b/examples/nettop.stp @@ -0,0 +1,53 @@ +global ifxmit, ifrecv, ifdevs, ifpid, execname, user + +probe netdev.transmit +{ + p = pid() + execname[p] = execname() + user[p] = uid() + ifdevs[p, dev_name] = dev_name + ifxmit[p, dev_name] <<< length + ifpid[p, dev_name] ++ +} + +probe netdev.receive +{ + p = pid() + execname[p] = execname() + user[p] = uid() + ifdevs[p, dev_name] = dev_name + ifrecv[p, dev_name] <<< length + ifpid[p, dev_name] ++ +} + + +function print_activity() +{ + printf("%5s %5s %-7s %7s %7s %7s %7s %-15s\n", + "PID", "UID", "DEV", "XMIT_PK", "RECV_PK", + "XMIT_KB", "RECV_KB", "COMMAND") + + foreach ([pid, dev] in ifpid-) { + n_xmit = @count(ifxmit[pid, dev]) + n_recv = @count(ifrecv[pid, dev]) + printf("%5d %5d %-7s %7d %7d %7d %7d %-15s\n", + pid, user[pid], dev, n_xmit, n_recv, + n_xmit ? @sum(ifxmit[pid, dev])/1024 : 0, + n_recv ? @sum(ifrecv[pid, dev])/1024 : 0, + execname[pid]) + } + + print("\n") + + delete execname + delete user + delete ifdevs + delete ifxmit + delete ifrecv + delete ifpid +} + +probe timer.ms(5000) +{ + print_activity() +} diff --git a/examples/nettop.txt b/examples/nettop.txt new file mode 100644 index 00000000..2bfd4967 --- /dev/null +++ b/examples/nettop.txt @@ -0,0 +1,20 @@ +From: http://sourceware.org/systemtap/wiki/WSNetTop + +# stap nettop.stp + PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND + 0 0 eth0 66 344 18 19 swapper + 2469 0 eth0 214 39 167 1 Xvnc +23470 0 eth0 24 35 5 1 firefox-bin + 2281 0 eth0 1 1 0 0 wcstatusd +22446 0 eth0 1 0 1 0 sshd + 2538 0 eth0 0 1 0 0 metacity +23557 0 eth0 0 1 0 0 sh +23559 0 eth0 0 1 0 0 lspci +23566 0 eth0 0 1 0 0 sh + + PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND + 0 0 eth0 14 80 0 3 swapper + 2469 0 eth0 32 2 20 0 Xvnc +22446 0 eth0 1 0 0 0 sshd + 2052 38 eth0 1 0 0 0 ntpd + diff --git a/examples/pf2.stp b/examples/pf2.stp new file mode 100644 index 00000000..dce2cdec --- /dev/null +++ b/examples/pf2.stp @@ -0,0 +1,15 @@ +#! stap +global profile, pcount +probe timer.profile { + pcount ++ + fn = probefunc () + if (fn != "") profile[fn] ++ # <<< 1 would be better ... +} +probe timer.ms(4000) { + printf ("\n--- %d samples recorded:\n", pcount) + foreach (f in profile- limit 10) { # ... but can only sort scalar arrays (bz #2305) + printf ("%s\t%d\n", f, profile[f]) + } + delete profile + pcount = 0 +} diff --git a/examples/pf2.txt b/examples/pf2.txt new file mode 100644 index 00000000..0fafe17e --- /dev/null +++ b/examples/pf2.txt @@ -0,0 +1,21 @@ +From: http://sourceware.org/systemtap/wiki/WSKernelProfile + +# stap pf2.stp + +--- 109 samples recorded: +mwait_idle 71 +check_poison_obj 4 +_spin_unlock_irqrestore 2 +dbg_redzone1 1 +kfree 1 +kmem_cache_free 1 +_spin_unlock_irq 1 +end_buffer_write_sync 1 +lock_acquire 1 + +--- 108 samples recorded: +mwait_idle 91 +check_poison_obj 3 +_spin_unlock_irq 2 +delay_tsc 1 + |