CMS 3D CMS Logo

HLTPerformanceInfo.h
Go to the documentation of this file.
1 // -*-c++-*-
2 #ifndef HLTPERFORMANCEINFO_H
3 #define HLTPERFORMANCEINFO_H
4 
5 #include <string>
6 #include <vector>
7 #include <cassert>
8 
11 
13 public:
14  class Path;
15  class Module;
16  typedef std::vector<Path> PathList;
17  typedef std::vector<Module> Modules;
18  typedef std::vector<cms_uint32_t> ModulesInPath;
20  //
21  class Module {
22  private:
23  std::string name_; // module instance name
24  double dt_; // Wall-clock time
25  double dtCPU_; // CPU time
26  // I am using this even for modules....
28 
29  public:
30  Module() : name_("unknown") {}
31  // new constructor adding cpu time
32  Module(const char *n, const double dt, const double dtCPU, edm::HLTPathStatus stat = edm::hlt::Ready)
33  : name_(n), dt_(dt), dtCPU_(dtCPU), status_(stat) {}
34  std::string name() const { return name_; }
35  double time() const { return dt_; }
36  double cputime() const { return dtCPU_; }
37  edm::HLTPathStatus status() const { return status_; }
38  bool operator==(const char *tname) { return std::string(tname) == name(); }
39  void clear() {
40  dt_ = 0;
41  dtCPU_ = 0;
42  status_.reset(); // = edm::hlt::Ready;
43  }
44  void setTime(double t) { dt_ = t; }
45  void setCPUTime(double t) { dtCPU_ = t; }
47  // pw - can't a module be on different paths?
48  //void setStatusByPath(Path *path) ;
49  //int indexInPath(Path path) const ;
50  };
51  // end Module class definition
52 
53  // in this version the module can no longer iterate over the paths
54  // by itself, since it has no access to the actual module list.
55  class Path {
56  private:
58  ModulesInPath moduleView_; // indices into the module vector
60 
61  public:
62  Path(const std::string n = "unknown") : name_(n), moduleView_(), status_() {}
63  std::string name() const { return name_; }
65 
66  edm::HLTPathStatus status() const { return status_; }
67  void clear() {
68  status_.reset();
69  // time is dynamic, nothing to reset
70  }
71  bool operator==(const char *tname) { return (std::string(tname) == name()); }
72 
73  const size_t operator[](size_t m) const { return moduleView_.at(m); }
74 
75  void addModuleRef(size_t m) { moduleView_.push_back(m); }
76 
77  ModulesInPath::const_iterator begin() { return moduleView_.begin(); }
78  ModulesInPath::const_iterator end() { return moduleView_.end(); }
79  size_t getModuleIndex(size_t j) const { return moduleView_.at(j); }
80 
81  size_t numberOfModules() const { return moduleView_.size(); };
82  };
83  // end Path class definition
84 private:
87 
88 public:
89  void addPath(const Path &p) { paths_.push_back(p); }
90  void addModule(const Module &m) { modules_.push_back(m); }
91  // by name
92  void addModuleToPath(const char *mod, const char *path) {
93  // first make sure module exists
94  Modules::iterator m = findModule(mod);
95  if (m == endModules()) {
96  // new module - create it and stick it on the end
97  Module newMod(mod, 0, 0); // time (wall and cpu) = 0 since it wasn't run
98  modules_.push_back(newMod);
99  }
100 
101  for (size_t i = 0; i < paths_.size(); ++i) {
102  if (!(paths_[i] == path))
103  continue;
104  // we found the path, add module to the end
105  for (size_t j = 0; j < modules_.size(); ++j) {
106  if (!(modules_[j] == mod))
107  continue;
108  paths_[i].addModuleRef(j);
109  break;
110  }
111  break;
112  }
113  }
114  // by index
115  void addModuleToPath(const size_t mod, const size_t path) {
116  assert((path < paths_.size()) && (mod < modules_.size()));
117  paths_[path].addModuleRef(mod);
118  }
119 
120  void clear() {
121  modules_.clear();
122  paths_.clear();
123  }
124  void clearModules() {
125  for (size_t i = 0; i < modules_.size(); ++i) {
126  modules_[i].clear();
127  }
128  }
129 
130  // non-const?
131  const Module &getModuleOnPath(size_t m, size_t p) const;
132  const Module &getModule(size_t m) const { return modules_.at(m); }
133  const Path &getPath(size_t p) const { return paths_.at(p); }
134 
135  // find a module, given its name.
136  // returns endModules() on failure
137  Modules::iterator findModule(const char *moduleInstanceName);
138  PathList::iterator findPath(const char *pathName);
139 
140  int moduleIndexInPath(const char *mod, const char *path);
141 
142  size_t numberOfPaths() const { return paths_.size(); }
143  size_t numberOfModules() const { return modules_.size(); }
144 
145  PathList::iterator beginPaths() { return paths_.begin(); }
146  PathList::iterator endPaths() { return paths_.end(); }
147 
148  Modules::const_iterator beginModules() const { return modules_.begin(); }
149 
150  Modules::const_iterator endModules() const { return modules_.end(); }
151 
152  double totalTime() const;
153  double totalCPUTime() const;
154  double longestModuleTime() const;
155  double longestModuleCPUTime() const;
158 
159  double totalPathTime(const size_t path);
160  double totalPathCPUTime(const size_t path);
161 
162  void setStatusOfModulesFromPath(const char *pathName);
163 
164  // double lastModuleOnPathTime(const size_t pathnumber);
165  // double lastModuleOnPathCPUTime(const size_t pathnumber);
166 
167  // is this module only on one path?
168  bool uniqueModule(const char *mod) const;
169 };
170 
171 typedef std::vector<HLTPerformanceInfo> HLTPerformanceInfoCollection;
172 
173 #endif // HLTPERFORMANCEINFO_H
PathList::iterator findPath(const char *pathName)
std::string name() const
float dt
Definition: AMPTWrapper.h:136
std::vector< HLTPerformanceInfo > HLTPerformanceInfoCollection
bool operator==(const char *tname)
not [yet] run
Definition: HLTenums.h:17
edm::HLTPathStatus status() const
void reset()
reset this path
Definition: HLTPathStatus.h:54
void addModuleToPath(const size_t mod, const size_t path)
void addPath(const Path &p)
double totalPathTime(const size_t path)
double totalTime() const
assert(be >=bs)
edm::HLTPathStatus status_
size_t getModuleIndex(size_t j) const
const size_t operator[](size_t m) const
PathList::iterator beginPaths()
Modules::const_iterator endModules() const
Modules::const_iterator beginModules() const
void setStatus(const edm::HLTPathStatus &result)
void setStatusOfModulesFromPath(const char *pathName)
PathList::iterator endPaths()
edm::HLTPathStatus status() const
double longestModuleTime() const
double totalCPUTime() const
Path(const std::string n="unknown")
std::string longestModuleCPUTimeName() const
const Module & getModuleOnPath(size_t m, size_t p) const
double longestModuleCPUTime() const
bool operator==(const char *tname)
size_t numberOfPaths() const
std::vector< cms_uint32_t > ModulesInPath
double totalPathCPUTime(const size_t path)
ModulesInPath::const_iterator end()
bool uniqueModule(const char *mod) const
const Module & getModule(size_t m) const
Module(const char *n, const double dt, const double dtCPU, edm::HLTPathStatus stat=edm::hlt::Ready)
ModulesInPath::const_iterator begin()
size_t numberOfModules() const
std::string tname(const std::string &tableName, const std::string &schemaVersion)
std::string longestModuleTimeName() const
Modules::iterator findModule(const char *moduleInstanceName)
void addModuleToPath(const char *mod, const char *path)
std::vector< Module > Modules
void setStatus(edm::HLTPathStatus status)
const Path & getPath(size_t p) const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::vector< Path > PathList
void addModule(const Module &m)
int moduleIndexInPath(const char *mod, const char *path)