DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ProcessorMetricCollector.hpp
Go to the documentation of this file.
1
9 #ifndef TPGLIBS_PROCESSORMETRICCOLLECTOR_HPP_
10 #define TPGLIBS_PROCESSORMETRICCOLLECTOR_HPP_
11
12
13#include <map>
14#include <unordered_map>
15#include <vector>
16#include <thread>
17#include <atomic>
18#include <mutex>
19#include <cstdint>
20#include <string>
21#include <nlohmann/json.hpp>
22
24
25namespace tpglibs {
26
27template <typename T> class AbstractProcessor;
28
29
32 std::vector<std::string> m_names_of_metrics;
33};
34
35template <typename T>
37public:
38
39 using signal_t = T;
40
41 void attach_processor(AbstractProcessor<signal_t>& processor, size_t pipeline_id) {
42 // Attach a processor to be observed (collected) by this
44
45 // Look up and fill in information about this processor: its pipeline belonging and what is collected
46 auto metrics = processor.get_metric_items();
47 m_processor_metric_table[m_attach_counter].m_names_of_metrics = metrics;
48 m_processor_metric_table[m_attach_counter].m_pipeline_id = pipeline_id;
49
51 metrics.size(),
52 std::vector<int16_t>(16)
53 );
54
55 // Then instantiate the space for storing collected metrics
56 // Preallocated to preconfigured number of metrics
57 m_processor_metric_collection_table.push_back(std::vector<signal_t>(metrics.size()));
58
59 for (size_t i = pipeline_id*16; i < (pipeline_id+1)*16; i++) {
60 for (size_t j = 0; j < metrics.size(); j++) {
61 // Record metric name and initial value 0 for this channel
62 m_metrics[m_channel_numbers[i]].emplace_back(metrics[j], int16_t{0});
63 }
64 }
65
67 }
68
69 void configure(const std::vector<std::pair<std::string, nlohmann::json>> configs,
70 const std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers,
71 uint8_t num_pipelines);
72
73 // These are method just for debug and tests
74 std::vector<AbstractProcessor<signal_t>*> _get_attached_processors();
75 std::vector<ProcessorMetricInformation> _get_processor_metric_table();
76 std::vector<std::vector<std::vector<int16_t>>> _get_processor_casted_data_table();
77
78 void signal_collect();
79 void run(); // main loop on its dedicated thread
80 std::vector<std::vector<signal_t>> _get_retrieved_processor_metrics() const;
81 std::unordered_map<dunedaq::trgdataformats::channel_t, std::vector<std::pair<std::string, int16_t>>> get_metrics();
82 void stop();
83
89
90 void lock_metric_modify();
92
93private:
97
98 std::vector<AbstractProcessor<signal_t>*> m_attached_processors;
99 std::vector<ProcessorMetricInformation> m_processor_metric_table;
100 std::vector<std::vector<std::vector<int16_t>>> m_processor_casted_data_table;
101 std::vector<std::vector<signal_t>> m_processor_metric_collection_table;
102
103 std::vector<dunedaq::trgdataformats::channel_t> m_channel_numbers;
104
105 std::unordered_map<dunedaq::trgdataformats::channel_t, std::vector<std::pair<std::string, int16_t>>> m_metrics;
106 std::mutex m_mutex;
107
108 std::atomic<bool> m_signal_collect{false};
110 std::atomic<bool> m_stop_flag{false};
112};
113
114} // namespace tpglibs
115
116 #endif // TPGLIBS_PROCESSORMETRICCOLLECTOR_HPP_
virtual std::vector< std::string > get_metric_items()
Returns the string name of metrics recorded (stored and can be read) for this processor.
std::vector< dunedaq::trgdataformats::channel_t > m_channel_numbers
std::vector< ProcessorMetricInformation > m_processor_metric_table
std::vector< std::vector< signal_t > > _get_retrieved_processor_metrics() const
void attach_processor(AbstractProcessor< signal_t > &processor, size_t pipeline_id)
std::unordered_map< dunedaq::trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > m_metrics
std::unordered_map< dunedaq::trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > get_metrics()
std::vector< std::vector< std::vector< int16_t > > > _get_processor_casted_data_table()
std::vector< ProcessorMetricInformation > _get_processor_metric_table()
void configure(const std::vector< std::pair< std::string, nlohmann::json > > configs, const std::vector< std::pair< dunedaq::trgdataformats::channel_t, int16_t > > channel_plane_numbers, uint8_t num_pipelines)
std::vector< std::vector< signal_t > > m_processor_metric_collection_table
std::vector< AbstractProcessor< signal_t > * > m_attached_processors
std::vector< AbstractProcessor< signal_t > * > _get_attached_processors()
std::vector< std::vector< std::vector< int16_t > > > m_processor_casted_data_table