Пример #1
0
def prof_view():
    """Called from a command line to generate an html viewer for profile data."""

    parser = argparse.ArgumentParser()
    parser.add_argument('--show', action='store_true', dest='show',
                        help="Pop up a browser to view the data.")
    parser.add_argument('-v','--viewer', action='store', dest='viewer',
                        default="icicle",
                        help="Select which viewer to use (sunburst or icicle)")
    parser.add_argument('rawfiles', metavar='rawfile', nargs='*',
                        help='File(s) containing raw profile data to be processed. Wildcards are allowed.')

    options = parser.parse_args()

    if not options.rawfiles:
        print("No files to process.")
        sys.exit(0)

    call_graph, totals = process_profile(options.rawfiles)

    viewer = options.viewer + ".html"
    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    graphjson = json.dumps(call_graph)

    outfile = 'profile_' + viewer
    with open(outfile, 'w') as f:
        s = template.replace("<call_graph_data>", graphjson)
        f.write(s)

    if options.show:
        webview(outfile)
Пример #2
0
def prof_view():
    """Called from a command line to generate an html viewer for profile data."""

    parser = argparse.ArgumentParser()
    parser.add_argument('--show',
                        action='store_true',
                        dest='show',
                        help="Pop up a browser to view the data.")
    parser.add_argument('-v',
                        '--viewer',
                        action='store',
                        dest='viewer',
                        default="icicle",
                        help="Select which viewer to use (sunburst or icicle)")
    parser.add_argument(
        'rawfiles',
        metavar='rawfile',
        nargs='*',
        help=
        'File(s) containing raw profile data to be processed. Wildcards are allowed.'
    )

    options = parser.parse_args()

    if not options.rawfiles:
        print("No files to process.")
        sys.exit(0)

    call_graph, totals = process_profile(options.rawfiles)

    viewer = options.viewer + ".html"
    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    graphjson = json.dumps(call_graph)

    outfile = 'profile_' + viewer
    with open(outfile, 'w') as f:
        s = template.replace("<call_graph_data>", graphjson)
        f.write(s)

    if options.show:
        webview(outfile)
Пример #3
0
def view_tree(problem, outfile='partition_tree_n2.html', show_browser=True):
    """
    Generates a self-contained html file containing a tree viewer
    of the specified type.  Optionally pops up a web browser to
    view the file.

    Args
    ----
    problem : Problem()
        The Problem (after problem.setup()) for the desired tree.

    outfile : str, optional
        The name of the output html file.  Defaults to 'partition_tree_n2.html'.

    show_browser : bool, optional
        If True, pop up a browser to view the generated html file.
        Defaults to True.
    """
    tree = _system_tree_dict(problem.root)
    viewer = 'partition_tree_n2.template'

    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    treejson = json.dumps(tree)

    myList = []
    for target, (src, idxs) in iteritems(problem._probdata.connections):
        myList.append({'src': src, 'tgt': target})
    connsjson = json.dumps(myList)

    with open(outfile, 'w') as f:
        f.write(template % (treejson, connsjson))

    if show_browser:
        from openmdao.devtools.d3graph import webview
        webview(outfile)
Пример #4
0
def view_tree(problem, outfile='partition_tree_n2.html', show_browser=True):
    """
    Generates a self-contained html file containing a tree viewer
    of the specified type.  Optionally pops up a web browser to
    view the file.

    Args
    ----
    problem : Problem()
        The Problem (after problem.setup()) for the desired tree.

    outfile : str, optional
        The name of the output html file.  Defaults to 'partition_tree_n2.html'.

    show_browser : bool, optional
        If True, pop up a browser to view the generated html file.
        Defaults to True.
    """
    tree = _system_tree_dict(problem.root)
    viewer = 'partition_tree_n2.template'

    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    treejson = json.dumps(tree)

    myList = []
    for target, (src, idxs) in iteritems(problem._probdata.connections):
        myList.append({'src':src, 'tgt':target})
    connsjson = json.dumps(myList)

    with open(outfile, 'w') as f:
        f.write(template % (treejson, connsjson))

    if show_browser:
        from openmdao.devtools.d3graph import webview
        webview(outfile)
Пример #5
0
def view_tree(problem, outfile='partition_tree_n2.html', show_browser=True, offline=True, embed=False):
    """
    Generates a self-contained html file containing a tree viewer
    of the specified type.  Optionally pops up a web browser to
    view the file.

    Args
    ----
    problem : Problem()
        The Problem (after problem.setup()) for the desired tree.

    outfile : str, optional
        The name of the output html file.  Defaults to 'partition_tree_n2.html'.

    show_browser : bool, optional
        If True, pop up the system default web browser to view the generated html file.
        Defaults to True.

    offline : bool, optional
        If True, embed the javascript d3 library into the generated html file so that the tree can be viewed
        offline without an internet connection.  Otherwise if False, have the html request the latest d3 file
        from https://d3js.org/d3.v4.min.js when opening the html file.
        Defaults to True.

    embed : bool, optional
        If True, export only the innerHTML that is between the body tags, used for embedding the viewer into another html file.
        If False, create a standalone HTML file that has the DOCTYPE, html, head, meta, and body tags.
        Defaults to False.
    """
    component_execution_orders = {}
    component_execution_index = [0] #list so pass by ref
    tree = _system_tree_dict(problem.root, component_execution_orders, component_execution_index)
    viewer = 'partition_tree_n2.template'

    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    html_begin_tags = ("<!DOCTYPE html>\n"
        "<html>\n"
        "<head>\n"
        "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"
        "</head>\n"
        "<body>\n")

    html_end_tags = ("</body>\n"
        "</html>\n")

    if embed:
        html_begin_tags = html_end_tags = ""

    d3_library = "<script src=\"https://d3js.org/d3.v4.min.js\" charset=\"utf-8\"></script>"
    if offline:
        with open(os.path.join(code_dir, 'd3.v4.min.js'), "r") as f:
            d3_library = "<script type=\"text/javascript\"> %s </script>" % (f.read())

    treejson = json.dumps(tree)

    connections_list = []
    G = problem._probdata.relevance._sgraph
    scc = nx.strongly_connected_components(G)
    scc_list = [s for s in scc if len(s)>1] #list(scc)

    for tgt, (src, idxs) in iteritems(problem._probdata.connections):
        src_subsystem = src.rsplit('.', 1)[0]
        tgt_subsystem = tgt.rsplit('.', 1)[0]


        count = 0
        edges_set = set()
        for li in scc_list:
            if src_subsystem in li and tgt_subsystem in li:
                count = count+1
                if(count > 1):
                    raise ValueError('Count greater than 1')

                exe_tgt = component_execution_orders[tgt_subsystem]
                exe_src = component_execution_orders[src_subsystem]
                exe_low = min(exe_tgt,exe_src)
                exe_high = max(exe_tgt,exe_src)
                subg = G.subgraph(li)
                for n in subg.nodes():
                    exe_order = component_execution_orders[n]
                    if(exe_order < exe_low or exe_order > exe_high):
                        subg.remove_node(n)


                list_sim = list(nx.all_simple_paths(subg,source=tgt_subsystem,target=src_subsystem))





                for this_list in list_sim:
                    if(len(this_list) >= 2):
                        for i in range(len(this_list)-1):
                            edge_str = this_list[i] + ' ' + this_list[i+1]
                            edges_set.add(edge_str)


        edges_set_list = list(edges_set)
        if(len(edges_set_list) > 0):
            connections_list.append({'src':src, 'tgt':tgt, 'cycle_arrows': edges_set_list})
        else:
            connections_list.append({'src':src, 'tgt':tgt})

    connsjson = json.dumps(connections_list)

    with open(outfile, 'w') as f:
        f.write(template % (html_begin_tags, d3_library, treejson, connsjson, html_end_tags))

    if show_browser:
        from openmdao.devtools.d3graph import webview
        webview(outfile)
Пример #6
0
def view_tree(problem, outfile='partition_tree_n2.html', show_browser=True):
    """
    Generates a self-contained html file containing a tree viewer
    of the specified type.  Optionally pops up a web browser to
    view the file.

    Args
    ----
    problem : Problem()
        The Problem (after problem.setup()) for the desired tree.

    outfile : str, optional
        The name of the output html file.  Defaults to 'partition_tree_n2.html'.

    show_browser : bool, optional
        If True, pop up a browser to view the generated html file.
        Defaults to True.
    """
    component_execution_orders = {}
    component_execution_index = [0] #list so pass by ref
    tree = _system_tree_dict(problem.root, component_execution_orders, component_execution_index)
    viewer = 'partition_tree_n2.template'

    code_dir = os.path.dirname(os.path.abspath(__file__))

    with open(os.path.join(code_dir, viewer), "r") as f:
        template = f.read()

    treejson = json.dumps(tree)

    connections_list = []
    G = problem._probdata.relevance._sgraph
    scc = nx.strongly_connected_components(G)
    scc_list = [s for s in scc if len(s)>1] #list(scc)

    for tgt, (src, idxs) in iteritems(problem._probdata.connections):
        src_subsystem = src.rsplit('.', 1)[0]
        tgt_subsystem = tgt.rsplit('.', 1)[0]


        count = 0
        edges_set = set()
        for li in scc_list:
            if src_subsystem in li and tgt_subsystem in li:
                count = count+1
                if(count > 1):
                    raise ValueError('Count greater than 1')

                exe_tgt = component_execution_orders[tgt_subsystem]
                exe_src = component_execution_orders[src_subsystem]
                exe_low = min(exe_tgt,exe_src)
                exe_high = max(exe_tgt,exe_src)
                subg = G.subgraph(li)
                for n in subg.nodes():
                    exe_order = component_execution_orders[n]
                    if(exe_order < exe_low or exe_order > exe_high):
                        subg.remove_node(n)


                list_sim = list(nx.all_simple_paths(subg,source=tgt_subsystem,target=src_subsystem))





                for this_list in list_sim:
                    if(len(this_list) >= 2):
                        for i in range(len(this_list)-1):
                            edge_str = this_list[i] + ' ' + this_list[i+1]
                            edges_set.add(edge_str)


        edges_set_list = list(edges_set)
        if(len(edges_set_list) > 0):
            connections_list.append({'src':src, 'tgt':tgt, 'cycle_arrows': edges_set_list})
        else:
            connections_list.append({'src':src, 'tgt':tgt})

    connsjson = json.dumps(connections_list)

    with open(outfile, 'w') as f:
        f.write(template % (treejson, connsjson))

    if show_browser:
        from openmdao.devtools.d3graph import webview
        webview(outfile)