CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/HLTrigger/Timer/src/TimerService.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sched.h>
00003 
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "HLTrigger/Timer/interface/TimerService.h"
00006 #include "HLTrigger/Timer/interface/CPUAffinity.h"
00007 
00008 TimerService::TimerService(const edm::ParameterSet& ps, 
00009                                  edm::ActivityRegistry& iAR) :
00010   useCPUtime( ps.getUntrackedParameter<bool>("useCPUtime", true) ),
00011   cpu_timer(useCPUtime),
00012   is_bound_(false)
00013 {
00014   if (useCPUtime) {
00015     is_bound_ = CPUAffinity::bindToCurrentCpu();
00016     if (is_bound_)
00017       // the process is (now) bound to a single CPU, the call to clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...) is safe to use
00018       edm::LogInfo("TimerService") << "this process is bound to CPU " << CPUAffinity::currentCpu();
00019     else
00020       // the process is NOT bound to a single CPU
00021       edm::LogError("TimerService") << "this process is NOT bound to a single CPU, the results of the TimerService may be undefined";
00022   }
00023 
00024   iAR.watchPreModule(this, &TimerService::preModule);
00025   iAR.watchPostModule(this, &TimerService::postModule);
00026 }
00027 
00028 TimerService::~TimerService()
00029 {
00030   if (useCPUtime and not is_bound_)
00031     std::cout << "this process is NOT bound to a single CPU, the results of the TimerService may be undefined";
00032   std::cout << "==========================================================\n";
00033   std::cout << " TimerService Info:\n";
00034   std::cout << " Used " << (useCPUtime ? "CPU" : "wall-clock") << "time for timing information\n";
00035   std::cout << "==========================================================\n";
00036   std::cout << std::flush;
00037 }
00038 
00039 // fwk calls this method before a module is processed
00040 void TimerService::preModule(const edm::ModuleDescription& iMod)
00041 {
00042   cpu_timer.reset();
00043   cpu_timer.start();  
00044 }
00045 
00046 // fwk calls this method after a module has been processed
00047 void TimerService::postModule(const edm::ModuleDescription& iMod)
00048 {
00049   cpu_timer.stop();
00050   double time = cpu_timer.delta();  // in secs
00051   newMeasurementSignal(iMod, time);
00052 }