CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FWCore/Framework/src/RunStopwatch.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_RunStopwatch_h
00002 #define FWCore_Framework_RunStopwatch_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 $Id: RunStopwatch.h,v 1.4 2010/10/30 02:41:41 chrjones Exp $
00007 
00008 Simple "guard" class as suggested by Chris Jones to start/stop the
00009 Stopwatch: creating an object of type RunStopwatch starts the clock
00010 pointed to, deleting it (when it goes out of scope) automatically
00011 calls the destructor which stops the clock.
00012 
00013 ----------------------------------------------------------------------*/
00014 
00015 #include "boost/shared_ptr.hpp"
00016 #include "FWCore/Utilities/interface/CPUTimer.h"
00017 
00018 namespace edm {
00019 
00020   class RunStopwatch {
00021 
00022   public:
00023     typedef boost::shared_ptr<CPUTimer> StopwatchPointer;
00024 
00025     RunStopwatch(const StopwatchPointer& ptr): stopwatch_(ptr) {
00026       if(stopwatch_) {
00027         stopwatch_->start();
00028       }
00029     }
00030 
00031     ~RunStopwatch(){
00032       if(stopwatch_) {
00033         stopwatch_->stop();
00034       }
00035     }
00036 
00037   private:
00038     StopwatchPointer stopwatch_;
00039 
00040   };
00041 
00042   class RunDualStopwatches {
00043     
00044   public:
00045     typedef boost::shared_ptr<CPUTimer> StopwatchPointer;
00046     
00047     RunDualStopwatches(const StopwatchPointer& ptr1, CPUTimer* const ptr2): stopwatch1_(ptr1),stopwatch2_(ptr2) {
00048       if(stopwatch1_ && 0 != stopwatch2_) {
00049         stopwatch1_->start();
00050       }
00051     }
00052     
00053     ~RunDualStopwatches(){
00054       if (stopwatch1_ && 0 != stopwatch2_) {
00055         stopwatch2_->add(stopwatch1_->stop());
00056       }
00057     }
00058     
00059   private:
00060     StopwatchPointer stopwatch1_;
00061     CPUTimer* const stopwatch2_;
00062     
00063   };
00064   
00065 }
00066 #endif