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(
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".