63 "NewLumiBusyEndingLS",
64 "NewLumiIdleEndingLS",
74 "NoRequestWithIdleThreads",
75 "NoRequestWithGlobalEoL",
76 "NoRequestWithEoLThreads",
79 "SupWaitFreeChunkCopying",
81 "SupWaitFreeThreadCopying",
84 "SupLockPollingCopying",
87 "SupNewFileWaitThreadCopying",
88 "SupNewFileWaitThread",
89 "SupNewFileWaitChunkCopying",
90 "SupNewFileWaitChunk",
91 "WaitInput_fileLimit",
92 "WaitInput_waitFreeChunk",
93 "WaitInput_waitFreeChunkCopying",
94 "WaitInput_waitFreeThread",
95 "WaitInput_waitFreeThreadCopying",
97 "WaitInput_lockPolling",
98 "WaitInput_lockPollingCopying",
102 "WaitInput_newFileWaitThreadCopying",
103 "WaitInput_newFileWaitThread",
104 "WaitInput_newFileWaitChunkCopying",
105 "WaitInput_newFileWaitChunk",
106 "WaitChunk_fileLimit",
107 "WaitChunk_waitFreeChunk",
108 "WaitChunk_waitFreeChunkCopying",
109 "WaitChunk_waitFreeThread",
110 "WaitChunk_waitFreeThreadCopying",
112 "WaitChunk_lockPolling",
113 "WaitChunk_lockPollingCopying",
117 "WaitChunk_newFileWaitThreadCopying",
118 "WaitChunk_newFileWaitThread",
119 "WaitChunk_newFileWaitChunkCopying",
120 "WaitChunk_newFileWaitChunk",
124 const std::string FastMonitoringService::nopath_ =
"NoPath";
131 sleepTime_(iPS.getUntrackedParameter<
int>(
"sleepTime", 1)),
132 fastMonIntervals_(iPS.getUntrackedParameter<unsigned
int>(
"fastMonIntervals", 2)),
133 fastName_(
"fastmoni"),
134 slowName_(
"slowmoni"),
135 filePerFwkStream_(iPS.getUntrackedParameter<
bool>(
"filePerFwkStream",
false)),
136 totalEventsProcessed_(0) {
174 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
176 if (
stat(microstatePath.c_str(), &statbuf)) {
177 microstatePath =
std::string(std::getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
178 if (
stat(microstatePath.c_str(), &statbuf)) {
179 microstatePath = microstateBaseSuffix;
180 if (
stat(microstatePath.c_str(), &statbuf))
181 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
191 desc.setComment(
"Service for File-based DAQ monitoring and event accounting");
192 desc.addUntracked<
int>(
"sleepTime", 1)->setComment(
"Sleep time of the monitoring thread");
193 desc.addUntracked<
unsigned int>(
"fastMonIntervals", 2)
194 ->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
195 desc.addUntracked<
bool>(
"filePerFwkStream",
false)
196 ->setComment(
"Switches on monitoring output per framework stream");
197 desc.setAllowAnything();
198 descriptions.
add(
"FastMonitoringService",
desc);
203 for (
int i = 0;
i <
fmt_->m_data.encPath_[0].current_;
i++)
204 legendaVector.
append(
Json::Value(*(static_cast<const std::string*>(
fmt_->m_data.encPath_[0].decode(
i)))));
207 pathLegend[
"names"] = legendaVector;
208 pathLegend[
"reserved"] = valReserved;
210 return writer.write(pathLegend);
215 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
217 Json::Value((static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel()));
219 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
221 (static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel() +
"__ACQ"));
226 moduleLegend[
"names"] = legendaVector;
227 moduleLegend[
"reserved"] = valReserved;
228 moduleLegend[
"special"] = valSpecial;
229 moduleLegend[
"output"] = valOutputModules;
231 return writer.write(moduleLegend);
239 moduleLegend[
"names"] = legendaVector;
241 return writer.write(moduleLegend);
260 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
271 <<
". No monitoring data will be written.";
274 std::ostringstream fastFileName;
276 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
278 fast /= fastFileName.str();
282 std::ostringstream fastFileNameTid;
283 fastFileNameTid <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
"_tid" <<
i 286 fastTid /= fastFileNameTid.str();
290 std::ostringstream moduleLegFile;
291 std::ostringstream moduleLegFileJson;
292 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
293 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
297 std::ostringstream pathLegFile;
298 std::ostringstream pathLegFileJson;
299 pathLegFile <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
301 pathLegFileJson <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
304 std::ostringstream inputLegFileJson;
305 inputLegFileJson <<
"inputlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
322 fmt_->m_data.encModule_.completeReservedWithDummies();
327 fmt_->m_data.microstateAcqFlag_.push_back(0);
333 fmt_->m_data.encPath_.emplace_back(0);
334 fmt_->m_data.encPath_[
i].update(static_cast<const void*>(&
nopath_));
337 fmt_->m_data.encPath_[
i].updatePreinit(
path);
339 for (
auto& endPath : pathsInfo.
endPaths()) {
340 fmt_->m_data.encPath_[
i].updatePreinit(endPath);
348 fmt_->m_data.microstateBins_ = 0;
350 fmt_->m_data.ministateBins_ =
fmt_->m_data.encPath_[0].vecsize();
360 monInit_.store(
false, std::memory_order_release);
381 context =
" FromAnotherContext";
383 context =
" FromExternalSignal";
387 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
397 context =
" FromAnotherContext";
399 context =
" FromExternalSignal";
403 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
413 context =
" FromAnotherContext";
415 context =
" FromExternalSignal";
417 <<
"earlyTermination -: " <<
context;
418 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
425 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
441 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
453 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
458 if (
desc.moduleName() ==
"Stream" ||
desc.moduleName() ==
"GlobalEvFOutputModule" ||
459 desc.moduleName() ==
"EvFOutputModule" ||
desc.moduleName() ==
"EventStreamFileWriter" ||
460 desc.moduleName() ==
"PoolOutputModule") {
461 fmt_->m_data.encModule_.updateReserved((
void*)&
desc);
464 fmt_->m_data.encModule_.update((
void*)&
desc);
480 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
482 fmt_->m_data.microstateBins_ =
fmt_->m_data.encModule_.vecsize() * 2;
496 timeval lumiStartTime;
497 gettimeofday(&lumiStartTime,
nullptr);
501 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
507 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " <<
lumi;
508 timeval lumiStopTime;
509 gettimeofday(&lumiStopTime,
nullptr);
511 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
516 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec) * 1000000 + (lumiStopTime.tv_usec - stt.tv_usec);
519 double throughput =
throughputFactor() * double(accuSize) / double(usecondsForLumi);
521 fmt_->m_data.fastThroughputJ_.value() = throughput;
527 IntJ* lumiProcessedJptr =
dynamic_cast<IntJ*
>(
fmt_->jsonMonitor_->getMergedIntJForLumi(
"Processed",
lumi));
528 if (!lumiProcessedJptr)
529 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
536 exception_detected =
true;
541 <<
" events were processed in LUMI " <<
lumi;
553 if (sourceReport.first) {
555 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " <<
lumi 557 <<
" events(source):" << sourceReport.second;
563 <<
"Statistics for lumisection -: lumi = " <<
lumi <<
" events = " << lumiProcessedJptr->
value()
564 <<
" time = " << usecondsForLumi / 1000000 <<
" size = " << accuSize <<
" thr = " << throughput;
565 delete lumiProcessedJptr;
572 std::stringstream slowFileNameStem;
573 slowFileNameStem <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
574 << std::setw(5) << getpid();
576 slow /= slowFileNameStem.str();
577 fmt_->jsonMonitor_->outputFullJSONs(slow.string(),
".jsn",
lumi,
output);
579 std::stringstream slowFileName;
580 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
581 << std::setw(5) << getpid() <<
".jsn";
583 slow /= slowFileName.str();
587 fmt_->jsonMonitor_->discardCollected(
lumi);
591 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
605 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
609 *(
fmt_->m_data.processed_[sid]) = 0;
621 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
649 fmt_->m_data.fastPathProcessedJ_ =
res + 1;
696 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
723 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
746 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
752 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
756 unsigned int proc = it->second.first;
758 *abortFlag = it->second.second;
762 <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: " 770 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
774 unsigned int abortFlag = it->second.second;
778 <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: " 786 monInit_.exchange(
true, std::memory_order_acquire);
787 while (!
fmt_->m_stoprequest) {
788 std::vector<std::vector<unsigned int>> lastEnc;
790 std::unique_lock<std::mutex>
lock(
fmt_->monlock_);
794 lastEnc.emplace_back(
fmt_->m_data.ministateEncoded_);
795 lastEnc.emplace_back(
fmt_->m_data.microstateEncoded_);
799 std::vector<std::string> CSVv;
801 CSVv.push_back(
fmt_->jsonMonitor_->getCSVString((
int)
i));
804 lock.release()->unlock();
812 lock.release()->unlock();
822 auto f = [&](std::vector<unsigned int>
const&
p) {
825 msg <<
"[" <<
p[
i] <<
",";
833 msg <<
"Current states: Ms=" <<
fmt_->m_data.fastMacrostateJ_.value() <<
" ms=";
846 fmt_->m_data.fastMacrostateJ_ =
fmt_->m_data.macrostate_;
848 std::vector<const void*> microstateCopy(
fmt_->m_data.microstate_.begin(),
fmt_->m_data.microstate_.end());
849 std::vector<unsigned char> microstateAcqCopy(
fmt_->m_data.microstateAcqFlag_.begin(),
850 fmt_->m_data.microstateAcqFlag_.end());
855 fmt_->m_data.fastAvgLeadTimeJ_ = itd->second;
857 fmt_->m_data.fastAvgLeadTimeJ_ = 0.;
861 fmt_->m_data.fastFilesProcessedJ_ = iti->second;
863 fmt_->m_data.fastFilesProcessedJ_ = 0;
867 fmt_->m_data.fastLockWaitJ_ = itrd->second.first;
868 fmt_->m_data.fastLockCountJ_ = itrd->second.second;
870 fmt_->m_data.fastLockWaitJ_ = 0.;
871 fmt_->m_data.fastLockCountJ_ = 0.;
876 fmt_->m_data.ministateEncoded_[
i] =
fmt_->m_data.encPath_[
i].encodeString(
fmt_->m_data.ministate_[
i]);
877 if (microstateAcqCopy[
i])
878 fmt_->m_data.microstateEncoded_[
i] =
879 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
881 fmt_->m_data.microstateEncoded_[
i] =
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
884 bool inputStatePerThread =
false;
987 inputStatePerThread =
true;
998 inputStatePerThread =
true;
1011 if (!inputStatePerThread)
1013 fmt_->m_data.inputState_[
i] =
fmt_->m_data.inputState_[0];
1016 fmt_->jsonMonitor_->snapGlobal(
ls);
1018 fmt_->jsonMonitor_->snap(
ls);
std::atomic< bool > has_data_exception_
void prePathEvent(edm::StreamContext const &, edm::PathContext const &)
std::atomic< FastMonState::InputState > inputState_
std::string pathLegendFileJson_
void watchPreStreamEarlyTermination(PreStreamEarlyTermination::slot_type const &iSlot)
static const std::string inputStateNames[FastMonState::inCOUNT]
void watchPreEvent(PreEvent::slot_type const &iSlot)
ModuleDescription const * moduleDescription() const
void postModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
LuminosityBlockNumber_t luminosityBlock() const
std::string pathLegendFile_
void postSourceEvent(edm::StreamID)
std::string makePathLegendaJson()
std::atomic< bool > isInitTransition_
void watchPrePathEvent(PrePathEvent::slot_type const &iSlot)
void watchPreallocate(Preallocate::slot_type const &iSlot)
void startedLookingForFile()
void setExceptionDetected(unsigned int ls)
void watchPreModuleEventAcquire(PreModuleEventAcquire::slot_type const &iSlot)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preallocate(edm::service::SystemBounds const &)
std::map< unsigned int, timeval > lumiStartTime_
void preGlobalBeginLumi(edm::GlobalContext const &)
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void postGlobalEndLumi(edm::GlobalContext const &)
void postEvent(edm::StreamContext const &)
void accumulateFileSize(unsigned int lumi, unsigned long fileSize)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
std::map< unsigned int, unsigned long > accuSize_
std::filesystem::path workingDirectory_
unsigned int snapCounter_
std::vector< std::atomic< bool > * > streamCounterUpdating_
void watchPostEvent(PostEvent::slot_type const &iSlot)
volatile std::atomic< bool > shutdown_flag
void watchPostStreamEndLumi(PostStreamEndLumi::slot_type const &iSlot)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
unsigned int nOutputModules_
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
Value & append(const Value &value)
Append value to array at the end.
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
std::pair< bool, unsigned int > getEventReport(unsigned int lumi, bool erase)
void preGlobalEndLumi(edm::GlobalContext const &)
void setMicroState(FastMonState::Microstate)
unsigned int lastGlobalLumi_
bool isExceptionOnData(unsigned int ls)
void watchPreStreamEndLumi(PreStreamEndLumi::slot_type const &iSlot)
void preGlobalEarlyTermination(edm::GlobalContext const &, edm::TerminationOrigin)
void watchPreSourceEarlyTermination(PreSourceEarlyTermination::slot_type const &iSlot)
static const edm::ModuleDescription reservedMicroStateNames[FastMonState::mCOUNT]
constexpr int nSpecialModules
std::string inputLegendFileJson_
std::vector< std::string > const & endPaths() const
LuminosityBlockNumber_t luminosityBlock() const
unsigned int fastMonIntervals_
void watchJobFailure(JobFailure::slot_type const &iSlot)
convenience function for attaching to signal
std::atomic< bool > monInit_
std::string makeModuleLegendaJson()
void preModuleBeginJob(edm::ModuleDescription const &)
std::string makeInputLegendaJson()
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
MicroStateService(const edm::ParameterSet &, edm::ActivityRegistry &)
unsigned int lumiFromSource_
std::string microstateDefPath_
void preStreamEndLumi(edm::StreamContext const &)
std::map< unsigned int, double > avgLeadTime_
std::string moduleLegendFile_
void watchPostStreamBeginLumi(PostStreamBeginLumi::slot_type const &iSlot)
void doSnapshot(const unsigned int ls, const bool isGlobalEOL)
void preStreamEarlyTermination(edm::StreamContext const &, edm::TerminationOrigin)
void watchPreGlobalEarlyTermination(PreGlobalEarlyTermination::slot_type const &iSlot)
std::atomic< FastMonState::InputState > inputSupervisorState_
StreamID const & streamID() const
static const std::string nopath_
constexpr double throughputFactor()
void watchPostModuleEventAcquire(PostModuleEventAcquire::slot_type const &iSlot)
std::string fastMicrostateDefPath_
std::filesystem::path runDirectory_
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
std::string moduleLegendFileJson_
virtual ~MicroStateService()
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void preModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
LuminosityBlockID const & luminosityBlockID() const
std::vector< std::string > fastPathList_
constexpr int nReservedPaths
void postStreamBeginLumi(edm::StreamContext const &)
Log< level::Info, false > LogInfo
void preSourceEvent(edm::StreamID)
void postStreamEndLumi(edm::StreamContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void preStreamBeginLumi(edm::StreamContext const &)
std::atomic< unsigned long > totalEventsProcessed_
FedRawDataInputSource * inputSource_
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
~FastMonitoringService() override
constexpr int nReservedModules
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > leadTimes_
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &pc)
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
void stoppedLookingForFile(unsigned int lumi)
std::atomic< bool > has_source_exception_
DAQSource * daqInputSource_
EventID const & eventID() const
void postGlobalBeginRun(edm::GlobalContext const &)
void preEvent(edm::StreamContext const &)
std::string const & pathName() const
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=nullptr)
void preSourceEarlyTermination(edm::TerminationOrigin)
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
unsigned int value() const
bool getAbortFlagForLumi(unsigned int lumi)
std::shared_ptr< FastMonitoringThread > fmt_
Log< level::Warning, false > LogWarning
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Writes a Value in JSON format in a human friendly way.
bool exceptionDetected() const
void reportLockWait(unsigned int ls, double waitTime, unsigned int lockCount)
std::vector< unsigned int > exceptionInLS_
std::vector< std::string > const & paths() const
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
array value (ordered list)