Skip to content

Commit

Permalink
Serialized Messages with Topic Statistics (ros2#2274)
Browse files Browse the repository at this point in the history
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
  • Loading branch information
CursedRock17 authored and Barry-Xu-2018 committed Jan 12, 2024
1 parent 812c8f3 commit 814170c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rclcpp/include/rclcpp/subscription.hpp
Expand Up @@ -325,8 +325,20 @@ class Subscription : public SubscriptionBase
const std::shared_ptr<rclcpp::SerializedMessage> & serialized_message,
const rclcpp::MessageInfo & message_info) override
{
// TODO(wjwwood): enable topic statistics for serialized messages
std::chrono::time_point<std::chrono::system_clock> 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);

if (subscription_topic_statistics_) {
const auto nanos = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
const auto time = rclcpp::Time(nanos.time_since_epoch().count());
subscription_topic_statistics_->handle_message(message_info.get_rmw_message_info(), time);
}
}

void
Expand Down

0 comments on commit 814170c

Please sign in to comment.