CMS 3D CMS Logo

Timing.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Services
00004 // Class  :     Timing
00005 // 
00006 // Implementation:
00007 //
00008 // Original Author:  Jim Kowalkowski
00009 // $Id: Timing.cc,v 1.13 2008/06/20 20:55:48 fischler Exp $
00010 //
00011 // Change Log
00012 //
00013 // 1 - mf 4/22/08   Facilitate summary output to job report and logs:
00014 //                  In Timing ctor, default for report_summary_ changed to true 
00015 //                  In postEndJob, add output to logger
00016 
00017 #include "FWCore/Services/interface/Timing.h"
00018 #include "FWCore/MessageLogger/interface/JobReport.h"
00019 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "FWCore/Utilities/interface/Exception.h"
00025 
00026 #include <iostream>
00027 #include <sys/time.h>
00028 
00029 namespace edm {
00030   namespace service {
00031 
00032     static double getTime()
00033     {
00034       struct timeval t;
00035       if(gettimeofday(&t,0)<0)
00036         throw cms::Exception("SysCallFailed","Failed call to gettimeofday");
00037 
00038       return (double)t.tv_sec + (double(t.tv_usec) * 1E-6);
00039     }
00040 
00041     Timing::Timing(const ParameterSet& iPS, ActivityRegistry&iRegistry):
00042       summary_only_(iPS.getUntrackedParameter<bool>("summaryOnly",false)),
00043       report_summary_(iPS.getUntrackedParameter<bool>("useJobReport",true)),
00044       max_event_time_(0.),
00045       min_event_time_(0.),
00046       total_event_count_(0)
00047      
00048     {
00049       iRegistry.watchPostBeginJob(this,&Timing::postBeginJob);
00050       iRegistry.watchPostEndJob(this,&Timing::postEndJob);
00051 
00052       iRegistry.watchPreProcessEvent(this,&Timing::preEventProcessing);
00053       iRegistry.watchPostProcessEvent(this,&Timing::postEventProcessing);
00054 
00055       iRegistry.watchPreModule(this,&Timing::preModule);
00056       iRegistry.watchPostModule(this,&Timing::postModule);
00057     }
00058 
00059 
00060     Timing::~Timing()
00061     {
00062     }
00063 
00064     void Timing::postBeginJob()
00065     {
00066       //edm::LogInfo("TimeReport")
00067       if (not summary_only_) {
00068         edm::LogAbsolute("TimeReport")
00069         << "TimeReport> Report activated" << "\n"
00070         << "TimeReport> Report columns headings for events: "
00071         << "eventnum runnum timetaken\n"
00072         << "TimeReport> Report columns headings for modules: "
00073         << "eventnum runnum modulelabel modulename timetaken";
00074       }
00075       curr_job_ = getTime();
00076     }
00077 
00078     void Timing::postEndJob()
00079     {
00080       double t = getTime() - curr_job_;
00081       double average_event_t = t / total_event_count_;
00082       //edm::LogInfo("TimeReport")
00083       edm::LogAbsolute("TimeReport")                            // Changelog 1
00084         << "TimeReport> Time report complete in "
00085         << t << " seconds"
00086         << "\n"
00087         << " Time Summary: \n" 
00088         << " Min: " << min_event_time_ << "\n"
00089         << " Max: " << max_event_time_ << "\n"
00090         << " Avg: " << average_event_t << "\n";
00091       if (report_summary_){
00092         Service<JobReport> reportSvc;
00093         std::map<std::string, double> reportData;
00094 
00095         reportData.insert(std::make_pair("MinEventTime", min_event_time_));
00096         reportData.insert(std::make_pair("MaxEventTime", max_event_time_));
00097         reportData.insert(std::make_pair("AvgEventTime", average_event_t));
00098         reportData.insert(std::make_pair("TotalTime", t));
00099         reportSvc->reportTimingInfo(reportData);
00100       }
00101 
00102     }
00103 
00104     void Timing::preEventProcessing(const edm::EventID& iID,
00105                                     const edm::Timestamp& iTime)
00106     {
00107       curr_event_ = iID;
00108       curr_event_time_ = getTime();
00109       
00110 
00111     }
00112     void Timing::postEventProcessing(const Event& e, const EventSetup&)
00113     {
00114       double t = getTime() - curr_event_time_;
00115       if (not summary_only_) {
00116         edm::LogAbsolute("TimeEvent")
00117         << "TimeEvent> "
00118         << curr_event_.event() << " "
00119         << curr_event_.run() << " "
00120         << t;
00121       }
00122       if (total_event_count_ == 0) {
00123         max_event_time_ = t;
00124         min_event_time_ = t;
00125       }
00126       
00127       if (t > max_event_time_) max_event_time_ = t;
00128       if (t < min_event_time_) min_event_time_ = t;
00129       total_event_count_ = total_event_count_ + 1;
00130     }
00131 
00132     void Timing::preModule(const ModuleDescription&)
00133     {
00134       curr_module_time_ = getTime();
00135     }
00136 
00137     void Timing::postModule(const ModuleDescription& desc)
00138     {
00139       double t = getTime() - curr_module_time_;
00140       //edm::LogInfo("TimeModule")
00141       if (not summary_only_) {
00142         edm::LogAbsolute("TimeModule") << "TimeModule> "
00143            << curr_event_.event() << " "
00144            << curr_event_.run() << " "
00145            << desc.moduleLabel_ << " "
00146            << desc.moduleName_ << " "
00147            << t;
00148       }
00149    
00150       newMeasurementSignal(desc,t);
00151     }
00152 
00153   }
00154 }

Generated on Tue Jun 9 17:36:40 2009 for CMSSW by  doxygen 1.5.4