CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/EventFilter/Utilities/src/TimeProfilerService.cc

Go to the documentation of this file.
00001 #include "EventFilter/Utilities/interface/TimeProfilerService.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 namespace evf{
00004 
00005 
00006   static double getTime()
00007   {
00008     struct timeval t;
00009     if(gettimeofday(&t,0)<0)
00010       throw cms::Exception("SysCallFailed","Failed call to gettimeofday");
00011     
00012     return (double)t.tv_sec + (double(t.tv_usec) * 1E-6);
00013   }
00014   
00015   TimeProfilerService::TimeProfilerService(const edm::ParameterSet& iPS, edm::ActivityRegistry&iRegistry)
00016   {
00017     iRegistry.watchPostBeginJob(this,&TimeProfilerService::postBeginJob);
00018     iRegistry.watchPostEndJob(this,&TimeProfilerService::postEndJob);
00019     
00020     iRegistry.watchPreProcessEvent(this,&TimeProfilerService::preEventProcessing);
00021     iRegistry.watchPostProcessEvent(this,&TimeProfilerService::postEventProcessing);
00022     
00023     iRegistry.watchPreModule(this,&TimeProfilerService::preModule);
00024     iRegistry.watchPostModule(this,&TimeProfilerService::postModule);
00025   }
00026 
00027   TimeProfilerService::~TimeProfilerService()
00028   {}
00029   
00030   void TimeProfilerService::postBeginJob()
00031   {}
00032   
00033   void TimeProfilerService::postEndJob()
00034   {}
00035   void TimeProfilerService::preEventProcessing(const edm::EventID& iID,
00036                                     const edm::Timestamp& iTime)
00037   {}
00038   void TimeProfilerService::postEventProcessing(const edm::Event& e, const edm::EventSetup&)
00039   {}
00040   void TimeProfilerService::preModule(const edm::ModuleDescription&)
00041   {
00042     curr_module_time_ = getTime();
00043   }
00044 
00045   void TimeProfilerService::postModule(const edm::ModuleDescription& desc)
00046   {
00047     double t = getTime() - curr_module_time_;
00048     std::map<std::string, times>::iterator it = profiles_.find(desc.moduleLabel());
00049     if(it==profiles_.end())
00050       {
00051         times tt;
00052         tt.ncalls_ = 0;
00053         tt.total_ = 0.;
00054         tt.max_ = 0.;
00055         tt.firstEvent_ = t;
00056         profiles_.insert(std::pair<std::string, times>(desc.moduleLabel(),tt));
00057       }      
00058     else
00059       {
00060         (*it).second.ncalls_++;
00061         (*it).second.total_ += t;
00062         (*it).second.max_  = ((*it).second.max_ > t) ? (*it).second.max_ : t;
00063       }
00064   }
00065   double TimeProfilerService::getFirst(std::string const &name) const
00066   {
00067     std::map<std::string, times>::const_iterator it = profiles_.find(name);
00068 
00069     if(it==profiles_.end())
00070       return -1.;
00071     return (*it).second.firstEvent_;
00072   }
00073 
00074   double TimeProfilerService::getMax(std::string const &name) const
00075   {
00076     std::map<std::string, times>::const_iterator it = profiles_.find(name);
00077 
00078     if(it == profiles_.end())
00079       return -1.;
00080     return (*it).second.max_;
00081   }
00082 
00083   double TimeProfilerService::getAve(std::string const &name) const
00084   {
00085     std::map<std::string, times>::const_iterator it = profiles_.find(name);
00086 
00087     if(it == profiles_.end())
00088       return -1.;
00089     return (*it).second.total_/(*it).second.ncalls_;
00090   }
00091 }