public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: William Cohen <wcohen@redhat.com>
To: systemtap@sourceware.org
Cc: William Cohen <wcohen@redhat.com>
Subject: [PATCH] Example to exercise stopwatch.stp tapset
Date: Thu, 26 Jan 2012 21:46:00 -0000	[thread overview]
Message-ID: <1327614376-1059-1-git-send-email-wcohen@redhat.com> (raw)


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

                 reply	other threads:[~2012-01-26 21:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327614376-1059-1-git-send-email-wcohen@redhat.com \
    --to=wcohen@redhat.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).