DOT: fixed broken code for visualizing configuration using dot
authorUri Wiener <uri.wiener@arm.com>
Thu, 10 May 2012 23:04:27 +0000 (18:04 -0500)
committerUri Wiener <uri.wiener@arm.com>
Thu, 10 May 2012 23:04:27 +0000 (18:04 -0500)
Fixed broken code which visualizes the system configuration by generating a
tree from each component's children, starting from root.
Requires DOT (hence pydot).

src/python/m5/SimObject.py
src/python/m5/main.py
src/python/m5/simulate.py

index c1f0ff63ee1642bad65595d4c42b5e3b8c964e47..04b4af69dcc6ccb2f09d0c054f62840b680b09ce 100644 (file)
@@ -1061,47 +1061,42 @@ class SimObject(object):
         self._ccObject.takeOverFrom(old_cpu._ccObject)
 
     # generate output file for 'dot' to display as a pretty graph.
-    # this code is currently broken.
     def outputDot(self, dot):
-        label = "{%s|" % self.path
-        if isSimObject(self.realtype):
-            label +=  '%s|' % self.type
+        if isRoot(self):
+            label = "{root|"
+        else:
+            label = "{%s|" % self._name
 
-        if self.children:
-            # instantiate children in same order they were added for
-            # backward compatibility (else we can end up with cpu1
-            # before cpu0).
-            for c in self.children:
-                dot.add_edge(pydot.Edge(self.path,c.path, style="bold"))
+        if isSimObject(self._base):
+            label +=  '%s|' % self.type
 
-        simobjs = []
-        for param in self.params:
-            try:
-                if param.value is None:
-                    raise AttributeError, 'Parameter with no value'
+        if self._children:
+            for c in self._children:
+                child = self._children[c]
+                if isSimObjectVector(child):
+                    for obj in child:
+                        dot.add_edge(pydot.Edge(self.path(), obj.path(), style="bold"))
+                else:
+                    dot.add_edge(pydot.Edge(self.path(), child.path(), style="bold"))
 
-                value = param.value
-                string = param.string(value)
-            except Exception, e:
-                msg = 'exception in %s:%s\n%s' % (self.name, param.name, e)
-                e.args = (msg, )
-                raise
-
-            if isSimObject(param.ptype) and string != "Null":
-                simobjs.append(string)
-            else:
-                label += '%s = %s\\n' % (param.name, string)
+        for param in self._params.keys():
+            value = self._values.get(param)
+            if value != None:
+                ini_str_value = self._values[param].ini_str()
+                label += '%s = %s\\n' % (param, re.sub(':', '-', ini_str_value))
 
-        for so in simobjs:
-            label += "|<%s> %s" % (so, so)
-            dot.add_edge(pydot.Edge("%s:%s" % (self.path, so), so,
-                                    tailport="w"))
         label += '}'
-        dot.add_node(pydot.Node(self.path,shape="Mrecord",label=label))
+
+        dot.add_node(pydot.Node(self.path(), shape="Mrecord",label=label))
 
         # recursively dump out children
-        for c in self.children:
-            c.outputDot(dot)
+        for c in self._children:
+            child = self._children[c]
+            if isSimObjectVector(child):
+                for obj in child:
+                    obj.outputDot(dot)
+            else:
+                child.outputDot(dot)
 
 # Function to provide to C++ so it can look up instances based on paths
 def resolveSimObject(name):
index 910cb6ce650c96d4c7089fe86c3e88534bac78e7..ce2979cd218d617fa1626aacb20aa83815af77e4 100644 (file)
@@ -89,6 +89,8 @@ def parse_options():
         help="Dump configuration output file [Default: %default]")
     option("--json-config", metavar="FILE", default="config.json",
         help="Create JSON output of the configuration [Default: %default]")
+    option("--dot-config", metavar="FILE", default="config.dot",
+        help="Create DOT & pdf outputs of the configuration [Default: %default]")
 
     # Debugging options
     group("Debugging Options")
index 38129592c0c05f5dad37f7d21edae41499ae3ec4..b1d01db3b45996ab8528dab30f94d7454f6d5b8d 100644 (file)
@@ -32,6 +32,12 @@ import atexit
 import os
 import sys
 
+try:
+    import pydot
+except:
+    pydot = False
+
+
 # import the SWIG-wrapped main C++ functions
 import internal
 import core
@@ -82,6 +88,8 @@ def instantiate(ckpt_dir=None):
         except ImportError:
             pass
 
+    if pydot:
+        doDot(root)
 
     # Initialize the global statistics
     stats.initSimStats()
@@ -113,14 +121,16 @@ def instantiate(ckpt_dir=None):
     stats.reset()
 
 def doDot(root):
+    from m5 import options
     dot = pydot.Dot()
-    instance.outputDot(dot)
+    root.outputDot(dot)
     dot.orientation = "portrait"
     dot.size = "8.5,11"
     dot.ranksep="equally"
     dot.rank="samerank"
-    dot.write("config.dot")
-    dot.write_ps("config.ps")
+    dot_filename = os.path.join(options.outdir, options.dot_config)
+    dot.write(dot_filename)
+    dot.write_pdf(dot_filename + ".pdf")
 
 need_resume = []
 need_startup = True