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] dot_flow_graph.stp tapset


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
>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: block_graph.stp
Description: Text document

Attachment: fsm.svg
Description: image/svg


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