110 "NewLumiBusyEndingLS",
111 "NewLumiIdleEndingLS",
121 "NoRequestWithIdleThreads",
122 "NoRequestWithGlobalEoL",
123 "NoRequestWithEoLThreads",
126 "SupWaitFreeChunkCopying",
128 "SupWaitFreeThreadCopying",
131 "SupLockPollingCopying",
134 "SupNewFileWaitThreadCopying",
135 "SupNewFileWaitThread",
136 "SupNewFileWaitChunkCopying",
137 "SupNewFileWaitChunk",
138 "WaitInput_fileLimit",
139 "WaitInput_waitFreeChunk",
140 "WaitInput_waitFreeChunkCopying",
141 "WaitInput_waitFreeThread",
142 "WaitInput_waitFreeThreadCopying",
144 "WaitInput_lockPolling",
145 "WaitInput_lockPollingCopying",
149 "WaitInput_newFileWaitThreadCopying",
150 "WaitInput_newFileWaitThread",
151 "WaitInput_newFileWaitChunkCopying",
152 "WaitInput_newFileWaitChunk",
153 "WaitChunk_fileLimit",
154 "WaitChunk_waitFreeChunk",
155 "WaitChunk_waitFreeChunkCopying",
156 "WaitChunk_waitFreeThread",
157 "WaitChunk_waitFreeThreadCopying",
159 "WaitChunk_lockPolling",
160 "WaitChunk_lockPollingCopying",
164 "WaitChunk_newFileWaitThreadCopying",
165 "WaitChunk_newFileWaitThread",
166 "WaitChunk_newFileWaitChunkCopying",
167 "WaitChunk_newFileWaitChunk",
178 : num_threads(),
max_threads(num_expected), threadactive_(num_expected, 0) {
185 threadactive_[tbb::this_task_arena::current_thread_index()] = 1;
190 threadactive_[tbb::this_task_arena::current_thread_index()] = 0;
199 tbbMonitoringMode_(iPS.getUntrackedParameter<
bool>(
"tbbMonitoringMode",
true)),
200 tbbConcurrencyTracker_(iPS.getUntrackedParameter<
bool>(
"tbbConcurrencyTracker",
true) && tbbMonitoringMode_),
201 sleepTime_(iPS.getUntrackedParameter<
int>(
"sleepTime", 1)),
202 fastMonIntervals_(iPS.getUntrackedParameter<unsigned
int>(
"fastMonIntervals", 2)),
203 fastName_(
"fastmoni"),
204 totalEventsProcessed_(0),
205 verbose_(iPS.getUntrackedParameter<
bool>(
"verbose")) {
242 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
244 if (
stat(microstatePath.c_str(), &statbuf)) {
245 microstatePath =
std::string(std::getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
246 if (
stat(microstatePath.c_str(), &statbuf)) {
247 microstatePath = microstateBaseSuffix;
248 if (
stat(microstatePath.c_str(), &statbuf))
249 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
259 desc.setComment(
"Service for File-based DAQ monitoring and event accounting");
260 desc.addUntracked<
bool>(
"tbbMonitoringMode",
true)
261 ->setComment(
"Monitor individual module processing per TBB thread instead of stream");
262 desc.addUntracked<
bool>(
"tbbConcurrencyTracker",
true)
263 ->setComment(
"Monitor TBB thread activity to flag microstate as real idle or overhead/other");
264 desc.addUntracked<
int>(
"sleepTime", 1)->setComment(
"Sleep time of the monitoring thread");
265 desc.addUntracked<
unsigned int>(
"fastMonIntervals", 2)
266 ->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
267 desc.addUntracked<
bool>(
"filePerFwkStream",
true)
268 ->setComment(
"Switches on monitoring output per framework stream");
269 desc.addUntracked<
bool>(
"verbose",
false)->setComment(
"Set to use LogInfo messages from the monitoring thread");
270 desc.setAllowAnything();
271 descriptions.
add(
"FastMonitoringService",
desc);
276 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
278 Json::Value((static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel()));
280 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
282 (static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel() +
"__ACQ"));
287 moduleLegend[
"names"] = legendaVector;
288 moduleLegend[
"reserved"] = valReserved;
289 moduleLegend[
"special"] = valSpecial;
290 moduleLegend[
"output"] = valOutputModules;
292 return writer.write(moduleLegend);
300 moduleLegend[
"names"] = legendaVector;
302 return writer.write(moduleLegend);
325 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
336 <<
". No monitoring data will be written.";
339 std::ostringstream fastFileName;
341 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
343 fast /= fastFileName.str();
346 std::ostringstream moduleLegFile;
347 std::ostringstream moduleLegFileJson;
348 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
349 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
353 std::ostringstream inputLegFileJson;
354 inputLegFileJson <<
"inputlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
370 fmt_->m_data.encModule_.completeReservedWithDummies();
384 fmt_->m_data.microstateBins_ = 0;
395 monInit_.store(
false, std::memory_order_release);
405 context =
" FromAnotherContext";
407 context =
" FromExternalSignal";
411 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
421 context =
" FromAnotherContext";
423 context =
" FromExternalSignal";
427 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
437 context =
" FromAnotherContext";
439 context =
" FromExternalSignal";
441 <<
"earlyTermination -: " <<
context;
442 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
449 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
465 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
477 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
482 if (
desc.moduleName() ==
"Stream" ||
desc.moduleName() ==
"GlobalEvFOutputModule" ||
483 desc.moduleName() ==
"EventStreamFileWriter" ||
desc.moduleName() ==
"PoolOutputModule") {
484 fmt_->m_data.encModule_.updateReserved((
void*)&
desc);
487 fmt_->m_data.encModule_.update((
void*)&
desc);
500 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
502 fmt_->m_data.microstateBins_ =
fmt_->m_data.encModule_.vecsize() * 2;
516 timeval lumiStartTime;
517 gettimeofday(&lumiStartTime,
nullptr);
521 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
532 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " <<
lumi;
533 timeval lumiStopTime;
534 gettimeofday(&lumiStopTime,
nullptr);
536 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
541 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec) * 1000000 + (lumiStopTime.tv_usec - stt.tv_usec);
544 double throughput =
throughputFactor() * double(accuSize) / double(usecondsForLumi);
546 fmt_->m_data.fastThroughputJ_.value() = throughput;
552 IntJ* lumiProcessedJptr =
dynamic_cast<IntJ*
>(
fmt_->jsonMonitor_->getMergedIntJForLumi(
"Processed",
lumi));
553 if (!lumiProcessedJptr)
554 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
561 exception_detected =
true;
566 <<
" events were processed in LUMI " <<
lumi;
578 if (sourceReport.first) {
580 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " <<
lumi 582 <<
" events(source):" << sourceReport.second;
588 <<
"Statistics for lumisection -: lumi = " <<
lumi <<
" events = " << lumiProcessedJptr->
value()
589 <<
" time = " << usecondsForLumi / 1000000 <<
" size = " << accuSize <<
" thr = " << throughput;
590 delete lumiProcessedJptr;
593 fmt_->jsonMonitor_->outputFullJSON(
"dummy",
lumi,
false);
594 fmt_->jsonMonitor_->discardCollected(
lumi);
598 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
610 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
624 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
644 fmt_->m_data.fastPathProcessedJ_ =
res + 1;
717 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
744 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
767 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
777 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
781 unsigned int proc =
it->second.first;
783 *abortFlag =
it->second.second;
787 <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: " 795 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
799 unsigned int abortFlag =
it->second.second;
803 <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: " 811 monInit_.exchange(
true, std::memory_order_acquire);
812 while (!
fmt_->m_stoprequest) {
813 std::vector<std::vector<unsigned int>> lastEnc;
815 std::unique_lock<std::mutex>
lock(
fmt_->monlock_);
819 lastEnc.emplace_back(
fmt_->m_data.tmicrostateEncoded_);
820 lastEnc.emplace_back(
fmt_->m_data.microstateEncoded_);
823 std::vector<std::string> CSVv;
825 CSVv.push_back(
fmt_->jsonMonitor_->getCSVString((
int)
i));
828 lock.release()->unlock();
836 auto f = [&](std::vector<unsigned int>
const&
p) {
839 msg <<
"[" <<
p[
i] <<
",";
847 msg <<
"Current states: Ms=" <<
fmt_->m_data.fastMacrostateJ_.value() <<
" ms=";
860 fmt_->m_data.fastMacrostateJ_ =
fmt_->m_data.macrostate_;
870 fmt_->m_data.fastAvgLeadTimeJ_ = itd->second;
872 fmt_->m_data.fastAvgLeadTimeJ_ = 0.;
876 fmt_->m_data.fastFilesProcessedJ_ = iti->second;
878 fmt_->m_data.fastFilesProcessedJ_ = 0;
882 fmt_->m_data.fastLockWaitJ_ = itrd->second.first;
883 fmt_->m_data.fastLockCountJ_ = itrd->second.second;
885 fmt_->m_data.fastLockWaitJ_ = 0.;
886 fmt_->m_data.fastLockCountJ_ = 0.;
891 if (tmicrostateCopy[
i] ==
getmIdle() &&
ct_->isThreadActive(
i)) {
895 if (tmicrostateAcqCopy[
i])
896 fmt_->m_data.tmicrostateEncoded_[
i] =
897 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(tmicrostateCopy[
i]);
899 fmt_->m_data.tmicrostateEncoded_[
i] =
fmt_->m_data.encModule_.encode(tmicrostateCopy[
i]);
903 if (microstateAcqCopy[
i])
904 fmt_->m_data.microstateEncoded_[
i] =
905 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
907 fmt_->m_data.microstateEncoded_[
i] =
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
910 bool inputStatePerThread =
false;
1013 inputStatePerThread =
true;
1017 else if (microstateCopy[
i] ==
getmIdle())
1025 inputStatePerThread =
true;
1039 if (!inputStatePerThread)
1041 fmt_->m_data.inputState_[
i] =
fmt_->m_data.inputState_[0];
1044 fmt_->jsonMonitor_->snapGlobal(
ls);
1046 fmt_->jsonMonitor_->snap(
ls);
std::atomic< bool > has_data_exception_
constexpr edm::ModuleDescription const * getmFwkEoL()
std::atomic< FastMonState::InputState > inputState_
void watchPreStreamEarlyTermination(PreStreamEarlyTermination::slot_type const &iSlot)
static const std::string inputStateNames[FastMonState::inCOUNT]
constexpr edm::ModuleDescription const * getmInvalid()
constexpr edm::ModuleDescription const * getmFwkOvhSrc()
void watchPreEvent(PreEvent::slot_type const &iSlot)
constexpr edm::ModuleDescription const * getmFwkOvhMod()
void postModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
LuminosityBlockNumber_t luminosityBlock() const
std::vector< ContainableAtomic< const void * > > microstate_
constexpr edm::ModuleDescription const * getmIdle()
void postSourceEvent(edm::StreamID)
std::atomic< bool > isInitTransition_
void watchPreallocate(Preallocate::slot_type const &iSlot)
void startedLookingForFile()
constexpr edm::ModuleDescription const * getmBoL()
void setExceptionDetected(unsigned int ls)
void on_scheduler_exit(bool) override
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_
constexpr edm::ModuleDescription const * getmIgnore()
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
bool tbbConcurrencyTracker_
void watchPostStreamEndLumi(PostStreamEndLumi::slot_type const &iSlot)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
unsigned int nOutputModules_
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
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 &)
unsigned int lastGlobalLumi_
std::vector< ContainableAtomic< unsigned int > > threadactive_
ModuleDescription const * moduleDescription() const noexcept
bool isExceptionOnData(unsigned int ls)
void watchPreStreamEndLumi(PreStreamEndLumi::slot_type const &iSlot)
std::unique_ptr< FastMonitoringThread > fmt_
constexpr edm::ModuleDescription const * getmFwk()
void preGlobalEarlyTermination(edm::GlobalContext const &, edm::TerminationOrigin)
void watchPreSourceEarlyTermination(PreSourceEarlyTermination::slot_type const &iSlot)
constexpr int nSpecialModules
std::string inputLegendFileJson_
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()
ConcurrencyTracker(unsigned num_expected)
void preModuleBeginJob(edm::ModuleDescription const &)
std::string makeInputLegendaJson()
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
constexpr edm::ModuleDescription const * getmEoL()
unsigned int lumiFromSource_
void on_scheduler_entry(bool) override
constexpr edm::ModuleDescription const * getmGlobEoL()
std::string microstateDefPath_
void preStreamEndLumi(edm::StreamContext const &)
std::vector< ContainableAtomic< unsigned char > > tmicrostateAcqFlag_
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)
Writes a Value in JSON format in a human friendly way.
std::atomic< FastMonState::InputState > inputSupervisorState_
unsigned int nMonThreads_
StreamID const & streamID() const
static unsigned int getTID()
constexpr double throughputFactor()
void watchPostModuleEventAcquire(PostModuleEventAcquire::slot_type const &iSlot)
std::string fastMicrostateDefPath_
array value (ordered list)
std::filesystem::path runDirectory_
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
std::string moduleLegendFileJson_
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
std::vector< ContainableAtomic< unsigned char > > microstateAcqFlag_
void preModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
LuminosityBlockID const & luminosityBlockID() const
void postStreamBeginLumi(edm::StreamContext const &)
static unsigned int getSID(edm::StreamContext const &sc)
std::unique_ptr< ConcurrencyTracker > ct_
Log< level::Info, false > LogInfo
void preSourceEvent(edm::StreamID)
void postStreamEndLumi(edm::StreamContext const &)
constexpr edm::ModuleDescription const * getmInput()
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_
Value & append(const Value &value)
Append value to array at the end.
void setTMicrostate(FastMonState::Microstate m)
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
std::atomic< int > num_threads
constexpr edm::ModuleDescription const * getmEvent()
void postGlobalBeginRun(edm::GlobalContext const &)
void preEvent(edm::StreamContext 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)
bool isThreadActive(unsigned index)
Log< level::Warning, false > LogWarning
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
static const edm::ModuleDescription specialMicroStateNames[FastMonState::mCOUNT]
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
bool exceptionDetected() const
JSON (JavaScript Object Notation).
void reportLockWait(unsigned int ls, double waitTime, unsigned int lockCount)
std::vector< unsigned int > exceptionInLS_
constexpr edm::ModuleDescription const * getmIdleSource()
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
constexpr edm::ModuleDescription const * getmDqm()
std::vector< ContainableAtomic< const void * > > tmicrostate_