From e52732a395444b2580e855036b62012081c62016 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Thu, 19 May 2022 23:10:17 +0800 Subject: [PATCH 1/2] Add statistics for handle_loaned_message (#1927) * Add statistics for handle_loaned_message Signed-off-by: Barry Xu (cherry picked from commit 5c688303b3cb994969f448979f64c12971243295) # Conflicts: # rclcpp/include/rclcpp/subscription.hpp --- rclcpp/include/rclcpp/subscription.hpp | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index b567d1910e..ce04c0efb4 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -287,11 +287,38 @@ class Subscription : public SubscriptionBase void * loaned_message, const rclcpp::MessageInfo & message_info) override { +<<<<<<< HEAD auto typed_message = static_cast(loaned_message); // message is loaned, so we have to make sure that the deleter does not deallocate the message auto sptr = std::shared_ptr( typed_message, [](CallbackMessageT * msg) {(void) msg;}); +======= + if (matches_any_intra_process_publishers(&message_info.get_rmw_message_info().publisher_gid)) { + // In this case, the message will be delivered via intra process and + // we should ignore this copy of the message. + return; + } + + auto typed_message = static_cast(loaned_message); + // message is loaned, so we have to make sure that the deleter does not deallocate the message + auto sptr = std::shared_ptr( + typed_message, [](ROSMessageType * msg) {(void) msg;}); + + std::chrono::time_point now; + if (subscription_topic_statistics_) { + // get current time before executing callback to + // exclude callback duration from topic statistics result. + now = std::chrono::system_clock::now(); + } + +>>>>>>> 5c688303 (Add statistics for handle_loaned_message (#1927)) any_callback_.dispatch(sptr, message_info); + + if (subscription_topic_statistics_) { + const auto nanos = std::chrono::time_point_cast(now); + const auto time = rclcpp::Time(nanos.time_since_epoch().count()); + subscription_topic_statistics_->handle_message(*typed_message, time); + } } /// Return the borrowed message. From b67818360d831554a9b21b8d2521a18a51078f91 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Sun, 22 May 2022 00:02:54 +0800 Subject: [PATCH 2/2] Fix merge conflicts (#1939) Signed-off-by: Barry Xu --- rclcpp/include/rclcpp/subscription.hpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index ce04c0efb4..08786c5c6d 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -287,22 +287,16 @@ class Subscription : public SubscriptionBase void * loaned_message, const rclcpp::MessageInfo & message_info) override { -<<<<<<< HEAD - auto typed_message = static_cast(loaned_message); - // message is loaned, so we have to make sure that the deleter does not deallocate the message - auto sptr = std::shared_ptr( - typed_message, [](CallbackMessageT * msg) {(void) msg;}); -======= if (matches_any_intra_process_publishers(&message_info.get_rmw_message_info().publisher_gid)) { // In this case, the message will be delivered via intra process and // we should ignore this copy of the message. return; } - auto typed_message = static_cast(loaned_message); + auto typed_message = static_cast(loaned_message); // message is loaned, so we have to make sure that the deleter does not deallocate the message - auto sptr = std::shared_ptr( - typed_message, [](ROSMessageType * msg) {(void) msg;}); + auto sptr = std::shared_ptr( + typed_message, [](CallbackMessageT * msg) {(void) msg;}); std::chrono::time_point now; if (subscription_topic_statistics_) { @@ -311,7 +305,6 @@ class Subscription : public SubscriptionBase now = std::chrono::system_clock::now(); } ->>>>>>> 5c688303 (Add statistics for handle_loaned_message (#1927)) any_callback_.dispatch(sptr, message_info); if (subscription_topic_statistics_) {