public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH]  dot_flow_graph.stp tapset
@ 2011-11-28 17:09 William Cohen
  0 siblings, 0 replies; only message in thread
From: William Cohen @ 2011-11-28 17:09 UTC (permalink / raw)
  To: SystemTAP

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

When trying to better understand how the various bio flow through the
the block io trace points I made a script to plot out the path that
various struct bio pointers take between the various trace points.  I
have factored out the graphing code into a tapset, dot_flow_graph.stp
and have a simple-minded script, block_graph.stp to demonstrate its
use. It doesn't take into account that bio structs getting merged with
other bio operations.  However, people might still find the code useful.
Below is the command line used to produce a simple state diagram using the tapset:

stap -v /tmp/block_graph.stp -c 'sleep 20'|dot -Tsvg -o /tmp/fsm.svg 

Attached are the patch for the dot_flow_graph.stp, block_graph.stp,
and example output.

Any feedback on the tapset would be appreciated.

-Will

[-- Attachment #2: 0001-Add-the-dot_flow_graph.stp-tapset.patch --]
[-- Type: text/x-patch, Size: 3179 bytes --]

From 8271d4cf5bfc949ad4bfb2b9bbd3791ac5f7fe9d Mon Sep 17 00:00:00 2001
From: William Cohen <wcohen@redhat.com>
Date: Mon, 28 Nov 2011 12:00:48 -0500
Subject: [PATCH 1/1] Add the dot_flow_graph.stp tapset

This simple tapset provide allow one to generate graphs showing the transitions
between different events.  The output of the tapset dot_print_graph function
is text that can be piped into the dot command to produce svg and pdf graphs.

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

diff --git a/doc/SystemTap_Tapset_Reference/tapsets.tmpl b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
index 685c733..9b8bbf8 100644
--- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl
+++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
@@ -389,4 +389,18 @@
 !Itapset/nfsd.stp
 !Itapset/nfsderrno.stp
   </chapter>
+
+  <chapter id="dot_flow_graph.stp">
+    <title>Graph Generation Functions</title>
+    <para>
+      Sometimes it is useful to see the transitions from one event
+      to another.
+      The <command>dot_flow_graph.stp</command> tapset
+      provides a set of functions
+      to generate output which the <command>dot</command> command uses
+      to produce a directed graph.
+      Each edge is labelled with the number of time the edge is taken.
+    </para>
+!Itapset/dot_flow_graph.stp
+  </chapter>
 </book>
diff --git a/tapset/dot_flow_graph.stp b/tapset/dot_flow_graph.stp
new file mode 100644
index 0000000..997a956
--- /dev/null
+++ b/tapset/dot_flow_graph.stp
@@ -0,0 +1,60 @@
+// Dot graphing tapset
+// Copyright (C) 2011 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 __dot_cfg
+
+/**
+ * sfunction dot_add_edge - Add an edge to dot graph
+ *
+ * @name: name of graph
+ * @src: source of edge
+ * @dest: destination of edge
+ *
+ */
+function dot_add_edge(name:string, src:string, dest:string)
+{
+	__dot_cfg[name, src, dest] <<< 1
+}
+
+/**
+ * sfunction dot_print_graph - Print the stored graph
+ *
+ * @name: which graph to print out
+ *
+ * Prints output to stdout that can be used by the dot graphing command to
+ * draw a directed graph.
+ */
+function dot_print_graph(name:string)
+{
+	__dot_header(name)
+	foreach ([n, src+, dest] in __dot_cfg) {
+		if (n == name)
+			printf ("\t\"%s\" -> \"%s\" [ label = \"%d\" ];\n",
+			       __dot_name_sanitizer(src),
+			       __dot_name_sanitizer(dest),
+			       @count(__dot_cfg[n, src, dest]));
+	}
+	__dot_footer()
+}
+
+/* need to escape quote characters for proper printing in dot */
+function __dot_name_sanitizer (name:string)
+{
+	return str_replace(name,"\"","\\\"")
+}
+
+function __dot_header(name:string)
+{
+	printf("digraph %s {\n", name)
+	printf("\tnode [shape = ellipse];\n")
+}
+
+function __dot_footer()
+{
+	printf("}\n")
+}
-- 
1.7.1


[-- Attachment #3: block_graph.stp --]
[-- Type: text/plain, Size: 282 bytes --]

#! /usr/bin/env stap

global last_pp

probe kernel.trace("block*")
{
  b = @defined($bio) ? $bio : 0
  if (b) {
    name = pn()
    if (last_pp[b] != "")
      dot_add_edge("block_graph", last_pp[b], name)
    last_pp[b] = name
  }
}

probe end {
  dot_print_graph("block_graph")
}

[-- Attachment #4: fsm.svg --]
[-- Type: image/svg+xml, Size: 8347 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-28 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-28 17:09 [PATCH] dot_flow_graph.stp tapset 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).