| The Gaudi Framework v32r1 (f65d50dc)

getCriticalPath.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """Determine critical path for a given precedence trace."""
3
4 __author__ = "Illya Shapoval"
5
6 import sys
7 import argparse
8 import networkx as nx
9
10
11 def get_critical_path(path_to_trace_file):
12 """Find critical path, print algorithms on it and its length."""
13
14 assert float(
15 nx.__version__
16 ) >= 2.0, "This script requires Networkx version 2.0 or higher"
17
18 trace = nx.read_graphml(path_to_trace_file)
19
20 for inNode, outNode, edge_attrs in trace.in_edges(data=True):
21 edge_attrs['Runtime'] = nx.get_node_attributes(trace,
22 'Runtime')[outNode]
23
24 cpath = nx.algorithms.dag.dag_longest_path(trace, weight='Runtime')
25
26 print "Algorithms on the critical path (%i): " % len(cpath)
27
28 print " {:<40} Runtime (ns)".format("Name")
29 print " -----------------------------------------------------"
30 for node_id in cpath:
31 print " {:<40}: {}".format(trace.node[node_id].get('Name'),
32 trace.node[node_id].get('Runtime'))
33
34 print "\nTotal critical path time: ", nx.algorithms.dag.dag_longest_path_length(
35 trace, weight='Runtime'), "ns"
36
37
38 def main():
39
40 parser = argparse.ArgumentParser(
41 description=
42 "Determine critical path for a precedence trace generated by the Avalanche Scheduler."
43 )
44 parser.add_argument(
45 "path_to_trace_file",
46 help="Path to GRAPHML precedence trace file.",
47 type=str)
48 args = parser.parse_args()
49
50 get_critical_path(args.path_to_trace_file)
51
52
53 if __name__ == '__main__':
54 sys.exit(main())
getCriticalPath.get_critical_path
def get_critical_path(path_to_trace_file)
Definition: getCriticalPath.py:11
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:332
getCriticalPath.main
def main()
Definition: getCriticalPath.py:38