The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
getCriticalPath.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
12"""Determine critical path for a given precedence trace."""
13
14__author__ = "Illya Shapoval"
15
16import argparse
17import sys
18
19# FIXME: workaround for the old version of networkx in LCG 100
20import warnings
21
22warnings.filterwarnings("ignore", message='"is" with a literal', category=SyntaxWarning)
23
24import networkx as nx
25
26
27def get_critical_path(path_to_trace_file):
28 """Find critical path, print algorithms on it and its length."""
29
30 assert tuple(map(int, nx.__version__.split("."))) >= (
31 2,
32 0,
33 ), "This script requires Networkx version 2.0 or higher"
34
35 trace = nx.read_graphml(path_to_trace_file)
36
37 for inNode, outNode, edge_attrs in trace.in_edges(data=True):
38 edge_attrs["Runtime"] = nx.get_node_attributes(trace, "Run Time (us)")[outNode]
39
40 cpath = nx.algorithms.dag.dag_longest_path(trace, weight="Runtime")
41
42 print("Algorithms on the critical path (%i): " % len(cpath))
43
44 print(" {:<40} Runtime (us)".format("Name"))
45 print(" -----------------------------------------------------")
46 for node_id in cpath:
47 print(
48 " {:<40}: {}".format(
49 trace.nodes[node_id].get("Name"),
50 trace.nodes[node_id].get("Run Time (us)"),
51 )
52 )
53
54 print(
55 "\nTotal critical path time: ",
56 nx.algorithms.dag.dag_longest_path_length(trace, weight="Runtime"),
57 "us",
58 )
59
60
61def main():
62 parser = argparse.ArgumentParser(
63 description="Determine critical path for a precedence trace generated by the Avalanche Scheduler."
64 )
65 parser.add_argument(
66 "path_to_trace_file", help="Path to GRAPHML precedence trace file.", type=str
67 )
68 args = parser.parse_args()
69
70 get_critical_path(args.path_to_trace_file)
71
72
73if __name__ == "__main__":
74 sys.exit(main())
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
get_critical_path(path_to_trace_file)