summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2009-06-06 12:29:51 -0400
committerFrank Ch. Eigler <fche@elastic.org>2009-06-06 12:29:51 -0400
commitb7f6cfc54e1d6db1d9475ac9cbeeb8ac0b7dada0 (patch)
tree2d9cc89da41ded67f8420dd9fe113ac1a162bc33
parent6d14a4a9f3b6b8a02fcac0b95961b9b08e9fda0b (diff)
downloadsystemtap-steved-b7f6cfc54e1d6db1d9475ac9cbeeb8ac0b7dada0.tar.gz
systemtap-steved-b7f6cfc54e1d6db1d9475ac9cbeeb8ac0b7dada0.tar.xz
systemtap-steved-b7f6cfc54e1d6db1d9475ac9cbeeb8ac0b7dada0.zip
ttyspy.stp: new sample script
-rw-r--r--testsuite/systemtap.examples/index.html3
-rw-r--r--testsuite/systemtap.examples/index.txt8
-rw-r--r--testsuite/systemtap.examples/io/ttyspy.meta6
-rwxr-xr-xtestsuite/systemtap.examples/io/ttyspy.stp46
-rw-r--r--testsuite/systemtap.examples/keyword-index.html20
-rw-r--r--testsuite/systemtap.examples/keyword-index.txt36
6 files changed, 118 insertions, 1 deletions
diff --git a/testsuite/systemtap.examples/index.html b/testsuite/systemtap.examples/index.html
index e5673138..b2ed3a3a 100644
--- a/testsuite/systemtap.examples/index.html
+++ b/testsuite/systemtap.examples/index.html
@@ -82,6 +82,9 @@ keywords: <a href="keyword-index.html#IO">IO</a> <br>
<li><a href="io/traceio2.stp">io/traceio2.stp</a> - Watch I/O Activity on a Particular Device<br>
keywords: <a href="keyword-index.html#IO">IO</a> <br>
<p>Print out the executable name and process number as reads and writes to the specified device occur.</p></li>
+<li><a href="io/ttyspy.stp">io/ttyspy.stp</a> - Monitor tty typing.<br>
+keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#TTY">TTY</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <a href="keyword-index.html#MONITOR">MONITOR</a> <br>
+<p>The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.</p></li>
<li><a href="memory/kmalloc-top">memory/kmalloc-top</a> - Show Paths to Kernel Malloc (kmalloc) Invocations<br>
keywords: <a href="keyword-index.html#MEMORY">MEMORY</a> <br>
<p>The kmalloc-top perl program runs a small systemtap script to collect stack traces for each call to the kmalloc function and counts the time that each stack trace is observed. When kmalloc-top exits it prints out sorted list. The output can be be filtered to print only only the first stack traces (-t) stack traces with more a minimum counts (-m), or exclude certain stack traces (-e).</p></li>
diff --git a/testsuite/systemtap.examples/index.txt b/testsuite/systemtap.examples/index.txt
index 4eef904c..91fc66ae 100644
--- a/testsuite/systemtap.examples/index.txt
+++ b/testsuite/systemtap.examples/index.txt
@@ -129,6 +129,14 @@ keywords: io
to the specified device occur.
+io/ttyspy.stp - Monitor tty typing.
+keywords: io tty per-process monitor
+
+ The ttyspy.stp script uses tty_audit hooks to monitor recent typing
+ activity on the system, printing a scrolling record of recent
+ keystrokes, on a per-tty basis.
+
+
memory/kmalloc-top - Show Paths to Kernel Malloc (kmalloc) Invocations
keywords: memory
diff --git a/testsuite/systemtap.examples/io/ttyspy.meta b/testsuite/systemtap.examples/io/ttyspy.meta
new file mode 100644
index 00000000..e29add1b
--- /dev/null
+++ b/testsuite/systemtap.examples/io/ttyspy.meta
@@ -0,0 +1,6 @@
+title: Monitor tty typing.
+name: ttyspy.stp
+keywords: io tty per-process monitor
+description: The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.
+test_check: stap -gp4 ttyspy.stp
+test_installcheck: stap --skip-badvars -g ttyspy.stp -c "sleep 7"
diff --git a/testsuite/systemtap.examples/io/ttyspy.stp b/testsuite/systemtap.examples/io/ttyspy.stp
new file mode 100755
index 00000000..c186e0e3
--- /dev/null
+++ b/testsuite/systemtap.examples/io/ttyspy.stp
@@ -0,0 +1,46 @@
+#! /usr/bin/stap -g
+# May also need --skip-badvars
+
+global activity_time, activity_log
+
+/* Concatenate head and tail, to a max of @num chars, preferring to keep the tail
+ (as if it were a recent history buffer). */
+function strcattail:string(head:string,tail:string,num:long) %{
+ unsigned taillen = strlen(THIS->tail);
+ unsigned headlen = strlen(THIS->head);
+ unsigned maxlen = THIS->num < MAXSTRINGLEN ? THIS->num : MAXSTRINGLEN;
+ unsigned headkeep = min(maxlen-taillen,headlen);
+ unsigned headdrop = headlen-headkeep;
+
+ if (headkeep)
+ strlcpy (THIS->__retvalue, &THIS->head[headdrop], headkeep+1); /* includes \0 */
+ strlcat (THIS->__retvalue, THIS->tail, maxlen);
+%}
+
+probe kernel.function("tty_audit_add_data") {
+ major=$tty->driver->major;
+ minor=$tty->driver->minor_start + $tty->index;
+ pgrp=$tty->pgrp %( kernel_v > "2.6.24" %? ->numbers[0]->nr %: %);
+ data=kernel_string_n($data,$size);
+ uid=uid()
+
+ activity_time[major,minor,pgrp,uid] = gettimeofday_s();
+ activity_log[major,minor,pgrp,uid]
+ = strcattail(activity_log[major,minor,pgrp,uid],data,40);
+}
+
+probe timer.s(3) {
+ ansi_clear_screen ()
+ printf("(%3s,%2s,%5s,%5s)\n", "maj","min","pgrp","uid");
+ foreach ([x,y,z,u] in activity_time-) {
+ printf("(%3d,%3d,%5d,%5d) %s\n", x,y,z,u,
+ text_str(activity_log[x,y,z,u]))
+ }
+
+ /* delete last record, if older than 60 seconds */
+ if (activity_time[x,y,z,u]+60 < gettimeofday_s()) {
+ delete activity_time[x,y,z,u]
+ delete activity_log[x,y,z,u]
+ }
+}
+
diff --git a/testsuite/systemtap.examples/keyword-index.html b/testsuite/systemtap.examples/keyword-index.html
index b7f52246..7306c164 100644
--- a/testsuite/systemtap.examples/keyword-index.html
+++ b/testsuite/systemtap.examples/keyword-index.html
@@ -39,7 +39,7 @@
</ul>
<h2>Examples by Keyword</h2>
-<p><tt><a href="#BACKTRACE">BACKTRACE</a> <a href="#BUFFER">BUFFER</a> <a href="#CALLGRAPH">CALLGRAPH</a> <a href="#CPU">CPU</a> <a href="#DISK">DISK</a> <a href="#FORMAT">FORMAT</a> <a href="#FREE">FREE</a> <a href="#FUNCTIONS">FUNCTIONS</a> <a href="#FUTEX">FUTEX</a> <a href="#GRAPH">GRAPH</a> <a href="#INTERRUPT">INTERRUPT</a> <a href="#IO">IO</a> <a href="#LOCKING">LOCKING</a> <a href="#MEMORY">MEMORY</a> <a href="#NETWORK">NETWORK</a> <a href="#PER-PROCESS">PER-PROCESS</a> <a href="#PROCESS">PROCESS</a> <a href="#PROFILING">PROFILING</a> <a href="#READ">READ</a> <a href="#SCHEDULER">SCHEDULER</a> <a href="#SIGNALS">SIGNALS</a> <a href="#SIMPLE">SIMPLE</a> <a href="#SLEEP">SLEEP</a> <a href="#SOCKET">SOCKET</a> <a href="#SYSCALL">SYSCALL</a> <a href="#TCP">TCP</a> <a href="#TIME">TIME</a> <a href="#TRACE">TRACE</a> <a href="#TRACEPOINT">TRACEPOINT</a> <a href="#TRAFFIC">TRAFFIC</a> <a href="#USE">USE</a> <a href="#WAIT4">WAIT4</a> <a href="#WRITE">WRITE</a> </tt></p>
+<p><tt><a href="#BACKTRACE">BACKTRACE</a> <a href="#BUFFER">BUFFER</a> <a href="#CALLGRAPH">CALLGRAPH</a> <a href="#CPU">CPU</a> <a href="#DISK">DISK</a> <a href="#FORMAT">FORMAT</a> <a href="#FREE">FREE</a> <a href="#FUNCTIONS">FUNCTIONS</a> <a href="#FUTEX">FUTEX</a> <a href="#GRAPH">GRAPH</a> <a href="#INTERRUPT">INTERRUPT</a> <a href="#IO">IO</a> <a href="#LOCKING">LOCKING</a> <a href="#MEMORY">MEMORY</a> <a href="#MONITOR">MONITOR</a> <a href="#NETWORK">NETWORK</a> <a href="#PER-PROCESS">PER-PROCESS</a> <a href="#PROCESS">PROCESS</a> <a href="#PROFILING">PROFILING</a> <a href="#READ">READ</a> <a href="#SCHEDULER">SCHEDULER</a> <a href="#SIGNALS">SIGNALS</a> <a href="#SIMPLE">SIMPLE</a> <a href="#SLEEP">SLEEP</a> <a href="#SOCKET">SOCKET</a> <a href="#SYSCALL">SYSCALL</a> <a href="#TCP">TCP</a> <a href="#TIME">TIME</a> <a href="#TRACE">TRACE</a> <a href="#TRACEPOINT">TRACEPOINT</a> <a href="#TRAFFIC">TRAFFIC</a> <a href="#TTY">TTY</a> <a href="#USE">USE</a> <a href="#WAIT4">WAIT4</a> <a href="#WRITE">WRITE</a> </tt></p>
<h3><a name="BACKTRACE">BACKTRACE</a></h3>
<ul>
<li><a href="interrupt/scf.stp">interrupt/scf.stp</a> - Tally Backtraces for Inter-Processor Interrupt (IPI)<br>
@@ -141,6 +141,9 @@ keywords: <a href="keyword-index.html#IO">IO</a> <br>
<li><a href="io/traceio2.stp">io/traceio2.stp</a> - Watch I/O Activity on a Particular Device<br>
keywords: <a href="keyword-index.html#IO">IO</a> <br>
<p>Print out the executable name and process number as reads and writes to the specified device occur.</p></li>
+<li><a href="io/ttyspy.stp">io/ttyspy.stp</a> - Monitor tty typing.<br>
+keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#TTY">TTY</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <a href="keyword-index.html#MONITOR">MONITOR</a> <br>
+<p>The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.</p></li>
<li><a href="process/sleepingBeauties.stp">process/sleepingBeauties.stp</a> - Generating Backtraces of Threads Waiting for IO Operations<br>
keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#SCHEDULER">SCHEDULER</a> <a href="keyword-index.html#BACKTRACE">BACKTRACE</a> <br>
<p>The script monitors the time that threads spend waiting for IO operations (in "D" state) in the wait_for_completion function. If a thread spends over 10ms, its name and backtrace is printed, and later so is the total delay.</p></li>
@@ -160,6 +163,12 @@ keywords: <a href="keyword-index.html#MEMORY">MEMORY</a> <br>
keywords: <a href="keyword-index.html#MEMORY">MEMORY</a> <br>
<p>The pfaults.stp script generates a simple log for each major and minor page fault that occurs on the system. Each line contains a timestamp (in microseconds) when the page fault servicing was completed, the pid of the process, the address of the page fault, the type of access (read or write), the type of fault (major or minor), and the elapsed time for page fault. This log can be examined to determine where the page faults are occuring.</p></li>
</ul>
+<h3><a name="MONITOR">MONITOR</a></h3>
+<ul>
+<li><a href="io/ttyspy.stp">io/ttyspy.stp</a> - Monitor tty typing.<br>
+keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#TTY">TTY</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <a href="keyword-index.html#MONITOR">MONITOR</a> <br>
+<p>The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.</p></li>
+</ul>
<h3><a name="NETWORK">NETWORK</a></h3>
<ul>
<li><a href="network/dropwatch.stp">network/dropwatch.stp</a> - Watch Where Socket Buffers are Freed in the Kernel<br>
@@ -180,6 +189,9 @@ keywords: <a href="keyword-index.html#NETWORK">NETWORK</a> <a href="keyword-inde
</ul>
<h3><a name="PER-PROCESS">PER-PROCESS</a></h3>
<ul>
+<li><a href="io/ttyspy.stp">io/ttyspy.stp</a> - Monitor tty typing.<br>
+keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#TTY">TTY</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <a href="keyword-index.html#MONITOR">MONITOR</a> <br>
+<p>The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.</p></li>
<li><a href="network/nettop.stp">network/nettop.stp</a> - Periodic Listing of Processes Using Network Interfaces<br>
keywords: <a href="keyword-index.html#NETWORK">NETWORK</a> <a href="keyword-index.html#TRAFFIC">TRAFFIC</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <br>
<p>Every five seconds the nettop.stp script prints out a list of processed (PID and command) with the number of packets sent/received and the amount of data sent/received by the process during that interval.</p></li>
@@ -328,6 +340,12 @@ keywords: <a href="keyword-index.html#NETWORK">NETWORK</a> <a href="keyword-inde
keywords: <a href="keyword-index.html#NETWORK">NETWORK</a> <a href="keyword-index.html#TRAFFIC">TRAFFIC</a> <br>
<p>The tcpdumplike.stp prints out a line for each TCP packet received. Each line includes the source and destination IP addresses, the source and destination ports, and flags.</p></li>
</ul>
+<h3><a name="TTY">TTY</a></h3>
+<ul>
+<li><a href="io/ttyspy.stp">io/ttyspy.stp</a> - Monitor tty typing.<br>
+keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#TTY">TTY</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <a href="keyword-index.html#MONITOR">MONITOR</a> <br>
+<p>The ttyspy.stp script uses tty_audit hooks to monitor recent typing activity on the system, printing a scrolling record of recent keystrokes, on a per-tty basis.</p></li>
+</ul>
<h3><a name="USE">USE</a></h3>
<ul>
<li><a href="general/graphs.stp">general/graphs.stp</a> - Graphing Disk and CPU Utilization<br>
diff --git a/testsuite/systemtap.examples/keyword-index.txt b/testsuite/systemtap.examples/keyword-index.txt
index c0082e36..eee89e22 100644
--- a/testsuite/systemtap.examples/keyword-index.txt
+++ b/testsuite/systemtap.examples/keyword-index.txt
@@ -222,6 +222,14 @@ keywords: io
to the specified device occur.
+io/ttyspy.stp - Monitor tty typing.
+keywords: io tty per-process monitor
+
+ The ttyspy.stp script uses tty_audit hooks to monitor recent typing
+ activity on the system, printing a scrolling record of recent
+ keystrokes, on a per-tty basis.
+
+
process/sleepingBeauties.stp - Generating Backtraces of Threads Waiting for IO Operations
keywords: io scheduler backtrace
@@ -267,6 +275,16 @@ keywords: memory
determine where the page faults are occuring.
+= MONITOR =
+
+io/ttyspy.stp - Monitor tty typing.
+keywords: io tty per-process monitor
+
+ The ttyspy.stp script uses tty_audit hooks to monitor recent typing
+ activity on the system, printing a scrolling record of recent
+ keystrokes, on a per-tty basis.
+
+
= NETWORK =
network/dropwatch.stp - Watch Where Socket Buffers are Freed in the Kernel
@@ -316,6 +334,14 @@ keywords: network traffic
= PER-PROCESS =
+io/ttyspy.stp - Monitor tty typing.
+keywords: io tty per-process monitor
+
+ The ttyspy.stp script uses tty_audit hooks to monitor recent typing
+ activity on the system, printing a scrolling record of recent
+ keystrokes, on a per-tty basis.
+
+
network/nettop.stp - Periodic Listing of Processes Using Network Interfaces
keywords: network traffic per-process
@@ -687,6 +713,16 @@ keywords: network traffic
source and destination ports, and flags.
+= TTY =
+
+io/ttyspy.stp - Monitor tty typing.
+keywords: io tty per-process monitor
+
+ The ttyspy.stp script uses tty_audit hooks to monitor recent typing
+ activity on the system, printing a scrolling record of recent
+ keystrokes, on a per-tty basis.
+
+
= USE =
general/graphs.stp - Graphing Disk and CPU Utilization