summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorwcohen <wcohen>2006-05-05 20:35:30 +0000
committerwcohen <wcohen>2006-05-05 20:35:30 +0000
commit708a511bd92ec7ba3ff8787c67b3058dbdaa5f3a (patch)
tree1898c9ac1f04c537c0e0790624700df88a620714 /examples
parent3897de04275daf1727e115e6bb7a5a4ae8fd46b3 (diff)
downloadsystemtap-steved-708a511bd92ec7ba3ff8787c67b3058dbdaa5f3a.tar.gz
systemtap-steved-708a511bd92ec7ba3ff8787c67b3058dbdaa5f3a.tar.xz
systemtap-steved-708a511bd92ec7ba3ff8787c67b3058dbdaa5f3a.zip
2006-05-05 Will Cohen <wcohen@redhat.com>
* small_demos/fileopen.stp: Shows use of target() to look at pid. * small_demos/rwtiming.stp: Shows per executable histograms of time spent in read and write system calls.
Diffstat (limited to 'examples')
-rw-r--r--examples/small_demos/fileopen.stp19
-rwxr-xr-xexamples/small_demos/rwtiming.stp71
2 files changed, 90 insertions, 0 deletions
diff --git a/examples/small_demos/fileopen.stp b/examples/small_demos/fileopen.stp
new file mode 100644
index 00000000..5d59ee55
--- /dev/null
+++ b/examples/small_demos/fileopen.stp
@@ -0,0 +1,19 @@
+# fileopen.stp
+#
+# This is based on dtrace script from
+# http://www.gnome.org/~gman/blog/2006/Jan
+#
+#stap fileopen.stp -c "zenity --about"
+
+global opens
+
+probe syscall.open {
+ if (target() == pid()) opens[filename] ++
+}
+
+probe end {
+ foreach([name] in opens+) {
+ printf("%-70s%5d\n", name, opens[name])
+ }
+}
+
diff --git a/examples/small_demos/rwtiming.stp b/examples/small_demos/rwtiming.stp
new file mode 100755
index 00000000..c5a9aed3
--- /dev/null
+++ b/examples/small_demos/rwtiming.stp
@@ -0,0 +1,71 @@
+#! /usr/bin/env stap
+# rwtiming.stp
+#
+# This is a simple example to track the amount of time
+# spent doing reads and writes for the various programs running on the
+# system.
+
+probe begin { log("starting probe") }
+
+global names, opens, reads, writes
+global entry_opens, entry_reads, entry_writes
+global time_opens, time_reads, time_writes
+
+probe kernel.function("sys_open") {
+ t=gettimeofday_us(); p=pid(); e=execname();
+ names[e]=1
+ opens[e] ++ # plain integer
+ entry_opens[p] = t;
+}
+
+probe kernel.function("sys_open").return {
+ t=gettimeofday_us(); p=pid(); e=execname();
+ time_opens[e] <<< t - entry_opens[p];
+}
+
+probe kernel.function("sys_read") {
+ t= gettimeofday_us(); p =pid(); e=execname();
+ names[e]=1
+ reads[e] <<< $count # statistics
+ entry_reads[p] = t;
+}
+
+probe kernel.function("sys_read").return {
+ t=gettimeofday_us(); p=pid(); e=execname();
+ time_reads[e] <<< t - entry_reads[p];
+}
+
+probe kernel.function("sys_write") {
+ t=gettimeofday_us(); p=pid(); e=execname();
+ names[e]=1
+ writes[e] <<< $count # statistics
+ entry_writes[p] = t;
+}
+
+probe kernel.function("sys_write").return {
+ t = gettimeofday_us(); p = pid(); e=execname();
+ time_writes[e] <<< t - entry_writes[p];
+}
+
+probe end {
+ foreach(name+ in names) { # sort by names
+ printf ("process: %s\n", name)
+ if (opens[name]) printf ("opens n=%d\n", opens[name])
+ if (@count(reads[name])) {
+ printf ("reads n=%d, sum=%d, avg=%d\n",
+ @count(reads[name]), # extracting stat results
+ @sum(reads[name]),
+ @avg(reads[name]))
+ print ("read timing distribution\n")
+ print (@hist_log(time_reads[name]))
+ }
+ if (@count(writes[name])) {
+ printf ("writes n=%d, sum=%d, avg=%d\n",
+ @count(writes[name]), # extracting stat results
+ @sum(writes[name]),
+ @avg(writes[name]))
+ print ("write timing distribution\n")
+ print (@hist_log(time_writes[name]))
+ }
+ }
+}