Go to the documentation of this file.00001 #ifndef FastTimerService_h
00002 #define FastTimerService_h
00003
00004
00005 #ifdef __linux
00006 #include <time.h>
00007 #else
00008 typedef int clockid_t;
00009 #endif
00010
00011
00012 #include <cmath>
00013 #include <string>
00014 #include <map>
00015 #include <tr1/unordered_map>
00016
00017
00018 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 #include "FWCore/Framework/interface/TriggerNamesService.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "DataFormats/Common/interface/HLTPathStatus.h"
00024 #include "DataFormats/Provenance/interface/EventID.h"
00025 #include "DataFormats/Provenance/interface/Timestamp.h"
00026 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 #include "DQMServices/Core/interface/MonitorElement.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 class FastTimerService {
00078 public:
00079 FastTimerService(const edm::ParameterSet &, edm::ActivityRegistry & );
00080 ~FastTimerService();
00081
00082
00083
00084 double currentModuleTime() const;
00085 double currentPathTime() const;
00086 double currentEventTime() const;
00087
00088
00089 double queryModuleTime(const edm::ModuleDescription &) const;
00090 double queryPathTime(const std::string &) const;
00091
00092
00093
00094
00095
00096
00097 double querySourceTime() const;
00098 double queryPathsTime() const;
00099 double queryEndPathsTime() const;
00100 double queryEventTime() const;
00101
00102
00103 double queryPreSourceOverhead() const;
00104 double queryPreEventOverhead() const;
00105 double queryPreEndPathsOverhead() const;
00106
00107
00108 private:
00109 void postBeginJob();
00110 void postEndJob();
00111 void preModuleBeginJob( edm::ModuleDescription const & );
00112 void preProcessEvent( edm::EventID const &, edm::Timestamp const & );
00113 void postProcessEvent( edm::Event const &, edm::EventSetup const & );
00114 void preSource();
00115 void postSource();
00116 void prePathBeginRun( std::string const & );
00117 void preProcessPath( std::string const & );
00118 void postProcessPath( std::string const &, edm::HLTPathStatus const & );
00119 void preModule( edm::ModuleDescription const & );
00120 void postModule( edm::ModuleDescription const & );
00121
00122 private:
00123
00124 struct ModuleInfo {
00125 double time_active;
00126 double summary_active;
00127 TH1F * dqm_active;
00128 bool has_just_run;
00129
00130 public:
00131 ModuleInfo() :
00132 time_active(0.),
00133 summary_active(0.),
00134 dqm_active(0),
00135 has_just_run(false)
00136 { }
00137 };
00138
00139 struct PathInfo {
00140 std::vector<ModuleInfo *> modules;
00141 double time_active;
00142 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00143 double time_premodules;
00144 double time_intermodules;
00145 double time_postmodules;
00146 #else
00147 double time_overhead;
00148 #endif
00149 double time_total;
00150 double summary_active;
00151 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00152 double summary_premodules;
00153 double summary_intermodules;
00154 double summary_postmodules;
00155 #else
00156 double summary_overhead;
00157 #endif
00158 double summary_total;
00159 TH1F * dqm_active;
00160 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00161 TH1F * dqm_premodules;
00162 TH1F * dqm_intermodules;
00163 TH1F * dqm_postmodules;
00164 #else
00165 TH1F * dqm_overhead;
00166 #endif
00167 TH1F * dqm_total;
00168 TH1F * dqm_module_counter;
00169 TH1F * dqm_module_active;
00170 TH1F * dqm_module_total;
00171
00172 public:
00173 PathInfo() :
00174 modules(),
00175 time_active(0.),
00176 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00177 time_premodules(0.),
00178 time_intermodules(0.),
00179 time_postmodules(0.),
00180 #else
00181 time_overhead(0.),
00182 #endif
00183 time_total(0.),
00184 summary_active(0.),
00185 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00186 summary_premodules(0.),
00187 summary_intermodules(0.),
00188 summary_postmodules(0.),
00189 #else
00190 summary_overhead(0.),
00191 #endif
00192 summary_total(0.),
00193 dqm_active(0),
00194 #ifdef FASTTIMERSERVICE_DETAILED_OVERHEAD_ACCOUNTING
00195 dqm_premodules(0),
00196 dqm_intermodules(0),
00197 dqm_postmodules(0),
00198 #else
00199 dqm_overhead(0),
00200 #endif
00201 dqm_total(0),
00202 dqm_module_counter(0),
00203 dqm_module_active(0),
00204 dqm_module_total(0)
00205 { }
00206 };
00207
00208 template <typename T> class PathMap : public std::tr1::unordered_map<std::string, T> {};
00209 template <typename T> class ModuleMap : public std::tr1::unordered_map<edm::ModuleDescription const *, T> {};
00210
00211
00212 const clockid_t m_timer_id;
00213 bool m_is_cpu_bound;
00214 const bool m_enable_timing_modules;
00215 const bool m_enable_timing_paths;
00216 const bool m_enable_timing_summary;
00217 const bool m_enable_dqm;
00218 const bool m_enable_dqm_bylumi;
00219
00220
00221 const double m_dqm_time_range;
00222 const double m_dqm_time_resolution;
00223 std::string m_dqm_path;
00224
00225
00226 std::string const * m_first_path;
00227 std::string const * m_last_path;
00228 std::string const * m_first_endpath;
00229 std::string const * m_last_endpath;
00230 bool m_is_first_module;
00231
00232
00233 double m_event;
00234 double m_source;
00235 double m_all_paths;
00236 double m_all_endpaths;
00237
00238
00239 unsigned int m_summary_events;
00240 double m_summary_event;
00241 double m_summary_source;
00242 double m_summary_all_paths;
00243 double m_summary_all_endpaths;
00244
00245
00246 DQMStore * m_dqms;
00247 TH1F * m_dqm_event;
00248 TH1F * m_dqm_source;
00249 TH1F * m_dqm_all_paths;
00250 TH1F * m_dqm_all_endpaths;
00251
00252
00253 PathInfo * m_current_path;
00254 PathMap<PathInfo> m_paths;
00255 ModuleMap<ModuleInfo> m_modules;
00256
00257 std::vector<PathInfo *> m_cache_paths;
00258 std::vector<ModuleInfo *> m_cache_modules;
00259
00260
00261
00262 std::pair<struct timespec, struct timespec> m_timer_event;
00263 std::pair<struct timespec, struct timespec> m_timer_source;
00264 std::pair<struct timespec, struct timespec> m_timer_paths;
00265 std::pair<struct timespec, struct timespec> m_timer_endpaths;
00266 std::pair<struct timespec, struct timespec> m_timer_path;
00267 std::pair<struct timespec, struct timespec> m_timer_module;
00268 struct timespec m_timer_first_module;
00269
00270 void gettime(struct timespec & stamp)
00271 {
00272 #if defined __linux
00273 clock_gettime(m_timer_id, & stamp);
00274 #elif defined __APPLE__ && defined __MACH__
00275
00276 #else
00277
00278 #endif
00279 }
00280
00281 void start(std::pair<struct timespec, struct timespec> & times)
00282 {
00283 gettime(times.first);
00284 }
00285
00286 void stop(std::pair<struct timespec, struct timespec> & times)
00287 {
00288 gettime(times.second);
00289 }
00290
00291 static
00292 double delta(const struct timespec & first, const struct timespec & second)
00293 {
00294 if (second.tv_nsec > first.tv_nsec)
00295 return (double) (second.tv_sec - first.tv_sec) + (double) (second.tv_nsec - first.tv_nsec) / (double) 1e9;
00296 else
00297 return (double) (second.tv_sec - first.tv_sec) - (double) (first.tv_nsec - second.tv_nsec) / (double) 1e9;
00298 }
00299
00300 static
00301 double delta(const std::pair<struct timespec, struct timespec> & times)
00302 {
00303 return delta(times.first, times.second);
00304 }
00305
00306
00307 edm::ModuleDescription const * findModuleDescription(const std::string & module) const;
00308
00309
00310 void fillPathMap(std::string const & name, std::vector<std::string> const & modules);
00311
00312 };
00313
00314 #endif // ! FastTimerService_h