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_);
395 context =
" FromAnotherContext";
397 context =
" FromExternalSignal";
401 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
410 context =
" FromAnotherContext";
412 context =
" FromExternalSignal";
414 <<
"earlyTermination -: " <<
context;
415 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
430 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
435 if (
desc.moduleName() ==
"Stream" ||
desc.moduleName() ==
"ShmStreamConsumer" ||
436 desc.moduleName() ==
"EvFOutputModule" ||
desc.moduleName() ==
"EventStreamFileWriter" ||
437 desc.moduleName() ==
"PoolOutputModule") {
438 fmt_->m_data.encModule_.updateReserved((
void*)&
desc);
441 fmt_->m_data.encModule_.update((
void*)&
desc);
457 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
459 fmt_->m_data.microstateBins_ =
fmt_->m_data.encModule_.vecsize() * 2;
473 timeval lumiStartTime;
474 gettimeofday(&lumiStartTime,
nullptr);
478 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
484 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " <<
lumi;
485 timeval lumiStopTime;
486 gettimeofday(&lumiStopTime,
nullptr);
488 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
493 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec) * 1000000 + (lumiStopTime.tv_usec - stt.tv_usec);
496 double throughput =
throughputFactor() * double(accuSize) / double(usecondsForLumi);
498 fmt_->m_data.fastThroughputJ_.value() = throughput;
504 IntJ* lumiProcessedJptr = dynamic_cast<IntJ*>(
fmt_->jsonMonitor_->getMergedIntJForLumi(
"Processed",
lumi));
505 if (!lumiProcessedJptr)
506 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
513 exception_detected =
true;
518 <<
" events were processed in LUMI " <<
lumi;
529 if (sourceReport.first) {
531 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " <<
lumi
533 <<
" events(source):" << sourceReport.second;
538 <<
"Statistics for lumisection -: lumi = " <<
lumi <<
" events = " << lumiProcessedJptr->
value()
539 <<
" time = " << usecondsForLumi / 1000000 <<
" size = " << accuSize <<
" thr = " << throughput;
540 delete lumiProcessedJptr;
547 std::stringstream slowFileNameStem;
548 slowFileNameStem <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
549 << std::setw(5) << getpid();
551 slow /= slowFileNameStem.str();
552 fmt_->jsonMonitor_->outputFullJSONs(slow.string(),
".jsn",
lumi,
output);
554 std::stringstream slowFileName;
555 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) <<
lumi <<
"_pid" << std::setfill(
'0')
556 << std::setw(5) << getpid() <<
".jsn";
558 slow /= slowFileName.str();
562 fmt_->jsonMonitor_->discardCollected(
lumi);
566 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
580 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
584 *(
fmt_->m_data.processed_[sid]) = 0;
596 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
624 fmt_->m_data.fastPathProcessedJ_ =
res + 1;
671 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
698 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
721 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
727 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
731 unsigned int proc = it->second.first;
733 *abortFlag = it->second.second;
737 <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: "
745 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
749 unsigned int abortFlag = it->second.second;
753 <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: "
761 monInit_.exchange(
true, std::memory_order_acquire);
762 while (!
fmt_->m_stoprequest) {
763 std::vector<std::vector<unsigned int>> lastEnc;
765 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
769 lastEnc.emplace_back(
fmt_->m_data.ministateEncoded_);
770 lastEnc.emplace_back(
fmt_->m_data.microstateEncoded_);
774 std::vector<std::string> CSVv;
776 CSVv.push_back(
fmt_->jsonMonitor_->getCSVString((
int)
i));
778 fmt_->monlock_.unlock();
786 fmt_->monlock_.unlock();
794 std::stringstream accum;
798 accum <<
"[" <<
p[
i] <<
",";
800 accum <<
p[
i] <<
",";
802 accum <<
p[
i] <<
"]";
806 accum <<
"Current states: Ms=" <<
fmt_->m_data.fastMacrostateJ_.value() <<
" ms=";
819 fmt_->m_data.fastMacrostateJ_ =
fmt_->m_data.macrostate_;
821 std::vector<const void*> microstateCopy(
fmt_->m_data.microstate_.begin(),
fmt_->m_data.microstate_.end());
822 std::vector<unsigned char> microstateAcqCopy(
fmt_->m_data.microstateAcqFlag_.begin(),
823 fmt_->m_data.microstateAcqFlag_.end());
828 fmt_->m_data.fastAvgLeadTimeJ_ = itd->second;
830 fmt_->m_data.fastAvgLeadTimeJ_ = 0.;
834 fmt_->m_data.fastFilesProcessedJ_ = iti->second;
836 fmt_->m_data.fastFilesProcessedJ_ = 0;
840 fmt_->m_data.fastLockWaitJ_ = itrd->second.first;
841 fmt_->m_data.fastLockCountJ_ = itrd->second.second;
843 fmt_->m_data.fastLockWaitJ_ = 0.;
844 fmt_->m_data.fastLockCountJ_ = 0.;
849 fmt_->m_data.ministateEncoded_[
i] =
fmt_->m_data.encPath_[
i].encodeString(
fmt_->m_data.ministate_[
i]);
850 if (microstateAcqCopy[
i])
851 fmt_->m_data.microstateEncoded_[
i] =
852 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
854 fmt_->m_data.microstateEncoded_[
i] =
fmt_->m_data.encModule_.encode(microstateCopy[
i]);
857 bool inputStatePerThread =
false;
960 inputStatePerThread =
true;
971 inputStatePerThread =
true;
984 if (!inputStatePerThread)
986 fmt_->m_data.inputState_[
i] =
fmt_->m_data.inputState_[0];
989 fmt_->jsonMonitor_->snapGlobal(
ls);
991 fmt_->jsonMonitor_->snap(
ls);