python: Don't assume RubyNetwork exists in do_ruby_dot.

If Ruby is disabled, then RubyNetwork is not a SimObject, and
do_ruby_dot which tries to reference it will crash. This more flexibly
checks for RubyNetwork, and if that isn't in m5.objects will gracefully
return instead of crashing.

Also streamline the code in that function a little bit using filter()
instead of preconstructing the list of ruby networks.

Change-Id: Ia4bdb04201df8453a1b6692a2f211b6cde00be2d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/59629
Maintainer: Gabe Black <gabe.black@gmail.com>
Reviewed-by: Yu-hsin Wang <yuhsingw@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2022-05-12 17:09:54 -07:00
committed by Gabe Black
parent ed6c57e4ab
commit 3d5bb844ee

View File

@@ -133,17 +133,17 @@ def _do_dot(network, outdir, dotFilename):
def do_ruby_dot(root, outdir, dotFilename):
if not pydot:
RubyNetwork = getattr(m5.objects, 'RubyNetwork', None)
if not pydot or not RubyNetwork:
return
# Generate a graph for all ruby systems
networks = []
for obj in root.descendants():
if isinstance(obj, m5.objects.RubyNetwork):
networks.append(obj)
# Generate a graph for all ruby networks.
def is_ruby_network(obj):
return isinstance(obj, RubyNetwork)
for network in networks:
# We assume each ruby system has a single network
for network in filter(is_ruby_network, root.descendants()):
# We assume each ruby system has a single network.
rubydotFilename = dotFilename.replace(".dot",
"." + network.get_parent().path() + ".dot")
_do_dot(network, outdir, rubydotFilename)