CMS 3D CMS Logo

ProcessCallGraph.h
Go to the documentation of this file.
1 #ifndef HLTrigger_Timer_interface_ProcessCallGraph_h
2 #define HLTrigger_Timer_interface_ProcessCallGraph_h
3 
4 /*
5  *
6  */
7 
8 #include <iostream>
9 #include <vector>
10 #include <string>
11 #include <type_traits>
12 
13 // boost optional (used by boost graph) results in some false positives with -Wmaybe-uninitialized
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
16 #include <boost/graph/adjacency_list.hpp>
17 #include <boost/graph/lookup_edge.hpp>
18 #include <boost/graph/subgraph.hpp>
19 #pragma GCC diagnostic pop
20 
25 
27 public:
28 
29  struct NodeType {
32  bool scheduled_;
33  };
34 
35  // directed graph, with `NodeType` properties attached to each vertex
36  using GraphType = boost::subgraph<boost::adjacency_list<
37  // edge list
38  boost::vecS,
39  // vertex list
40  boost::vecS,
41  boost::directedS,
42  // vertex properties
43  NodeType,
44  // edge propoerties, used internally by boost::subgraph
45  boost::property<boost::edge_index_t, int>,
46  // graph properties, used to name each boost::subgraph
47  boost::property<boost::graph_name_t, std::string>
48  >>;
49 
50  // store the details of each path: name, modules on the path, and their dependencies
51  struct PathType {
53  std::vector<unsigned int> modules_on_path_;
54  std::vector<unsigned int> modules_and_dependencies_;
55  std::vector<unsigned int> last_dependency_of_module_; // one-after-the-last dependency of each module, as indices into modules_and_dependencies_
56 
57  PathType() = default;
58 
59  PathType(std::string const & name, std::vector<unsigned int> const & mop, std::vector<unsigned int> const & mad, std::vector<unsigned int> const & ldom) :
60  name_(name),
61  modules_on_path_(mop),
62  modules_and_dependencies_(mad),
63  last_dependency_of_module_(ldom)
64  { }
65 
66  PathType(std::string && name, std::vector<unsigned int> && mop, std::vector<unsigned int> && mad, std::vector<unsigned int> && ldom) :
67  name_(std::move(name)),
68  modules_on_path_(std::move(mop)),
69  modules_and_dependencies_(std::move(mad)),
70  last_dependency_of_module_(std::move(ldom))
71  { }
72 
73  PathType(PathType const & other) = default;
74 
75  PathType(PathType && other) = default;
76 
77  ~PathType() = default;
78 
79  PathType & operator=(PathType const & other) = default;
80 
81  };
82 
83  // store the details of each process: name, modules call subgraph, modules, paths and endpaths, subprocess pids
84  struct ProcessType {
86  GraphType const & graph_;
87  std::vector<unsigned int> modules_;
88  std::vector<PathType> paths_;
89  std::vector<PathType> endPaths_;
90  std::vector<unsigned int> subprocesses_;
91 
92  ProcessType() = delete;
93 
95  std::string const & name,
96  GraphType const & graph,
97  std::vector<unsigned int> const & modules,
98  std::vector<PathType> const & paths,
99  std::vector<PathType> const & endPaths,
100  std::vector<unsigned int> const & subprocesses = {}
101  ) :
102  name_(name),
103  graph_(graph),
104  modules_(modules),
105  paths_(paths),
106  endPaths_(endPaths),
107  subprocesses_(subprocesses)
108  { }
109 
111  std::string && name,
112  GraphType const & graph,
113  std::vector<unsigned int> && modules,
114  std::vector<PathType> && paths,
115  std::vector<PathType> && endPaths,
116  std::vector<unsigned int> && subprocesses = {}
117  ) :
118  name_(std::move(name)),
119  graph_(graph),
120  modules_(std::move(modules)),
121  paths_(std::move(paths)),
122  endPaths_(std::move(endPaths)),
123  subprocesses_(std::move(subprocesses))
124  { }
125 
126  ProcessType(ProcessType const & other) = default;
127  ProcessType(ProcessType && other) = default;
128 
129  ProcessType & operator=(ProcessType const & other) = default;
130  ProcessType & operator=(ProcessType && other) = default;
131  };
132 
133 public:
134  // default c'tor
136 
137  // to be called from preSourceConstruction(...)
139 
140  // to be called from preBeginJob(...)
142 
143  // number of modules stored in the call graph
144  unsigned int size() const;
145 
146  // retrieve the ModuleDescription associated to the Source
147  edm::ModuleDescription const & source() const;
148 
149  // retrieve the ModuleDescription associated to the given id
150  edm::ModuleDescription const & module(unsigned int module) const;
151 
152  // retrieve the full information for a given module
153  NodeType const & operator[](unsigned int module) const;
154 
155  // find the dependencies of the given module
156  std::vector<unsigned int> depends(unsigned int module) const;
157 
158  // find the dependencies of all modules in the given path
159  std::pair<std::vector<unsigned int>, std::vector<unsigned int>> dependencies(std::vector<unsigned int> const & path);
160 
161  // retrieve the "process id" of a process, given its ProcessContex
162  unsigned int processId(edm::ProcessContext const &) const;
163 
164  // retrieve the "process id" of a process, given its name
165  unsigned int processId(std::string const &) const;
166 
167  // retrieve the processes
168  std::vector<ProcessType> const & processes() const;
169 
170  // retrieve information about a process, given its "process id"
171  ProcessType const & processDescription(unsigned int) const;
172 
173  // retrieve information about a process, given its ProcessContex
174  ProcessType const & processDescription(edm::ProcessContext const &) const;
175 
176  // retrieve information about a process, given its name
177  ProcessType const & processDescription(std::string const &) const;
178 
179 private:
180 
181  // register a (sub)process and assigns it a "process id"
182  unsigned int registerProcess(edm::ProcessContext const &);
183 
184 private:
185 
187 
188  // module id of the Source
189  unsigned int source_;
190 
191  // map each (sub)process name to a "process id"
192  std::unordered_map<std::string, unsigned int> process_id_;
193 
194  // description of each process
195  std::vector<ProcessType> process_description_;
196 
197 };
198 
199 #endif // not defined HLTrigger_Timer_interface_ProcessCallGraph_h
std::vector< unsigned int > modules_on_path_
unsigned int registerProcess(edm::ProcessContext const &)
PathType(std::string &&name, std::vector< unsigned int > &&mop, std::vector< unsigned int > &&mad, std::vector< unsigned int > &&ldom)
std::vector< unsigned int > modules_and_dependencies_
EDMModuleType
Definition: EDMModuleType.h:8
PathType(std::string const &name, std::vector< unsigned int > const &mop, std::vector< unsigned int > const &mad, std::vector< unsigned int > const &ldom)
unsigned int processId(edm::ProcessContext const &) const
std::unordered_map< std::string, unsigned int > process_id_
edm::ModuleDescription const & source() const
ProcessType(std::string &&name, GraphType const &graph, std::vector< unsigned int > &&modules, std::vector< PathType > &&paths, std::vector< PathType > &&endPaths, std::vector< unsigned int > &&subprocesses={})
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
std::vector< ProcessType > const & processes() const
std::vector< PathType > paths_
ProcessType const & processDescription(unsigned int) const
edm::ModuleDescription module_
void preSourceConstruction(edm::ModuleDescription const &)
boost::subgraph< boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, NodeType, boost::property< boost::edge_index_t, int >, boost::property< boost::graph_name_t, std::string > >> GraphType
std::vector< ProcessType > process_description_
Definition: adjgraph.h:12
ProcessType(std::string const &name, GraphType const &graph, std::vector< unsigned int > const &modules, std::vector< PathType > const &paths, std::vector< PathType > const &endPaths, std::vector< unsigned int > const &subprocesses={})
std::vector< unsigned int > depends(unsigned int module) const
edm::EDMModuleType type_
std::vector< unsigned int > subprocesses_
std::vector< PathType > endPaths_
std::pair< std::vector< unsigned int >, std::vector< unsigned int > > dependencies(std::vector< unsigned int > const &path)
unsigned int size() const
edm::ModuleDescription const & module(unsigned int module) const
unsigned int source_
std::vector< unsigned int > last_dependency_of_module_
Definition: vlib.h:208
std::vector< unsigned int > modules_
def move(src, dest)
Definition: eostools.py:510
NodeType const & operator[](unsigned int module) const