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