Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:21

0001 // -*-c++-*-
0002 #ifndef HLTPERFORMANCEINFO_H
0003 #define HLTPERFORMANCEINFO_H
0004 
0005 #include <string>
0006 #include <vector>
0007 #include <cassert>
0008 
0009 #include "FWCore/Utilities/interface/typedefs.h"
0010 #include "DataFormats/Common/interface/HLTPathStatus.h"
0011 
0012 class HLTPerformanceInfo {
0013 public:
0014   class Path;
0015   class Module;
0016   typedef std::vector<Path> PathList;
0017   typedef std::vector<Module> Modules;
0018   typedef std::vector<cms_uint32_t> ModulesInPath;
0019   HLTPerformanceInfo();
0020   //
0021   class Module {
0022   private:
0023     std::string name_;  // module instance name
0024     double dt_;         // Wall-clock time
0025     double dtCPU_;      // CPU time
0026     // I am using this even for modules....
0027     edm::HLTPathStatus status_;
0028 
0029   public:
0030     Module() : name_("unknown") {}
0031     // new constructor adding cpu time
0032     Module(const char *n, const double dt, const double dtCPU, edm::HLTPathStatus stat = edm::hlt::Ready)
0033         : name_(n), dt_(dt), dtCPU_(dtCPU), status_(stat) {}
0034     std::string name() const { return name_; }
0035     double time() const { return dt_; }
0036     double cputime() const { return dtCPU_; }
0037     edm::HLTPathStatus status() const { return status_; }
0038     bool operator==(const char *tname) { return std::string(tname) == name(); }
0039     void clear() {
0040       dt_ = 0;
0041       dtCPU_ = 0;
0042       status_.reset();  // = edm::hlt::Ready;
0043     }
0044     void setTime(double t) { dt_ = t; }
0045     void setCPUTime(double t) { dtCPU_ = t; }
0046     void setStatus(edm::HLTPathStatus status) { status_ = status; }
0047     // pw - can't a module be on different paths?
0048     //void setStatusByPath(Path *path) ;
0049     //int indexInPath(Path path) const ;
0050   };
0051   // end Module class definition
0052 
0053   // in this version the module can no longer iterate over the paths
0054   // by itself, since it has no access to the actual module list.
0055   class Path {
0056   private:
0057     std::string name_;
0058     ModulesInPath moduleView_;  // indices into the module vector
0059     edm::HLTPathStatus status_;
0060 
0061   public:
0062     Path(const std::string n = "unknown") : name_(n), moduleView_(), status_() {}
0063     std::string name() const { return name_; }
0064     void setStatus(const edm::HLTPathStatus &result) { status_ = result; }
0065 
0066     edm::HLTPathStatus status() const { return status_; }
0067     void clear() {
0068       status_.reset();
0069       // time is dynamic, nothing to reset
0070     }
0071     bool operator==(const char *tname) { return (std::string(tname) == name()); }
0072 
0073     const size_t operator[](size_t m) const { return moduleView_.at(m); }
0074 
0075     void addModuleRef(size_t m) { moduleView_.push_back(m); }
0076 
0077     ModulesInPath::const_iterator begin() { return moduleView_.begin(); }
0078     ModulesInPath::const_iterator end() { return moduleView_.end(); }
0079     size_t getModuleIndex(size_t j) const { return moduleView_.at(j); }
0080 
0081     size_t numberOfModules() const { return moduleView_.size(); };
0082   };
0083   // end Path class definition
0084 private:
0085   PathList paths_;
0086   Modules modules_;
0087 
0088 public:
0089   void addPath(const Path &p) { paths_.push_back(p); }
0090   void addModule(const Module &m) { modules_.push_back(m); }
0091   // by name
0092   void addModuleToPath(const char *mod, const char *path) {
0093     // first make sure module exists
0094     Modules::iterator m = findModule(mod);
0095     if (m == endModules()) {
0096       // new module - create it and stick it on the end
0097       Module newMod(mod, 0, 0);  // time (wall and cpu) = 0 since it wasn't run
0098       modules_.push_back(newMod);
0099     }
0100 
0101     for (size_t i = 0; i < paths_.size(); ++i) {
0102       if (!(paths_[i] == path))
0103         continue;
0104       // we found the path, add module to the end
0105       for (size_t j = 0; j < modules_.size(); ++j) {
0106         if (!(modules_[j] == mod))
0107           continue;
0108         paths_[i].addModuleRef(j);
0109         break;
0110       }
0111       break;
0112     }
0113   }
0114   // by index
0115   void addModuleToPath(const size_t mod, const size_t path) {
0116     assert((path < paths_.size()) && (mod < modules_.size()));
0117     paths_[path].addModuleRef(mod);
0118   }
0119 
0120   void clear() {
0121     modules_.clear();
0122     paths_.clear();
0123   }
0124   void clearModules() {
0125     for (size_t i = 0; i < modules_.size(); ++i) {
0126       modules_[i].clear();
0127     }
0128   }
0129 
0130   // non-const?
0131   const Module &getModuleOnPath(size_t m, size_t p) const;
0132   const Module &getModule(size_t m) const { return modules_.at(m); }
0133   const Path &getPath(size_t p) const { return paths_.at(p); }
0134 
0135   // find a module, given its name.
0136   // returns endModules() on failure
0137   Modules::iterator findModule(const char *moduleInstanceName);
0138   PathList::iterator findPath(const char *pathName);
0139 
0140   int moduleIndexInPath(const char *mod, const char *path);
0141 
0142   size_t numberOfPaths() const { return paths_.size(); }
0143   size_t numberOfModules() const { return modules_.size(); }
0144 
0145   PathList::iterator beginPaths() { return paths_.begin(); }
0146   PathList::iterator endPaths() { return paths_.end(); }
0147 
0148   Modules::const_iterator beginModules() const { return modules_.begin(); }
0149 
0150   Modules::const_iterator endModules() const { return modules_.end(); }
0151 
0152   double totalTime() const;
0153   double totalCPUTime() const;
0154   double longestModuleTime() const;
0155   double longestModuleCPUTime() const;
0156   std::string longestModuleTimeName() const;
0157   std::string longestModuleCPUTimeName() const;
0158 
0159   double totalPathTime(const size_t path);
0160   double totalPathCPUTime(const size_t path);
0161 
0162   void setStatusOfModulesFromPath(const char *pathName);
0163 
0164   //   double lastModuleOnPathTime(const size_t pathnumber);
0165   //   double lastModuleOnPathCPUTime(const size_t pathnumber);
0166 
0167   // is this module only on one path?
0168   bool uniqueModule(const char *mod) const;
0169 };
0170 
0171 typedef std::vector<HLTPerformanceInfo> HLTPerformanceInfoCollection;
0172 
0173 #endif  // HLTPERFORMANCEINFO_H