From 90d30d603987153ed77a89c1fcdf73edb39a94e0 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 29 Apr 2021 11:56:14 +0200 Subject: [PATCH 1/5] Refs 10789. Unit test upgraded. Signed-off-by: Miguel Company --- .../statistics/rtps/RTPSStatisticsTests.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp index f06dcbc45d9..8ded178a1a4 100644 --- a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp +++ b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp @@ -63,6 +63,9 @@ struct MockListener : IListener auto kind = data._d(); switch (kind) { + case HISTORY2HISTORY_LATENCY: + on_history_latency(data.writer_reader_data()); + break; case RTPS_SENT: on_rtps_sent(data.entity2locator_traffic()); break; @@ -102,6 +105,7 @@ struct MockListener : IListener } } + MOCK_METHOD1(on_history_latency, void(const eprosima::fastdds::statistics::WriterReaderData&)); MOCK_METHOD1(on_rtps_sent, void(const eprosima::fastdds::statistics::Entity2LocatorTraffic&)); MOCK_METHOD1(on_heartbeat_count, void(const eprosima::fastdds::statistics::EntityCount&)); MOCK_METHOD1(on_acknack_count, void(const eprosima::fastdds::statistics::EntityCount&)); @@ -584,7 +588,8 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) // reader callbacks through participant listener auto participant_reader_listener = make_shared(); - ASSERT_TRUE(participant_->add_statistics_listener(participant_reader_listener, EventKind::ACKNACK_COUNT)); + ASSERT_TRUE(participant_->add_statistics_listener(participant_reader_listener, + EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); // reader specific callbacks auto reader_listener = make_shared(); @@ -619,8 +624,12 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) // optionally: ACKNACK_COUNT EXPECT_CALL(*reader_listener, on_acknack_count) .Times(AtLeast(1)); + EXPECT_CALL(*reader_listener, on_history_latency) + .Times(AtLeast(1)); EXPECT_CALL(*participant_reader_listener, on_acknack_count) .Times(AtLeast(1)); + EXPECT_CALL(*participant_reader_listener, on_history_latency) + .Times(AtLeast(1)); // match writer and reader on a dummy topic match_endpoints(false, "string", "statisticsSmallTopic"); @@ -646,7 +655,8 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) EXPECT_TRUE(participant_->remove_statistics_listener(participant_listener, EventKind::RTPS_SENT)); EXPECT_TRUE(participant_->remove_statistics_listener(participant_writer_listener, EventKind::DATA_COUNT | EventKind::RESENT_DATAS | EventKind::SAMPLE_DATAS)); - EXPECT_TRUE(participant_->remove_statistics_listener(participant_reader_listener, EventKind::ACKNACK_COUNT)); + EXPECT_TRUE(participant_->remove_statistics_listener(participant_reader_listener, + EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); } /* @@ -694,7 +704,7 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks_fragmented) // writer callbacks through participant listener auto participant_listener = make_shared(); uint32_t mask = EventKind::DATA_COUNT | EventKind::HEARTBEAT_COUNT - | EventKind::ACKNACK_COUNT | EventKind::NACKFRAG_COUNT; + | EventKind::ACKNACK_COUNT | EventKind::NACKFRAG_COUNT | EventKind::HISTORY2HISTORY_LATENCY; ASSERT_TRUE(participant_->add_statistics_listener(participant_listener, mask)); EXPECT_CALL(*participant_listener, on_data_count) @@ -703,6 +713,8 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks_fragmented) .Times(AtLeast(1)); EXPECT_CALL(*participant_listener, on_acknack_count) .Times(AtLeast(1)); + EXPECT_CALL(*participant_listener, on_history_latency) + .Times(AtLeast(1)); EXPECT_CALL(*participant_listener, on_nackfrag_count) .Times(AtLeast(1)); From 472dd24506a170b0ee5fd4e3a3974069b41ea818 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 29 Apr 2021 12:37:01 +0200 Subject: [PATCH 2/5] Refs 10789. Added methods to StatisticsReaderImpl. Signed-off-by: Miguel Company --- .../statistics/rtps/StatisticsCommon.hpp | 10 +++++++ .../statistics/rtps/StatisticsCommonEmpty.hpp | 13 +++++++++ .../rtps/reader/StatisticsReaderImpl.cpp | 27 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/include/fastdds/statistics/rtps/StatisticsCommon.hpp b/include/fastdds/statistics/rtps/StatisticsCommon.hpp index 64ddeafc538..ef5eb77cdce 100644 --- a/include/fastdds/statistics/rtps/StatisticsCommon.hpp +++ b/include/fastdds/statistics/rtps/StatisticsCommon.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -217,6 +218,15 @@ class StatisticsReaderImpl // TODO: methods for listeners callbacks + /** + * @brief Report that a sample has been notified to the user. + * @param writer_guid GUID of the writer from where the sample was received. + * @param source_timestamp Source timestamp received from the writer for the sample being notified. + */ + void on_data_notify( + const fastrtps::rtps::GUID_t& writer_guid, + const fastrtps::rtps::Time_t& source_timestamp); + /** * @brief Report that an ACKNACK message is sent * @param count current count of ACKNACKs diff --git a/include/fastdds/statistics/rtps/StatisticsCommonEmpty.hpp b/include/fastdds/statistics/rtps/StatisticsCommonEmpty.hpp index 635708cc911..cb3c91632ac 100644 --- a/include/fastdds/statistics/rtps/StatisticsCommonEmpty.hpp +++ b/include/fastdds/statistics/rtps/StatisticsCommonEmpty.hpp @@ -19,8 +19,10 @@ #ifndef _FASTDDS_STATISTICS_RTPS_STATISTICSCOMMON_HPP_ #define _FASTDDS_STATISTICS_RTPS_STATISTICSCOMMON_HPP_ +#include #include #include +#include #include namespace eprosima { @@ -96,6 +98,17 @@ class StatisticsReaderImpl // TODO: methods for listeners callbacks + /** + * @brief Report that a sample has been notified to the user. + * @param GUID of the writer from where the sample was received. + * @param Source timestamp received from the writer for the sample being notified. + */ + inline void on_data_notify( + const fastrtps::rtps::GUID_t&, + const fastrtps::rtps::Time_t&) + { + } + /** * @brief Report that an ACKNACK message is sent * @param current count of ACKNACKs diff --git a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp index b6bd15d5255..7d653b0542e 100644 --- a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp +++ b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp @@ -60,6 +60,33 @@ const GUID_t& StatisticsReaderImpl::get_guid() const return static_cast(this)->getGuid(); } +void StatisticsReaderImpl::on_data_notify( + const fastrtps::rtps::GUID_t& writer_guid, + const fastrtps::rtps::Time_t& source_timestamp) +{ + // Get current timestamp + fastrtps::rtps::Time_t current_time; + fastrtps::rtps::Time_t::now(current_time); + + // Calc latency + auto ns = (current_time - source_timestamp).to_ns(); + + WriterReaderData notification; + notification.reader_guid(to_statistics_type(get_guid())); + notification.writer_guid(to_statistics_type(writer_guid)); + notification.data(ns * 1.0f); + + // Perform the callback + Data data; + // note that the setter sets HISTORY2HISTORY_LATENCY by default + data.writer_reader_data(notification); + + for_each_listener([&data](const std::shared_ptr& listener) + { + listener->on_statistics_data(data); + }); +} + void StatisticsReaderImpl::on_acknack( int32_t count) { From cdb9262a72cc323b440c274aed0547adbc51d0ed Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 29 Apr 2021 13:10:08 +0200 Subject: [PATCH 3/5] Refs 10789. Call on_data_notify just before calling listener. Signed-off-by: Miguel Company --- src/cpp/rtps/reader/StatefulReader.cpp | 2 ++ src/cpp/rtps/reader/StatelessReader.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/cpp/rtps/reader/StatefulReader.cpp b/src/cpp/rtps/reader/StatefulReader.cpp index 75782b4334a..684e07c5c37 100644 --- a/src/cpp/rtps/reader/StatefulReader.cpp +++ b/src/cpp/rtps/reader/StatefulReader.cpp @@ -868,6 +868,8 @@ void StatefulReader::NotifyChanges( { ++total_unread_; + on_data_notify(ch_to_give->writerGUID, ch_to_give->sourceTimestamp); + if (getListener() != nullptr) { getListener()->onNewCacheChangeAdded((RTPSReader*)this, ch_to_give); diff --git a/src/cpp/rtps/reader/StatelessReader.cpp b/src/cpp/rtps/reader/StatelessReader.cpp index b903eda7e1c..f4e13b5b56e 100644 --- a/src/cpp/rtps/reader/StatelessReader.cpp +++ b/src/cpp/rtps/reader/StatelessReader.cpp @@ -247,6 +247,8 @@ bool StatelessReader::change_received( update_last_notified(change->writerGUID, change->sequenceNumber); ++total_unread_; + on_data_notify(change->writerGUID, change->sourceTimestamp); + if (getListener() != nullptr) { getListener()->onNewCacheChangeAdded(this, change); From 9f42feeaf3564ec3ef78a6ed771c6e7ce953507e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 29 Apr 2021 15:11:05 +0200 Subject: [PATCH 4/5] Refs 10789. Linters. Signed-off-by: Miguel Company --- src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp | 6 +++--- test/unittest/statistics/rtps/RTPSStatisticsTests.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp index 7d653b0542e..3e2a3c92f9d 100644 --- a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp +++ b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp @@ -82,9 +82,9 @@ void StatisticsReaderImpl::on_data_notify( data.writer_reader_data(notification); for_each_listener([&data](const std::shared_ptr& listener) - { - listener->on_statistics_data(data); - }); + { + listener->on_statistics_data(data); + }); } void StatisticsReaderImpl::on_acknack( diff --git a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp index 8ded178a1a4..c4c6e359f2f 100644 --- a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp +++ b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp @@ -589,7 +589,7 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) // reader callbacks through participant listener auto participant_reader_listener = make_shared(); ASSERT_TRUE(participant_->add_statistics_listener(participant_reader_listener, - EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); + EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); // reader specific callbacks auto reader_listener = make_shared(); @@ -656,7 +656,7 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) EXPECT_TRUE(participant_->remove_statistics_listener(participant_writer_listener, EventKind::DATA_COUNT | EventKind::RESENT_DATAS | EventKind::SAMPLE_DATAS)); EXPECT_TRUE(participant_->remove_statistics_listener(participant_reader_listener, - EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); + EventKind::ACKNACK_COUNT | EventKind::HISTORY2HISTORY_LATENCY)); } /* From 9a1348b73516044c7e505f97d5c6353da4717a03 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 11 May 2021 08:57:25 +0200 Subject: [PATCH 5/5] Refs 10789. Adressed review comments. Signed-off-by: Miguel Company --- src/cpp/statistics/rtps/StatisticsBase.cpp | 3 +-- src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp | 2 +- test/unittest/statistics/rtps/RTPSStatisticsTests.cpp | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpp/statistics/rtps/StatisticsBase.cpp b/src/cpp/statistics/rtps/StatisticsBase.cpp index 4a805af9bbb..e9bb40a126d 100644 --- a/src/cpp/statistics/rtps/StatisticsBase.cpp +++ b/src/cpp/statistics/rtps/StatisticsBase.cpp @@ -135,8 +135,7 @@ bool StatisticsParticipantImpl::are_writers_involved( { using namespace fastdds::statistics; - constexpr uint32_t writers_maks = HISTORY2HISTORY_LATENCY \ - | PUBLICATION_THROUGHPUT \ + constexpr uint32_t writers_maks = PUBLICATION_THROUGHPUT \ | RESENT_DATAS \ | HEARTBEAT_COUNT \ | GAP_COUNT \ diff --git a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp index 3e2a3c92f9d..fe3fa3300d4 100644 --- a/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp +++ b/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp @@ -74,7 +74,7 @@ void StatisticsReaderImpl::on_data_notify( WriterReaderData notification; notification.reader_guid(to_statistics_type(get_guid())); notification.writer_guid(to_statistics_type(writer_guid)); - notification.data(ns * 1.0f); + notification.data(static_cast(ns)); // Perform the callback Data data; diff --git a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp index c4c6e359f2f..067a5dffbab 100644 --- a/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp +++ b/test/unittest/statistics/rtps/RTPSStatisticsTests.cpp @@ -523,6 +523,7 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_management) /* * This test checks RTPSParticipant, RTPSWriter and RTPSReader statistics module related APIs. * - RTPS_SENT callbacks are performed + * - HISTORY2HISTORY_LATENCY callbacks are performed * - DATA_COUNT callbacks are performed for DATA submessages * - RESENT_DATAS callbacks are performed for DATA submessages demanded by the readers * - ACKNACK_COUNT callbacks are performed @@ -662,6 +663,7 @@ TEST_F(RTPSStatisticsTests, statistics_rpts_listener_callbacks) /* * This test checks RTPSParticipant, RTPSWriter and RTPSReader statistics module related APIs. * - participant listeners management with late joiners + * - HISTORY2HISTORY_LATENCY callbacks are performed * - DATA_COUNT callbacks with DATA_FRAGS are performed * - NACK_FRAG callbacks assessment */