Skip to content

Commit 5049c45

Browse files
authored
Serialized Messages with Topic Statistics (#2274)
Signed-off-by: CursedRock17 <[email protected]>
1 parent 4691063 commit 5049c45

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rclcpp/include/rclcpp/subscription.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,20 @@ class Subscription : public SubscriptionBase
325325
const std::shared_ptr<rclcpp::SerializedMessage> & serialized_message,
326326
const rclcpp::MessageInfo & message_info) override
327327
{
328-
// TODO(wjwwood): enable topic statistics for serialized messages
328+
std::chrono::time_point<std::chrono::system_clock> now;
329+
if (subscription_topic_statistics_) {
330+
// get current time before executing callback to
331+
// exclude callback duration from topic statistics result.
332+
now = std::chrono::system_clock::now();
333+
}
334+
329335
any_callback_.dispatch(serialized_message, message_info);
336+
337+
if (subscription_topic_statistics_) {
338+
const auto nanos = std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
339+
const auto time = rclcpp::Time(nanos.time_since_epoch().count());
340+
subscription_topic_statistics_->handle_message(message_info.get_rmw_message_info(), time);
341+
}
330342
}
331343

332344
void

0 commit comments

Comments
 (0)