62 "NewLumiBusyEndingLS",
63 "NewLumiIdleEndingLS",
73 "NoRequestWithIdleThreads",
74 "NoRequestWithGlobalEoL",
75 "NoRequestWithEoLThreads",
78 "SupWaitFreeChunkCopying",
80 "SupWaitFreeThreadCopying",
83 "SupLockPollingCopying",
86 "SupNewFileWaitThreadCopying",
87 "SupNewFileWaitThread",
88 "SupNewFileWaitChunkCopying",
89 "SupNewFileWaitChunk",
90 "WaitInput_fileLimit",
91 "WaitInput_waitFreeChunk",
92 "WaitInput_waitFreeChunkCopying",
93 "WaitInput_waitFreeThread",
94 "WaitInput_waitFreeThreadCopying",
96 "WaitInput_lockPolling",
97 "WaitInput_lockPollingCopying",
101 "WaitInput_newFileWaitThreadCopying",
102 "WaitInput_newFileWaitThread",
103 "WaitInput_newFileWaitChunkCopying",
104 "WaitInput_newFileWaitChunk",
105 "WaitChunk_fileLimit",
106 "WaitChunk_waitFreeChunk",
107 "WaitChunk_waitFreeChunkCopying",
108 "WaitChunk_waitFreeThread",
109 "WaitChunk_waitFreeThreadCopying",
111 "WaitChunk_lockPolling",
112 "WaitChunk_lockPollingCopying",
116 "WaitChunk_newFileWaitThreadCopying",
117 "WaitChunk_newFileWaitThread",
118 "WaitChunk_newFileWaitChunkCopying",
119 "WaitChunk_newFileWaitChunk",
123 const std::string FastMonitoringService::nopath_ =
"NoPath";
130 sleepTime_(iPS.getUntrackedParameter<
int>(
"sleepTime", 1)),
131 fastMonIntervals_(iPS.getUntrackedParameter<unsigned
int>(
"fastMonIntervals", 2)),
132 fastName_(
"fastmoni"),
133 slowName_(
"slowmoni"),
134 filePerFwkStream_(iPS.getUntrackedParameter<
bool>(
"filePerFwkStream",
false)),
135 totalEventsProcessed_(0) {
173 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
175 if (
stat(microstatePath.c_str(), &statbuf)) {
176 microstatePath =
std::string(std::getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
177 if (
stat(microstatePath.c_str(), &statbuf)) {
178 microstatePath = microstateBaseSuffix;
179 if (
stat(microstatePath.c_str(), &statbuf))
180 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
190 desc.setComment(
"Service for File-based DAQ monitoring and event accounting");
191 desc.addUntracked<
int>(
"sleepTime", 1)->setComment(
"Sleep time of the monitoring thread");
192 desc.addUntracked<
unsigned int>(
"fastMonIntervals", 2)
193 ->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
194 desc.addUntracked<
bool>(
"filePerFwkStream",
false)
195 ->setComment(
"Switches on monitoring output per framework stream");
196 desc.setAllowAnything();
197 descriptions.
add(
"FastMonitoringService",
desc);
202 for (
int i = 0;
i <
fmt_->m_data.encPath_[0].current_;
i++)
203 legendaVector.
append(
Json::Value(*(static_cast<const std::string*>(
fmt_->m_data.encPath_[0].decode(
i)))));
206 pathLegend[
"names"] = legendaVector;
207 pathLegend[
"reserved"] = valReserved;
209 return writer.write(pathLegend);
214 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
216 Json::Value((static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel()));
218 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
220 (static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel() +
"__ACQ"));
225 moduleLegend[
"names"] = legendaVector;
226 moduleLegend[
"reserved"] = valReserved;
227 moduleLegend[
"special"] = valSpecial;
228 moduleLegend[
"output"] = valOutputModules;
230 return writer.write(moduleLegend);
238 moduleLegend[
"names"] = legendaVector;
240 return writer.write(moduleLegend);
259 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
270 <<
". No monitoring data will be written.";
273 std::ostringstream fastFileName;
275 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
277 fast /= fastFileName.str();
281 std::ostringstream fastFileNameTid;
282 fastFileNameTid <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
"_tid" <<
i 285 fastTid /= fastFileNameTid.str();
289 std::ostringstream moduleLegFile;
290 std::ostringstream moduleLegFileJson;
291 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
292 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
296 std::ostringstream pathLegFile;
297 std::ostringstream pathLegFileJson;
298 pathLegFile <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
300 pathLegFileJson <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
303 std::ostringstream inputLegFileJson;
304 inputLegFileJson <<
"inputlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
321 fmt_->m_data.encModule_.completeReservedWithDummies();
326 fmt_->m_data.microstateAcqFlag_.push_back(0);
332 fmt_->m_data.encPath_.emplace_back(0);
333 fmt_->m_data.encPath_[
i].update(static_cast<const void*>(&
nopath_));
336 fmt_->m_data.encPath_[
i].updatePreinit(
path);
338 for (
auto& endPath : pathsInfo.
endPaths()) {
339 fmt_->m_data.encPath_[
i].updatePreinit(endPath);
347 fmt_->m_data.microstateBins_ = 0;
349 fmt_->m_data.ministateBins_ =
fmt_->m_data.encPath_[0].vecsize();
359 monInit_.store(
false, std::memory_order_release);
380 context =
" FromAnotherContext";
382 context =
" FromExternalSignal";
386 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
396 context =
" FromAnotherContext";
398 context =
" FromExternalSignal";
402 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
412 context =
" FromAnotherContext";
414 context =
" FromExternalSignal";
416 <<
"earlyTermination -: " <<
context;
417 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
424 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
440 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
452 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
457 if (
desc.moduleName() ==
"Stream" ||
desc.moduleName() ==
"GlobalEvFOutputModule" ||
458 desc.moduleName() ==
"EvFOutputModule" ||
desc.moduleName() ==
"EventStreamFileWriter" ||
459 desc.moduleName() ==
"PoolOutputModule") {
460 fmt_->m_data.encModule_.updateReserved((
void*)&
desc);
463 fmt_->m_data.encModule_.update((
void*)&
desc);
479 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
481 fmt_->m_data.microstateBins_ =
fmt_->m_data.encModule_.vecsize() * 2;
495 timeval lumiStartTime;
496 gettimeofday(&lumiStartTime,
nullptr);
500 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
506 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " <<
lumi;
507 timeval lumiStopTime;
508 gettimeofday(&lumiStopTime,
nullptr);
510 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
515 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec) * 1000000 + (lumiStopTime.tv_usec - stt.tv_usec);
518 double throughput =
throughputFactor() * double(accuSize) / double(usecondsForLumi);
520 fmt_->m_data.fastThroughputJ_.value() = throughput;
526 IntJ* lumiProcessedJptr =
dynamic_cast<IntJ*
>(
fmt_->jsonMonitor_->getMergedIntJForLumi(
"Processed",
lumi));
527 if (!lumiProcessedJptr)
528 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
535 exception_detected =
true;
540 <<
" events were processed in LUMI " <<
lumi;
551 if (sourceReport.first) {
553 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " <<
lumi 555 <<
" events(source):" << sourceReport.second;
560 <<
"Statistics for lumisection -: lumi = " <<
lumi <<
" events = " << lumiProcessedJptr->
value()
561 <<
" time = " << usecondsForLumi / 1000000 <<
" size = " << accuSize <<
" thr = " << throughput;
562 delete lumiProcessedJptr;
569 std::stringstream slowFileNameStem;
570 slowFileNameStem <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
571 << std::setw(5) << getpid();
573 slow /= slowFileNameStem.str();
574 fmt_->jsonMonitor_->outputFullJSONs(slow.string(),
".jsn",
lumi,
output);
576 std::stringstream slowFileName;
577 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
578 << std::setw(5) << getpid() <<
".jsn";
580 slow /= slowFileName.str();
584 fmt_->jsonMonitor_->discardCollected(
lumi);
588 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
602 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
606 *(
fmt_->m_data.processed_[sid]) = 0;
618 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
646 fmt_->m_data.fastPathProcessedJ_ =
res + 1;
693 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
720 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
743 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
749 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
753 unsigned int proc = it->second.first;
755 *abortFlag = it->second.second;
759 <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: " 767 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
771 unsigned int abortFlag = it->second.second;
775 <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: " 783 monInit_.exchange(
true, std::memory_order_acquire);
784 while (!
fmt_->m_stoprequest) {
785 std::vector<std::vector<unsigned int>> lastEnc;
787 std::unique_lock<std::mutex>
lock(
fmt_->monlock_);
791 lastEnc.emplace_back(
fmt_->m_data.ministateEncoded_);
792 lastEnc.emplace_back(
fmt_->m_data.microstateEncoded_);
796 std::vector<std::string> CSVv;
798 CSVv.push_back(
fmt_->jsonMonitor_->getCSVString((
int)
i));
801 lock.release()->unlock();
809 lock.release()->unlock();
819 auto f = [&](std::vector<unsigned int>
const&
p) {
822 msg <<
"[" <<
p[
i] <<
",";
830 msg <<
"Current states: Ms=" <<
fmt_->m_data.fastMacrostateJ_.value() <<
" ms=";
843 fmt_->m_data.fastMacrostateJ_ =
fmt_->m_data.macrostate_;
845 std::vector<const void*> microstateCopy(
fmt_->m_data.microstate_.begin(),
fmt_->m_data.microstate_.end());
846 std::vector<unsigned char> microstateAcqCopy(
fmt_->m_data.microstateAcqFlag_.begin(),
847 fmt_->m_data.microstateAcqFlag_.end());
852 fmt_->m_data.fastAvgLeadTimeJ_ = itd->second;
854 fmt_->m_data.fastAvgLeadTimeJ_ = 0.;
858 fmt_->m_data.fastFilesProcessedJ_ = iti->second;
860 fmt_->m_data.fastFilesProcessedJ_ = 0;
864 fmt_->m_data.fastLockWaitJ_ = itrd->second.first;
865 fmt_->m_data.fastLockCountJ_ = itrd->second.second;
867 fmt_->m_data.fastLockWaitJ_ = 0.;
868 fmt_->m_data.fastLockCountJ_ = 0.;
873 fmt_->m_data.ministateEncoded_[
i] =
fmt_->m_data.encPath_[
i].encodeString(
fmt_->m_data.ministate_[
i]);
874 if (microstateAcqCopy[
i])
875 fmt_->m_data.microstateEncoded_[
i] =
876 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
878 fmt_->m_data.microstateEncoded_[
i] =
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
881 bool inputStatePerThread =
false;
984 inputStatePerThread =
true;
995 inputStatePerThread =
true;
1008 if (!inputStatePerThread)
1010 fmt_->m_data.inputState_[
i] =
fmt_->m_data.inputState_[0];
1013 fmt_->jsonMonitor_->snapGlobal(
ls);
1015 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_
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_
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)