CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTPerformanceInfo.h
Go to the documentation of this file.
1 // -*-c++-*-
2 // $Id: HLTPerformanceInfo.h,v 1.15 2013/04/02 09:10:28 fwyzard Exp $
3 #ifndef HLTPERFORMANCEINFO_H
4 #define HLTPERFORMANCEINFO_H
5 
6 #include <string>
7 #include <vector>
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  public:
29  Module()
30  : name_("unknown")
31  {}
32  // new constructor adding cpu time
33  Module(const char *n, const double dt, const double dtCPU,
35  : name_(n), dt_(dt), dtCPU_(dtCPU), status_(stat)
36  { }
37  std::string name() const {
38  return name_;
39  }
40  double time() const { return dt_; }
41  double cputime() const { return dtCPU_; }
42  edm::HLTPathStatus status() const { return status_; }
43  bool operator==(const char *tname ) {
44  return std::string(tname) == name();
45  }
46  void clear() {
47  dt_ = 0 ;
48  dtCPU_ = 0 ;
49  status_.reset();// = edm::hlt::Ready;
50  }
51  void setTime(double t) { dt_=t;}
52  void setCPUTime(double t) { dtCPU_=t;}
54  // pw - can't a module be on different paths?
55  //void setStatusByPath(Path *path) ;
56  //int indexInPath(Path path) const ;
57 
58  };
59  // end Module class definition
60 
61  // in this version the module can no longer iterate over the paths
62  // by itself, since it has no access to the actual module list.
63  class Path {
64  private:
66  ModulesInPath moduleView_; // indices into the module vector
68 
69  public:
70  Path(const std::string n = "unknown") :
71  name_(n),
72  moduleView_(),
73  status_()
74  {}
75  std::string name() const {
76  return name_;
77  }
79  status_ = result;
80  }
81 
83  return status_;
84  }
85  void clear() {
86  status_.reset();
87  // time is dynamic, nothing to reset
88  }
89  bool operator==( const char* tname) {
90  return (std::string(tname) == name());
91  }
92 
93  const size_t operator[](size_t m) const {
94  return moduleView_.at(m);
95  }
96 
97  void addModuleRef( size_t m) {
98  moduleView_.push_back(m);
99  }
100 
101  ModulesInPath::const_iterator begin() {
102  return moduleView_.begin();
103  }
104  ModulesInPath::const_iterator end() {
105  return moduleView_.end();
106  }
107  size_t getModuleIndex(size_t j) const {
108  return moduleView_.at(j);
109  }
110 
111  size_t numberOfModules() const { return moduleView_.size(); };
112 
113  };
114  // end Path class definition
115 private:
118 
119 public:
120  void addPath(const Path & p) {
121  paths_.push_back(p);
122  }
123  void addModule(const Module & m ) {
124  modules_.push_back(m);
125  }
126  // by name
127  void addModuleToPath(const char *mod, const char *path) {
128  // first make sure module exists
129  Modules::iterator m = findModule(mod);
130  if ( m == endModules() ) {
131  // new module - create it and stick it on the end
132  Module newMod(mod, 0, 0); // time (wall and cpu) = 0 since it wasn't run
133  modules_.push_back(newMod);
134  }
135 
136  for ( size_t i = 0; i < paths_.size(); ++i ) {
137  if ( !( paths_[i] == path ) ) continue;
138  // we found the path, add module to the end
139  for ( size_t j = 0; j < modules_.size(); ++j ) {
140  if ( !(modules_[j] == mod) ) continue;
141  paths_[i].addModuleRef(j);
142  break;
143  }
144  break;
145  }
146  }
147  // by index
148  void addModuleToPath(const size_t mod, const size_t path) {
149  assert(( path <paths_.size()) && (mod < modules_.size()) );
150  paths_[path].addModuleRef(mod);
151  }
152 
153  void clear() {
154  modules_.clear(); paths_.clear();
155  }
156  void clearModules() {
157  for ( size_t i = 0; i < modules_.size(); ++i ) {
158  modules_[i].clear();
159  }
160  }
161 
162  // non-const?
163  const Module & getModuleOnPath(size_t m, size_t p) const ;
164  const Module & getModule(size_t m) const { return modules_.at(m); }
165  const Path & getPath(size_t p) const { return paths_.at(p); }
166 
167 
168  // find a module, given its name.
169  // returns endModules() on failure
170  Modules::iterator findModule(const char* moduleInstanceName) ;
171  PathList::iterator findPath(const char* pathName) ;
172 
173  int moduleIndexInPath(const char *mod, const char *path);
174 
175  size_t numberOfPaths() const {
176  return paths_.size();
177  }
178  size_t numberOfModules() const {
179  return modules_.size();
180  }
181 
182  PathList::iterator beginPaths() {
183  return paths_.begin();
184  }
185  PathList::iterator endPaths() {
186  return paths_.end();
187  }
188 
189  Modules::const_iterator beginModules() const {
190  return modules_.begin();
191  }
192 
193  Modules::const_iterator endModules() const {
194  return modules_.end();
195  }
196 
197  double totalTime() const;
198  double totalCPUTime() const;
199  double longestModuleTime() const;
200  double longestModuleCPUTime() const;
201  const char* longestModuleTimeName() const;
202  const char* longestModuleCPUTimeName() const;
203 
204  double totalPathTime(const size_t path);
205  double totalPathCPUTime(const size_t path);
206 
207 
208  void setStatusOfModulesFromPath(const char* pathName);
209 
210 // double lastModuleOnPathTime(const size_t pathnumber);
211 // double lastModuleOnPathCPUTime(const size_t pathnumber);
212 
213  // is this module only on one path?
214  bool uniqueModule(const char *mod) const ;
215 };
216 
217 
218 typedef std::vector<HLTPerformanceInfo> HLTPerformanceInfoCollection;
219 
220 #endif // HLTPERFORMANCEINFO_H
PathList::iterator findPath(const char *pathName)
float dt
Definition: AMPTWrapper.h:126
std::vector< HLTPerformanceInfo > HLTPerformanceInfoCollection
const Module & getModule(size_t m) const
size_t numberOfModules() const
bool operator==(const char *tname)
int i
Definition: DBlmapReader.cc:9
std::string name() const
not [yet] run
Definition: HLTenums.h:21
void reset()
reset this path
Definition: HLTPathStatus.h:58
double longestModuleCPUTime() const
const Module & getModuleOnPath(size_t m, size_t p) const
void addModuleToPath(const size_t mod, const size_t path)
void addPath(const Path &p)
double totalPathTime(const size_t path)
Modules::const_iterator endModules() const
#define Module(md)
Definition: vmac.h:202
double longestModuleTime() const
edm::HLTPathStatus status_
size_t numberOfPaths() const
PathList::iterator beginPaths()
edm::HLTPathStatus status() const
void setStatus(const edm::HLTPathStatus &result)
bool uniqueModule(const char *mod) const
void setStatusOfModulesFromPath(const char *pathName)
PathList::iterator endPaths()
edm::HLTPathStatus status() const
tuple result
Definition: query.py:137
size_t getModuleIndex(size_t j) const
int j
Definition: DBlmapReader.cc:9
Path(const std::string n="unknown")
Modules::const_iterator beginModules() const
double totalTime() const
bool operator==(const char *tname)
const size_t operator[](size_t m) const
std::vector< cms_uint32_t > ModulesInPath
double totalPathCPUTime(const size_t path)
ModulesInPath::const_iterator end()
Module(const char *n, const double dt, const double dtCPU, edm::HLTPathStatus stat=edm::hlt::Ready)
ModulesInPath::const_iterator begin()
const char * longestModuleTimeName() const
const Path & getPath(size_t p) const
Modules::iterator findModule(const char *moduleInstanceName)
void addModuleToPath(const char *mod, const char *path)
const char * longestModuleCPUTimeName() const
std::vector< Module > Modules
void setStatus(edm::HLTPathStatus status)
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)
double totalCPUTime() const
std::string name() const