| Fast DDS Version 3.3.0 Fast DDS

Loading...
Searching...
No Matches
StatisticsCommon.hpp
1// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
18
19#ifndef FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP
20#define FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP
21
22#include <memory>
23#include <type_traits>
24
25#include <fastdds/rtps/common/Guid.hpp>
26#include <fastdds/rtps/common/SampleIdentity.hpp>
27#include <fastdds/rtps/common/Time_t.hpp>
28#include <fastdds/statistics/IListeners.hpp>
29#include <fastdds/utils/TimedMutex.hpp>
30
31
32 namespace eprosima {
33
34 namespace fastdds {
35 namespace rtps {
36
37 class RTPSMessageGroup;
38
39} // rtps
40
41 namespace statistics {
42
43#ifdef FASTDDS_STATISTICS
44
45// Members are private details
46 struct StatisticsAncillary;
47
48 class StatisticsListenersImpl
49{
50 std::unique_ptr<StatisticsAncillary> members_;
51
52 protected:
53
58 template<class A>
59 void init_statistics()
60 {
61 static_assert(
62 std::is_base_of<StatisticsAncillary, A>::value,
63 "Auxiliary structure must derive from StatisticsAncillary");
64
65 if (!members_)
66 {
67 members_.reset(new A);
68 }
69 }
70
75 StatisticsAncillary* get_aux_members() const;
76
82 bool add_statistics_listener_impl(
83 std::shared_ptr<fastdds::statistics::IListener> listener);
84
90 bool remove_statistics_listener_impl(
91 std::shared_ptr<fastdds::statistics::IListener> listener);
92
98 void set_enabled_statistics_writers_mask_impl(
99 uint32_t enabled_writers);
100
107 bool are_statistics_writers_enabled(
108 uint32_t checked_enabled_writers);
109
115 template<class Function>
116 Function for_each_listener(
117 Function f);
118
123 virtual fastdds::RecursiveTimedMutex& get_statistics_mutex() = 0;
124
129 virtual const fastdds::rtps::GUID_t& get_guid() const = 0;
130};
131
132// Members are private details
133 struct StatisticsWriterAncillary;
134
135 class StatisticsWriterImpl
136 : protected StatisticsListenersImpl
137{
138 friend class fastdds::rtps::RTPSMessageGroup;
139
144 StatisticsWriterAncillary* get_members() const;
145
150 fastdds::RecursiveTimedMutex& get_statistics_mutex() final;
151
156 const fastdds::rtps::GUID_t& get_guid() const final;
157
158protected:
159
163 StatisticsWriterImpl();
164
165 // TODO: methods for listeners callbacks
166
172 void on_sample_datas(
173 const fastdds::rtps::SampleIdentity& sample_identity,
174 size_t num_sent_submessages);
175
180 void on_heartbeat(
181 uint32_t count);
182
187 void on_data_generated(
188 size_t num_destinations);
189
191 void on_data_sent();
192
197 void on_publish_throughput(
198 uint32_t payload);
199
201 void on_gap();
202
203 /*
204 * @brief Report that several changes are marked for redelivery
205 * @param number of changes to redeliver
206 */
207 void on_resent_data(
208 uint32_t to_send);
209};
210
211// Members are private details
212struct StatisticsReaderAncillary;
213
214class StatisticsReaderImpl
215 : protected StatisticsListenersImpl
216{
217 friend class fastdds::rtps::RTPSMessageGroup;
218
223 StatisticsReaderAncillary* get_members() const;
224
229 fastdds::RecursiveTimedMutex& get_statistics_mutex() final;
230
235 const fastdds::rtps::GUID_t& get_guid() const final;
236
237protected:
238
242 StatisticsReaderImpl();
243
244 // TODO: methods for listeners callbacks
245
251 void on_data_notify(
252 const fastdds::rtps::GUID_t& writer_guid,
253 const fastdds::rtps::Time_t& source_timestamp);
254
259 void on_acknack(
260 int32_t count);
261
266 void on_nackfrag(
267 int32_t count);
268
273 void on_subscribe_throughput(
274 uint32_t payload);
275};
276
277#else // when FASTDDS_STATISTICS is not defined a dummy implementation is used
278
279 class StatisticsWriterImpl
280{
281 friend class fastdds::rtps::RTPSMessageGroup;
282
283 protected:
284
285 // TODO: methods for listeners callbacks
286
292 inline void on_sample_datas(
293 const fastdds::rtps::SampleIdentity&,
294 size_t)
295 {
296 }
297
302 inline void on_heartbeat(
303 uint32_t)
304 {
305 }
306
311 inline void on_data_generated(
312 size_t)
313 {
314 }
315
317 inline void on_data_sent()
318 {
319 }
320
325 inline void on_publish_throughput(
326 uint32_t)
327 {
328 }
329
331 inline void on_gap()
332 {
333 }
334
335 /*
336 * @brief Report that several changes are marked for redelivery
337 * Parameter: number of changes to redeliver
338 */
339 inline void on_resent_data(
340 uint32_t)
341 {
342 }
343
344};
345
346 class StatisticsReaderImpl
347{
348 friend class fastdds::rtps::RTPSMessageGroup;
349
350 protected:
351
352 // TODO: methods for listeners callbacks
353
359 inline void on_data_notify(
360 const fastdds::rtps::GUID_t&,
361 const fastdds::rtps::Time_t&)
362 {
363 }
364
369 inline void on_acknack(
370 int32_t)
371 {
372 }
373
378 inline void on_nackfrag(
379 int32_t)
380 {
381 }
382
387 inline void on_subscribe_throughput(
388 uint32_t)
389 {
390 }
391
392};
393
394#endif // FASTDDS_STATISTICS
395
396} // namespace statistics
397} // namespace fastdds
398} // namespace eprosima
399
400#endif // FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP
eprosima::fastdds::rtps::SampleIdentity
This class is used to specify a sample.
Definition SampleIdentity.hpp:34
eprosima::fastdds::rtps::Time_t
Structure Time_t, used to describe times at RTPS protocol.
Definition Time_t.hpp:38
eprosima::fastdds::statistics::StatisticsReaderImpl
Definition StatisticsCommon.hpp:347
eprosima::fastdds::statistics::StatisticsReaderImpl::on_acknack
void on_acknack(int32_t)
Report that an ACKNACK message is sent Parameter: current count of ACKNACKs.
Definition StatisticsCommon.hpp:369
eprosima::fastdds::statistics::StatisticsReaderImpl::on_nackfrag
void on_nackfrag(int32_t)
Report that a NACKFRAG message is sent Parameter: current count of NACKFRAGs.
Definition StatisticsCommon.hpp:378
eprosima::fastdds::statistics::StatisticsReaderImpl::on_data_notify
void on_data_notify(const fastdds::rtps::GUID_t &, const fastdds::rtps::Time_t &)
Report that a sample has been notified to the user.
Definition StatisticsCommon.hpp:359
eprosima::fastdds::statistics::StatisticsReaderImpl::on_subscribe_throughput
void on_subscribe_throughput(uint32_t)
Reports subscription throughtput based on last added sample to reader's history Parameter: size of th...
Definition StatisticsCommon.hpp:387
eprosima::fastdds::statistics::StatisticsWriterImpl
Definition StatisticsCommon.hpp:280
eprosima::fastdds::statistics::StatisticsWriterImpl::on_publish_throughput
void on_publish_throughput(uint32_t)
Reports publication throughtput based on last added sample to writer's history Parameter: size of the...
Definition StatisticsCommon.hpp:325
eprosima::fastdds::statistics::StatisticsWriterImpl::on_gap
void on_gap()
Report that a GAP message is sent.
Definition StatisticsCommon.hpp:331
eprosima::fastdds::statistics::StatisticsWriterImpl::on_data_sent
void on_data_sent()
Notify listeners of DATA / DATA_FRAG counts.
Definition StatisticsCommon.hpp:317
eprosima::fastdds::statistics::StatisticsWriterImpl::on_data_generated
void on_data_generated(size_t)
Report that a DATA / DATA_FRAG message is generated Parameter: number of locators to which the messag...
Definition StatisticsCommon.hpp:311
eprosima::fastdds::statistics::StatisticsWriterImpl::RTPSMessageGroup
friend class fastdds::rtps::RTPSMessageGroup
Definition StatisticsCommon.hpp:281
eprosima::fastdds::statistics::StatisticsWriterImpl::on_resent_data
void on_resent_data(uint32_t)
Definition StatisticsCommon.hpp:339
eprosima::fastdds::statistics::StatisticsWriterImpl::on_heartbeat
void on_heartbeat(uint32_t)
Report that a HEARTBEAT message is sent Parameter: current count of heartbeats.
Definition StatisticsCommon.hpp:302
eprosima::fastdds::statistics::StatisticsWriterImpl::on_sample_datas
void on_sample_datas(const fastdds::rtps::SampleIdentity &, size_t)
Report a change on the number of DATA / DATAFRAG submessages sent for a specific sample.
Definition StatisticsCommon.hpp:292
eprosima::fastdds::rtps
Contains the RTPS protocol implementation.
eprosima::fastdds::statistics
Definition DomainParticipant.hpp:35
eprosima::fastdds
eprosima::fastdds::RecursiveTimedMutex
std::recursive_timed_mutex RecursiveTimedMutex
Definition TimedMutex.hpp:206
eprosima
eProsima namespace.
eprosima::fastdds::rtps::GUID_t
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40