This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] Example to exercise stopwatch.stp tapset


Signed-off-by: William Cohen <wcohen@redhat.com>
---
 .../systemtap.examples/general/stopwatches.meta    |   13 ++++
 .../systemtap.examples/general/stopwatches.stp     |   67 ++++++++++++++++++++
 2 files changed, 80 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..a7293f3
--- /dev/null
+++ b/testsuite/systemtap.examples/general/stopwatches.meta
@@ -0,0 +1,13 @@
+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..6c60a7f
--- /dev/null
+++ b/testsuite/systemtap.examples/general/stopwatches.stp
@@ -0,0 +1,67 @@
+#! /usr/bin/env stap
+# Copyright (C) 2012 Red Hat, Inc.
+# by William Cohen <wcohen@redhat.com>
+#
+# exercise the stopwatch tapset
+
+probe begin
+{
+  start_stopwatch("wall");
+  /* The following assumes that target starts in user space */
+  /* If the target is already running and in the kernel, it is wrong. */
+  start_stopwatch("user");
+  stop_stopwatch("system")
+}
+
+probe syscall.*
+{
+  if (pid() != target()) next
+  stop_stopwatch("user")
+  start_stopwatch("system")
+}
+
+probe syscall.*.return
+{
+  if (pid() != target()) next
+  start_stopwatch("user")
+  stop_stopwatch("system")
+}
+
+probe end
+{
+  stop_stopwatch("wall")
+  stop_stopwatch("user")
+  stop_stopwatch("system")
+
+  w = read_stopwatch_s("wall")
+  u = read_stopwatch_s("user")
+  s = read_stopwatch_s("system")
+  printf ("real\t%6ds\n", w);
+  printf ("user\t%6ds\n", u);
+  printf ("sys\t%6ds\n", s);
+
+  w = read_stopwatch_ms("wall")
+  u = read_stopwatch_ms("user")
+  s = read_stopwatch_ms("system")
+  printf ("real\t%9dms\n", w);
+  printf ("user\t%9dms\n", u);
+  printf ("sys\t%9dms\n", s);
+
+  w = read_stopwatch_us("wall")
+  u = read_stopwatch_us("user")
+  s = read_stopwatch_us("system")
+  printf ("real\t%12dus\n", w);
+  printf ("user\t%12dus\n", u);
+  printf ("sys\t%12dus\n", s);
+
+  w = read_stopwatch_ns("wall")
+  u = read_stopwatch_ns("user")
+  s = read_stopwatch_ns("system")
+  printf ("real\t%15dns\n", w);
+  printf ("user\t%15dns\n", u);
+  printf ("sys\t%15dns\n", s);
+
+  delete_stopwatch("wall")
+  delete_stopwatch("user")
+  delete_stopwatch("system")
+}
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]