summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.examples/process
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/systemtap.examples/process')
-rw-r--r--testsuite/systemtap.examples/process/futexes.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/futexes.stp36
-rw-r--r--testsuite/systemtap.examples/process/futexes.txt18
-rw-r--r--testsuite/systemtap.examples/process/pf2.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/pf2.stp16
-rw-r--r--testsuite/systemtap.examples/process/pf2.txt21
-rwxr-xr-xtestsuite/systemtap.examples/process/proc_snoop.stp55
-rw-r--r--testsuite/systemtap.examples/process/sig_by_pid.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/sig_by_pid.stp42
-rw-r--r--testsuite/systemtap.examples/process/sig_by_pid.txt24
-rw-r--r--testsuite/systemtap.examples/process/sig_by_proc.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/sig_by_proc.stp36
-rw-r--r--testsuite/systemtap.examples/process/sig_by_proc.txt20
-rw-r--r--testsuite/systemtap.examples/process/sigkill.meta14
-rw-r--r--testsuite/systemtap.examples/process/sigkill.stp23
-rw-r--r--testsuite/systemtap.examples/process/sigmon.meta14
-rwxr-xr-xtestsuite/systemtap.examples/process/sigmon.stp35
-rw-r--r--testsuite/systemtap.examples/process/sleepingBeauties.meta13
-rw-r--r--testsuite/systemtap.examples/process/sleepingBeauties.stp58
-rw-r--r--testsuite/systemtap.examples/process/sleeptime.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/sleeptime.stp62
-rw-r--r--testsuite/systemtap.examples/process/syscalls_by_pid.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/syscalls_by_pid.stp28
-rw-r--r--testsuite/systemtap.examples/process/syscalls_by_pid.txt35
-rw-r--r--testsuite/systemtap.examples/process/syscalls_by_proc.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/syscalls_by_proc.stp28
-rw-r--r--testsuite/systemtap.examples/process/syscalls_by_proc.txt58
-rwxr-xr-xtestsuite/systemtap.examples/process/syscalltimes248
-rw-r--r--testsuite/systemtap.examples/process/syscalltimes.txt155
-rw-r--r--testsuite/systemtap.examples/process/wait4time.meta13
-rwxr-xr-xtestsuite/systemtap.examples/process/wait4time.stp59
31 files changed, 1202 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/process/futexes.meta b/testsuite/systemtap.examples/process/futexes.meta
new file mode 100644
index 00000000..ff303122
--- /dev/null
+++ b/testsuite/systemtap.examples/process/futexes.meta
@@ -0,0 +1,13 @@
+title: System-Wide Futex Contention
+name: futexes.stp
+version: 1.0
+author: anonymous
+keywords: syscall locking futex
+subsystem: locking
+status: production
+exit: user-controlled
+output: sorted-list on-exit
+scope: system-wide
+description: The script watches the futex syscall on the system. On exit the futexes address, the number of contentions, and the average time for each contention on the futex are printed from lowest pid number to highest.
+test_check: stap -p4 futexes.stp
+test_installcheck: stap futexes.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/futexes.stp b/testsuite/systemtap.examples/process/futexes.stp
new file mode 100755
index 00000000..16c62937
--- /dev/null
+++ b/testsuite/systemtap.examples/process/futexes.stp
@@ -0,0 +1,36 @@
+#! /usr/bin/env 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/testsuite/systemtap.examples/process/futexes.txt b/testsuite/systemtap.examples/process/futexes.txt
new file mode 100644
index 00000000..51de4352
--- /dev/null
+++ b/testsuite/systemtap.examples/process/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/testsuite/systemtap.examples/process/pf2.meta b/testsuite/systemtap.examples/process/pf2.meta
new file mode 100644
index 00000000..d0a534bd
--- /dev/null
+++ b/testsuite/systemtap.examples/process/pf2.meta
@@ -0,0 +1,13 @@
+title: Profile kernel functions
+name: pf2.stp
+version: 1.0
+author: anonymous
+keywords: profiling
+subsystem: kernel
+status: production
+exit: user-controlled
+output: sorted-list
+scope: system-wide
+description: The pf2.stp script sets up time-based sampling. Every five seconds it prints out a sorted list with the top ten kernel functions with samples.
+test_check: stap -p4 pf2.stp
+test_installcheck: stap pf2.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/pf2.stp b/testsuite/systemtap.examples/process/pf2.stp
new file mode 100755
index 00000000..a804c3ff
--- /dev/null
+++ b/testsuite/systemtap.examples/process/pf2.stp
@@ -0,0 +1,16 @@
+#! /usr/bin/env stap
+
+global profile, pcount
+probe timer.profile {
+ pcount <<< 1
+ fn = probefunc ()
+ if (fn != "") profile[fn] <<< 1
+}
+probe timer.ms(5000) {
+ printf ("\n--- %d samples recorded:\n", @count(pcount))
+ foreach (f in profile- limit 10) {
+ printf ("%-30s\t%6d\n", f, @count(profile[f]))
+ }
+ delete profile
+ delete pcount
+}
diff --git a/testsuite/systemtap.examples/process/pf2.txt b/testsuite/systemtap.examples/process/pf2.txt
new file mode 100644
index 00000000..0fafe17e
--- /dev/null
+++ b/testsuite/systemtap.examples/process/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
+
diff --git a/testsuite/systemtap.examples/process/proc_snoop.stp b/testsuite/systemtap.examples/process/proc_snoop.stp
new file mode 100755
index 00000000..24499b4b
--- /dev/null
+++ b/testsuite/systemtap.examples/process/proc_snoop.stp
@@ -0,0 +1,55 @@
+#!/usr/bin/env stap
+
+global start_ts
+
+probe begin {
+ start_ts = gettimeofday_us()
+ printf("%12s %5s %5s %-16s ACTION\n",
+ "TIMESTAMP", "PID", "TID", "EXECNAME")
+}
+
+function report(action:string) {
+ printf("%12d %5d %5d %-16s %s\n", gettimeofday_us() - start_ts,
+ pid(), tid(), execname(), action)
+}
+
+function id:string(task:long) {
+ return sprintf("p:%d t:%d n:%s", task_pid(task), task_tid(task),
+ task_execname(task))
+}
+
+probe process.create {
+ report(sprintf("create %s", id(task)))
+}
+
+probe process.start {
+ report("start")
+}
+
+probe process.exec {
+ report(sprintf("exec %s", filename))
+}
+
+probe process.exec_complete {
+ if (success)
+ report("exec success")
+ else
+ report(sprintf("exec failed %d (%s)", errno, errno_str(errno)))
+}
+
+probe process.exit {
+ report(sprintf("exit %d", code))
+}
+
+probe process.release {
+ report(sprintf("remove %s", id(task)))
+}
+
+probe signal.send {
+ report(sprintf("sigsend %d (%s) to %s%s", sig, sig_name, id(task),
+ shared? " [SHARED]" : ""))
+}
+
+probe signal.handle {
+ report(sprintf("sighandle %d (%s)", sig, sig_name))
+}
diff --git a/testsuite/systemtap.examples/process/sig_by_pid.meta b/testsuite/systemtap.examples/process/sig_by_pid.meta
new file mode 100644
index 00000000..03b02fba
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_pid.meta
@@ -0,0 +1,13 @@
+title: Signal Counts by Process ID
+name: sig_by_pid.stp
+version: 1.0
+author: IBM
+keywords: signals
+subsystem: signals
+status: experimental
+exit: user-controlled
+output: sorted-list on-exit
+scope: system-wide
+description: Print signal counts by process ID in descending order.
+test_check: stap -p4 sig_by_pid.stp
+test_installcheck: stap sig_by_pid.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/sig_by_pid.stp b/testsuite/systemtap.examples/process/sig_by_pid.stp
new file mode 100755
index 00000000..9c1493f5
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_pid.stp
@@ -0,0 +1,42 @@
+#! /usr/bin/env stap
+
+# Copyright (C) 2006 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+#
+# Print signal counts by process IDs in descending order.
+#
+
+global sigcnt, pid2name, sig2name
+
+probe begin {
+ print("Collecting data... Type Ctrl-C to exit and display results\n")
+}
+
+probe signal.send
+{
+ snd_pid = pid()
+ rcv_pid = sig_pid
+
+ sigcnt[snd_pid, rcv_pid, sig]++
+
+ if (!(snd_pid in pid2name)) pid2name[snd_pid] = execname()
+ if (!(rcv_pid in pid2name)) pid2name[rcv_pid] = pid_name
+ if (!(sig in sig2name)) sig2name[sig] = sig_name
+}
+
+probe end
+{
+ printf("%-8s %-16s %-5s %-16s %-16s %s\n",
+ "SPID", "SENDER", "RPID", "RECEIVER", "SIGNAME", "COUNT")
+
+ foreach ([snd_pid, rcv_pid, sig_num] in sigcnt-) {
+ printf("%-8d %-16s %-5d %-16s %-16s %d\n",
+ snd_pid, pid2name[snd_pid], rcv_pid, pid2name[rcv_pid],
+ sig2name[sig_num], sigcnt[snd_pid, rcv_pid, sig_num])
+ }
+}
diff --git a/testsuite/systemtap.examples/process/sig_by_pid.txt b/testsuite/systemtap.examples/process/sig_by_pid.txt
new file mode 100644
index 00000000..927b4607
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_pid.txt
@@ -0,0 +1,24 @@
+# stap sig_by_pid.stp
+Collecting data... Type Ctrl-C to exit and display results
+^C
+Collecting data... Type Ctrl-C to exit and display results
+SPID SENDER RPID RECEIVER SIGNAME COUNT
+0 swapper 25273 Xvnc SIGALRM 1576
+25273 Xvnc 25273 Xvnc SIGALRM 17
+29219 firefox-bin 25273 Xvnc SIGALRM 12
+0 swapper 2442 automount SIGALRM 12
+26754 xterm 26756 bash SIGWINCH 9
+0 swapper 2199 syslogd SIGALRM 6
+25345 metacity 25273 Xvnc SIGALRM 3
+2791 wclientd 2791 wclientd SIGUSR1 2
+30385 ifconfig 30384 sh SIGCHLD 1
+30384 sh 2802 wcstatusd SIGCHLD 1
+30387 mii-tool 30386 sh SIGCHLD 1
+30386 sh 2802 wcstatusd SIGCHLD 1
+30388 lspci 2802 wcstatusd SIGCHLD 1
+30389 sh 2802 wcstatusd SIGCHLD 1
+30391 ifconfig 25273 Xvnc SIGALRM 1
+30391 ifconfig 30390 sh SIGCHLD 1
+30390 sh 2802 wcstatusd SIGCHLD 1
+30393 mii-tool 30392 sh SIGCHLD 1
+30392 sh 2802 wcstatusd SIGCHLD 1
diff --git a/testsuite/systemtap.examples/process/sig_by_proc.meta b/testsuite/systemtap.examples/process/sig_by_proc.meta
new file mode 100644
index 00000000..eea42be4
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_proc.meta
@@ -0,0 +1,13 @@
+title: Signal Counts by Process Name
+name: sig_by_proc.stp
+version: 1.0
+author: IBM
+keywords: signals
+subsystem: signals
+status: experimental
+exit: user-controlled
+output: sorted-list on-exit
+scope: system-wide
+description: Print signal counts by process name in descending order.
+test_check: stap -p4 sig_by_proc.stp
+test_installcheck: stap sig_by_proc.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/sig_by_proc.stp b/testsuite/systemtap.examples/process/sig_by_proc.stp
new file mode 100755
index 00000000..ce845aed
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_proc.stp
@@ -0,0 +1,36 @@
+#! /usr/bin/env stap
+
+# Copyright (C) 2006 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+#
+# Print signal counts by process name in descending order.
+#
+
+global sigcnt, sig2name
+
+probe begin {
+ print("Collecting data... Type Ctrl-C to exit and display results\n")
+}
+
+probe signal.send
+{
+ sigcnt[execname(), pid_name, sig]++
+
+ if (!(sig in sig2name)) sig2name[sig] = sig_name
+}
+
+probe end
+{
+ printf("%-16s %-16s %-16s %s\n",
+ "SENDER", "RECEIVER", "SIGNAL", "COUNT")
+
+ foreach ([snd_name, rcv_name, sig_num] in sigcnt-)
+ printf("%-16s %-16s %-16s %d\n",
+ snd_name, rcv_name, sig2name[sig_num],
+ sigcnt[snd_name, rcv_name, sig_num])
+}
diff --git a/testsuite/systemtap.examples/process/sig_by_proc.txt b/testsuite/systemtap.examples/process/sig_by_proc.txt
new file mode 100644
index 00000000..d09da9fe
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sig_by_proc.txt
@@ -0,0 +1,20 @@
+# stap sig_by_proc.stp
+Collecting data... Type Ctrl-C to exit and display results
+^C
+SENDER RECEIVER SIGNAL COUNT
+swapper Xvnc SIGALRM 448
+sh wcstatusd SIGCHLD 318
+ifconfig sh SIGCHLD 106
+mii-tool sh SIGCHLD 106
+lspci wcstatusd SIGCHLD 106
+automount automount SIGCHLD 14
+swapper automount SIGALRM 13
+swapper syslogd SIGALRM 7
+swapper sendmail SIGALRM 2
+sendmail sendmail SIGCHLD 2
+lspci Xvnc SIGALRM 2
+ifconfig automount SIGALRM 1
+sh Xvnc SIGALRM 1
+xterm staprun SIGINT 1
+xterm stap SIGINT 1
+
diff --git a/testsuite/systemtap.examples/process/sigkill.meta b/testsuite/systemtap.examples/process/sigkill.meta
new file mode 100644
index 00000000..57032224
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sigkill.meta
@@ -0,0 +1,14 @@
+title: Track SIGKILL Signals
+name: sigkill.stp
+version: 1.0
+author: Red Hat
+keywords: signals
+subsystem: signals
+status: production
+exit: user-controlled
+output: trace
+scope: systemwide
+description: The script traces any SIGKILL signals. When that SIGKILL signal is sent to a process, the script prints out the signal name, the desination executable and process ID, the executable name user ID that sent the signal.
+arg_1: The name of the signal to look for on selected process.
+test_check: stap -p4 sigkill.stp
+test_installcheck: stap sigkill.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/sigkill.stp b/testsuite/systemtap.examples/process/sigkill.stp
new file mode 100644
index 00000000..8f754219
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sigkill.stp
@@ -0,0 +1,23 @@
+#!/usr/bin/env stap
+# sigkill.stp
+# Copyright (C) 2007 Red Hat, Inc., Eugene Teo <eteo@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# /usr/share/systemtap/tapset/signal.stp:
+# [...]
+# probe signal.send = _signal.send.*
+# {
+# sig=$sig
+# sig_name = _signal_name($sig)
+# sig_pid = task_pid(task)
+# pid_name = task_execname(task)
+# [...]
+
+probe signal.send {
+ if (sig_name == "SIGKILL")
+ printf("%s was sent to %s (pid:%d) by %s uid:%d\n",
+ sig_name, pid_name, sig_pid, execname(), uid())
+}
diff --git a/testsuite/systemtap.examples/process/sigmon.meta b/testsuite/systemtap.examples/process/sigmon.meta
new file mode 100644
index 00000000..18834997
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sigmon.meta
@@ -0,0 +1,14 @@
+title: System-Wide Count of Syscalls by PID
+name: syscalls_by_pid.stp
+version: 1.0
+author: IBM
+keywords: signals
+subsystem: signals
+status: experimental
+exit: user-controlled
+output: trace
+scope: pid
+description: The script watches for a particular signal sent to a specific process. When that signal is sent to the specified process, the script prints out the PID and executable of the process sending the signal, the PID and executable name of the process receiving the signal, and the signal number and name.
+arg_1: The name of the signal to look for on selected process.
+test_check: stap -p4 sigmon.stp SIGKILL
+test_installcheck: stap sigmon.stp -c "sleep 1" SIGKILL
diff --git a/testsuite/systemtap.examples/process/sigmon.stp b/testsuite/systemtap.examples/process/sigmon.stp
new file mode 100755
index 00000000..31d7822e
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sigmon.stp
@@ -0,0 +1,35 @@
+#! /usr/bin/env stap
+
+# Copyright (C) 2006 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+#
+# Track when a specific process ID receives a specific signal. For example,
+# when process ID 31994 receives a SIGKILL signal.
+#
+# Example command line:
+#
+# stap -x 31994 sigmon.stp SIGKILL
+#
+# Example output:
+#
+# SPID SNAME RPID RNAME SIGNUM SIGNAME
+# 5609 bash 31994 find 9 SIGKILL
+#
+
+probe begin
+{
+ printf("%-8s %-16s %-5s %-16s %6s %-16s\n",
+ "SPID", "SNAME", "RPID", "RNAME", "SIGNUM", "SIGNAME")
+}
+
+probe signal.send
+{
+ if (sig_name == @1 && sig_pid == target())
+ printf("%-8d %-16s %-5d %-16s %-6d %-16s\n",
+ pid(), execname(), sig_pid, pid_name, sig, sig_name)
+}
diff --git a/testsuite/systemtap.examples/process/sleepingBeauties.meta b/testsuite/systemtap.examples/process/sleepingBeauties.meta
new file mode 100644
index 00000000..95e08361
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sleepingBeauties.meta
@@ -0,0 +1,13 @@
+title: Generating Backtraces of Threads Waiting for IO Operations
+name: sleepingBeauties.stp
+version: 1.0
+author: anonymous
+keywords: io scheduler
+subsystem: scheduler
+status: production
+exit: user-controlled
+output: trace
+scope: system-wide
+description: The script monitor time threads spend waiting for IO operations (in "D" state) in the wait_for_completion function. If a thread spends over 10ms wall-clock time waiting, information is printed out describing the thread number and executable name. When slow the wait_for_completion function complete, backtraces for the long duration calls are printed out.
+test_check: stap -p4 sleepingBeauties.stp
+test_installcheck: stap sleepingBeauties.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/sleepingBeauties.stp b/testsuite/systemtap.examples/process/sleepingBeauties.stp
new file mode 100644
index 00000000..64c563a3
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sleepingBeauties.stp
@@ -0,0 +1,58 @@
+#! /usr/bin/stap
+
+function time () { return gettimeofday_ms() }
+global time_name = "ms"
+global boredom = 10 # in time units
+global name, back, backtime, bored
+
+/* Note: the order that the probes are listed should not matter.
+ However, the following order for
+ probe kernel.function("wait_for_completion").return and
+ probe kernel.function("wait_for_completion").call
+ avoids have the kretprobe stuff in the backtrace.
+ for more information see:
+ http://sources.redhat.com/bugzilla/show_bug.cgi?id=6436
+*/
+
+
+probe kernel.function("wait_for_completion").return
+{
+ t=tid()
+
+ if ([t] in bored) {
+ patience = time() - backtime[t]
+ printf ("thread %d (%s) bored for %d %s\n",
+ t, name[t], patience, time_name)
+ }
+
+ delete bored[t]
+ delete back[t]
+ delete name[t]
+ delete backtime[t]
+}
+
+
+probe kernel.function("wait_for_completion").call
+{
+ t=tid()
+ back[t]=backtrace()
+ name[t]=execname()
+ backtime[t]=time()
+ delete bored[t]
+}
+
+
+probe timer.profile {
+ foreach (tid+ in back) {
+ if ([tid] in bored) continue
+
+ patience = time() - backtime[tid]
+ if (patience >= boredom) {
+ printf ("thread %d (%s) impatient after %d %s\n",
+ tid, name[tid], patience, time_name)
+ print_stack (back[tid])
+ printf ("\n")
+ bored[tid] = 1 # defer further reports to wakeup
+ }
+ }
+}
diff --git a/testsuite/systemtap.examples/process/sleeptime.meta b/testsuite/systemtap.examples/process/sleeptime.meta
new file mode 100644
index 00000000..d6c59345
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sleeptime.meta
@@ -0,0 +1,13 @@
+title: Trace Time Spent in nanosleep Syscalls
+name: sleeptime.stp
+version: 1.0
+author: Daniel Berrange and Will Cohen
+keywords: syscall sleep
+subsystem: syscall
+status: production
+exit: user-controlled
+output: trace
+scope: system-wide
+description: The script watches each nanosleep syscall on the system. At the end of each nanosleep syscall the script prints out a line with a timestamp in microseconds, the pid, the executable name in paretheses, the "nanosleep:" key, and the duration of the sleep in microseconds.
+test_check: stap -p4 sleeptime.stp
+test_installcheck: stap sleeptime.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/sleeptime.stp b/testsuite/systemtap.examples/process/sleeptime.stp
new file mode 100755
index 00000000..b5729ceb
--- /dev/null
+++ b/testsuite/systemtap.examples/process/sleeptime.stp
@@ -0,0 +1,62 @@
+#! /usr/bin/env stap
+
+/*
+ * Copyright (C) 2006-2007 Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Print out the amount of time spent in the nanosleep and compat_nanosleep
+ * systemcalls. This can help find which processes are waking based on time
+ * rather than some real event than needs to be handled.
+ *
+ * Format is:
+ * 12799538 3389 (xchat) nanosleep: 9547
+ * 12846944 2805 (NetworkManager) nanosleep: 100964
+ * 12947924 2805 (NetworkManager) nanosleep: 100946
+ * 13002925 4757 (sleep) nanosleep: 13000717
+ */
+
+global start
+global entry_nanosleep
+
+function timestamp:long() {
+ return gettimeofday_us() - start
+}
+
+function proc:string() {
+ return sprintf("%d (%s)", pid(), execname())
+}
+
+probe begin {
+ start = gettimeofday_us()
+}
+
+probe syscall.nanosleep {
+ t = gettimeofday_us(); p = pid()
+ entry_nanosleep[p] = t
+}
+
+probe syscall.nanosleep.return {
+ t = gettimeofday_us(); p = pid()
+ elapsed_time = t - entry_nanosleep[p]
+ printf("%d %s nanosleep: %d\n", timestamp(), proc(), elapsed_time)
+ delete entry_nanosleep[p]
+}
+
+probe syscall.compat_nanosleep ? {
+ t = gettimeofday_us(); p = pid()
+ entry_nanosleep[p] = t
+}
+
+probe syscall.compat_nanosleep.return ? {
+ t = gettimeofday_us(); p = pid()
+ elapsed_time = t - entry_nanosleep[p]
+ printf("%d %s compat_nanosleep: %d\n", timestamp(), proc(), elapsed_time)
+ delete entry_nanosleep[p]
+}
diff --git a/testsuite/systemtap.examples/process/syscalls_by_pid.meta b/testsuite/systemtap.examples/process/syscalls_by_pid.meta
new file mode 100644
index 00000000..590652b3
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_pid.meta
@@ -0,0 +1,13 @@
+title: System-Wide Count of Syscalls by PID
+name: syscalls_by_pid.stp
+version: 1.0
+author: anonymous
+keywords: syscall
+subsystem: syscall
+status: production
+exit: user-controlled
+output: sorted-list on-exit
+scope: system-wide
+description: The script watches all syscall on the system. On exit the script prints a list showing the number of systemcalls executed by each PID ordered from greatest to least number of syscalls.
+test_check: stap -p4 syscalls_by_pid.stp
+test_installcheck: stap syscalls_by_pid.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/syscalls_by_pid.stp b/testsuite/systemtap.examples/process/syscalls_by_pid.stp
new file mode 100755
index 00000000..47aa4955
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_pid.stp
@@ -0,0 +1,28 @@
+#! /usr/bin/env stap
+
+# Copyright (C) 2006 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+#
+# Print the system call count by process ID in descending order.
+#
+
+global syscalls
+
+probe begin {
+ print ("Collecting data... Type Ctrl-C to exit and display results\n")
+}
+
+probe syscall.* {
+ syscalls[pid()]++
+}
+
+probe end {
+ printf ("%-10s %-s\n", "#SysCalls", "PID")
+ foreach (pid in syscalls-)
+ printf("%-10d %-d\n", syscalls[pid], pid)
+}
diff --git a/testsuite/systemtap.examples/process/syscalls_by_pid.txt b/testsuite/systemtap.examples/process/syscalls_by_pid.txt
new file mode 100644
index 00000000..4943a139
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_pid.txt
@@ -0,0 +1,35 @@
+# stap syscalls_by_pid.stp
+Collecting data... Type Ctrl-C to exit and display results
+^C
+#SysCalls PID
+2293 31866
+765 31081
+567 30983
+557 30965
+554 31008
+523 30985
+273 30991
+118 9585
+115 2130
+77 30928
+65 1988
+50 31006
+42 2492
+40 31077
+36 2487
+35 2490
+23 2257
+22 2366
+20 8682
+20 2048
+17 31197
+16 31067
+14 2313
+10 31011
+8 1
+5 31074
+3 1978
+3 1975
+3 2467
+3 30932
+
diff --git a/testsuite/systemtap.examples/process/syscalls_by_proc.meta b/testsuite/systemtap.examples/process/syscalls_by_proc.meta
new file mode 100644
index 00000000..79aa3e87
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_proc.meta
@@ -0,0 +1,13 @@
+title: System-Wide Count of Syscalls by Executable
+name: syscalls_by_proc.stp
+version: 1.0
+author: anonymous
+keywords: syscall
+subsystem: syscall
+status: production
+exit: user-controlled
+output: sorted-list on-exit
+scope: system-wide
+description: The script watches all syscall on the system. On exit the script prints a list showing the number of systemcalls executed by each executable ordered from greates to least number of syscalls.
+test_check: stap -p4 syscalls_by_proc.stp
+test_installcheck: stap syscalls_by_proc.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/syscalls_by_proc.stp b/testsuite/systemtap.examples/process/syscalls_by_proc.stp
new file mode 100755
index 00000000..af7d6932
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_proc.stp
@@ -0,0 +1,28 @@
+#! /usr/bin/env stap
+
+# Copyright (C) 2006 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+#
+# Print the system call count by process name in descending order.
+#
+
+global syscalls
+
+probe begin {
+ print ("Collecting data... Type Ctrl-C to exit and display results\n")
+}
+
+probe syscall.* {
+ syscalls[execname()]++
+}
+
+probe end {
+ printf ("%-10s %-s\n", "#SysCalls", "Process Name")
+ foreach (proc in syscalls-)
+ printf("%-10d %-s\n", syscalls[proc], proc)
+}
diff --git a/testsuite/systemtap.examples/process/syscalls_by_proc.txt b/testsuite/systemtap.examples/process/syscalls_by_proc.txt
new file mode 100644
index 00000000..dd554083
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalls_by_proc.txt
@@ -0,0 +1,58 @@
+# stap syscalls_by_proc.stp
+Collecting data... Type Ctrl-C to exit and display results
+^C
+#SysCalls Process Name
+53832 make
+15275 sh
+6764 staprun
+2291 gcc
+2225 mixer_applet2
+1638 gnome-settings-
+1603 gnome-panel
+1577 rm
+1567 nautilus
+1557 trashapplet
+1443 cat
+1404 sshd
+1207 cc1
+779 ls
+764 gnome-vfs-daemo
+638 bash
+610 collect2
+356 mkdir
+354 artsd
+340 hald-addon-stor
+338 hidd
+280 ld
+260 irqbalance
+238 xterm
+212 automount
+182 sed
+176 as
+141 dnsdomainname
+130 date
+129 cmp
+124 clock-applet
+122 nm-applet
+104 grep
+88 hostname
+75 whoami
+70 rpc.idmapd
+68 httpd
+68 python
+61 gam_server
+56 pam_timestamp_c
+53 wc
+49 sendmail
+46 echo
+40 tail
+39 expr
+37 uname
+35 pam-panel-icon
+24 init
+17 mapping-daemon
+9 syslogd
+3 klogd
+3 hald
+3 gconfd-2
+1 cupsd
diff --git a/testsuite/systemtap.examples/process/syscalltimes b/testsuite/systemtap.examples/process/syscalltimes
new file mode 100755
index 00000000..84ca77a9
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalltimes
@@ -0,0 +1,248 @@
+#!/bin/bash
+
+# Syscalltimes systemtap script
+# Copyright (C) 2007 IBM Corp.
+#
+# This file is part of systemtap, and is free software. You can
+# redistribute it and/or modify it under the terms of the GNU General
+# Public License (GPL); either version 2, or (at your option) any
+# later version.
+
+###
+### syscalltime - Combination shell/systemtap script to measure system call
+### counts and times. Can be filtered by process IDs, process
+### names and users.
+###
+
+# Filter options
+F_PIDSTR=""; F_PID=0 # Filter by process ID
+F_EXECSTR=""; F_EXEC=0 # Filter by process name
+F_UIDSTR=""; F_UID=0 # Filter by user
+FILTER=0 # Any filters specified?
+
+# Print options
+P_TOTALS=0 # Print totals
+P_VERBOSE_STR="" # Print verbose build output
+
+DELIM=","
+
+function usage {
+ echo "USAGE: syscalltimes [-n pname]... [-p pid]... [-u username]..."
+ echo " [-v]... [-t] [-h]"
+ echo " -n pname # filter by this process name"
+ echo " -p pid # filter by this process ID"
+ echo " -u username # filter by this user"
+ echo " -t # print totals (default with filters: OFF"
+ echo " default without filters: ON)"
+ echo " -v # print verbose output during SystemTap module creation"
+ echo " -h # print this help text"
+ echo ""
+ echo "NOTE: This script can take long time to build. Use -v[vv] to monitor"
+ echo " the module creation and build process."
+}
+
+# Process options
+while getopts n:p:u:vth option; do
+ case $option in
+ n) let "F_EXEC++"
+ F_EXECSTR=$OPTARG$DELIM$F_EXECSTR ;;
+
+ p) let "F_PID++"
+ F_PIDSTR=$OPTARG$DELIM$F_PIDSTR ;;
+
+ u) uid=`awk -F: '$1 == name {print $3}' name=$OPTARG /etc/passwd`
+ if [[ $uid != "" ]]; then
+ let "F_UID++"
+ F_UIDSTR=$uid$DELIM$F_UIDSTR
+ else
+ echo "ERROR: Unknown user:" $OPTARG
+ let "ERROR++"
+ fi ;;
+
+ v) P_VERBOSE_STR="-v "$P_VERBOSE_STR ;;
+
+ t) P_TOTALS=1 ;;
+
+ h|?|*) usage
+ exit 1 ;;
+ esac
+done
+
+if [[ $ERROR > 0 ]]; then
+ exit 1
+fi
+
+if [[ $F_EXEC > 0 || $F_PID > 0 || $F_UID > 0 ]]; then
+ FILTER=1
+fi
+
+echo "Creating and building SystemTap module..."
+
+#
+# SystemTap script
+#
+stap $P_VERBOSE_STR -e '
+global start, timebycall, timebypid, timebyuid, timebyexec
+global f_exec_str, f_pid_str, f_uid_str
+global f_exec, f_pid, f_uid
+global prt_totals, filter_str
+
+probe begin {
+ printf("Collecting data - type Ctrl-C to print output and exit...\n")
+
+ # If no filters specified, skip filter processing
+ if ('$FILTER' == 0) {
+ filter_str = " (unfiltered)"
+ prt_totals = 1 // On by default if no filtering
+ next
+ } else
+ filter_str = " (filtered)"
+
+ prt_totals = '$P_TOTALS'
+ f_exec_str = "'$F_EXECSTR'"
+ f_pid_str = "'$F_PIDSTR'"
+ f_uid_str = "'$F_UIDSTR'"
+
+ delim = "'$DELIM'"
+
+ # Process names
+ if ('$F_EXEC') {
+ pname = tokenize(f_exec_str, delim)
+ while (pname != "") {
+ f_exec[pname] = 1
+ pname = tokenize("", delim)
+ }
+ }
+
+ # Process IDs
+ if ('$F_PID') {
+ pid = tokenize(f_pid_str, delim)
+ while (pid != "") {
+ f_pid[strtol(pid, 10)] = 1
+ pid = tokenize("", delim)
+ }
+ }
+
+ # User IDs
+ if ('$F_UID') {
+ uid = tokenize(f_uid_str, delim)
+ while (uid != "") {
+ f_uid[strtol(uid, 10)] = 1
+ uid = tokenize("", delim)
+ }
+ }
+}
+
+probe syscall.* {
+ start[name, tid()] = gettimeofday_ns()
+}
+
+probe syscall.*.return {
+ # Skip if we have not seen this before
+ if (!([name, tid()] in start)) next
+
+ delta = gettimeofday_ns() - start[name, tid()]
+
+ # Check filters
+ if ('$FILTER') {
+ target = 0
+ if (pid() in f_pid) {
+ timebypid[name, pid()] <<< delta
+ target = 1
+ }
+ if (uid() in f_uid) {
+ timebyuid[name, uid()] <<< delta
+ target = 1
+ }
+ if (execname() in f_exec) {
+ timebyexec[name, execname()] <<< delta
+ target = 1
+ }
+ } else
+ target = 1
+
+ # Totals
+ if (target && prt_totals)
+ timebycall[name] <<< delta
+
+ delete start[name, tid()]
+}
+
+function print_header() {
+ printf("%22s %10s %12s %12s %12s %12s\n",
+ "System Call", "Count", "Total ns",
+ "Avg ns", "Min ns", "Max ns")
+}
+
+probe end {
+ if (prt_totals) {
+ printf("\nTimes for all processes%s:\n\n", filter_str)
+ print_header()
+ foreach (call in timebycall)
+ printf("%22s %10d %12d %12d %12d %12d\n", call,
+ @count(timebycall[call]),
+ @sum(timebycall[call]),
+ @avg(timebycall[call]),
+ @min(timebycall[call]),
+ @max(timebycall[call]))
+ }
+
+ if ('$F_PID') {
+ curpid = -1
+ foreach ([call, pid-] in timebypid) {
+ if (curpid != pid) {
+ curpid = pid
+ printf("\nTimes for process ID %d:\n\n", curpid)
+ print_header()
+ }
+ printf("%22s %10d %12d %12d %12d %12d\n", call,
+ @count(timebypid[call, pid]),
+ @sum(timebypid[call, pid]),
+ @avg(timebypid[call, pid]),
+ @min(timebypid[call, pid]),
+ @max(timebypid[call, pid]))
+ }
+ printf("\n")
+ }
+
+ if ('$F_EXEC') {
+ curexec = ""
+ foreach ([call, exec-] in timebyexec) {
+ if (curexec != exec) {
+ curexec = exec
+ printf("\nTimes for process name %s:\n\n", curexec)
+ print_header()
+ }
+ printf("%22s %10d %12d %12d %12d %12d\n", call,
+ @count(timebyexec[call, exec]),
+ @sum(timebyexec[call, exec]),
+ @avg(timebyexec[call, exec]),
+ @min(timebyexec[call, exec]),
+ @max(timebyexec[call, exec]))
+ }
+ printf("\n")
+ }
+
+ if ('$F_UID') {
+ curuid = -1
+ foreach ([call, uid-] in timebyuid) {
+ if (curuid != uid) {
+ curuid = uid
+ printf("\nTimes for user ID %d:\n\n", curuid)
+ print_header()
+ }
+ printf("%22s %10d %12d %12d %12d %12d\n", call,
+ @count(timebyuid[call, uid]),
+ @sum(timebyuid[call, uid]),
+ @avg(timebyuid[call, uid]),
+ @min(timebyuid[call, uid]),
+ @max(timebyuid[call, uid]))
+ }
+ printf("\n")
+ }
+
+ delete timebycall
+ delete timebypid
+ delete timebyuid
+ delete timebyexec
+}'
diff --git a/testsuite/systemtap.examples/process/syscalltimes.txt b/testsuite/systemtap.examples/process/syscalltimes.txt
new file mode 100644
index 00000000..d50f73ad
--- /dev/null
+++ b/testsuite/systemtap.examples/process/syscalltimes.txt
@@ -0,0 +1,155 @@
+# ./syscalltimes -h
+USAGE: syscalltimes [-n pname]... [-p pid]... [-u username]...
+ [-v]... [-t] [-h]
+ -n pname # filter by this process name
+ -p pid # filter by this process ID
+ -u username # filter by this user
+ -t # print totals (default with filters: OFF
+ default without filters: ON)
+ -v # print verbose output during SystemTap module creation
+ -h # print this help text
+
+NOTE: This script can take long time to build. Use -v[vv] to monitor
+ the module creation and build process.
+
+
+# ./syscalltimes -n top -n vi
+Creating and building SystemTap module...
+Collecting data - type Ctrl-C to print output and exit...
+
+Times for process name vi:
+
+ System Call Count Total ns Avg ns Min ns Max ns
+ access 4 59169 14792 7770 27556
+ rt_sigprocmask 6 32879 5479 5328 6132
+ rt_sigaction 22 119127 5414 5291 6293
+ select 15 1605144751 107009650 7386 1117677549
+ sysinfo 1 13178 13178 13178 13178
+ lseek 2 12869 6434 6331 6538
+ getuid 3 16839 5613 5468 5757
+ getrlimit 1 5558 5558 5558 5558
+ munmap 8 103326 12915 9689 19190
+ getpid 1 5639 5639 5639 5639
+ unlink 3 143502 47834 20291 97191
+ arch_prctl 1 6296 6296 6296 6296
+ chdir 6 58086 9681 7213 16062
+ getcwd 9 81327 9036 6820 17583
+ read 28 341507 12196 6007 54806
+ fcntl 4 23418 5854 5478 6459
+ sigaltstack 1 5845 5845 5845 5845
+ mprotect 13 130272 10020 8255 17130
+ statfs 1 10223 10223 10223 10223
+ fstat 20 118660 5933 5446 7050
+ readlink 1 17884 17884 17884 17884
+ readlinkat 1 7889 7889 7889 7889
+ socket 2 24932 12466 8090 16842
+ stat 13 120911 9300 7376 19549
+ ioctl 19 135172 7114 5504 11711
+ execve 1 262658 262658 262658 262658
+ write 15 382744 25516 8391 136359
+ uname 1 6772 6772 6772 6772
+ close 30 210468 7015 5478 12543
+ fchdir 6 34269 5711 5496 6185
+ open 31 474649 15311 7807 54475
+ chmod 1 12865 12865 12865 12865
+ brk 6 48116 8019 5782 10240
+ lstat 2 15369 7684 7334 8035
+ connect 2 29287 14643 10616 18671
+
+Times for process name top:
+
+ System Call Count Total ns Avg ns Min ns Max ns
+ arch_prctl 1 6424 6424 6424 6424
+ fcntl 97 607311 6260 5170 10873
+ read 970 12341710 12723 5574 446707
+ lseek 11 66250 6022 5481 7165
+ rt_sigaction 71 380049 5352 5255 6374
+ access 5 66406 13281 8942 24323
+ select 3 6385526578 2128508859 499261647 2999551597
+ getdents 21 889837 42373 6386 73490
+ getuid 1 5494 5494 5494 5494
+ munmap 15 174255 11617 8872 17670
+ write 10 2309851 230985 16248 2006254
+ uname 1 10474 10474 10474 10474
+ close 932 5749946 6169 5348 21248
+ ioctl 14 122233 8730 5824 14243
+ execve 1 261447 261447 261447 261447
+ brk 4 26527 6631 5493 8285
+ connect 2 28533 14266 10756 17777
+ open 934 9289314 9945 8473 30315
+ mprotect 10 97990 9799 8295 14636
+ stat 455 3834994 8428 7920 26084
+ socket 2 21980 10990 8990 12990
+ fstat 26 150418 5785 5426 7127
+ alarm 90 536017 5955 5543 11487
+
+
+# ./syscalltimes -v
+Creating and building SystemTap module...
+Pass 1: parsed user script and 42 library script(s) in 200usr/10sys/218real ms.
+Pass 2: analyzed script: 768 probe(s), 15 function(s), 15 embed(s), 13 global(s) in 35870usr/140sys/36036real ms.
+Pass 3: using cached /root/.systemtap/cache/d5/stap_d5fcd430388d4f4a30f63d03aaa3eb80_392196.c
+Pass 4: using cached /root/.systemtap/cache/d5/stap_d5fcd430388d4f4a30f63d03aaa3eb80_392196.ko
+Pass 5: starting run.
+Collecting data - type Ctrl-C to print output and exit...
+
+Times for all processes (unfiltered):
+
+ System Call Count Total ns Avg ns Min ns Max ns
+ writev 681 6526983 9584 6807 18709
+ write 421 4367057 10373 6424 52077
+ uname 15 98071 6538 6336 6787
+ close 459 9528659 20759 5265 1346856
+ inotify_add_watch 17 164258 9662 8000 17280
+ ioctl 1205 28994711 24062 5211 2928218
+ execve 12 2148953 179079 10195 280392
+ brk 309 2400150 7767 5383 23454
+ lstat 5 43864 8772 7938 10426
+ connect 24 352784 14699 10679 25868
+ getppid 12 71219 5934 5812 6123
+ wait4 24 20952033 873001 5664 3387688
+ open 377 22181286 58836 8819 3011655
+ dup2 18 109197 6066 5865 6403
+ bind 3 25322 8440 8263 8759
+ poll 1034 36509105361 35308612 5499 1999784046
+ getgid 12 65851 5487 5335 5667
+ compat_execve 12 3012173 251014 182782 472356
+ mprotect 150 1434021 9560 7854 13812
+ gettimeofday 10 60416 6041 5238 7429
+ recvmsg 9 116065 12896 6889 37388
+ readlink 12 638216 53184 46337 64203
+ readlinkat 12 530499 44208 37794 55136
+ stat 140 1244798 8891 6702 17331
+ socket 39 435318 11162 7642 16694
+ getsockname 3 18899 6299 6198 6443
+ statfs 6 62737 10456 10311 10671
+ fstat 238 1400126 5882 5502 12739
+ geteuid 12 73475 6122 5248 14048
+ readv 27 349998 12962 7150 21210
+ arch_prctl 21 135320 6443 6231 6832
+ nanosleep 28 8927802107 318850075 150954837 2001911237
+ futex 595 8755563465 14715232 5431 1000945645
+ read 2586 5154654212 1993292 5622 4985306501
+ getpgrp 12 67137 5594 5469 5740
+ fcntl 51 289553 5677 5353 6835
+ pipe 12 122220 10185 8771 13959
+ setitimer 159 1004756 6319 5551 8776
+ lseek 4 24304 6076 5900 6253
+ mmap2 19 182403 9600 7496 13574
+ access 105 1220874 11627 8077 33600
+ rt_sigreturn 93 665180 7152 5541 8265
+ rt_sigaction 171 967575 5658 5278 18684
+ rt_sigprocmask 132 760337 5760 5273 14170
+ clock_gettime 151 997395 6605 5275 9090
+ pread 192 2387721 12436 5679 43553
+ select 925 24357064459 26331961 6669 2861600879
+ getegid 12 63624 5302 5200 5466
+ getpid 12 66761 5563 5348 5701
+ getuid 12 67112 5592 5483 5790
+ sendto 3 54766 18255 17541 19501
+ munmap 116 1432698 12350 8634 48526
+ getdents 6 57855 9642 6248 13313
+ times 10 59281 5928 5514 6617
+ ppoll 24 4799366329 199973597 199872030 200070128
+Pass 5: run completed in 20usr/90sys/8215real ms.
+
diff --git a/testsuite/systemtap.examples/process/wait4time.meta b/testsuite/systemtap.examples/process/wait4time.meta
new file mode 100644
index 00000000..a939d466
--- /dev/null
+++ b/testsuite/systemtap.examples/process/wait4time.meta
@@ -0,0 +1,13 @@
+title: Trace Time Spent in wait4 Syscalls
+name: wait4time.stp
+version: 1.0
+author: Daniel Berrange and Will Cohen
+keywords: syscall wait4
+subsystem: syscall
+status: production
+exit: user-controlled
+output: trace
+scope: system-wide
+description: The script watches each wait4 syscall on the system. At the end of each wait4 syscall the script prints out a line with a timestamp in microseconds, the pid, the executable name in paretheses, the "wait4:" key, the duration of the wait and the PID that the wait4 was waiting for. If the waited for PID is not specified , it is "-1".
+test_check: stap -p4 wait4time.stp
+test_installcheck: stap wait4time.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/process/wait4time.stp b/testsuite/systemtap.examples/process/wait4time.stp
new file mode 100755
index 00000000..ba300ea7
--- /dev/null
+++ b/testsuite/systemtap.examples/process/wait4time.stp
@@ -0,0 +1,59 @@
+#! /usr/bin/env stap
+
+/*
+ * Copyright (C) 2006-2007 Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Print out the amount of time spent in the read and write systemcall
+ * when a process closes each file is closed. Note that the script needs
+ * to be running before the open operations occur for the script
+ * to record data.
+ *
+ * Format is:
+ * timestamp pid (executabable) wait4: time_us pid
+ *
+ * 155789807 4196 (ssh) wait4: 12 4197
+ * 158270531 3215 (bash) wait4: 5410460 -1
+ * 158270659 3215 (bash) wait4: 9 -1
+ * 158557461 2614 (sendmail) wait4: 27 -1
+ * 158557487 2614 (sendmail) wait4: 5 -1
+ *
+ */
+
+global start
+global entry_wait4
+global wait4_pid
+
+function timestamp:long() {
+ return gettimeofday_us() - start
+}
+
+function proc:string() {
+ return sprintf("%d (%s)", pid(), execname())
+}
+
+probe begin {
+ start = gettimeofday_us()
+}
+
+probe syscall.wait4 {
+ t = gettimeofday_us(); p = pid()
+ entry_wait4[p] = t
+ wait4_pid[p]=pid
+}
+
+probe syscall.wait4.return {
+ t = gettimeofday_us(); p = pid()
+ elapsed_time = t - entry_wait4[p]
+ printf("%d %s wait4: %d %d\n", timestamp(), proc(), elapsed_time,
+ wait4_pid[p])
+ delete entry_wait4[p]
+ delete wait4_pid[p]
+}