@@ -65,6 +65,11 @@ void StfSenderDevice::InitTask()
6565 I ().mInputChannelName = GetConfig ()->GetValue <std::string>(OptionKeyInputChannelName);
6666 I ().mStandalone = GetConfig ()->GetValue <bool >(OptionKeyStandalone);
6767
68+ // start monitoring
69+ DataDistMonitor::start_datadist (ProcessType::StfSender, GetConfig ()->GetValue <std::string>(" monitoring-backend" ));
70+ DataDistMonitor::set_rate (GetConfig ()->GetValue <float >(" monitoring-rate" ));
71+ DataDistMonitor::set_log (GetConfig ()->GetValue <bool >(" monitoring-log" ));
72+
6873 if (!standalone ()) {
6974 // Discovery
7075 I ().mDiscoveryConfig = std::make_shared<ConsulStfSender>(ProcessType::StfSender, Config::getEndpointOption (*GetConfig ()));
@@ -77,11 +82,17 @@ void StfSenderDevice::InitTask()
7782
7883 // wait for "partition-id"
7984 while (!Config::getPartitionOption (*GetConfig ())) {
80- WDDLOG (" TfBuilder waiting on 'discovery-partition' config parameter." );
85+ WDDLOG (" StfSender waiting on 'discovery-partition' config parameter." );
8186 std::this_thread::sleep_for (1s);
8287 }
8388
84- lStatus.mutable_partition ()->set_partition_id (*Config::getPartitionOption (*GetConfig ()));
89+ I ().mPartitionId = Config::getPartitionOption (*GetConfig ()).value_or (" " );
90+ if (I ().mPartitionId .empty ()) {
91+ WDDLOG (" StfSender 'discovery-partition' parameter not set." );
92+ std::this_thread::sleep_for (1s); exit (-1 );
93+ }
94+
95+ lStatus.mutable_partition ()->set_partition_id (I ().mPartitionId );
8596 I ().mDiscoveryConfig ->write ();
8697 }
8798
@@ -144,11 +155,19 @@ void StfSenderDevice::PreRun()
144155 I ().mDiscoveryConfig ->write ();
145156 }
146157
158+ // reset counters
159+ if (I ().mOutputHandler ) {
160+ I ().mOutputHandler ->resetCounters ();
161+ }
162+
147163 // make directory for file sink
148164 if (I ().mFileSink ) {
149165 I ().mFileSink ->makeDirectory ();
150166 }
151167
168+ // enable monitoring
169+ DataDistMonitor::enable_datadist (DataDistLogger::sRunNumber , I ().mPartitionId );
170+
152171 // start accepting data
153172 I ().mAcceptingData = true ;
154173
@@ -160,13 +179,21 @@ void StfSenderDevice::PostRun()
160179 // stop accepting data
161180 I ().mAcceptingData = false ;
162181
182+ // disable monitoring
183+ DataDistMonitor::disable_datadist ();
184+
163185 // update running state
164186 if (!standalone () && I ().mDiscoveryConfig ) {
165187 auto & lStatus = I ().mDiscoveryConfig ->status ();
166188 lStatus.mutable_info ()->set_process_state (BasicInfo::NOT_RUNNING);
167189 I ().mDiscoveryConfig ->write ();
168190 }
169191
192+ // reset counters
193+ if (I ().mOutputHandler ) {
194+ I ().mOutputHandler ->resetCounters ();
195+ }
196+
170197 IDDLOG (" Exiting running state. RunNumber: {}" , DataDistLogger::sRunNumberStr );
171198}
172199
@@ -204,6 +231,9 @@ void StfSenderDevice::ResetTask()
204231 I ().mTfSchedulerRpcClient .stop ();
205232 }
206233
234+ // stop monitoring
235+ DataDistMonitor::stop_datadist ();
236+
207237 DDDLOG (" ResetTask() done." );
208238}
209239
@@ -218,7 +248,7 @@ void StfSenderDevice::StfReceiverThread()
218248 DplToStfAdapter lStfReceiver;
219249 std::unique_ptr<SubTimeFrame> lStf;
220250
221- auto lStfStartTime = hres_clock::now ();
251+ decltype ( hres_clock::now ()) lStfStartTime = hres_clock::now ();
222252
223253 while (running ()) {
224254 try {
@@ -235,18 +265,20 @@ void StfSenderDevice::StfReceiverThread()
235265 if (lStf) {
236266 WDDLOG_RL (1000 , " StfSender: received STF but not in the running state." );
237267 }
238- std::this_thread::sleep_for (10ms);
268+ DDMON (" stfsender" , " stf_input.rate" , 0.0 );
269+ DDMON (" stfsender" , " stf_input.size" , 0.0 );
270+ std::this_thread::sleep_for (20ms);
239271 continue ;
240272 }
241273
242274 { // Input STF frequency
243275 const auto lNow = hres_clock::now ();
244276 const auto lStfDur = std::chrono::duration<double >(lNow - lStfStartTime);
245277 lStfStartTime = lNow;
246- I ().mStfTimeMean += (lStfDur.count ()/100.0 - I ().mStfTimeMean /100.0 );
247278
248- // get data size
249- I ().mStfSizeMean += (lStf->getDataSize ()/128 - I ().mStfSizeMean /128 );
279+ DDMON (" stfsender" , " stf_input.rate" , (1.0 / lStfDur.count ()));
280+ DDMON (" stfsender" , " stf_input.size" , lStf->getDataSize ());
281+ DDMON (" stfsender" , " stf_input.id" , (uint64_t )lStf->header ().mId );
250282 }
251283
252284 ++lReceivedStfs;
@@ -265,11 +297,10 @@ void StfSenderDevice::StfReceiverThread()
265297void StfSenderDevice::InfoThread ()
266298{
267299 while (running ()) {
268- IDDLOG (" StfSender: SubTimeFrame size_mean={} in_frequency_mean={:.4}" , I ().mStfSizeMean , (1.0 / I ().mStfTimeMean ));
269300 if (!standalone ()) {
270301 const auto lCounters = I ().mOutputHandler ->getCounters ();
271302
272- IDDLOG (" StfSender: SubTimeFrame queued_stf_num={} queued_stf_size={} sending_stf_num={} sending_stf_size={} " ,
303+ DDDLOG (" StfSender: SubTimeFrame queued_stf_num={} queued_stf_size={} sending_stf_num={} sending_stf_size={} " ,
273304 lCounters.mBuffered .mCnt , lCounters.mBuffered .mSize ,
274305 lCounters.mInSending .mCnt , lCounters.mInSending .mSize );
275306 }
0 commit comments