The Gaudi Framework  master (37c0b60a)
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 
16 import argparse
17 import sys
18 
19 # FIXME: workaround for the old version of networkx in LCG 100
20 import warnings
21 
22 warnings.filterwarnings("ignore", message='"is" with a literal', category=SyntaxWarning)
23 
24 import networkx as nx
25 
26 
27 def 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 
61 def 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 
73 if __name__ == "__main__":
74  sys.exit(main())
getCriticalPath.main
def main()
Definition: getCriticalPath.py:61
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:35
getCriticalPath.get_critical_path
def get_critical_path(path_to_trace_file)
Definition: getCriticalPath.py:27
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119