CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/Timer/src/TimerService.cc

Go to the documentation of this file.
00001 #include "HLTrigger/Timer/interface/TimerService.h"
00002 #include <iostream>
00003 
00004 edm::CPUTimer * TimerService::cpu_timer = 0;
00005 
00006 TimerService::TimerService(const edm::ParameterSet& ps, 
00007                                  edm::ActivityRegistry& iAR)
00008 {
00009   // whether to use CPU-time (default) or wall-clock time
00010   useCPUtime = ps.getUntrackedParameter<bool>("useCPUtime", true);
00011 
00012   iAR.watchPreModule(this, &TimerService::preModule);
00013   iAR.watchPostModule(this, &TimerService::postModule);
00014   
00015   if(!cpu_timer)
00016     cpu_timer = new edm::CPUTimer();
00017 
00018 }
00019 
00020 TimerService::~TimerService()
00021 {
00022   if(cpu_timer){
00023     using namespace std;
00024 
00025     string longLine("=========================================================="); 
00026     cout << longLine << endl;
00027     cout << " TimerService Info:\n";
00028     
00029     if(useCPUtime)
00030       cout << " Used CPU-time ";
00031     else
00032       cout << " Used wall-clock-time ";
00033     cout << "for timing information " << endl;
00034     cout << longLine << endl;
00035     
00036     delete cpu_timer; cpu_timer = 0;
00037   }
00038 }
00039 
00040 // fwk calls this method before a module is processed
00041 void TimerService::preModule(const edm::ModuleDescription& iMod)
00042 {
00043   cpu_timer->reset();
00044   cpu_timer->start();  
00045 }
00046 
00047 // fwk calls this method after a module has been processed
00048 void TimerService::postModule(const edm::ModuleDescription& iMod)
00049 {
00050   cpu_timer->stop();
00051 
00052   double time = -999; // in secs
00053   if(useCPUtime)
00054     time = cpu_timer->cpuTime();
00055   else
00056     time = cpu_timer->realTime();
00057 
00058   newMeasurementSignal(iMod, time);
00059 }