The Gaudi Framework  v33r1 (b1225454)
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 
14 __author__ = "Illya Shapoval"
15 
16 import sys
17 import argparse
18 import networkx as nx
19 
20 
21 def get_critical_path(path_to_trace_file):
22  """Find critical path, print algorithms on it and its length."""
23 
24  assert float(
25  nx.__version__
26  ) >= 2.0, "This script requires Networkx version 2.0 or higher"
27 
28  trace = nx.read_graphml(path_to_trace_file)
29 
30  for inNode, outNode, edge_attrs in trace.in_edges(data=True):
31  edge_attrs['Runtime'] = nx.get_node_attributes(trace,
32  'Runtime')[outNode]
33 
34  cpath = nx.algorithms.dag.dag_longest_path(trace, weight='Runtime')
35 
36  print "Algorithms on the critical path (%i): " % len(cpath)
37 
38  print " {:<40} Runtime (ns)".format("Name")
39  print " -----------------------------------------------------"
40  for node_id in cpath:
41  print " {:<40}: {}".format(trace.node[node_id].get('Name'),
42  trace.node[node_id].get('Runtime'))
43 
44  print "\nTotal critical path time: ", nx.algorithms.dag.dag_longest_path_length(
45  trace, weight='Runtime'), "ns"
46 
47 
48 def main():
49 
50  parser = argparse.ArgumentParser(
51  description=
52  "Determine critical path for a precedence trace generated by the Avalanche Scheduler."
53  )
54  parser.add_argument(
55  "path_to_trace_file",
56  help="Path to GRAPHML precedence trace file.",
57  type=str)
58  args = parser.parse_args()
59 
60  get_critical_path(args.path_to_trace_file)
61 
62 
63 if __name__ == '__main__':
64  sys.exit(main())
def get_critical_path(path_to_trace_file)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))