33 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
35 #include "../util/ControlThreadOutputBuffer.h"
40 struct DoLoggingDurations;
50 defineOptionalProperty<std::size_t>(
53 "Period of the rt-logging thread in milliseconds. "
54 "A high period can cause spikes in disk activity if data is logged to disk. "
55 "A low period causes more computation overhead and memory consumption. "
58 defineOptionalProperty<std::string>(
"RTLogging_DefaultLog",
60 "If rt logging is active and a file path is given, "
61 "all data is logged to this file.");
63 defineOptionalProperty<std::size_t>(
64 "RTLogging_MessageNumber",
66 "Number of messages that can be logged in the control thread");
67 defineOptionalProperty<std::size_t>(
68 "RTLogging_MessageBufferSize",
70 "Number of bytes that can be logged in the control thread");
71 defineOptionalProperty<std::size_t>(
72 "RTLogging_MaxMessageNumber",
74 "Max number of messages that can be logged in the control thread");
75 defineOptionalProperty<std::size_t>(
76 "RTLogging_MaxMessageBufferSize",
78 "Max number of bytes that can be logged in the control thread");
80 defineOptionalProperty<bool>(
81 "RTLogging_EnableBacklog",
83 "Enable/Disable the backlog (SensorValues, ControlTargets, Messages) that is kept"
84 "and can be dumped in case of an error.");
85 defineOptionalProperty<std::size_t>(
"RTLogging_KeepIterationsForMs",
87 "All logging data (SensorValues, ControlTargets, "
88 "Messages) is kept for this duration "
89 "and can be dumped in case of an error.");
90 defineOptionalProperty<std::size_t>(
91 "RTLogging_MaxBacklogSize",
93 "Maximum size of the backlog (SensorValues, ControlTargets, Messages) that is kept"
94 "and can be dumped in case of an error.");
96 defineOptionalProperty<std::size_t>(
97 "RTLogging_StreamingDataMaxClientConnectionFailures",
99 "If sending data to a client fails this often, the client is removed from the "
102 defineOptionalProperty<int>(
103 "RTLogging_LogLastNMessagesOnly",
105 "If greater than 0, logs/streams only the last n timesteps that are in the entry "
106 "cue of the ControlThreadOutputBuffer");
132 return ModuleBase::Instance<Logging>();
140 void _postOnInitRobotUnit();
142 void _postFinishDeviceInitialization();
144 void _preFinishControlThreadInitialization();
146 void _preFinishRunning();
157 SimpleRemoteReferenceCounterBasePtr
159 const Ice::StringSeq& loggingNames,
160 const Ice::Current& = Ice::emptyCurrent)
override;
168 SimpleRemoteReferenceCounterBasePtr
170 const StringStringDictionary& aliasNames,
171 const Ice::Current& = Ice::emptyCurrent)
override;
177 void stopRtLogging(
const armarx::SimpleRemoteReferenceCounterBasePtr& token,
178 const Ice::Current& = Ice::emptyCurrent)
override;
185 const std::string& marker,
186 const Ice::Current& = Ice::emptyCurrent)
override;
192 Ice::StringSeq
getLoggingNames(
const Ice::Current& = Ice::emptyCurrent)
const override;
199 const Ice::Current& = Ice::emptyCurrent)
const override;
201 RobotUnitDataStreaming::DataStreamingDescription
203 const RobotUnitDataStreaming::Config& config,
204 const Ice::Current& = Ice::emptyCurrent)
override;
207 const Ice::Current& = Ice::emptyCurrent)
override;
219 static bool MatchName(
const std::string& pattern,
const std::string& name);
226 struct CSVLoggingEntry
229 std::atomic_bool stopLogging{
false};
231 std::vector<std::vector<std::vector<char>>> loggedControlDeviceValues;
233 std::vector<std::vector<char>> loggedSensorDeviceValues;
235 std::ofstream stream;
242 struct DataStreamingEntry
262 bool stopStreaming =
false;
264 std::size_t numBools = 0;
265 std::size_t numBytes = 0;
266 std::size_t numShorts = 0;
267 std::size_t numInts = 0;
268 std::size_t numLongs = 0;
269 std::size_t numFloats = 0;
270 std::size_t numDoubles = 0;
272 bool onlyNewestFrame =
false;
273 std::size_t connectionFailures = 0;
274 std::size_t rtStreamMaxClientErrors = 0;
276 std::vector<std::vector<OutVal>> sensDevs;
277 std::vector<std::vector<std::vector<OutVal>>> ctrlDevs;
279 RobotUnitDataStreaming::TimeStepSeq result;
280 std::deque<RobotUnitDataStreaming::TimeStep> entryBuffer;
281 std::deque<Ice::AsyncResultPtr> updateCalls;
283 RobotUnitDataStreaming::TimeStep getResultElement();
284 RobotUnitDataStreaming::TimeStep allocateResultElement()
const;
292 void processSens(
const SensorValueBase& val, std::size_t didx, std::size_t fidx);
293 void send(
const RobotUnitDataStreaming::ReceiverPrx& r, uint64_t msgId);
296 std::map<RobotUnitDataStreaming::ReceiverPrx, DataStreamingEntry> rtDataStreamingEntry;
297 std::uint64_t rtDataStreamingMsgID = 0;
300 std::thread rtLoggingTask;
301 std::atomic_bool stopRtLoggingTask{
false};
303 std::map<std::string, std::shared_ptr<CSVLoggingEntry>> rtLoggingEntries;
305 SimpleRemoteReferenceCounterBasePtr defaultLogHandle;
307 std::deque<::armarx::detail::ControlThreadOutputBufferEntry> backlog;
311 mutable std::mutex rtLoggingMutex;
321 std::vector<FieldMetaData> fields;
325 std::vector<std::vector<ValueMetaData>> controlDeviceValueMetaData;
327 std::vector<ValueMetaData> sensorDeviceValueMetaData;
330 std::size_t messageBufferSize{0};
332 std::size_t messageBufferNumberEntries{0};
334 std::size_t messageBufferMaxSize{0};
336 std::size_t messageBufferMaxNumberEntries{0};
338 std::size_t rtLoggingTimestepMs{0};
342 std::size_t rtLoggingBacklogMaxSize;
344 bool rtLoggingBacklogEnabled;
347 int numberOfEntriesToLog{-1};
349 friend void WriteTo(
const auto& dentr,
350 const Logging::DataStreamingEntry::OutVal& out,