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