Hello Tiago Mück,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/c/public/gem5/+/17548
to review the following change.
Change subject: misc: Added dot_writer for Ruby's network topology
......................................................................
misc: Added dot_writer for Ruby's network topology
Change-Id: Ic71ca7bc2eb4174d70afa368bc9cc987f3df89e9
---
M src/python/SConscript
M src/python/m5/simulate.py
A src/python/m5/util/dot_writer_ruby.py
3 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/src/python/SConscript b/src/python/SConscript
index fb1666c..758ab3d 100644
--- a/src/python/SConscript
+++ b/src/python/SConscript
@@ -52,6 +52,7 @@
PySource('m5.util', 'm5/util/code_formatter.py')
PySource('m5.util', 'm5/util/convert.py')
PySource('m5.util', 'm5/util/dot_writer.py')
+PySource('m5.util', 'm5/util/dot_writer_ruby.py')
PySource('m5.util', 'm5/util/grammar.py')
PySource('m5.util', 'm5/util/jobfile.py')
PySource('m5.util', 'm5/util/multidict.py')
diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py
index 6f02327..1add414 100644
--- a/src/python/m5/simulate.py
+++ b/src/python/m5/simulate.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2012 ARM Limited
+# Copyright (c) 2012,2019 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
@@ -56,6 +56,7 @@
from . import ticks
from . import objects
from m5.util.dot_writer import do_dot, do_dvfs_dot
+import m5.util.dot_writer_ruby as dot_writer_ruby
from .util import fatal
from .util import attrdict
@@ -111,6 +112,10 @@
do_dot(root, options.outdir, options.dot_config)
+ if hasattr(root.system,'ruby'):
+ dot_writer_ruby.do_dot(root.system.ruby.network,
+ options.outdir, options.dot_config + '.ruby')
+
# Initialize the global statistics
stats.initSimStats()
diff --git a/src/python/m5/util/dot_writer_ruby.py
b/src/python/m5/util/dot_writer_ruby.py
new file mode 100644
index 0000000..408d9c0
--- /dev/null
+++ b/src/python/m5/util/dot_writer_ruby.py
@@ -0,0 +1,123 @@
+# Copyright (c) 2019 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Tiago Muck
+
+# Creates a visual representation of a Ruby network topology
+
+import m5, os, re
+from m5.SimObject import isRoot, isSimObjectVector
+from m5.params import PortRef, isNullPointer
+from m5.util import warn
+try:
+ import pydot
+except:
+ pydot = False
+
+
+def dot_rgb_to_html(r, g, b):
+ return "#%.2x%.2x%.2x" % (r, g, b)
+
+def dot_create_router_node(full_path, label):
+ return pydot.Node( \
+ full_path, \
+ shape = "Mrecord", \
+ label = label, \
+ style = "\"rounded, filled\"", \
+ color = "#000000", \
+ fillcolor = dot_rgb_to_html(204, 230, 252), \
+ fontname = "Arial", \
+ fontsize = "14", \
+ fontcolor = "#000000" \
+ )
+
+def dot_create_ctrl_node(full_path, label):
+ return pydot.Node( \
+ full_path, \
+ shape = "Mrecord", \
+ label = label, \
+ style = "\"rounded, filled\"", \
+ color = "#000000", \
+ fillcolor = dot_rgb_to_html(229, 188, 208), \
+ fontname = "Arial", \
+ fontsize = "14", \
+ fontcolor = "#000000" \
+ )
+
+
+def dot_create(network, callgraph):
+ for r in network.routers:
+ callgraph.add_node(dot_create_router_node(r.path(),
+ 'R %d' % r.router_id))
+
+ # One link for each direction but draw one edge only
+ connected = dict()
+ for link in network.int_links:
+ if (link.src_node.path() in connected) and \
+ (connected[link.src_node.path()] == link.dst_node.path()):
+ continue
+ callgraph.add_edge(
+ pydot.Edge(link.src_node.path(), link.dst_node.path())
+ )
+ connected[link.dst_node.path()] = link.src_node.path()
+
+ for link in network.ext_links:
+ ctrl = link.ext_node
+ label = ctrl._name
+ if hasattr(ctrl, '_node_type'):
+ label += ' (' + ctrl._node_type + ')'
+ callgraph.add_node(
+ dot_create_ctrl_node(ctrl.path(), label)
+ )
+
+ callgraph.add_edge(
+ pydot.Edge(link.ext_node.path(), link.int_node.path())
+ )
+
+def do_dot(network, outdir, dotFilename):
+ if not pydot:
+ return
+
+ callgraph = pydot.Dot(graph_type='graph', rankdir='LR')
+ dot_create(network, callgraph)
+ dot_filename = os.path.join(outdir, dotFilename)
+ callgraph.write(dot_filename)
+ try:
+ # dot crashes if the figure is extremely wide.
+ # So avoid terminating simulation unnecessarily
+ callgraph.write_svg(dot_filename + ".svg", prog='neato')
+ callgraph.write_pdf(dot_filename + ".pdf", prog='neato')
+ except:
+ warn("failed to generate dot output from %s", dot_filename)
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/17548
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ic71ca7bc2eb4174d70afa368bc9cc987f3df89e9
Gerrit-Change-Number: 17548
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Tiago Mück <tiago.m...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev