The Gaudi Framework  v36r1 (3e2fb5a8)
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 sys
18 import argparse
19 
20 # FIXME: workaround for the old version of networkx in LCG 100
21 import warnings
22 warnings.filterwarnings(
23  "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, 0)), "This script requires Networkx version 2.0 or higher"
33 
34  trace = nx.read_graphml(path_to_trace_file)
35 
36  for inNode, outNode, edge_attrs in trace.in_edges(data=True):
37  edge_attrs['Runtime'] = nx.get_node_attributes(trace,
38  'Runtime')[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 (ns)".format("Name"))
45  print(" -----------------------------------------------------")
46  for node_id in cpath:
47  print(" {:<40}: {}".format(trace.node[node_id].get('Name'),
48  trace.node[node_id].get('Runtime')))
49 
50  print("\nTotal critical path time: ",
51  nx.algorithms.dag.dag_longest_path_length(trace, weight='Runtime'),
52  "ns")
53 
54 
55 def main():
56 
57  parser = argparse.ArgumentParser(
58  description=
59  "Determine critical path for a precedence trace generated by the Avalanche Scheduler."
60  )
61  parser.add_argument(
62  "path_to_trace_file",
63  help="Path to GRAPHML precedence trace file.",
64  type=str)
65  args = parser.parse_args()
66 
67  get_critical_path(args.path_to_trace_file)
68 
69 
70 if __name__ == '__main__':
71  sys.exit(main())
getCriticalPath.main
def main()
Definition: getCriticalPath.py:55
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:391
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