From 7eb4123b29fd88d9762c3d0b836fd930c2a7d41b Mon Sep 17 00:00:00 2001 From: CursedRock17 Date: Tue, 15 Aug 2023 13:02:18 -0400 Subject: [PATCH 1/4] Starting idea Signed-off-by: CursedRock17 --- rclcpp/include/rclcpp/subscription.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index 8e1aac2aa7..5f8e200b42 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -44,6 +44,7 @@ #include "rclcpp/subscription_base.hpp" #include "rclcpp/subscription_options.hpp" #include "rclcpp/subscription_traits.hpp" +#include "rclcpp/serialization.hpp" #include "rclcpp/type_support_decl.hpp" #include "rclcpp/visibility_control.hpp" #include "rclcpp/waitable.hpp" @@ -326,7 +327,25 @@ class Subscription : public SubscriptionBase const rclcpp::MessageInfo & message_info) override { // TODO(wjwwood): enable topic statistics for serialized messages + 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(); + } + any_callback_.dispatch(serialized_message, message_info); + + ROSMessageType deserialized_message; + auto serializer = rclcpp::Serialization(); + serializer.deserialize_message(serialized_message.get(), &deserialized_message); + + + 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(deserialized_message, time); + } } void From 8914d43b6a8fa691aed51c4617788387ef2dfa29 Mon Sep 17 00:00:00 2001 From: CursedRock17 Date: Tue, 15 Aug 2023 17:25:33 -0400 Subject: [PATCH 2/4] intra process available Signed-off-by: CursedRock17 --- rclcpp/include/rclcpp/subscription.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index 5f8e200b42..d11d23185b 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -326,7 +326,12 @@ class Subscription : public SubscriptionBase const std::shared_ptr & serialized_message, const rclcpp::MessageInfo & message_info) override { - // TODO(wjwwood): enable topic statistics for serialized messages + 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; + } + std::chrono::time_point now; if (subscription_topic_statistics_) { // get current time before executing callback to From 78a317da1b73b7c64b1b3258925430a2613e96a8 Mon Sep 17 00:00:00 2001 From: CursedRock17 Date: Sat, 2 Sep 2023 20:37:40 -0400 Subject: [PATCH 3/4] removed intra Signed-off-by: CursedRock17 Correct version of handle_message Signed-off-by: CursedRock17 --- rclcpp/include/rclcpp/subscription.hpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index d11d23185b..22c875ee0a 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -326,12 +326,6 @@ class Subscription : public SubscriptionBase const std::shared_ptr & serialized_message, const rclcpp::MessageInfo & message_info) override { - 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; - } - std::chrono::time_point now; if (subscription_topic_statistics_) { // get current time before executing callback to @@ -341,15 +335,10 @@ class Subscription : public SubscriptionBase any_callback_.dispatch(serialized_message, message_info); - ROSMessageType deserialized_message; - auto serializer = rclcpp::Serialization(); - serializer.deserialize_message(serialized_message.get(), &deserialized_message); - - 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(deserialized_message, time); + subscription_topic_statistics_->handle_message(message_info.get_rmw_message_info(), time); } } From 09327885d5c7bf0af6e1b0c36828d435dbc47398 Mon Sep 17 00:00:00 2001 From: Lucas Wendland <82680922+CursedRock17@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:58:30 -0400 Subject: [PATCH 4/4] Removing serialization header Signed-off-by: CursedRock17 --- rclcpp/include/rclcpp/subscription.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index 22c875ee0a..d6e0f536ed 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -44,7 +44,6 @@ #include "rclcpp/subscription_base.hpp" #include "rclcpp/subscription_options.hpp" #include "rclcpp/subscription_traits.hpp" -#include "rclcpp/serialization.hpp" #include "rclcpp/type_support_decl.hpp" #include "rclcpp/visibility_control.hpp" #include "rclcpp/waitable.hpp"