CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
PeriodicAllocMonitor Class Reference

Public Member Functions

 PeriodicAllocMonitor (edm::ParameterSet const &iPS, edm::ActivityRegistry &iAR)
 
 ~PeriodicAllocMonitor ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &iDesc)
 

Private Attributes

std::atomic< bool > continueRunning_ = true
 
std::atomic< std::size_t > nEventsFinished_ = 0
 
std::atomic< std::size_t > nEventsStarted_ = 0
 
std::atomic< std::size_t > nLumisStarted_ = 0
 
std::atomic< std::size_t > nRunsStarted_ = 0
 
std::thread thread_
 
bool threadShutDown_ = true
 

Detailed Description

Definition at line 93 of file PeriodicAllocMonitor.cc.

Constructor & Destructor Documentation

◆ PeriodicAllocMonitor()

PeriodicAllocMonitor::PeriodicAllocMonitor ( edm::ParameterSet const &  iPS,
edm::ActivityRegistry iAR 
)
inline

Definition at line 95 of file PeriodicAllocMonitor.cc.

References continueRunning_, submitPVResolutionJobs::count, cms::perftools::AllocMonitorRegistry::createAndRegisterMonitor(), cms::perftools::AllocMonitorRegistry::deregisterMonitor(), MillePedeFileConverter_cfg::fileName, compareTotals::fs, edm::ParameterSet::getUntrackedParameter(), cms::perftools::AllocMonitorRegistry::instance(), MergeJob_cfg::interval, nEventsFinished_, nEventsStarted_, nLumisStarted_, submitPVValidationJobs::now, nRunsStarted_, zeeHLT_cff::report, isotrackNtupler::start, AlCaHLTBitMon_QueryRunRegistry::string, thread_, threadShutDown_, edm::ActivityRegistry::watchPostEvent(), edm::ActivityRegistry::watchPreEndJob(), edm::ActivityRegistry::watchPreEvent(), edm::ActivityRegistry::watchPreGlobalBeginLumi(), and edm::ActivityRegistry::watchPreGlobalBeginRun().

95  {
97  auto fileName = iPS.getUntrackedParameter<std::string>("filename");
98  auto interval = iPS.getUntrackedParameter<unsigned long long>("millisecondsPerMeasurement");
99 
100  threadShutDown_ = false;
101  thread_ = std::thread([this, fileName, interval, adaptor]() {
102  auto const start = std::chrono::steady_clock::now();
103  std::ofstream fs(fileName);
104  fs << "timestamp, runs-started, lumis-started, events-started, events-finished, total-requested, max-actual, "
105  "present-actual, max-single, nAllocs, nDeallocs\n";
106  while (continueRunning_.load()) {
107  auto rStarted = nRunsStarted_.load(std::memory_order_acquire);
108  auto lStarted = nLumisStarted_.load(std::memory_order_acquire);
109  auto const now = std::chrono::steady_clock::now();
110  auto eStarted = nEventsStarted_.load(std::memory_order_acquire);
111  auto eFinished = nEventsFinished_.load(std::memory_order_acquire);
112  auto report = adaptor->report();
113 
114  fs << std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count() << ", " << rStarted << ", "
115  << lStarted << ", " << eStarted << ", " << eFinished << ", " << report.requested_ << ", "
116  << report.maxActual_ << ", " << report.presentActual_ << ", " << report.maxSingleRequested_ << ", "
117  << report.nAllocations_ << ", " << report.nDeallocations_ << std::endl;
118  std::this_thread::sleep_for(std::chrono::milliseconds(interval));
119  }
120  });
121 
122  iAR.watchPreEvent([this](auto const&) { nEventsStarted_.fetch_add(1, std::memory_order_acq_rel); });
123  iAR.watchPostEvent([this](auto const&) { nEventsFinished_.fetch_add(1, std::memory_order_acq_rel); });
124  iAR.watchPreGlobalBeginRun([this](auto const&) { nRunsStarted_.fetch_add(1, std::memory_order_acq_rel); });
125  iAR.watchPreGlobalBeginLumi([this](auto const&) { nLumisStarted_.fetch_add(1, std::memory_order_acq_rel); });
126  iAR.watchPreEndJob([adaptor, this]() {
127  continueRunning_ = false;
128  thread_.join();
129  threadShutDown_ = true;
131  });
132  }
Definition: start.py:1
void watchPreEvent(PreEvent::slot_type const &iSlot)
void watchPostEvent(PostEvent::slot_type const &iSlot)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
std::atomic< std::size_t > nRunsStarted_
static AllocMonitorRegistry & instance()
std::atomic< bool > continueRunning_
std::atomic< std::size_t > nLumisStarted_
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
std::atomic< std::size_t > nEventsFinished_
void watchPreEndJob(PreEndJob::slot_type const &iSlot)
std::atomic< std::size_t > nEventsStarted_

◆ ~PeriodicAllocMonitor()

PeriodicAllocMonitor::~PeriodicAllocMonitor ( )
inline

Definition at line 133 of file PeriodicAllocMonitor.cc.

References continueRunning_, thread_, and threadShutDown_.

133  {
134  if (not threadShutDown_) {
135  continueRunning_ = false;
136  thread_.join();
137  }
138  }
std::atomic< bool > continueRunning_

Member Function Documentation

◆ fillDescriptions()

static void PeriodicAllocMonitor::fillDescriptions ( edm::ConfigurationDescriptions iDesc)
inlinestatic

Definition at line 140 of file PeriodicAllocMonitor.cc.

References edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

140  {
142  ps.addUntracked<std::string>("filename", "timing.log")->setComment("Name of file to write the reports");
143  ps.addUntracked<unsigned long long>("millisecondsPerMeasurement", 1000)
144  ->setComment("The frequency at which to write reports");
145  iDesc.addDefault(ps);
146  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void addDefault(ParameterSetDescription const &psetDescription)

Member Data Documentation

◆ continueRunning_

std::atomic<bool> PeriodicAllocMonitor::continueRunning_ = true
private

Definition at line 154 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor(), and ~PeriodicAllocMonitor().

◆ nEventsFinished_

std::atomic<std::size_t> PeriodicAllocMonitor::nEventsFinished_ = 0
private

Definition at line 153 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor().

◆ nEventsStarted_

std::atomic<std::size_t> PeriodicAllocMonitor::nEventsStarted_ = 0
private

Definition at line 152 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor().

◆ nLumisStarted_

std::atomic<std::size_t> PeriodicAllocMonitor::nLumisStarted_ = 0
private

Definition at line 151 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor().

◆ nRunsStarted_

std::atomic<std::size_t> PeriodicAllocMonitor::nRunsStarted_ = 0
private

Definition at line 150 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor().

◆ thread_

std::thread PeriodicAllocMonitor::thread_
private

Definition at line 149 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor(), and ~PeriodicAllocMonitor().

◆ threadShutDown_

bool PeriodicAllocMonitor::threadShutDown_ = true
private

Definition at line 155 of file PeriodicAllocMonitor.cc.

Referenced by PeriodicAllocMonitor(), and ~PeriodicAllocMonitor().