summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Cohen <wcohen@redhat.com>2008-05-20 16:07:50 -0400
committerWilliam Cohen <wcohen@redhat.com>2008-05-20 16:07:50 -0400
commitd15495ebff9e91135ae0923f4a36b2d2538bab54 (patch)
treec3a4a7bd1f5b9749bf58f3fd199d2bf787904f24
parentfc5a2d42b6cc46a9d4f7f3919ddc74ce70ad2a66 (diff)
downloadsystemtap-steved-d15495ebff9e91135ae0923f4a36b2d2538bab54.tar.gz
systemtap-steved-d15495ebff9e91135ae0923f4a36b2d2538bab54.tar.xz
systemtap-steved-d15495ebff9e91135ae0923f4a36b2d2538bab54.zip
Add some scripts and descriptions to the systemtap.examples.
-rw-r--r--testsuite/systemtap.examples/ChangeLog8
-rw-r--r--testsuite/systemtap.examples/disktop.meta13
-rw-r--r--testsuite/systemtap.examples/disktop.stp69
-rw-r--r--testsuite/systemtap.examples/io_submit.meta13
-rw-r--r--testsuite/systemtap.examples/io_submit.stp71
-rw-r--r--testsuite/systemtap.examples/iotop.meta13
-rw-r--r--testsuite/systemtap.examples/iotop.stp25
-rw-r--r--testsuite/systemtap.examples/sigkill.meta14
-rw-r--r--testsuite/systemtap.examples/sigkill.stp23
-rw-r--r--testsuite/systemtap.examples/traceio.meta13
-rw-r--r--testsuite/systemtap.examples/traceio.stp32
11 files changed, 294 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/ChangeLog b/testsuite/systemtap.examples/ChangeLog
index 41b70135..743e7adf 100644
--- a/testsuite/systemtap.examples/ChangeLog
+++ b/testsuite/systemtap.examples/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-20 William Cohen <wcohen@redhat.com>
+
+ * io_submit.stp, io_submit.meta:
+ * traceio.stp, traceio.meta:
+ * iotop.stp, iotop.meta:
+ * disktop.stp, disktop.meta:
+ * sigkill.stp, sigkill.meta: New.
+
2008-05-09 William Cohen <wcohen@redhat.com>
* syscalls_by_pid.meta, syscalls_by_proc.meta:
diff --git a/testsuite/systemtap.examples/disktop.meta b/testsuite/systemtap.examples/disktop.meta
new file mode 100644
index 00000000..b063075b
--- /dev/null
+++ b/testsuite/systemtap.examples/disktop.meta
@@ -0,0 +1,13 @@
+title: Summarize Disk Read/Write Traffic
+name: disktop.stp
+version: 1.0
+author: Oracle
+keywords: disk
+subsystem: disk
+status: production
+exit: user-controlled
+output: timed
+scope: system-wide
+description: Get the status of reading/writing disk every 5 seconds, output top ten entries during that period.
+test_check: stap -p4 disktop.stp
+test_installcheck: stap disktop.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/disktop.stp b/testsuite/systemtap.examples/disktop.stp
new file mode 100644
index 00000000..24b1e331
--- /dev/null
+++ b/testsuite/systemtap.examples/disktop.stp
@@ -0,0 +1,69 @@
+#!/usr/bin/env stap
+#
+# Copyright (C) 2007 Oracle Corp.
+#
+# Get the status of reading/writing disk every 5 seconds, output top ten entries
+#
+# This is free software,GNU General Public License (GPL); either version 2, or (at your option) any
+# later version.
+#
+# Usage:
+# ./disktop.stp
+#
+
+global io_stat,device
+global read_bytes,write_bytes
+
+probe kernel.function("vfs_read").return {
+ if ($return>0) {
+ dev = __file_dev($file)
+ devname = __find_bdevname(dev,__file_bdev($file))
+
+ if (devname!="N/A") {/*skip read from cache*/
+ io_stat[pid(),execname(),uid(),ppid(),"R"] += $return
+ device[pid(),execname(),uid(),ppid(),"R"] = devname
+ read_bytes += $return
+ }
+ }
+}
+
+probe kernel.function("vfs_write").return {
+ if ($return>0) {
+ dev = __file_dev($file)
+ devname = __find_bdevname(dev,__file_bdev($file))
+
+ if (devname!="N/A") { /*skip update cache*/
+ io_stat[pid(),execname(),uid(),ppid(),"W"] += $return
+ device[pid(),execname(),uid(),ppid(),"W"] = devname
+ write_bytes += $return
+ }
+ }
+}
+
+probe timer.ms(5000) {
+ /* skip non-read/write disk */
+ if (read_bytes+write+bytes) {
+
+ printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:",
+ ((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024)
+
+ /* print header */
+ printf("%8s %8s %8s %25s %8s %4s %12s\n","UID","PID","PPID","CMD","DEVICE","T","BYTES")
+ }
+ /* print top ten I/O */
+ foreach ([process,cmd,userid,parent,action] in io_stat- limit 10)
+ printf("%8d %8d %8d %25s %8s %4s %12d\n",userid,process,parent,cmd,device[process,cmd,userid,parent,action],action,io_stat[process,cmd,userid,parent,action])
+
+ /* clear data */
+ delete io_stat
+ delete device
+ read_bytes = 0
+ write_bytes = 0
+}
+
+probe end{
+ delete io_stat
+ delete device
+ delete read_bytes
+ delete write_bytes
+}
diff --git a/testsuite/systemtap.examples/io_submit.meta b/testsuite/systemtap.examples/io_submit.meta
new file mode 100644
index 00000000..911cb837
--- /dev/null
+++ b/testsuite/systemtap.examples/io_submit.meta
@@ -0,0 +1,13 @@
+title: Tally Reschedule Reason During AIO io_submit Call
+name: io_submit.stp
+version: 1.0
+author: Oracle
+keywords: io backtrace
+subsystem: io
+status: production
+exit: user-controlled
+output: sorted on-exit
+scope: system-wide
+description: When a reschedule occurs during an AIO io_submit call, accumulate the traceback in a histogram. When the script exits prints out a sorted list from most common to least common backtrace.
+test_check: stap -p4 io_submit.stp
+test_installcheck: stap io_submit.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/io_submit.stp b/testsuite/systemtap.examples/io_submit.stp
new file mode 100644
index 00000000..735dd6f9
--- /dev/null
+++ b/testsuite/systemtap.examples/io_submit.stp
@@ -0,0 +1,71 @@
+#!/bin/env stap
+#
+# Copyright (C) 2007 Oracle Corp. Chris Mason <chris.mason@oracle.com>
+#
+# This was implemented to find the most common causes of schedule during
+# the AIO io_submit call. It does this by recording which pids are inside
+# AIO, and recording the current stack trace if one of those pids is
+# inside schedule.
+# When the probe exits, it prints out the 30 most common call stacks for
+# schedule().
+#
+# This file 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.
+
+global in_iosubmit
+global traces
+
+/*
+ * add a probe to sys_io_submit, on entry, record in the in_iosubmit
+ * hash table that this proc is in io_submit
+ */
+probe syscall.io_submit {
+ in_iosubmit[tid()] = 1
+}
+
+/*
+ * when we return from sys_io_submit, record that we're no longer there
+ */
+probe syscall.io_submit.return {
+ /* this assumes a given proc will do lots of io_submit calls, and
+ * so doesn't do the more expensive "delete in_iosubmit[p]". If
+ * there are lots of procs doing small number of io_submit calls,
+ * the hash may grow pretty big, so using delete may be better
+ */
+ in_iosubmit[tid()] = 0
+}
+
+/*
+ * every time we call schedule, check to see if we started off in
+ * io_submit. If so, record our backtrace into the traces histogram
+ */
+probe kernel.function("schedule") {
+ if (tid() in in_iosubmit) {
+ traces[backtrace()]++
+
+ /*
+ * change this to if (1) if you want a backtrace every time
+ * you go into schedule from io_submit. Unfortunately, the traces
+ * saved into the traces histogram above are truncated to just a
+ * few lines. so the only way to see the full trace is via the
+ * more verbose print_backtrace() right here.
+ */
+ if (0) {
+ printf("schedule in io_submit!\n")
+ print_backtrace()
+ }
+ }
+}
+
+/*
+ * when stap is done (via ctrl-c) go through the record of all the
+ * trace paths and print the 30 most common.
+ */
+probe end {
+ foreach (stack in traces- limit 30) {
+ printf("%d:", traces[stack])
+ print_stack(stack);
+ }
+}
+
diff --git a/testsuite/systemtap.examples/iotop.meta b/testsuite/systemtap.examples/iotop.meta
new file mode 100644
index 00000000..4eba0130
--- /dev/null
+++ b/testsuite/systemtap.examples/iotop.meta
@@ -0,0 +1,13 @@
+title: Periodically Print I/O Activity by Process Name
+name: iotop.stp
+version: 1.0
+author: anonymous
+keywords: io
+subsystem: io
+status: production
+exit: user-controlled
+output: timed
+scope: system-wide
+description: Every five seconds print out the top ten executables generating I/O traffic during that interval sorted in decending order.
+test_check: stap -p4 iotop.stp
+test_installcheck: stap iotop.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/iotop.stp b/testsuite/systemtap.examples/iotop.stp
new file mode 100644
index 00000000..6050343c
--- /dev/null
+++ b/testsuite/systemtap.examples/iotop.stp
@@ -0,0 +1,25 @@
+global reads, writes, total_io
+
+probe kernel.function("vfs_read") {
+ reads[execname()] += $count
+}
+
+probe kernel.function("vfs_write") {
+ writes[execname()] += $count
+}
+
+# print top 10 IO processes every 5 seconds
+probe timer.s(5) {
+ foreach (name in writes)
+ total_io[name] += writes[name]
+ foreach (name in reads)
+ total_io[name] += reads[name]
+ printf ("%16s\t%10s\t%10s\n", "Process", "KB Read", "KB Written")
+ foreach (name in total_io- limit 10)
+ printf("%16s\t%10d\t%10d\n", name,
+ reads[name]/1024, writes[name]/1024)
+ delete reads
+ delete writes
+ delete total_io
+ print("\n")
+}
diff --git a/testsuite/systemtap.examples/sigkill.meta b/testsuite/systemtap.examples/sigkill.meta
new file mode 100644
index 00000000..57032224
--- /dev/null
+++ b/testsuite/systemtap.examples/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/sigkill.stp b/testsuite/systemtap.examples/sigkill.stp
new file mode 100644
index 00000000..8f754219
--- /dev/null
+++ b/testsuite/systemtap.examples/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/traceio.meta b/testsuite/systemtap.examples/traceio.meta
new file mode 100644
index 00000000..a82a26aa
--- /dev/null
+++ b/testsuite/systemtap.examples/traceio.meta
@@ -0,0 +1,13 @@
+title: Track Cumulative I/O Activity by Process Name
+name: traceio.stp
+version: 1.0
+author: Red Hat
+keywords: io
+subsystem: io
+status: production
+exit: user-controlled
+output: timed
+scope: system-wide
+description: Every second print out the top ten executables sorted in decending order based on cumulative I/O traffic observed.
+test_check: stap -p4 traceio.stp
+test_installcheck: stap traceio.stp -c "sleep 1"
diff --git a/testsuite/systemtap.examples/traceio.stp b/testsuite/systemtap.examples/traceio.stp
new file mode 100644
index 00000000..d3757c23
--- /dev/null
+++ b/testsuite/systemtap.examples/traceio.stp
@@ -0,0 +1,32 @@
+#!/usr/bin/env stap
+# traceio.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.
+#
+
+global reads, writes, total_io
+
+probe kernel.function("vfs_read").return {
+ reads[execname()] += $return
+}
+
+probe kernel.function("vfs_write").return {
+ writes[execname()] += $return
+}
+
+probe timer.s(1) {
+ foreach (p in reads)
+ total_io[p] += reads[p]
+ foreach (p in writes)
+ total_io[p] += writes[p]
+ foreach(p in total_io- limit 10)
+ printf("%15s r: %8d KiB w: %8d KiB\n",
+ p, reads[p]/1024,
+ writes[p]/1024)
+ printf("\n")
+ # Note we don't zero out reads, writes and total_io,
+ # so the values are cumulative since the script started.
+}