public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add the stopwatch.stp tapset
  2012-01-31 15:51 [PATCH 0/2] V2 stopwatch.stp tapset William Cohen
@ 2012-01-31 15:51 ` William Cohen
  2012-01-31 15:51 ` [PATCH 2/2] Example to exercise " William Cohen
  1 sibling, 0 replies; 3+ messages in thread
From: William Cohen @ 2012-01-31 15:51 UTC (permalink / raw)
  To: systemtap; +Cc: William Cohen

The stopwatch.stp tapset provides multiple, independent timers to user
scripts.  Stopwatches can be created by the user script at
anytime. The created stopwatches can be stopped and started by the
user script. The times from the stopwatches can be read in seconds,
milliseconds, microsecons, and nanoseconds.

Signed-off-by: William Cohen <wcohen@redhat.com>
---
 doc/SystemTap_Tapset_Reference/tapsets.tmpl |    1 +
 tapset/stopwatch.stp                        |  126 +++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 0 deletions(-)
 create mode 100644 tapset/stopwatch.stp

diff --git a/doc/SystemTap_Tapset_Reference/tapsets.tmpl b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
index 41fe99b..4c734c4 100644
--- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl
+++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
@@ -140,6 +140,7 @@
 !Itapset/timestamp.stp
 !Itapset/timestamp_gtod.stp
 !Itapset/timestamp_monotonic.stp
+!Itapset/stopwatch.stp
   </chapter>
 
   <chapter id="ctime.stp">
diff --git a/tapset/stopwatch.stp b/tapset/stopwatch.stp
new file mode 100644
index 0000000..97cb39e
--- /dev/null
+++ b/tapset/stopwatch.stp
@@ -0,0 +1,126 @@
+// stopwatch tapset
+// Copyright (C) 2012 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software.  You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+global _stopwatch_starttime, _stopwatch_acc
+
+/*
+ * Description of the stopwatch states:
+ * if (! name in _stopwatch_acc) {stopwatch doesn't exist}
+ * if (_stopwatch_starttime[name] == 0 ) {stopwatch not running}
+ * if (_stopwatch_starttime[name] != 0 ) {stopwatch running}
+ */
+
+
+/**
+ * sfunction delete_stopwatch - Remove an existing stopwatch
+ * @name: the stopwatch name
+ *
+ * Remove stopwatch @name.
+ */
+function delete_stopwatch (name:string)
+{
+	delete _stopwatch_starttime[name];
+	delete _stopwatch_acc[name];
+}
+
+
+/**
+ * sfunction start_stopwatch - Start a stopwatch 
+ * @name: the stopwatch name
+ *
+ * Start stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function start_stopwatch (name:string)
+{
+	stime = _stopwatch_starttime[name]
+	if (stime == 0)
+		_stopwatch_starttime[name] = gettimeofday_ns()
+	/* make sure there is an entry in _stopwatch_acc */
+	_stopwatch_acc[name] = _stopwatch_acc[name]
+}
+
+
+/**
+ * sfunction stop_stopwatch - Stop a stopwatch 
+ * @name: the stopwatch name
+ *
+ * Stop stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function stop_stopwatch (name:string)
+{
+	stime = _stopwatch_starttime[name]
+
+	if (stime != 0)
+		delta =  gettimeofday_ns() - stime
+	else
+		delta = 0
+
+	_stopwatch_starttime[name] = 0
+	_stopwatch_acc[name] = _stopwatch_acc[name] + delta
+}
+
+
+/**
+ * sfunction read_stopwatch_ns - Reads the time in nanoseconds for a stopwatch
+ * @name: stopwatch name
+ *
+ * Returns time in nanoseconds for stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function read_stopwatch_ns:long (name:string)
+{
+	stime = _stopwatch_starttime[name]
+	if (stime != 0)
+		delta = gettimeofday_ns() - stime
+	else
+		delta = 0
+
+	_stopwatch_acc[name] = _stopwatch_acc[name]
+	return (_stopwatch_acc[name] + delta)
+}
+
+
+/**
+ * sfunction read_stopwatch_us - Reads the time in microseconds for a stopwatch
+ * @name: stopwatch name
+ *
+ * Returns time in microseconds for stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function read_stopwatch_us:long (name:string)
+{
+	return read_stopwatch_ns(name)/1000;
+}
+
+
+/**
+ * sfunction read_stopwatch_ms - Reads the time in milliseconds for a stopwatch
+ * @name: stopwatch name
+ *
+ * Returns time in milliseconds for stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function read_stopwatch_ms:long (name:string)
+{
+	return read_stopwatch_ns(name)/1000000;
+}
+
+
+/**
+ * sfunction read_stopwatch_ms - Reads the time in seconds for a stopwatch
+ * @name: stopwatch name
+ *
+ * Returns time in seconds for stopwatch @name.
+ * Creates stopwatch @name if it does not currently exist.
+ */
+function read_stopwatch_s:long (name:string)
+{
+	return read_stopwatch_ns(name)/1000000000;
+}
-- 
1.7.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Example to exercise stopwatch.stp tapset
  2012-01-31 15:51 [PATCH 0/2] V2 stopwatch.stp tapset William Cohen
  2012-01-31 15:51 ` [PATCH 1/2] Add the " William Cohen
@ 2012-01-31 15:51 ` William Cohen
  1 sibling, 0 replies; 3+ messages in thread
From: William Cohen @ 2012-01-31 15:51 UTC (permalink / raw)
  To: systemtap; +Cc: William Cohen


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 0/2] V2 stopwatch.stp tapset
@ 2012-01-31 15:51 William Cohen
  2012-01-31 15:51 ` [PATCH 1/2] Add the " William Cohen
  2012-01-31 15:51 ` [PATCH 2/2] Example to exercise " William Cohen
  0 siblings, 2 replies; 3+ messages in thread
From: William Cohen @ 2012-01-31 15:51 UTC (permalink / raw)
  To: systemtap; +Cc: William Cohen

I have incorporated Frank's comments into the stopwatch tapset API.
The patches are in the same format as before. The first patch is the
actual tapset and inclusion into the documentation. The second patch
is an example script that will exercise the stopwatch tapset.

William Cohen (2):
  Add the stopwatch.stp tapset
  Example to exercise stopwatch.stp tapset

 doc/SystemTap_Tapset_Reference/tapsets.tmpl        |    1 +
 tapset/stopwatch.stp                               |  126 ++++++++++++++++++++
 .../systemtap.examples/general/stopwatches.meta    |   13 ++
 .../systemtap.examples/general/stopwatches.stp     |   67 +++++++++++
 4 files changed, 207 insertions(+), 0 deletions(-)
 create mode 100644 tapset/stopwatch.stp
 create mode 100644 testsuite/systemtap.examples/general/stopwatches.meta
 create mode 100755 testsuite/systemtap.examples/general/stopwatches.stp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-31 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 15:51 [PATCH 0/2] V2 stopwatch.stp tapset William Cohen
2012-01-31 15:51 ` [PATCH 1/2] Add the " William Cohen
2012-01-31 15:51 ` [PATCH 2/2] Example to exercise " William Cohen

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).