RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
ipcqRecordingUnit.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_COMPONENTFRAMEWORK_IPCQRECORDINGUNIT_HPP
13#define RTCTK_COMPONENTFRAMEWORK_IPCQRECORDINGUNIT_HPP
14
23
24#include <fmt/format.h>
25
26#include <cstdint>
27#include <string>
28#include <thread>
29
31
32template <typename T, typename = int>
33struct HasSampleIdWithCorrectType : std::false_type {};
34
35template <typename T>
36struct HasSampleIdWithCorrectType<T, decltype(std::declval<T>().sample_id, 0)>
37 : std::conditional<std::is_same<uint32_t, decltype(std::declval<T>().sample_id)>::value,
38 std::true_type,
39 std::false_type>::type {};
40// first check if the member exists. If yes, then check if it has the right type
41
42template <typename T>
44
51template <typename RecInfoType>
53public:
55 "Topic struct must contain member 'sample_id' with type 'uint32_t'!");
56
64 IpcqRecordingUnit(const std::string& comp_id,
65 const std::string& unit_id,
66 ServiceContainer& services)
67 : RecordingUnit(comp_id, unit_id, "IPCQ", services)
68 , m_queue_name(m_rtr.GetDataPoint<std::string>(
69 DataPointPath(fmt::format(RTR_PATH_QUEUE_NAME, comp_id, unit_id))))
70 , m_output(RecInfoType::COLUMNS) {
71 auto queue_name_path = DataPointPath(fmt::format(OLDB_PATH_QUEUE_NAME, comp_id, unit_id));
73 m_oldb.SetDataPoint<std::string>(queue_name_path, m_queue_name);
74
76 DataPointPath(fmt::format(RTR_PATH_CPU_AFFINITY, comp_id, unit_id));
79 }
80
81 m_samples_written_reg = m_metrics.AddCounter(
82 &m_samples_written,
83 CounterMetricInfo(unit_id + "/samples_written",
84 "Number of samples successfully written to file"));
85 m_last_observed_sample_id_reg =
86 m_metrics.AddCounter(&m_last_observed_sample_id,
87 CounterMetricInfo(unit_id + "/last_sample_id_written",
88 "Last sample id successfully written to file"));
89
90 m_freq_estimator = std::make_unique<FrequencyEstimator<>>(
91 m_metrics, "Estimated frequency of the data writer", unit_id);
92
93 m_dur_monitor = std::make_unique<DurationMonitor<>>(
94 m_metrics, "Duration of writing data to file", unit_id);
95
96 m_buffer_monitor =
97 std::make_unique<BufferMonitor<>>(m_metrics, "SHM read buffer occupancy", unit_id);
98
99 Update();
100 }
101
103 m_stop = true;
104 if (m_process_thread.joinable()) {
105 m_process_thread.join();
106 }
107 }
108
113 void Prepare(const std::filesystem::path& file_path) override;
117 void Start() override;
122 std::vector<std::filesystem::path> Stop() override;
126 void Update() override;
127
128protected:
136 static typename RecInfoType::Recorder::DisabledFields
138
139private:
143 void Process();
147 std::thread m_process_thread;
151 std::atomic<bool> m_start = false;
152 std::atomic<bool> m_stop = false;
156 std::string m_queue_name;
160 std::optional<size_t> m_cpu_affinity;
164 typename RecInfoType::Recorder m_output;
168 int64_t m_subsample_factor;
172 int64_t m_start_sample_id;
176 int64_t m_stop_after_num_samples;
180 uint64_t m_sampling_counter;
184 perfc::CounterI64 m_samples_written;
185 perfc::ScopedRegistration m_samples_written_reg;
189 perfc::CounterI64 m_last_observed_sample_id;
190 perfc::ScopedRegistration m_last_observed_sample_id_reg;
191
192 std::unique_ptr<FrequencyEstimator<>> m_freq_estimator;
193 std::unique_ptr<DurationMonitor<>> m_dur_monitor;
194 std::unique_ptr<BufferMonitor<>> m_buffer_monitor;
198 inline static constexpr std::string_view RTR_PATH_QUEUE_NAME =
199 "/{}/static/rec_units/{}/shm_queue_name";
203 inline static constexpr std::string_view RTR_PATH_CPU_AFFINITY =
204 "/{}/static/rec_units/{}/cpu_affinity";
208 inline static constexpr std::string_view RTR_PATH_TELEMETRY_SUBSET =
209 "/{}/dynamic/rec_units/{}/telemetry_subset";
213 inline static constexpr std::string_view RTR_PATH_SUBSAMPLE_FACTOR =
214 "/{}/dynamic/rec_units/{}/subsample_factor";
218 inline static constexpr std::string_view RTR_PATH_START_SAMPLE_ID =
219 "/{}/dynamic/rec_units/{}/start_at_sample_id";
223 inline static constexpr std::string_view RTR_PATH_STOP_AFTER_NUM_SAMPLES =
224 "/{}/dynamic/rec_units/{}/stop_after_num_samples";
228 inline static constexpr std::string_view OLDB_PATH_QUEUE_NAME = "/{}/rec_units/{}/queue_name";
229
233 inline static constexpr size_t MAX_SAMPLES_READ = 16;
234};
235
236} // namespace rtctk::componentFramework
237
239
240#endif // RTCTK_COMPONENTFRAMEWORK_IPCQRECORDINGUNIT_HPP
Header file for Buffer Monitor.
virtual perfc::ScopedRegistration AddCounter(CounterVariant counter, CounterMetricInfo info)=0
Add a counter to be included in component metrics, identified by its address, together with info to t...
Defines auxiliary information associated with each counter registered with ComponentMetricsIf.
Definition componentMetricsIf.hpp:46
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
Recording Unit that can record from shared memory queue.
Definition ipcqRecordingUnit.hpp:52
std::vector< std::filesystem::path > Stop() override
Stop the recording thread and wait for it's termination.
Definition ipcqRecordingUnit.ipp:53
void Update() override
Update settings from RuntimeRepo.
Definition ipcqRecordingUnit.ipp:68
virtual ~IpcqRecordingUnit()
Definition ipcqRecordingUnit.hpp:102
void Prepare(const std::filesystem::path &file_path) override
Prepare the recording thread and start recording.
Definition ipcqRecordingUnit.ipp:30
static RecInfoType::Recorder::DisabledFields GetDisabled(RepositoryIf &rtr, const DataPointPath &sub_path)
get disabled fields from a DataPoint in the runtime repo.
Definition ipcqRecordingUnit.ipp:246
IpcqRecordingUnit(const std::string &comp_id, const std::string &unit_id, ServiceContainer &services)
Create a new Ipcq Recorder reading from a given queue and outputting to the given output stage.
Definition ipcqRecordingUnit.hpp:64
void Start() override
Start the recording.
Definition ipcqRecordingUnit.ipp:48
Abstract base class for all sources that can be recorded by the MetadataCollector and TelemetryRecord...
Definition recordingUnit.hpp:51
OldbIf & m_oldb
Definition recordingUnit.hpp:173
ComponentMetricsIf & m_metrics
Definition recordingUnit.hpp:174
RuntimeRepoIf & m_rtr
Definition recordingUnit.hpp:172
Abstract interface providing basic read and write facilities to a repository.
Definition repositoryIf.hpp:104
T GetDataPoint(const DataPointPath &path) const
Fetches a datapoint from the repository.
Definition repositoryIf.ipp:1711
void CreateDataPoint(const DataPointPath &path)
Creates a new datapoint in the repository.
Definition repositoryIf.ipp:1696
void SetDataPoint(const DataPointPath &path, const T &value)
Sets a datapoint in the repository.
Definition repositoryIf.ipp:1720
bool DataPointExists(const DataPointPath &path) const
Checks for the existence of a datapoint in the repository.
Definition repositoryIf.cpp:461
Container class that holds services of any type.
Definition serviceContainer.hpp:39
Header file for ComponentMetricsIf.
Provides an abstract DataRecorder class as the output stage for a recording unit.
Header file for Duration Monitor.
Provides macros and utilities for exception handling.
Header file for Frequency Estimator.
Recording Unit that can record from shared memory queue.
Definition ddsSub.hpp:151
Definition commandReplier.cpp:22
constexpr bool HAS_MEMBER_SAMPLE_ID_UINT32T
Definition ipcqRecordingUnit.hpp:43
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
FitsRecorder allows to write ColumnData to into fits files in a specified directory.
Abstract base class defining functionality common to all recording units.