1 #include "artdaq-core/Core/StatisticsCollection.hh"
11 return singletonInstance;
14 StatisticsCollection::StatisticsCollection()
16 thread_stop_requested_ =
false;
21 snprintf(tname,
sizeof(tname) - 1,
"%s",
"StatColl");
22 tname[
sizeof(tname) - 1] =
'\0';
23 auto handle = calculation_thread_->native_handle();
24 pthread_setname_np(handle, tname);
26 catch (
const boost::exception& e)
28 TLOG(TLVL_ERROR) <<
"Caught boost::exception starting Statistics Collection thread: " << boost::diagnostic_information(e) <<
", errno=" << errno;
29 std::cerr <<
"Caught boost::exception starting Statistics Collection thread: " << boost::diagnostic_information(e) <<
", errno=" << errno << std::endl;
37 thread_stop_requested_ =
true;
42 if (calculation_thread_ && calculation_thread_->joinable() && calculation_thread_->get_id() != boost::this_thread::get_id())
44 calculation_thread_->join();
57 std::lock_guard<std::mutex> scopedLock(map_mutex_);
58 monitoredQuantityMap_[name] = std::move(mqPtr);
64 std::lock_guard<std::mutex> scopedLock(map_mutex_);
66 std::map<std::string, MonitoredQuantityPtr>::const_iterator iter;
67 iter = monitoredQuantityMap_.find(name);
68 if (iter == monitoredQuantityMap_.end()) {
return emptyResult; }
74 std::lock_guard<std::mutex> scopedLock(map_mutex_);
75 std::map<std::string, MonitoredQuantityPtr>::const_iterator iter;
76 std::map<std::string, MonitoredQuantityPtr>::const_iterator iterEnd;
77 iterEnd = monitoredQuantityMap_.end();
78 for (iter = monitoredQuantityMap_.begin(); iter != iterEnd; ++iter)
80 iter->second->reset();
86 thread_stop_requested_ =
true;
91 while (!thread_stop_requested_)
93 auto useconds =
static_cast<uint64_t
>(calculationInterval_ * 1000000);
96 std::lock_guard<std::mutex> scopedLock(map_mutex_);
97 std::map<std::string, MonitoredQuantityPtr>::const_iterator iter;
98 std::map<std::string, MonitoredQuantityPtr>::const_iterator iterEnd;
99 iterEnd = monitoredQuantityMap_.end();
100 for (iter = monitoredQuantityMap_.begin(); iter != iterEnd; ++iter)
102 iter->second->calculateStatistics();
void addMonitoredQuantity(const std::string &name, MonitoredQuantityPtr mqPtr)
Registers a new MonitoredQuantity to be tracked by the StatisticsCollection.
static StatisticsCollection & getInstance()
Returns the singleton instance of the StatisticsCollection.
void reset()
Reset all MonitoredQuantity object in this StatisticsCollection.
void requestStop()
Stops the statistics calculation thread.
virtual ~StatisticsCollection() noexcept
StatisticsCollection Destructor.
A collection of MonitoredQuantity instances describing low-level statistics of the artdaq system...
MonitoredQuantityPtr getMonitoredQuantity(const std::string &name) const
Lookup and return a MonitoredQuantity from the StatisticsCollection.
void run()
Start the background thread that performs MonitoredQuantity statistics calculation.
std::shared_ptr< MonitoredQuantity > MonitoredQuantityPtr
A shared_ptr to a MonitoredQuantity instance.