CMS 3D CMS Logo

FastMonitoringThread.h
Go to the documentation of this file.
1 #ifndef EVF_FASTMONITORINGTHREAD
2 #define EVF_FASTMONITORINGTHREAD
3 
5 
6 #include <iostream>
7 #include <vector>
8 #include <thread>
9 #include <mutex>
10 
11 namespace evf {
12 
14 
16  public:
17  // a copy of the Framework/EventProcessor states
18  enum Macrostate {
19  sInit = 0,
32  };
33 
34  enum InputState {
35  inIgnore = 0,
53  //supervisor thread and worker threads state
68  //combined with inWaitInput
84  //combined with inWaitChunk
101  };
102 
103  struct MonitorData {
104  //fastpath global monitorables
112 
113  unsigned int varIndexThrougput_;
114 
115  //per stream
116  std::vector<unsigned int> microstateEncoded_;
117  std::vector<unsigned int> ministateEncoded_;
118  std::vector<jsoncollector::AtomicMonUInt*> processed_;
120  std::vector<unsigned int> threadMicrostateEncoded_;
121  std::vector<unsigned int> inputState_;
122 
123  //tracking luminosity of a stream
124  std::vector<unsigned int> streamLumi_;
125 
126  //N bins for histograms
127  unsigned int macrostateBins_;
128  unsigned int ministateBins_;
129  unsigned int microstateBins_;
130  unsigned int inputstateBins_;
131 
132  //unsigned int prescaleindex_; // ditto
133 
136  fastThroughputJ_ = 0;
137  fastAvgLeadTimeJ_ = 0;
139  fastLockWaitJ_ = 0;
140  fastLockCountJ_ = 0;
141  fastMacrostateJ_.setName("Macrostate");
142  fastThroughputJ_.setName("Throughput");
143  fastAvgLeadTimeJ_.setName("AverageLeadTime");
144  fastFilesProcessedJ_.setName("FilesProcessed");
145  fastLockWaitJ_.setName("LockWaitUs");
146  fastLockCountJ_.setName("LockCount");
147 
149  fastPathProcessedJ_.setName("Processed");
150  }
151 
152  //to be called after fast monitor is constructed
153  void registerVariables(jsoncollector::FastMonitor* fm, unsigned int nStreams, unsigned int nThreads) {
154  //tell FM to track these global variables(for fast and slow monitoring)
161 
162  for (unsigned int i = 0; i < nStreams; i++) {
164  *p = 0;
165  processed_.push_back(p);
166  streamLumi_.push_back(0);
167  }
168 
170  ministateEncoded_.resize(nStreams);
172  inputState_.resize(nStreams);
173  for (unsigned int j = 0; j < inputState_.size(); j++)
174  inputState_[j] = 0;
175 
176  //tell FM to track these int vectors
178 
179  if (nThreads <= nStreams) //no overlapping in module execution per stream
181  else
183 
184  fm->registerStreamMonitorableUIntVecAtomic("Processed", &processed_, false, nullptr);
185 
186  //input source state tracking (not stream, but other than first item in vector is set to Ignore state)
188 
189  //global cumulative event counter is used for fast path
191 
192  //provide vector with updated per stream lumis and let it finish initialization
193  fm->commit(&streamLumi_);
194  }
195  };
196 
197  //constructor
199 
200  void resetFastMonitor(std::string const& microStateDefPath, std::string const& fastMicroStateDefPath) {
201  std::string defGroup = "data";
202  jsonMonitor_.reset(new jsoncollector::FastMonitor(microStateDefPath, defGroup, false));
203  if (!fastMicroStateDefPath.empty())
204  jsonMonitor_->addFastPathDefinition(fastMicroStateDefPath, defGroup, false);
205  }
206 
208  assert(!m_thread);
209  m_thread = std::make_shared<std::thread>(fp, cp);
210  }
211  void stop() {
212  assert(m_thread);
213  m_stoprequest = true;
214  m_thread->join();
215  }
216 
217  private:
218  std::atomic<bool> m_stoprequest;
219  std::shared_ptr<std::thread> m_thread;
222 
223  std::unique_ptr<jsoncollector::FastMonitor> jsonMonitor_;
224 
225  friend class FastMonitoringService;
226  };
227 } //end namespace evf
228 #endif
evf::FastMonitoringThread::MonitorData::microstateEncoded_
std::vector< unsigned int > microstateEncoded_
Definition: FastMonitoringThread.h:116
evf::FastMonitoringThread::inWaitChunk_newFile
Definition: FastMonitoringThread.h:95
evf::FastMonitoringThread::inNewLumiBusyEndingLS
Definition: FastMonitoringThread.h:39
evf::FastMonitoringThread::MonitorData::processed_
std::vector< jsoncollector::AtomicMonUInt * > processed_
Definition: FastMonitoringThread.h:118
evf::FastMonitoringThread::monlock_
std::mutex monlock_
Definition: FastMonitoringThread.h:221
mps_fire.i
i
Definition: mps_fire.py:428
evf::FastMonitoringThread::MonitorData::MonitorData
MonitorData()
Definition: FastMonitoringThread.h:134
evf::FastMonitoringThread::MonitorData::threadMicrostateEncoded_
std::vector< unsigned int > threadMicrostateEncoded_
Definition: FastMonitoringThread.h:120
funct::false
false
Definition: Factorize.h:29
evf::FastMonitoringThread::inSupFileLimit
Definition: FastMonitoringThread.h:54
evf::FastMonitoringThread::MonitorData::fastAvgLeadTimeJ_
jsoncollector::DoubleJ fastAvgLeadTimeJ_
Definition: FastMonitoringThread.h:107
evf::FastMonitoringThread::MonitorData::fastLockWaitJ_
jsoncollector::DoubleJ fastLockWaitJ_
Definition: FastMonitoringThread.h:109
evf::FastMonitoringThread::inSupWaitFreeChunk
Definition: FastMonitoringThread.h:55
evf::FastMonitoringThread::inWaitInput_waitFreeChunkCopying
Definition: FastMonitoringThread.h:71
jsoncollector::FastMonitor::commit
void commit(std::vector< unsigned int > *streamLumisPtr)
Definition: FastMonitor.cc:115
evf::FastMonitoringThread::MonitorData::inputstateBins_
unsigned int inputstateBins_
Definition: FastMonitoringThread.h:130
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
evf::FastMonitoringThread::inRunEnd
Definition: FastMonitoringThread.h:41
cms::cuda::assert
assert(be >=bs)
evf::FastMonitoringThread::sInvalid
Definition: FastMonitoringThread.h:30
evf::FastMonitoringThread::sRunning
Definition: FastMonitoringThread.h:22
evf::FastMonitoringThread::inWaitChunk_newFileWaitThread
Definition: FastMonitoringThread.h:97
evf::FastMonitoringThread::sJobReady
Definition: FastMonitoringThread.h:20
personalPlayback.fp
fp
Definition: personalPlayback.py:523
evf::FastMonitoringThread
Definition: FastMonitoringThread.h:15
evf::FastMonitoringThread::inCachedEvent
Definition: FastMonitoringThread.h:46
evf::FastMonitoringThread::inWaitChunk_newFileWaitThreadCopying
Definition: FastMonitoringThread.h:96
evf::FastMonitoringThread::resetFastMonitor
void resetFastMonitor(std::string const &microStateDefPath, std::string const &fastMicroStateDefPath)
Definition: FastMonitoringThread.h:200
evf::FastMonitoringThread::sJobEnded
Definition: FastMonitoringThread.h:26
evf::FastMonitoringThread::sEnd
Definition: FastMonitoringThread.h:29
evf::FastMonitoringThread::FastMonitoringThread
FastMonitoringThread()
Definition: FastMonitoringThread.h:198
evf::FastMonitoringThread::inWaitChunk
Definition: FastMonitoringThread.h:43
runTheMatrix.nStreams
nStreams
Definition: runTheMatrix.py:362
jsoncollector::FastMonitor::registerGlobalMonitorable
void registerGlobalMonitorable(JsonMonitorable *newMonitorable, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:66
evf::FastMonitoringThread::inWaitChunk_fileLimit
Definition: FastMonitoringThread.h:85
evf::FastMonitoringThread::inProcessingFile
Definition: FastMonitoringThread.h:42
evf::FastMonitoringThread::inSupWaitFreeChunkCopying
Definition: FastMonitoringThread.h:56
evf::FastMonitoringThread::MonitorData::fastFilesProcessedJ_
jsoncollector::IntJ fastFilesProcessedJ_
Definition: FastMonitoringThread.h:108
evf::FastMonitoringThread::m_data
MonitorData m_data
Definition: FastMonitoringThread.h:220
evf::FastMonitoringThread::inWaitInput_lockPolling
Definition: FastMonitoringThread.h:75
evf::FastMonitoringThread::sInit
Definition: FastMonitoringThread.h:19
evf::FastMonitoringService
Definition: FastMonitoringService.h:71
jsoncollector::FastMonitor::registerStreamMonitorableUIntVec
void registerStreamMonitorableUIntVec(std::string const &name, std::vector< unsigned int > *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:87
jsoncollector::JsonMonitorable::setName
virtual void setName(std::string name)
Definition: JsonMonitorable.h:38
jsoncollector::DoubleJ
Definition: JsonMonitorable.h:106
evf::FastMonitoringThread::inWaitChunk_newFileWaitChunkCopying
Definition: FastMonitoringThread.h:98
evf::FastMonitoringThread::inWaitChunk_waitFreeThreadCopying
Definition: FastMonitoringThread.h:89
evf::FastMonitoringThread::MonitorData::inputState_
std::vector< unsigned int > inputState_
Definition: FastMonitoringThread.h:121
evf::FastMonitoringThread::inSupWaitFreeThread
Definition: FastMonitoringThread.h:57
evf::FastMonitoringThread::inWaitInput
Definition: FastMonitoringThread.h:37
evf::FastMonitoringThread::inWaitChunk_noFile
Definition: FastMonitoringThread.h:94
evf::FastMonitoringThread::inReadCleanup
Definition: FastMonitoringThread.h:48
evf::FastMonitoringThread::inWaitInput_lockPollingCopying
Definition: FastMonitoringThread.h:76
evf::FastMonitoringThread::stop
void stop()
Definition: FastMonitoringThread.h:211
evf::FastMonitoringThread::MonitorData::varIndexThrougput_
unsigned int varIndexThrougput_
Definition: FastMonitoringThread.h:113
evf::FastMonitoringThread::MonitorData::fastThroughputJ_
jsoncollector::DoubleJ fastThroughputJ_
Definition: FastMonitoringThread.h:106
evf::FastMonitoringThread::inNoRequestWithEoLThreads
Definition: FastMonitoringThread.h:52
evf::FastMonitoringThread::inChecksumEvent
Definition: FastMonitoringThread.h:45
runTheMatrix.nThreads
nThreads
Definition: runTheMatrix.py:361
evf::FastMonitoringThread::inNewLumi
Definition: FastMonitoringThread.h:38
evf::FastMonitoringThread::inSupNewFileWaitThreadCopying
Definition: FastMonitoringThread.h:64
evf::FastMonitoringThread::sShuttingDown
Definition: FastMonitoringThread.h:24
evf::FastMonitoringThread::MonitorData
Definition: FastMonitoringThread.h:103
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
evf::FastMonitoringThread::sError
Definition: FastMonitoringThread.h:27
evf::FastMonitoringThread::inWaitInput_runEnd
Definition: FastMonitoringThread.h:77
evf::FastMonitoringThread::MonitorData::microstateBins_
unsigned int microstateBins_
Definition: FastMonitoringThread.h:129
evf::FastMonitoringThread::m_stoprequest
std::atomic< bool > m_stoprequest
Definition: FastMonitoringThread.h:218
evf::FastMonitoringThread::MonitorData::streamLumi_
std::vector< unsigned int > streamLumi_
Definition: FastMonitoringThread.h:124
evf::FastMonitoringThread::inWaitChunk_lockPolling
Definition: FastMonitoringThread.h:91
evf::FastMonitoringThread::inWaitInput_newFileWaitChunkCopying
Definition: FastMonitoringThread.h:82
evf::FastMonitoringThread::MCOUNT
Definition: FastMonitoringThread.h:31
evf::FastMonitoringThread::inChunkReceived
Definition: FastMonitoringThread.h:44
jsoncollector::AtomicMonUInt
unsigned int AtomicMonUInt
Definition: DataPoint.h:31
evf::FastMonitoringThread::inSupNewFileWaitChunk
Definition: FastMonitoringThread.h:67
evf::FastMonitoringThread::MonitorData::registerVariables
void registerVariables(jsoncollector::FastMonitor *fm, unsigned int nStreams, unsigned int nThreads)
Definition: FastMonitoringThread.h:153
mutex
static std::mutex mutex
Definition: Proxy.cc:8
jsoncollector::FastMonitor::registerStreamMonitorableUIntVecAtomic
void registerStreamMonitorableUIntVecAtomic(std::string const &name, std::vector< AtomicMonUInt * > *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:100
evf::FastMonitoringThread::inSupNewFile
Definition: FastMonitoringThread.h:63
evf::FastMonitoringThread::MonitorData::macrostateBins_
unsigned int macrostateBins_
Definition: FastMonitoringThread.h:127
evf::FastMonitoringThread::inWaitChunk_newFileWaitChunk
Definition: FastMonitoringThread.h:99
jsoncollector::FastMonitor::registerFastGlobalMonitorable
void registerFastGlobalMonitorable(JsonMonitorable *newMonitorable)
Definition: FastMonitor.cc:80
evf::FastMonitoringThread::inNewLumiIdleEndingLS
Definition: FastMonitoringThread.h:40
evf::FastMonitoringThread::MonitorData::fastEventsProcessedJ_
jsoncollector::IntJ fastEventsProcessedJ_
Definition: FastMonitoringThread.h:111
evf::FastMonitoringThread::inSupNewFileWaitThread
Definition: FastMonitoringThread.h:65
evf::FastMonitoringThread::inSupLockPolling
Definition: FastMonitoringThread.h:60
jsoncollector::FastMonitor
Definition: FastMonitor.h:19
evf::FastMonitoringThread::m_thread
std::shared_ptr< std::thread > m_thread
Definition: FastMonitoringThread.h:219
evf::FastMonitoringThread::inInit
Definition: FastMonitoringThread.h:36
evf::FastMonitoringThread::sStopping
Definition: FastMonitoringThread.h:23
evf::FastMonitoringThread::inWaitInput_noFile
Definition: FastMonitoringThread.h:78
evf::FastMonitoringThread::MonitorData::fastPathProcessedJ_
jsoncollector::IntJ fastPathProcessedJ_
Definition: FastMonitoringThread.h:119
evf::FastMonitoringThread::inNoRequest
Definition: FastMonitoringThread.h:49
evf::FastMonitoringThread::inWaitChunk_busy
Definition: FastMonitoringThread.h:90
evf::FastMonitoringThread::inWaitInput_newFileWaitThread
Definition: FastMonitoringThread.h:81
evf::FastMonitoringThread::jsonMonitor_
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
Definition: FastMonitoringThread.h:223
evf::FastMonitoringThread::inNoRequestWithGlobalEoL
Definition: FastMonitoringThread.h:51
evf::FastMonitoringThread::inSupBusy
Definition: FastMonitoringThread.h:59
evf::FastMonitoringThread::sErrorEnded
Definition: FastMonitoringThread.h:28
evf
Definition: fillJson.h:27
evf::FastMonitoringThread::MonitorData::fastLockCountJ_
jsoncollector::IntJ fastLockCountJ_
Definition: FastMonitoringThread.h:110
evf::FastMonitoringThread::MonitorData::fastMacrostateJ_
jsoncollector::IntJ fastMacrostateJ_
Definition: FastMonitoringThread.h:105
evf::FastMonitoringThread::inReadEvent
Definition: FastMonitoringThread.h:47
evf::FastMonitoringThread::inWaitChunk_waitFreeChunk
Definition: FastMonitoringThread.h:86
evf::FastMonitoringThread::inNoRequestWithIdleThreads
Definition: FastMonitoringThread.h:50
evf::FastMonitoringThread::inSupNoFile
Definition: FastMonitoringThread.h:62
jsoncollector::IntJ
Definition: JsonMonitorable.h:66
evf::FastMonitoringThread::inSupLockPollingCopying
Definition: FastMonitoringThread.h:61
evf::FastMonitoringThread::inWaitInput_waitFreeChunk
Definition: FastMonitoringThread.h:70
SiStripCommissioningSource_FromEDM_cfg.FastMonitoringService
FastMonitoringService
Definition: SiStripCommissioningSource_FromEDM_cfg.py:49
evf::FastMonitoringThread::inSupNewFileWaitChunkCopying
Definition: FastMonitoringThread.h:66
evf::FastMonitoringThread::inWaitChunk_runEnd
Definition: FastMonitoringThread.h:93
evf::FastMonitoringThread::inIgnore
Definition: FastMonitoringThread.h:35
evf::FastMonitoringThread::InputState
InputState
Definition: FastMonitoringThread.h:34
evf::FastMonitoringThread::inWaitInput_waitFreeThread
Definition: FastMonitoringThread.h:72
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
evf::FastMonitoringThread::inWaitInput_newFileWaitThreadCopying
Definition: FastMonitoringThread.h:80
evf::FastMonitoringThread::inSupWaitFreeThreadCopying
Definition: FastMonitoringThread.h:58
evf::FastMonitoringThread::inCOUNT
Definition: FastMonitoringThread.h:100
evf::FastMonitoringThread::inWaitInput_fileLimit
Definition: FastMonitoringThread.h:69
evf::FastMonitoringThread::inWaitChunk_waitFreeChunkCopying
Definition: FastMonitoringThread.h:87
evf::FastMonitoringThread::inWaitChunk_lockPollingCopying
Definition: FastMonitoringThread.h:92
CommonMethods.cp
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
Definition: CommonMethods.py:192
evf::FastMonitoringThread::inWaitInput_newFile
Definition: FastMonitoringThread.h:79
evf::FastMonitoringThread::inWaitInput_newFileWaitChunk
Definition: FastMonitoringThread.h:83
evf::FastMonitoringThread::sRunGiven
Definition: FastMonitoringThread.h:21
evf::FastMonitoringThread::MonitorData::ministateBins_
unsigned int ministateBins_
Definition: FastMonitoringThread.h:128
evf::FastMonitoringThread::MonitorData::ministateEncoded_
std::vector< unsigned int > ministateEncoded_
Definition: FastMonitoringThread.h:117
evf::FastMonitoringThread::inWaitChunk_waitFreeThread
Definition: FastMonitoringThread.h:88
evf::FastMonitoringThread::inWaitInput_waitFreeThreadCopying
Definition: FastMonitoringThread.h:73
FastMonitor.h
evf::FastMonitoringThread::inWaitInput_busy
Definition: FastMonitoringThread.h:74
evf::FastMonitoringThread::sDone
Definition: FastMonitoringThread.h:25
evf::FastMonitoringThread::start
void start(void(FastMonitoringService::*fp)(), FastMonitoringService *cp)
Definition: FastMonitoringThread.h:207
evf::FastMonitoringThread::Macrostate
Macrostate
Definition: FastMonitoringThread.h:18