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