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 #if defined(__APPLE__) || defined(__MACH__)
00013 #include <mach/clock.h>
00014 #include <mach/mach.h>
00015 #endif // defined(__APPLE__) || defined(__MACH__)
00016
00017
00018 #include <cmath>
00019 #include <string>
00020 #include <map>
00021 #include <unordered_map>
00022 #include <unistd.h>
00023
00024
00025 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00026 #include "FWCore/ServiceRegistry/interface/Service.h"
00027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00028 #include "FWCore/Framework/interface/TriggerNamesService.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 #include "DataFormats/Common/interface/HLTPathStatus.h"
00031 #include "DataFormats/Provenance/interface/EventID.h"
00032 #include "DataFormats/Provenance/interface/Timestamp.h"
00033 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00034 #include "DQMServices/Core/interface/DQMStore.h"
00035 #include "DQMServices/Core/interface/MonitorElement.h"
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
00078
00079
00080
00081
00082
00083
00084 class FastTimerService {
00085 public:
00086 FastTimerService(const edm::ParameterSet &, edm::ActivityRegistry & );
00087 ~FastTimerService();
00088
00089
00090
00091 double currentModuleTime() const;
00092 double currentPathTime() const;
00093 double currentEventTime() const;
00094
00095
00096 double queryModuleTime(const edm::ModuleDescription &) const;
00097 double queryModuleTimeByLabel(const std::string &) const;
00098 double queryModuleTimeByType(const std::string &) const;
00099 double queryPathActiveTime(const std::string &) const;
00100 double queryPathTotalTime(const std::string &) const;
00101
00102
00103
00104
00105
00106
00107 double querySourceTime() const;
00108 double queryPathsTime() const;
00109 double queryEndPathsTime() const;
00110 double queryEventTime() const;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void setNumberOfProcesses(unsigned int);
00121
00122 private:
00123 void postEndJob();
00124 void preBeginRun( edm::RunID const &, edm::Timestamp const & );
00125 void preModuleBeginJob( edm::ModuleDescription const & );
00126 void preProcessEvent( edm::EventID const &, edm::Timestamp const & );
00127 void postProcessEvent( edm::Event const &, edm::EventSetup const & );
00128 void preSource();
00129 void postSource();
00130 void prePathBeginRun( std::string const & );
00131 void preProcessPath( std::string const & );
00132 void postProcessPath( std::string const &, edm::HLTPathStatus const & );
00133 void preModule( edm::ModuleDescription const & );
00134 void postModule( edm::ModuleDescription const & );
00135
00136
00137 void reset();
00138
00139 public:
00140 static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00141
00142 private:
00143
00144 struct ModuleInfo {
00145 double time_active;
00146 double summary_active;
00147 TH1F * dqm_active;
00148 bool has_just_run;
00149 bool is_exclusive;
00150
00151 public:
00152 ModuleInfo() :
00153 time_active(0.),
00154 summary_active(0.),
00155 dqm_active(0),
00156 has_just_run(false),
00157 is_exclusive(false)
00158 { }
00159
00160 ~ModuleInfo() {
00161 reset();
00162 }
00163
00164
00165 void reset() {
00166 time_active = 0.;
00167 summary_active = 0.;
00168
00169 dqm_active = 0;
00170 has_just_run = false;
00171 is_exclusive = false;
00172 }
00173 };
00174
00175 struct PathInfo {
00176 std::vector<ModuleInfo *> modules;
00177 double time_active;
00178 double time_premodules;
00179 double time_intermodules;
00180 double time_postmodules;
00181 double time_overhead;
00182 double time_total;
00183 double summary_active;
00184 double summary_premodules;
00185 double summary_intermodules;
00186 double summary_postmodules;
00187 double summary_overhead;
00188 double summary_total;
00189 uint32_t last_run;
00190 uint32_t index;
00191 TH1F * dqm_active;
00192 TH1F * dqm_exclusive;
00193 TH1F * dqm_premodules;
00194 TH1F * dqm_intermodules;
00195 TH1F * dqm_postmodules;
00196 TH1F * dqm_overhead;
00197 TH1F * dqm_total;
00198 TH1F * dqm_module_counter;
00199 TH1F * dqm_module_active;
00200 TH1F * dqm_module_total;
00201
00202 public:
00203 PathInfo() :
00204 modules(),
00205 time_active(0.),
00206 time_premodules(0.),
00207 time_intermodules(0.),
00208 time_postmodules(0.),
00209 time_overhead(0.),
00210 time_total(0.),
00211 summary_active(0.),
00212 summary_premodules(0.),
00213 summary_intermodules(0.),
00214 summary_postmodules(0.),
00215 summary_overhead(0.),
00216 summary_total(0.),
00217 last_run(0),
00218 index(0),
00219 dqm_active(0),
00220 dqm_exclusive(0),
00221 dqm_premodules(0),
00222 dqm_intermodules(0),
00223 dqm_postmodules(0),
00224 dqm_overhead(0),
00225 dqm_total(0),
00226 dqm_module_counter(0),
00227 dqm_module_active(0),
00228 dqm_module_total(0)
00229 { }
00230
00231 ~PathInfo() {
00232 reset();
00233 }
00234
00235
00236 void reset() {
00237 modules.clear();
00238 time_active = 0.;
00239 time_premodules = 0.;
00240 time_intermodules = 0.;
00241 time_postmodules = 0.;
00242 time_overhead = 0.;
00243 time_total = 0.;
00244 summary_active = 0.;
00245 summary_premodules = 0.;
00246 summary_intermodules = 0.;
00247 summary_postmodules = 0.;
00248 summary_overhead = 0.;
00249 summary_total = 0.;
00250 last_run = 0;
00251 index = 0;
00252
00253
00254 dqm_active = 0;
00255 dqm_premodules = 0;
00256 dqm_intermodules = 0;
00257 dqm_postmodules = 0;
00258 dqm_overhead = 0;
00259 dqm_total = 0;
00260 dqm_module_counter = 0;
00261 dqm_module_active = 0;
00262 dqm_module_total = 0;
00263 }
00264 };
00265
00266 template <typename T> class PathMap : public std::unordered_map<std::string, T> {};
00267 template <typename T> class ModuleMap : public std::unordered_map<edm::ModuleDescription const *, T> {};
00268
00269
00270 const clockid_t m_timer_id;
00271 bool m_is_cpu_bound;
00272 bool m_enable_timing_paths;
00273 bool m_enable_timing_modules;
00274 bool m_enable_timing_exclusive;
00275 const bool m_enable_timing_summary;
00276 const bool m_skip_first_path;
00277
00278
00279 const bool m_enable_dqm;
00280 const bool m_enable_dqm_bypath_active;
00281 const bool m_enable_dqm_bypath_total;
00282 const bool m_enable_dqm_bypath_overhead;
00283 const bool m_enable_dqm_bypath_details;
00284 const bool m_enable_dqm_bypath_counters;
00285 const bool m_enable_dqm_bypath_exclusive;
00286 const bool m_enable_dqm_bymodule;
00287 const bool m_enable_dqm_bymoduletype;
00288 const bool m_enable_dqm_summary;
00289 const bool m_enable_dqm_byluminosity;
00290 const bool m_enable_dqm_byls;
00291 const bool m_enable_dqm_bynproc;
00292 bool m_nproc_enabled;
00293 const double m_dqm_eventtime_range;
00294 const double m_dqm_eventtime_resolution;
00295 const double m_dqm_pathtime_range;
00296 const double m_dqm_pathtime_resolution;
00297 const double m_dqm_moduletime_range;
00298 const double m_dqm_moduletime_resolution;
00299 const double m_dqm_luminosity_range;
00300 const double m_dqm_luminosity_resolution;
00301 const uint32_t m_dqm_ls_range;
00302 const std::string m_dqm_path;
00303 const edm::InputTag m_luminosity_label;
00304 const std::vector<unsigned int> m_supported_processes;
00305
00306
00307 std::string const * m_first_path;
00308 std::string const * m_last_path;
00309 std::string const * m_first_endpath;
00310 std::string const * m_last_endpath;
00311 bool m_is_first_module;
00312 bool m_is_first_event;
00313
00314
00315 double m_event;
00316 double m_presource;
00317 double m_source;
00318 double m_postsource;
00319 double m_all_paths;
00320 double m_all_endpaths;
00321 double m_interpaths;
00322
00323
00324 unsigned int m_summary_events;
00325 double m_summary_event;
00326 double m_summary_presource;
00327 double m_summary_source;
00328 double m_summary_postsource;
00329 double m_summary_all_paths;
00330 double m_summary_all_endpaths;
00331 double m_summary_interpaths;
00332
00333
00334 DQMStore * m_dqms;
00335
00336
00337 TH1F * m_dqm_event;
00338 TH1F * m_dqm_presource;
00339 TH1F * m_dqm_source;
00340 TH1F * m_dqm_postsource;
00341 TH1F * m_dqm_all_paths;
00342 TH1F * m_dqm_all_endpaths;
00343 TH1F * m_dqm_interpaths;
00344
00345
00346 TH1F * m_dqm_nproc_event;
00347 TH1F * m_dqm_nproc_presource;
00348 TH1F * m_dqm_nproc_source;
00349 TH1F * m_dqm_nproc_postsource;
00350 TH1F * m_dqm_nproc_all_paths;
00351 TH1F * m_dqm_nproc_all_endpaths;
00352 TH1F * m_dqm_nproc_interpaths;
00353
00354
00355 TProfile * m_dqm_paths_active_time;
00356 TProfile * m_dqm_paths_total_time;
00357 TProfile * m_dqm_paths_exclusive_time;
00358 TProfile * m_dqm_paths_interpaths;
00359
00360
00361 TProfile * m_dqm_byls_event;
00362 TProfile * m_dqm_byls_presource;
00363 TProfile * m_dqm_byls_source;
00364 TProfile * m_dqm_byls_postsource;
00365 TProfile * m_dqm_byls_all_paths;
00366 TProfile * m_dqm_byls_all_endpaths;
00367 TProfile * m_dqm_byls_interpaths;
00368
00369
00370 TProfile * m_dqm_nproc_byls_event;
00371 TProfile * m_dqm_nproc_byls_presource;
00372 TProfile * m_dqm_nproc_byls_source;
00373 TProfile * m_dqm_nproc_byls_postsource;
00374 TProfile * m_dqm_nproc_byls_all_paths;
00375 TProfile * m_dqm_nproc_byls_all_endpaths;
00376 TProfile * m_dqm_nproc_byls_interpaths;
00377
00378
00379 TProfile * m_dqm_byluminosity_event;
00380 TProfile * m_dqm_byluminosity_presource;
00381 TProfile * m_dqm_byluminosity_source;
00382 TProfile * m_dqm_byluminosity_postsource;
00383 TProfile * m_dqm_byluminosity_all_paths;
00384 TProfile * m_dqm_byluminosity_all_endpaths;
00385 TProfile * m_dqm_byluminosity_interpaths;
00386
00387
00388 TProfile * m_dqm_nproc_byluminosity_event;
00389 TProfile * m_dqm_nproc_byluminosity_presource;
00390 TProfile * m_dqm_nproc_byluminosity_source;
00391 TProfile * m_dqm_nproc_byluminosity_postsource;
00392 TProfile * m_dqm_nproc_byluminosity_all_paths;
00393 TProfile * m_dqm_nproc_byluminosity_all_endpaths;
00394 TProfile * m_dqm_nproc_byluminosity_interpaths;
00395
00396
00397 PathInfo * m_current_path;
00398 PathMap<PathInfo> m_paths;
00399 std::unordered_map<std::string, ModuleInfo> m_modules;
00400 std::unordered_map<std::string, ModuleInfo> m_moduletypes;
00401 ModuleMap<ModuleInfo *> m_fast_modules;
00402 ModuleMap<ModuleInfo *> m_fast_moduletypes;
00403
00404
00405 std::pair<struct timespec, struct timespec> m_timer_event;
00406 std::pair<struct timespec, struct timespec> m_timer_source;
00407 std::pair<struct timespec, struct timespec> m_timer_paths;
00408 std::pair<struct timespec, struct timespec> m_timer_endpaths;
00409 std::pair<struct timespec, struct timespec> m_timer_path;
00410 std::pair<struct timespec, struct timespec> m_timer_module;
00411 struct timespec m_timer_first_module;
00412
00413 #if defined(__APPLE__) || defined (__MACH__)
00414 clock_serv_t m_clock_port;
00415 #endif // defined(__APPLE__) || defined(__MACH__)
00416
00417 void gettime(struct timespec & stamp) const
00418 {
00419 #if defined(_POSIX_TIMERS) && _POSIX_TIMERS >= 0
00420 clock_gettime(m_timer_id, & stamp);
00421 #else
00422
00423 #if defined(__APPLE__) || defined (__MACH__)
00424 mach_timespec_t timespec;
00425 clock_get_time(m_clock_port, ×pec);
00426 stamp.tv_sec = timespec.tv_sec;
00427 stamp.tv_nsec = timespec.tv_nsec;
00428 #endif // defined(__APPLE__) || defined(__MACH__)
00429 #endif // defined(_POSIX_TIMERS) && _POSIX_TIMERS >= 0
00430 }
00431
00432 void start(std::pair<struct timespec, struct timespec> & times) const
00433 {
00434 gettime(times.first);
00435 }
00436
00437 void stop(std::pair<struct timespec, struct timespec> & times) const
00438 {
00439 gettime(times.second);
00440 }
00441
00442 static
00443 double delta(const struct timespec & first, const struct timespec & second)
00444 {
00445 if (second.tv_nsec > first.tv_nsec)
00446 return (double) (second.tv_sec - first.tv_sec) + (double) (second.tv_nsec - first.tv_nsec) / (double) 1e9;
00447 else
00448 return (double) (second.tv_sec - first.tv_sec) - (double) (first.tv_nsec - second.tv_nsec) / (double) 1e9;
00449 }
00450
00451 static
00452 double delta(const std::pair<struct timespec, struct timespec> & times)
00453 {
00454 return delta(times.first, times.second);
00455 }
00456
00457
00458 void fillPathMap(std::string const & name, std::vector<std::string> const & modules);
00459
00460 };
00461
00462 #endif // ! FastTimerService_h