summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.examples
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/systemtap.examples')
-rw-r--r--testsuite/systemtap.examples/ChangeLog20
-rw-r--r--testsuite/systemtap.examples/graphs.meta13
-rw-r--r--testsuite/systemtap.examples/graphs.stp60
-rw-r--r--testsuite/systemtap.examples/sleepingBeauties.meta13
-rw-r--r--testsuite/systemtap.examples/sleepingBeauties.stp58
-rw-r--r--testsuite/systemtap.examples/thread-times.meta13
-rw-r--r--testsuite/systemtap.examples/thread-times.stp32
-rw-r--r--testsuite/systemtap.examples/traceio2.meta13
-rw-r--r--testsuite/systemtap.examples/traceio2.stp20
9 files changed, 242 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/ChangeLog b/testsuite/systemtap.examples/ChangeLog
index 743e7adf..b1c34347 100644
--- a/testsuite/systemtap.examples/ChangeLog
+++ b/testsuite/systemtap.examples/ChangeLog
@@ -1,3 +1,23 @@
+2008-06-20 William Cohen <wcohen@redhat.com>
+
+ * traceio2.meta: Correct test_check and test_installcheck commands.
+
+2008-06-20 William Cohen <wcohen@redhat.com>
+
+ * traceio2.stp, traceio2.meta: New.
+
+2008-06-18 William Cohen <wcohen@redhat.com>
+
+ * sleepingBeauties.stp, sleepingBeauties.meta: New.
+
+2008-06-17 William Cohen <wcohen@redhat.com>
+
+ * graphs.stp, graphs.meta: New.
+
+2008-06-12 William Cohen <wcohen@redhat.com>
+
+ * thread-times.stp, thread-times.meta: New.
+
2008-05-20 William Cohen <wcohen@redhat.com>
* io_submit.stp, io_submit.meta:
diff --git a/testsuite/systemtap.examples/graphs.meta b/testsuite/systemtap.examples/graphs.meta
new file mode 100644
index 00000000..60a522b3
--- /dev/null
+++ b/testsuite/systemtap.examples/graphs.meta
@@ -0,0 +1,13 @@
+title: Graphing Disk and CPU Utilization
+name: graphs.stp
+version: 1.0
+author: anonymous
+keywords: disk cpu use graph
+subsystem: disk cpu
+status: production
+exit: user-controlled
+output: plot data
+scope: system-wide
+description: The script tracks the disk and CPU utilization. The resulting output of the script can be piped into gnuplot to generate a graph of disk and CPU USE.
+test_check: stap -p4 graphs.stp
+test_installcheck: stap graphs.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/graphs.stp b/testsuite/systemtap.examples/graphs.stp
new file mode 100644
index 00000000..0c8e3796
--- /dev/null
+++ b/testsuite/systemtap.examples/graphs.stp
@@ -0,0 +1,60 @@
+#! stap
+
+# ------------------------------------------------------------------------
+# data collection
+
+# disk I/O stats
+probe begin { qnames["ioblock"] ++; qsq_start ("ioblock") }
+probe ioblock.request { qs_wait ("ioblock") qs_run("ioblock") }
+probe ioblock.end { qs_done ("ioblock") }
+
+# CPU utilization
+probe begin { qnames["cpu"] ++; qsq_start ("cpu") }
+probe scheduler.cpu_on { if (!idle) {qs_wait ("cpu") qs_run ("cpu") }}
+probe scheduler.cpu_off { if (!idle) qs_done ("cpu") }
+
+
+# ------------------------------------------------------------------------
+# utilization history tracking
+
+global N
+probe begin { N = 50 }
+
+global qnames, util, histidx
+
+function qsq_util_reset(q) {
+ u=qsq_utilization (q, 100)
+ qsq_start (q)
+ return u
+}
+
+probe timer.ms(100) { # collect utilization percentages frequently
+ histidx = (histidx + 1) % N # into circular buffer
+ foreach (q in qnames)
+ util[histidx,q] = qsq_util_reset(q)
+}
+
+
+# ------------------------------------------------------------------------
+# general gnuplot graphical report generation
+
+probe timer.ms(1000) {
+ # emit gnuplot command to display recent history
+
+ printf ("set yrange [0:100]\n")
+ printf ("plot ")
+ foreach (q in qnames+)
+ {
+ if (++nq >= 2) printf (", ")
+ printf ("'-' title \"%s\" with lines", q)
+ }
+ printf ("\n")
+
+ foreach (q in qnames+) {
+ for (i = (histidx + 1) % N; i != histidx; i = (i + 1) % N)
+ printf("%d\n", util[i,q])
+ printf ("e\n")
+ }
+
+ printf ("pause 1\n")
+}
diff --git a/testsuite/systemtap.examples/sleepingBeauties.meta b/testsuite/systemtap.examples/sleepingBeauties.meta
new file mode 100644
index 00000000..95e08361
--- /dev/null
+++ b/testsuite/systemtap.examples/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/sleepingBeauties.stp b/testsuite/systemtap.examples/sleepingBeauties.stp
new file mode 100644
index 00000000..64c563a3
--- /dev/null
+++ b/testsuite/systemtap.examples/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/thread-times.meta b/testsuite/systemtap.examples/thread-times.meta
new file mode 100644
index 00000000..fcbf062e
--- /dev/null
+++ b/testsuite/systemtap.examples/thread-times.meta
@@ -0,0 +1,13 @@
+title: Profile kernel functions
+name: thread-times.stp
+version: 1.0
+author: anonymous
+keywords: profiling
+subsystem: kernel
+status: production
+exit: user-controlled
+output: sorted-list
+scope: system-wide
+description: The thread-times.stp script sets up time-based sampling. Every five seconds it prints out a sorted list with the top twenty processes with samples broken down into percentage total time spent in user-space and kernel-space.
+test_check: stap -p4 thread-times.stp
+test_installcheck: stap thread-times.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/thread-times.stp b/testsuite/systemtap.examples/thread-times.stp
new file mode 100644
index 00000000..1aeb2037
--- /dev/null
+++ b/testsuite/systemtap.examples/thread-times.stp
@@ -0,0 +1,32 @@
+#! /usr/bin/stap
+
+probe timer.profile {
+ tid=tid()
+ if (!user_mode())
+ kticks[tid] <<< 1
+ else
+ uticks[tid] <<< 1
+ ticks <<< 1
+ tids[tid] <<< 1
+}
+
+global uticks, kticks, ticks
+
+global tids
+
+probe timer.s(5), end {
+ allticks = @count(ticks)
+ printf ("%5s %7s %7s (of %d ticks)\n", "tid", "%user", "%kernel", allticks)
+ foreach (tid in tids- limit 20) {
+ uscaled = @count(uticks[tid])*10000/allticks
+ kscaled = @count(kticks[tid])*10000/allticks
+ printf ("%5d %3d.%02d%% %3d.%02d%%\n",
+ tid, uscaled/100, uscaled%100, kscaled/100, kscaled%100)
+ }
+ printf("\n")
+
+ delete uticks
+ delete kticks
+ delete ticks
+ delete tids
+}
diff --git a/testsuite/systemtap.examples/traceio2.meta b/testsuite/systemtap.examples/traceio2.meta
new file mode 100644
index 00000000..e6bca1a9
--- /dev/null
+++ b/testsuite/systemtap.examples/traceio2.meta
@@ -0,0 +1,13 @@
+title: Watch I/O Activity on a Particular Device
+name: traceio2.stp
+version: 1.0
+author: Red Hat
+keywords: io
+subsystem: io
+status: production
+exit: user-controlled
+output: trace
+scope: system-wide
+description: Print out the executable name and process number as reads and writes to the specified device occur.
+test_check: stap -p4 traceio2.stp 0x0801
+test_installcheck: /bin/sh eval stap traceio2.stp 0x0801 -c "sleep 1"
diff --git a/testsuite/systemtap.examples/traceio2.stp b/testsuite/systemtap.examples/traceio2.stp
new file mode 100644
index 00000000..656c38b3
--- /dev/null
+++ b/testsuite/systemtap.examples/traceio2.stp
@@ -0,0 +1,20 @@
+global device_of_interest
+
+probe begin {
+ /* The following is not the most efficient way to do this.
+ One could directly put the result of usrdev2kerndev()
+ into device_of_interest. However, want to test out
+ the other device functions */
+ dev = usrdev2kerndev($1)
+ device_of_interest = MKDEV(MAJOR(dev), MINOR(dev))
+}
+
+probe kernel.function ("vfs_write"),
+ kernel.function ("vfs_read")
+{
+ dev_nr = $file->f_path->dentry->d_inode->i_sb->s_dev
+
+ if (dev_nr == device_of_interest)
+ printf ("%s(%d) %s 0x%x\n",
+ execname(), pid(), probefunc(), dev_nr)
+}