summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--examples/small_demos/fileopen.stp19
-rwxr-xr-xexamples/small_demos/rwtiming.stp71
3 files changed, 96 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e2d5149..391f2734 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2006-05-05 Eugene Teo <eteo@redhat.com>
PR 2433
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]))
+ }
+ }
+}