summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.examples/iotime.stp
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2008-04-25 16:33:24 -0400
committerFrank Ch. Eigler <fche@elastic.org>2008-04-25 16:33:24 -0400
commit76d647dc1fdf1d6bb4397f4a3b819003492dfda6 (patch)
tree51b9d7a1f0ee75a41c487828d5e62c6a70b7fd28 /testsuite/systemtap.examples/iotime.stp
parentc47ccf304e6560cb50c86c2a5213c8de56678449 (diff)
parent9f99b110fbee8a6935ca60c152cc3c7cd809461b (diff)
downloadsystemtap-steved-76d647dc1fdf1d6bb4397f4a3b819003492dfda6.tar.gz
systemtap-steved-76d647dc1fdf1d6bb4397f4a3b819003492dfda6.tar.xz
systemtap-steved-76d647dc1fdf1d6bb4397f4a3b819003492dfda6.zip
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap into pr6429-comp-unwindsyms
* 'master' of ssh://sources.redhat.com/git/systemtap: simplify systemtap.spec configuration vars Handles markers with no format string. Fixed task_finder.c kernel 2.6.25 change. PR6454: fix "stap -l" listing of space-laden probe point names Move examples to testsuite/systemtap.examples. PR6451: avoid one class of staprun shutdown deadlock (module/.ctl filehandle = 0) Made kernel 2.6.25 changes in task_finder.c. Move examples to testsuite/systemtap.examples PR6416: extend probing blacklist with more init/exit sections
Diffstat (limited to 'testsuite/systemtap.examples/iotime.stp')
-rwxr-xr-xtestsuite/systemtap.examples/iotime.stp114
1 files changed, 114 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/iotime.stp b/testsuite/systemtap.examples/iotime.stp
new file mode 100755
index 00000000..a5b36449
--- /dev/null
+++ b/testsuite/systemtap.examples/iotime.stp
@@ -0,0 +1,114 @@
+#! /usr/bin/env stap
+
+/*
+ * Copyright (C) 2006 Daniel Berrange, Red Hat Inc.
+ * Copyright (C) 2007 Will Cohen, 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 systemtap
+ * script needs to be running before the open operations occur for
+ * the script to record data.
+ *
+ * This script could be used to to find out which files are slow to load
+ * on a machine. e.g.
+ *
+ * stap iotime.stp -c 'firefox'
+ *
+ * Output format is:
+ * timestamp pid (executabable) info_type path ...
+ *
+ * 200283135 2573 (cupsd) access /etc/printcap read: 0 write: 7063
+ * 200283143 2573 (cupsd) iotime /etc/printcap time: 69
+ *
+ */
+
+global start
+global entry_io
+global fd_io
+global time_io
+
+function timestamp:long() {
+ return gettimeofday_us() - start
+}
+
+function proc:string() {
+ return sprintf("%d (%s)", pid(), execname())
+}
+
+probe begin {
+ start = gettimeofday_us()
+}
+
+global filenames
+global filehandles
+global fileread
+global filewrite
+
+probe syscall.open {
+ filenames[pid()] = user_string($filename)
+}
+
+probe syscall.open.return {
+ if ($return != -1) {
+ filehandles[pid(), $return] = filenames[pid()]
+ fileread[pid(), $return] = 0
+ filewrite[pid(), $return] = 0
+ } else {
+ printf("%d %s access %s fail\n", timestamp(), proc(), filenames[pid()])
+ }
+ delete filenames[pid()]
+}
+
+probe syscall.read {
+ if ($count > 0) {
+ fileread[pid(), $fd] += $count
+ }
+ t = gettimeofday_us(); p = pid()
+ entry_io[p] = t
+ fd_io[p] = $fd
+}
+
+probe syscall.read.return {
+ t = gettimeofday_us(); p = pid()
+ fd = fd_io[p]
+ time_io[p,fd] <<< t - entry_io[p]
+}
+
+probe syscall.write {
+ if ($count > 0) {
+ filewrite[pid(), $fd] += $count
+ }
+ t = gettimeofday_us(); p = pid()
+ entry_io[p] = t
+ fd_io[p] = $fd
+}
+
+probe syscall.write.return {
+ t = gettimeofday_us(); p = pid()
+ fd = fd_io[p]
+ time_io[p,fd] <<< t - entry_io[p]
+}
+
+probe syscall.close {
+ if (filehandles[pid(), $fd] != "") {
+ printf("%d %s access %s read: %d write: %d\n", timestamp(), proc(),
+ filehandles[pid(), $fd], fileread[pid(), $fd], filewrite[pid(), $fd])
+ if (@count(time_io[pid(), $fd]))
+ printf("%d %s iotime %s time: %d\n", timestamp(), proc(),
+ filehandles[pid(), $fd], @sum(time_io[pid(), $fd]))
+ }
+ delete fileread[pid(), $fd]
+ delete filewrite[pid(), $fd]
+ delete filehandles[pid(), $fd]
+ delete fd_io[pid()]
+ delete entry_io[pid()]
+ delete time_io[pid(),$fd]
+}