This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] Example to exercise stopwatch.stp tapset
- From: William Cohen <wcohen at redhat dot com>
- To: systemtap at sourceware dot org
- Cc: William Cohen <wcohen at redhat dot com>
- Date: Thu, 26 Jan 2012 16:46:16 -0500
- Subject: [PATCH] Example to exercise stopwatch.stp tapset
Signed-off-by: William Cohen <wcohen@redhat.com>
---
.../systemtap.examples/general/stopwatches.meta | 14 +++++
.../systemtap.examples/general/stopwatches.stp | 60 ++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)
create mode 100644 testsuite/systemtap.examples/general/stopwatches.meta
create mode 100755 testsuite/systemtap.examples/general/stopwatches.stp
diff --git a/testsuite/systemtap.examples/general/stopwatches.meta b/testsuite/systemtap.examples/general/stopwatches.meta
new file mode 100644
index 0000000..e0b7f7c
--- /dev/null
+++ b/testsuite/systemtap.examples/general/stopwatches.meta
@@ -0,0 +1,14 @@
+title: See the amount of wall clock time a process spends in various states
+name: stopwatches.stp
+version: 1.0
+author: William Cohen
+keywords: time
+subsystem: process
+status: experimental
+exit: user-controlled
+output: on-exit
+scope: process
+description: The stopwatch.stp script illustrates how to use multiple stopwatches record how much wallclock time a process spends in kernel- and user-space. On exit the script prints out the time in seconds, milliseconds, microseconds, and nanoseconds. Note that this output of this script is not
+directly comparable to the time command because time records the time that the process is actually active in kernel- and user-space.
+test_check: stap -p4 stopwatches.stp
+test_installcheck: stap stopwatches.stp -c "sleep 0.2"
diff --git a/testsuite/systemtap.examples/general/stopwatches.stp b/testsuite/systemtap.examples/general/stopwatches.stp
new file mode 100755
index 0000000..0fb2854
--- /dev/null
+++ b/testsuite/systemtap.examples/general/stopwatches.stp
@@ -0,0 +1,60 @@
+#! /usr/bin/env stap
+# Copyright (C) 2012 Red Hat, Inc.
+# by William Cohen <wcohen@redhat.com>
+#
+# exercise the stopwatch tapset
+
+global wall, system, user
+
+
+probe begin
+{
+ wall = create_stopwatch();
+ system = create_stopwatch(); read_stopwatch_ns(system, STOPWATCH_STOP)
+ user = create_stopwatch(); read_stopwatch_ns(user, STOPWATCH_STOP)
+}
+
+probe syscall.*
+{
+ if (pid() != target()) next
+ read_stopwatch_ns(system, STOPWATCH_START)
+ read_stopwatch_ns(user, STOPWATCH_STOP)
+}
+
+probe syscall.*.return
+{
+ if (pid() != target()) next
+ read_stopwatch_ns(system, STOPWATCH_STOP)
+ read_stopwatch_ns(user, STOPWATCH_START)
+}
+
+probe end
+{
+ w = read_stopwatch_s(wall, STOPWATCH_STOP)
+ u = read_stopwatch_s(user, STOPWATCH_STOP)
+ s = read_stopwatch_s(system, STOPWATCH_STOP)
+ printf ("real\t%6ds\n", w);
+ printf ("user\t%6ds\n", u);
+ printf ("sys\t%6ds\n", s);
+
+ w = read_stopwatch_ms(wall, STOPWATCH_STOP)
+ u = read_stopwatch_ms(user, STOPWATCH_STOP)
+ s = read_stopwatch_ms(system, STOPWATCH_STOP)
+ printf ("real\t%9dms\n", w);
+ printf ("user\t%9dms\n", u);
+ printf ("sys\t%9dms\n", s);
+
+ w = read_stopwatch_us(wall, STOPWATCH_STOP)
+ u = read_stopwatch_us(user, STOPWATCH_STOP)
+ s = read_stopwatch_us(system, STOPWATCH_STOP)
+ printf ("real\t%12dus\n", w);
+ printf ("user\t%12dus\n", u);
+ printf ("sys\t%12dus\n", s);
+
+ w = read_stopwatch_ns(wall, STOPWATCH_STOP)
+ u = read_stopwatch_ns(user, STOPWATCH_STOP)
+ s = read_stopwatch_ns(system, STOPWATCH_STOP)
+ printf ("real\t%15dns\n", w);
+ printf ("user\t%15dns\n", u);
+ printf ("sys\t%15dns\n", s);
+}
--
1.7.1