114060Stiago.muck@arm.com# Copyright (c) 2012-2013,2019 ARM Limited
28999Suri.wiener@arm.com# All rights reserved.
38999Suri.wiener@arm.com#
48999Suri.wiener@arm.com# The license below extends only to copyright in the software and shall
58999Suri.wiener@arm.com# not be construed as granting a license to any other intellectual
68999Suri.wiener@arm.com# property including but not limited to intellectual property relating
78999Suri.wiener@arm.com# to a hardware implementation of the functionality of the software
88999Suri.wiener@arm.com# licensed hereunder.  You may use the software subject to the license
98999Suri.wiener@arm.com# terms below provided that you ensure that this notice is replicated
108999Suri.wiener@arm.com# unmodified and in its entirety in all distributions of the software,
118999Suri.wiener@arm.com# modified or unmodified, in source code or in binary form.
128999Suri.wiener@arm.com#
138999Suri.wiener@arm.com# Redistribution and use in source and binary forms, with or without
148999Suri.wiener@arm.com# modification, are permitted provided that the following conditions are
158999Suri.wiener@arm.com# met: redistributions of source code must retain the above copyright
168999Suri.wiener@arm.com# notice, this list of conditions and the following disclaimer;
178999Suri.wiener@arm.com# redistributions in binary form must reproduce the above copyright
188999Suri.wiener@arm.com# notice, this list of conditions and the following disclaimer in the
198999Suri.wiener@arm.com# documentation and/or other materials provided with the distribution;
208999Suri.wiener@arm.com# neither the name of the copyright holders nor the names of its
218999Suri.wiener@arm.com# contributors may be used to endorse or promote products derived from
228999Suri.wiener@arm.com# this software without specific prior written permission.
238999Suri.wiener@arm.com#
248999Suri.wiener@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
258999Suri.wiener@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
268999Suri.wiener@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
278999Suri.wiener@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
288999Suri.wiener@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
298999Suri.wiener@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
308999Suri.wiener@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
318999Suri.wiener@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
328999Suri.wiener@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
338999Suri.wiener@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
348999Suri.wiener@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
358999Suri.wiener@arm.com#
368999Suri.wiener@arm.com# Authors: Andreas Hansson
378999Suri.wiener@arm.com#          Uri Wiener
3811418Ssascha.bischoff@arm.com#          Sascha Bischoff
398999Suri.wiener@arm.com
408999Suri.wiener@arm.com#####################################################################
418999Suri.wiener@arm.com#
428999Suri.wiener@arm.com# System visualization using DOT
438999Suri.wiener@arm.com#
448999Suri.wiener@arm.com# While config.ini and config.json provide an almost complete listing
459852Sandreas.hansson@arm.com# of a system's components and connectivity, they lack a birds-eye
469852Sandreas.hansson@arm.com# view. The output generated by do_dot() is a DOT-based figure (as a
479852Sandreas.hansson@arm.com# pdf and an editable svg file) and its source dot code. Nodes are
489852Sandreas.hansson@arm.com# components, and edges represent the memory hierarchy: the edges are
499852Sandreas.hansson@arm.com# directed, from a master to slave. Initially all nodes are
509852Sandreas.hansson@arm.com# generated, and then all edges are added. do_dot should be called
519852Sandreas.hansson@arm.com# with the top-most SimObject (namely root but not necessarily), the
529852Sandreas.hansson@arm.com# output folder and the output dot source filename. From the given
539852Sandreas.hansson@arm.com# node, both processes (node and edge creation) is performed
549852Sandreas.hansson@arm.com# recursivly, traversing all children of the given root.
558999Suri.wiener@arm.com#
568999Suri.wiener@arm.com# pydot is required. When missing, no output will be generated.
578999Suri.wiener@arm.com#
588999Suri.wiener@arm.com#####################################################################
598999Suri.wiener@arm.com
6013714Sandreas.sandberg@arm.comfrom __future__ import print_function
6113714Sandreas.sandberg@arm.comfrom __future__ import absolute_import
6213714Sandreas.sandberg@arm.com
638999Suri.wiener@arm.comimport m5, os, re
648999Suri.wiener@arm.comfrom m5.SimObject import isRoot, isSimObjectVector
6512202Sgabeblack@google.comfrom m5.params import PortRef, isNullPointer
669528Ssascha.bischoff@arm.comfrom m5.util import warn
678999Suri.wiener@arm.comtry:
688999Suri.wiener@arm.com    import pydot
698999Suri.wiener@arm.comexcept:
708999Suri.wiener@arm.com    pydot = False
718999Suri.wiener@arm.com
7212202Sgabeblack@google.comdef simnode_children(simNode):
7313709Sandreas.sandberg@arm.com    for child in simNode._children.values():
7412202Sgabeblack@google.com        if isNullPointer(child):
7512202Sgabeblack@google.com            continue
7612202Sgabeblack@google.com        if isSimObjectVector(child):
7712202Sgabeblack@google.com            for obj in child:
7812202Sgabeblack@google.com                if not isNullPointer(obj):
7912202Sgabeblack@google.com                    yield obj
8012202Sgabeblack@google.com        else:
8112202Sgabeblack@google.com            yield child
8212202Sgabeblack@google.com
838999Suri.wiener@arm.com# need to create all nodes (components) before creating edges (memory channels)
848999Suri.wiener@arm.comdef dot_create_nodes(simNode, callgraph):
858999Suri.wiener@arm.com    if isRoot(simNode):
868999Suri.wiener@arm.com        label = "root"
878999Suri.wiener@arm.com    else:
888999Suri.wiener@arm.com        label = simNode._name
898999Suri.wiener@arm.com    full_path = re.sub('\.', '_', simNode.path())
909852Sandreas.hansson@arm.com    # add class name under the label
919852Sandreas.hansson@arm.com    label = "\"" + label + " \\n: " + simNode.__class__.__name__ + "\""
928999Suri.wiener@arm.com
938999Suri.wiener@arm.com    # each component is a sub-graph (cluster)
948999Suri.wiener@arm.com    cluster = dot_create_cluster(simNode, full_path, label)
958999Suri.wiener@arm.com
968999Suri.wiener@arm.com    # create nodes per port
978999Suri.wiener@arm.com    for port_name in simNode._ports.keys():
988999Suri.wiener@arm.com        port = simNode._port_refs.get(port_name, None)
998999Suri.wiener@arm.com        if port != None:
1008999Suri.wiener@arm.com            full_port_name = full_path + "_" + port_name
1018999Suri.wiener@arm.com            port_node = dot_create_node(simNode, full_port_name, port_name)
1028999Suri.wiener@arm.com            cluster.add_node(port_node)
1038999Suri.wiener@arm.com
1048999Suri.wiener@arm.com    # recurse to children
10512202Sgabeblack@google.com    for child in simnode_children(simNode):
10612202Sgabeblack@google.com        dot_create_nodes(child, cluster)
1078999Suri.wiener@arm.com
1088999Suri.wiener@arm.com    callgraph.add_subgraph(cluster)
1098999Suri.wiener@arm.com
1108999Suri.wiener@arm.com# create all edges according to memory hierarchy
1118999Suri.wiener@arm.comdef dot_create_edges(simNode, callgraph):
1128999Suri.wiener@arm.com    for port_name in simNode._ports.keys():
1138999Suri.wiener@arm.com        port = simNode._port_refs.get(port_name, None)
1148999Suri.wiener@arm.com        if port != None:
1158999Suri.wiener@arm.com            full_path = re.sub('\.', '_', simNode.path())
1168999Suri.wiener@arm.com            full_port_name = full_path + "_" + port_name
1178999Suri.wiener@arm.com            port_node = dot_create_node(simNode, full_port_name, port_name)
1188999Suri.wiener@arm.com            # create edges
11910176Ssascha.bischoff@arm.com            if isinstance(port, PortRef):
12014250Sgabeblack@google.com                if port.peer:
12114250Sgabeblack@google.com                    dot_add_edge(simNode, callgraph, full_port_name, port)
1228999Suri.wiener@arm.com            else:
1238999Suri.wiener@arm.com                for p in port.elements:
12414250Sgabeblack@google.com                    if p.peer:
12514250Sgabeblack@google.com                        dot_add_edge(simNode, callgraph, full_port_name, p)
1268999Suri.wiener@arm.com
1278999Suri.wiener@arm.com    # recurse to children
12812202Sgabeblack@google.com    for child in simnode_children(simNode):
12912202Sgabeblack@google.com        dot_create_edges(child, callgraph)
1308999Suri.wiener@arm.com
13113870Sgabeblack@google.comdef dot_add_edge(simNode, callgraph, full_port_name, port):
13213870Sgabeblack@google.com    peer = port.peer
13313870Sgabeblack@google.com    full_peer_path = re.sub('\.', '_', peer.simobj.path())
13413870Sgabeblack@google.com    full_peer_port_name = full_peer_path + "_" + peer.name
13513870Sgabeblack@google.com
13613870Sgabeblack@google.com    # Each edge is encountered twice, once for each peer. We only want one
13713870Sgabeblack@google.com    # edge, so we'll arbitrarily chose which peer "wins" based on their names.
13813870Sgabeblack@google.com    if full_peer_port_name < full_port_name:
13913870Sgabeblack@google.com        dir_type = {
14013870Sgabeblack@google.com            (False, False) : 'both',
14113870Sgabeblack@google.com            (True,  False) : 'forward',
14213870Sgabeblack@google.com            (False, True)  : 'back',
14313870Sgabeblack@google.com            (True,  True)  : 'none'
14413870Sgabeblack@google.com        }[ (port.is_source,
14513870Sgabeblack@google.com            peer.is_source) ]
14613870Sgabeblack@google.com        edge = pydot.Edge(full_port_name, full_peer_port_name, dir=dir_type)
14713870Sgabeblack@google.com        callgraph.add_edge(edge)
1488999Suri.wiener@arm.com
1498999Suri.wiener@arm.comdef dot_create_cluster(simNode, full_path, label):
1509854Sandreas.hansson@arm.com    # get the parameter values of the node and use them as a tooltip
1519854Sandreas.hansson@arm.com    ini_strings = []
1529854Sandreas.hansson@arm.com    for param in sorted(simNode._params.keys()):
1539854Sandreas.hansson@arm.com        value = simNode._values.get(param)
1549854Sandreas.hansson@arm.com        if value != None:
1559854Sandreas.hansson@arm.com            # parameter name = value in HTML friendly format
1569854Sandreas.hansson@arm.com            ini_strings.append(str(param) + "&#61;" +
1579854Sandreas.hansson@arm.com                               simNode._values[param].ini_str())
1589854Sandreas.hansson@arm.com    # join all the parameters with an HTML newline
15914060Stiago.muck@arm.com    tooltip = "&#10;\\".join(ini_strings)
1609854Sandreas.hansson@arm.com
1618999Suri.wiener@arm.com    return pydot.Cluster( \
1628999Suri.wiener@arm.com                         full_path, \
1638999Suri.wiener@arm.com                         shape = "Mrecord", \
1648999Suri.wiener@arm.com                         label = label, \
1659854Sandreas.hansson@arm.com                         tooltip = "\"" + tooltip + "\"", \
1668999Suri.wiener@arm.com                         style = "\"rounded, filled\"", \
1678999Suri.wiener@arm.com                         color = "#000000", \
1689853Sandreas.hansson@arm.com                         fillcolor = dot_gen_colour(simNode), \
1698999Suri.wiener@arm.com                         fontname = "Arial", \
1708999Suri.wiener@arm.com                         fontsize = "14", \
1718999Suri.wiener@arm.com                         fontcolor = "#000000" \
1728999Suri.wiener@arm.com                         )
1738999Suri.wiener@arm.com
1748999Suri.wiener@arm.comdef dot_create_node(simNode, full_path, label):
1758999Suri.wiener@arm.com    return pydot.Node( \
1768999Suri.wiener@arm.com                         full_path, \
1778999Suri.wiener@arm.com                         shape = "Mrecord", \
1788999Suri.wiener@arm.com                         label = label, \
1798999Suri.wiener@arm.com                         style = "\"rounded, filled\"", \
1808999Suri.wiener@arm.com                         color = "#000000", \
1819853Sandreas.hansson@arm.com                         fillcolor = dot_gen_colour(simNode, True), \
1828999Suri.wiener@arm.com                         fontname = "Arial", \
1838999Suri.wiener@arm.com                         fontsize = "14", \
1848999Suri.wiener@arm.com                         fontcolor = "#000000" \
1858999Suri.wiener@arm.com                         )
1868999Suri.wiener@arm.com
1879853Sandreas.hansson@arm.com# an enumerator for different kinds of node types, at the moment we
1889853Sandreas.hansson@arm.com# discern the majority of node types, with the caches being the
1899853Sandreas.hansson@arm.com# notable exception
1909853Sandreas.hansson@arm.comclass NodeType:
1919853Sandreas.hansson@arm.com    SYS = 0
1929853Sandreas.hansson@arm.com    CPU = 1
19310405Sandreas.hansson@arm.com    XBAR = 2
1949853Sandreas.hansson@arm.com    MEM = 3
1959853Sandreas.hansson@arm.com    DEV = 4
1969853Sandreas.hansson@arm.com    OTHER = 5
1979853Sandreas.hansson@arm.com
1989853Sandreas.hansson@arm.com# based on the sim object, determine the node type
1999853Sandreas.hansson@arm.comdef get_node_type(simNode):
2009853Sandreas.hansson@arm.com    if isinstance(simNode, m5.objects.System):
2019853Sandreas.hansson@arm.com        return NodeType.SYS
2029853Sandreas.hansson@arm.com    # NULL ISA has no BaseCPU or PioDevice, so check if these names
2039853Sandreas.hansson@arm.com    # exists before using them
2049853Sandreas.hansson@arm.com    elif 'BaseCPU' in dir(m5.objects) and \
2059853Sandreas.hansson@arm.com            isinstance(simNode, m5.objects.BaseCPU):
2069853Sandreas.hansson@arm.com        return NodeType.CPU
2079853Sandreas.hansson@arm.com    elif 'PioDevice' in dir(m5.objects) and \
2089853Sandreas.hansson@arm.com            isinstance(simNode, m5.objects.PioDevice):
2099853Sandreas.hansson@arm.com        return NodeType.DEV
21010405Sandreas.hansson@arm.com    elif isinstance(simNode, m5.objects.BaseXBar):
21110405Sandreas.hansson@arm.com        return NodeType.XBAR
2129853Sandreas.hansson@arm.com    elif isinstance(simNode, m5.objects.AbstractMemory):
2139853Sandreas.hansson@arm.com        return NodeType.MEM
2149853Sandreas.hansson@arm.com    else:
2159853Sandreas.hansson@arm.com        return NodeType.OTHER
2169853Sandreas.hansson@arm.com
2179853Sandreas.hansson@arm.com# based on the node type, determine the colour as an RGB tuple, the
2189853Sandreas.hansson@arm.com# palette is rather arbitrary at this point (some coherent natural
2199853Sandreas.hansson@arm.com# tones), and someone that feels artistic should probably have a look
2209853Sandreas.hansson@arm.comdef get_type_colour(nodeType):
2219853Sandreas.hansson@arm.com    if nodeType == NodeType.SYS:
2229853Sandreas.hansson@arm.com        return (228, 231, 235)
2239853Sandreas.hansson@arm.com    elif nodeType == NodeType.CPU:
2249853Sandreas.hansson@arm.com        return (187, 198, 217)
22510405Sandreas.hansson@arm.com    elif nodeType == NodeType.XBAR:
2269853Sandreas.hansson@arm.com        return (111, 121, 140)
2279853Sandreas.hansson@arm.com    elif nodeType == NodeType.MEM:
2289853Sandreas.hansson@arm.com        return (94, 89, 88)
2299853Sandreas.hansson@arm.com    elif nodeType == NodeType.DEV:
2309853Sandreas.hansson@arm.com        return (199, 167, 147)
2319853Sandreas.hansson@arm.com    elif nodeType == NodeType.OTHER:
2329853Sandreas.hansson@arm.com        # use a relatively gray shade
2339853Sandreas.hansson@arm.com        return (186, 182, 174)
2349853Sandreas.hansson@arm.com
2359853Sandreas.hansson@arm.com# generate colour for a node, either corresponding to a sim object or a
2369853Sandreas.hansson@arm.com# port
2379853Sandreas.hansson@arm.comdef dot_gen_colour(simNode, isPort = False):
2389853Sandreas.hansson@arm.com    # determine the type of the current node, and also its parent, if
2399853Sandreas.hansson@arm.com    # the node is not the same type as the parent then we use the base
2409853Sandreas.hansson@arm.com    # colour for its type
2419853Sandreas.hansson@arm.com    node_type = get_node_type(simNode)
2429853Sandreas.hansson@arm.com    if simNode._parent:
2439853Sandreas.hansson@arm.com        parent_type = get_node_type(simNode._parent)
2449853Sandreas.hansson@arm.com    else:
2459853Sandreas.hansson@arm.com        parent_type = NodeType.OTHER
2469853Sandreas.hansson@arm.com
2479853Sandreas.hansson@arm.com    # if this node is the same type as the parent, then scale the
2489853Sandreas.hansson@arm.com    # colour based on the depth such that the deeper levels in the
2499853Sandreas.hansson@arm.com    # hierarchy get darker colours
2509853Sandreas.hansson@arm.com    if node_type == parent_type:
2519853Sandreas.hansson@arm.com        # start out with a depth of zero
2529853Sandreas.hansson@arm.com        depth = 0
2539853Sandreas.hansson@arm.com        parent = simNode._parent
2549853Sandreas.hansson@arm.com        # find the closes parent that is not the same type
2559853Sandreas.hansson@arm.com        while parent and get_node_type(parent) == parent_type:
2569853Sandreas.hansson@arm.com            depth = depth + 1
2579853Sandreas.hansson@arm.com            parent = parent._parent
2589853Sandreas.hansson@arm.com        node_colour = get_type_colour(parent_type)
2599853Sandreas.hansson@arm.com        # slightly arbitrary, but assume that the depth is less than
2609853Sandreas.hansson@arm.com        # five levels
2619853Sandreas.hansson@arm.com        r, g, b = map(lambda x: x * max(1 - depth / 7.0, 0.3), node_colour)
2629853Sandreas.hansson@arm.com    else:
2639853Sandreas.hansson@arm.com        node_colour = get_type_colour(node_type)
2649853Sandreas.hansson@arm.com        r, g, b = node_colour
2659853Sandreas.hansson@arm.com
2669853Sandreas.hansson@arm.com    # if we are colouring a port, then make it a slightly darker shade
2679853Sandreas.hansson@arm.com    # than the node that encapsulates it, once again use a magic constant
2689853Sandreas.hansson@arm.com    if isPort:
2699853Sandreas.hansson@arm.com        r, g, b = map(lambda x: 0.8 * x, (r, g, b))
2708999Suri.wiener@arm.com
2719852Sandreas.hansson@arm.com    return dot_rgb_to_html(r, g, b)
2729852Sandreas.hansson@arm.com
2739852Sandreas.hansson@arm.comdef dot_rgb_to_html(r, g, b):
2748999Suri.wiener@arm.com    return "#%.2x%.2x%.2x" % (r, g, b)
2758999Suri.wiener@arm.com
27611418Ssascha.bischoff@arm.com# We need to create all of the clock domains. We abuse the alpha channel to get
27711418Ssascha.bischoff@arm.com# the correct domain colouring.
27811418Ssascha.bischoff@arm.comdef dot_add_clk_domain(c_dom, v_dom):
27911418Ssascha.bischoff@arm.com    label = "\"" + str(c_dom) + "\ :\ " + str(v_dom) + "\""
28011418Ssascha.bischoff@arm.com    label = re.sub('\.', '_', str(label))
28111418Ssascha.bischoff@arm.com    full_path = re.sub('\.', '_', str(c_dom))
28211418Ssascha.bischoff@arm.com    return pydot.Cluster( \
28311418Ssascha.bischoff@arm.com                     full_path, \
28411418Ssascha.bischoff@arm.com                     shape = "Mrecord", \
28511418Ssascha.bischoff@arm.com                     label = label, \
28611418Ssascha.bischoff@arm.com                     style = "\"rounded, filled, dashed\"", \
28711418Ssascha.bischoff@arm.com                     color = "#000000", \
28811418Ssascha.bischoff@arm.com                     fillcolor = "#AFC8AF8F", \
28911418Ssascha.bischoff@arm.com                     fontname = "Arial", \
29011418Ssascha.bischoff@arm.com                     fontsize = "14", \
29111418Ssascha.bischoff@arm.com                     fontcolor = "#000000" \
29211418Ssascha.bischoff@arm.com                     )
29311418Ssascha.bischoff@arm.com
29411418Ssascha.bischoff@arm.comdef dot_create_dvfs_nodes(simNode, callgraph, domain=None):
29511418Ssascha.bischoff@arm.com    if isRoot(simNode):
29611418Ssascha.bischoff@arm.com        label = "root"
29711418Ssascha.bischoff@arm.com    else:
29811418Ssascha.bischoff@arm.com        label = simNode._name
29911418Ssascha.bischoff@arm.com    full_path = re.sub('\.', '_', simNode.path())
30011418Ssascha.bischoff@arm.com    # add class name under the label
30111418Ssascha.bischoff@arm.com    label = "\"" + label + " \\n: " + simNode.__class__.__name__ + "\""
30211418Ssascha.bischoff@arm.com
30311418Ssascha.bischoff@arm.com    # each component is a sub-graph (cluster)
30411418Ssascha.bischoff@arm.com    cluster = dot_create_cluster(simNode, full_path, label)
30511418Ssascha.bischoff@arm.com
30611418Ssascha.bischoff@arm.com    # create nodes per port
30711418Ssascha.bischoff@arm.com    for port_name in simNode._ports.keys():
30811418Ssascha.bischoff@arm.com        port = simNode._port_refs.get(port_name, None)
30911418Ssascha.bischoff@arm.com        if port != None:
31011418Ssascha.bischoff@arm.com            full_port_name = full_path + "_" + port_name
31111418Ssascha.bischoff@arm.com            port_node = dot_create_node(simNode, full_port_name, port_name)
31211418Ssascha.bischoff@arm.com            cluster.add_node(port_node)
31311418Ssascha.bischoff@arm.com
31411418Ssascha.bischoff@arm.com    # Dictionary of DVFS domains
31511418Ssascha.bischoff@arm.com    dvfs_domains = {}
31611418Ssascha.bischoff@arm.com
31711418Ssascha.bischoff@arm.com    # recurse to children
31812202Sgabeblack@google.com    for child in simnode_children(simNode):
31912202Sgabeblack@google.com        try:
32012202Sgabeblack@google.com            c_dom = child.__getattr__('clk_domain')
32112202Sgabeblack@google.com            v_dom = c_dom.__getattr__('voltage_domain')
32212202Sgabeblack@google.com        except AttributeError:
32312202Sgabeblack@google.com            # Just re-use the domain from above
32412202Sgabeblack@google.com            c_dom = domain
32512202Sgabeblack@google.com            v_dom = c_dom.__getattr__('voltage_domain')
32612202Sgabeblack@google.com            pass
32711418Ssascha.bischoff@arm.com
32812202Sgabeblack@google.com        if c_dom == domain or c_dom == None:
32912202Sgabeblack@google.com            dot_create_dvfs_nodes(child, cluster, domain)
33012202Sgabeblack@google.com        else:
33112202Sgabeblack@google.com            if c_dom not in dvfs_domains:
33212202Sgabeblack@google.com                dvfs_cluster = dot_add_clk_domain(c_dom, v_dom)
33312202Sgabeblack@google.com                dvfs_domains[c_dom] = dvfs_cluster
33411418Ssascha.bischoff@arm.com            else:
33512202Sgabeblack@google.com                dvfs_cluster = dvfs_domains[c_dom]
33612202Sgabeblack@google.com            dot_create_dvfs_nodes(child, dvfs_cluster, c_dom)
33711418Ssascha.bischoff@arm.com
33811418Ssascha.bischoff@arm.com    for key in dvfs_domains:
33911418Ssascha.bischoff@arm.com        cluster.add_subgraph(dvfs_domains[key])
34011418Ssascha.bischoff@arm.com
34111418Ssascha.bischoff@arm.com    callgraph.add_subgraph(cluster)
34211418Ssascha.bischoff@arm.com
3438999Suri.wiener@arm.comdef do_dot(root, outdir, dotFilename):
3448999Suri.wiener@arm.com    if not pydot:
3458999Suri.wiener@arm.com        return
3469852Sandreas.hansson@arm.com    # * use ranksep > 1.0 for for vertical separation between nodes
3479852Sandreas.hansson@arm.com    # especially useful if you need to annotate edges using e.g. visio
3489852Sandreas.hansson@arm.com    # which accepts svg format
3499852Sandreas.hansson@arm.com    # * no need for hoizontal separation as nothing moves horizonally
3509852Sandreas.hansson@arm.com    callgraph = pydot.Dot(graph_type='digraph', ranksep='1.3')
3518999Suri.wiener@arm.com    dot_create_nodes(root, callgraph)
3528999Suri.wiener@arm.com    dot_create_edges(root, callgraph)
3538999Suri.wiener@arm.com    dot_filename = os.path.join(outdir, dotFilename)
3548999Suri.wiener@arm.com    callgraph.write(dot_filename)
3558999Suri.wiener@arm.com    try:
3568999Suri.wiener@arm.com        # dot crashes if the figure is extremely wide.
3578999Suri.wiener@arm.com        # So avoid terminating simulation unnecessarily
3589852Sandreas.hansson@arm.com        callgraph.write_svg(dot_filename + ".svg")
3598999Suri.wiener@arm.com        callgraph.write_pdf(dot_filename + ".pdf")
3608999Suri.wiener@arm.com    except:
3619853Sandreas.hansson@arm.com        warn("failed to generate dot output from %s", dot_filename)
36211418Ssascha.bischoff@arm.com
36311418Ssascha.bischoff@arm.comdef do_dvfs_dot(root, outdir, dotFilename):
36411418Ssascha.bischoff@arm.com    if not pydot:
36511418Ssascha.bischoff@arm.com        return
36611431Ssascha.bischoff@arm.com
36711431Ssascha.bischoff@arm.com    # There is a chance that we are unable to resolve the clock or
36811431Ssascha.bischoff@arm.com    # voltage domains. If so, we fail silently.
36911431Ssascha.bischoff@arm.com    try:
37011431Ssascha.bischoff@arm.com        dvfsgraph = pydot.Dot(graph_type='digraph', ranksep='1.3')
37111431Ssascha.bischoff@arm.com        dot_create_dvfs_nodes(root, dvfsgraph)
37211431Ssascha.bischoff@arm.com        dot_create_edges(root, dvfsgraph)
37311431Ssascha.bischoff@arm.com        dot_filename = os.path.join(outdir, dotFilename)
37411431Ssascha.bischoff@arm.com        dvfsgraph.write(dot_filename)
37511431Ssascha.bischoff@arm.com    except:
37611431Ssascha.bischoff@arm.com        warn("Failed to generate dot graph for DVFS domains")
37711431Ssascha.bischoff@arm.com        return
37811431Ssascha.bischoff@arm.com
37911418Ssascha.bischoff@arm.com    try:
38011418Ssascha.bischoff@arm.com        # dot crashes if the figure is extremely wide.
38111418Ssascha.bischoff@arm.com        # So avoid terminating simulation unnecessarily
38211418Ssascha.bischoff@arm.com        dvfsgraph.write_svg(dot_filename + ".svg")
38311418Ssascha.bischoff@arm.com        dvfsgraph.write_pdf(dot_filename + ".pdf")
38411418Ssascha.bischoff@arm.com    except:
38511418Ssascha.bischoff@arm.com        warn("failed to generate dot output from %s", dot_filename)
386