CMS 3D CMS Logo

ThroughputService.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <algorithm>
3 #include <chrono>
4 #include <ctime>
5 
6 // {fmt} headers
7 #include <fmt/printf.h>
8 
9 // CMSSW headers
14 #include "ThroughputService.h"
15 
16 // describe the module's configuration
19  desc.addUntracked<uint32_t>("eventRange", 10000)->setComment("Preallocate a buffer for N events");
20  desc.addUntracked<uint32_t>("eventResolution", 1)->setComment("Sample the processing time every N events");
21  desc.addUntracked<bool>("printEventSummary", false);
22  desc.ifValue(edm::ParameterDescription<bool>("enableDQM", true, false), // "false" means untracked
23  // parameters if "enableDQM" is "true"
24  true >> (edm::ParameterDescription<bool>("dqmPathByProcesses", false, false) and
25  edm::ParameterDescription<std::string>("dqmPath", "HLT/Throughput", false) and
26  edm::ParameterDescription<double>("timeRange", 60000.0, false) and
27  edm::ParameterDescription<double>("timeResolution", 10.0, false)) or
28  // parameters if "enableDQM" is "false"
29  false >> edm::EmptyGroupDescription());
30  descriptions.add("ThroughputService", desc);
31 }
32 
34  : // startup time
35  m_startup(std::chrono::system_clock::now()),
36  // configuration
37  m_resolution(config.getUntrackedParameter<uint32_t>("eventResolution")),
38  m_counter(0),
39  m_events(config.getUntrackedParameter<uint32_t>("eventRange") / m_resolution), // allocate initial size
40  m_print_event_summary(config.getUntrackedParameter<bool>("printEventSummary")),
41  m_enable_dqm(config.getUntrackedParameter<bool>("enableDQM")),
42  m_dqm_bynproc(m_enable_dqm ? config.getUntrackedParameter<bool>("dqmPathByProcesses") : false),
43  m_dqm_path(m_enable_dqm ? config.getUntrackedParameter<std::string>("dqmPath") : ""),
44  m_time_range(m_enable_dqm ? config.getUntrackedParameter<double>("timeRange") : 0.),
45  m_time_resolution(m_enable_dqm ? config.getUntrackedParameter<double>("timeResolution") : 0.) {
46  m_events.clear(); // erases all elements, but does not free internal arrays
51 }
52 
54  auto concurrent_streams = bounds.maxNumberOfStreams();
55  auto concurrent_threads = bounds.maxNumberOfThreads();
56 
58  m_dqm_path += fmt::sprintf(
59  "/Running on %s with %d streams on %d threads", processor_model, concurrent_streams, concurrent_threads);
60 }
61 
63  // if the DQMStore is available, book the DQM histograms
64  // check that the DQMStore service is available
65  if (m_enable_dqm and not edm::Service<dqm::legacy::DQMStore>().isAvailable()) {
66  // the DQMStore is not available, disable all DQM plots
67  m_enable_dqm = false;
68  edm::LogWarning("ThroughputService") << "The DQMStore is not avalable, the DQM plots will not be generated";
69  }
70 
71  if (m_enable_dqm) {
72  std::string y_axis_title = fmt::sprintf("events / %g s", m_time_resolution);
73  unsigned int bins = std::round(m_time_range / m_time_resolution);
74  double range = bins * m_time_resolution;
75 
76  // define a callback that can book the histograms
77  auto bookTransactionCallback = [&, this](DQMStore::IBooker& booker, DQMStore::IGetter&) {
79  m_sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range);
80  m_sourced_events->setXTitle("time [s]");
81  m_sourced_events->setYTitle(y_axis_title);
82  m_retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range);
83  m_retired_events->setXTitle("time [s]");
84  m_retired_events->setYTitle(y_axis_title);
85  };
86 
87  // book MonitorElement's for this run
88  edm::Service<DQMStore>()->meBookerGetter(bookTransactionCallback);
89  } else {
90  m_sourced_events = nullptr;
91  m_retired_events = nullptr;
92  }
93 }
94 
97  auto interval = std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count();
98  if (m_enable_dqm) {
100  }
101 }
102 
105  auto interval = std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count();
106  if (m_enable_dqm) {
108  }
109  ++m_counter;
110  if (m_counter % m_resolution == 0) {
111  m_events.push_back(timestamp);
112  }
113 }
114 
116  if (m_counter < 2 * m_resolution) {
117  // not enough mesurements to estimate the throughput
118  edm::LogWarning("ThroughputService") << "Not enough events to measure the throughput with a resolution of "
119  << m_resolution << " events";
120  return;
121  }
122 
123  edm::LogInfo info("ThroughputService");
124 
125  if (m_print_event_summary) {
126  for (uint32_t i = 0; i < m_events.size(); ++i) {
127  info << std::setw(8) << (i + 1) * m_resolution << ", " << std::setprecision(6) << edm::TimeOfDay(m_events[i])
128  << "\n";
129  }
130  info << '\n';
131  }
132 
133  // measure the time to process each block of m_resolution events
134  uint32_t blocks = m_counter / m_resolution - 1;
135  std::vector<double> delta(blocks);
136  for (uint32_t i = 0; i < blocks; ++i) {
137  delta[i] = std::chrono::duration_cast<std::chrono::duration<double>>(m_events[i + 1] - m_events[i]).count();
138  }
139  // measure the average and standard deviation of the time to process m_resolution
140  double time_avg = TMath::Mean(delta.begin(), delta.begin() + blocks);
141  double time_dev = TMath::StdDev(delta.begin(), delta.begin() + blocks);
142  // compute the throughput and its standard deviation across the job
143  double throughput_avg = double(m_resolution) / time_avg;
144  double throughput_dev = double(m_resolution) * time_dev / time_avg / time_avg;
145 
146  info << "Average throughput: " << throughput_avg << " ± " << throughput_dev << " ev/s";
147 }
148 
149 // declare ThroughputService as a framework Service
void preallocate(edm::service::SystemBounds const &bounds)
dqm::reco::MonitorElement * m_sourced_events
static const TGPicture * info(bool iBackgroundIsBlack)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void preSourceEvent(edm::StreamID sid)
void watchPostEvent(PostEvent::slot_type const &iSlot)
dqm::reco::MonitorElement * m_retired_events
void postEvent(edm::StreamContext const &sc)
Definition: config.py:1
tbb::concurrent_vector< std::chrono::system_clock::time_point > m_events
void preGlobalBeginRun(edm::GlobalContext const &gc)
void Fill(long long x)
virtual void setXTitle(std::string const &title)
std::string m_dqm_path
const std::string processor_model
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:97
virtual void setYTitle(std::string const &title)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ThroughputService(const edm::ParameterSet &, edm::ActivityRegistry &)
std::atomic< uint32_t > m_counter
std::chrono::system_clock::time_point m_startup
const double m_time_resolution
const double m_time_range
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const bool m_dqm_bynproc
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const uint32_t m_resolution
def StdDev(data_list)
Definition: TkAlMap.py:117