hz_subscriber is a ROS 2 component package intended to replace ros2 topic hz ... when the topic producer is running as a composable node or component.
The main goal is to measure topic frequency with much lower overhead by loading the frequency subscriber into the same component container as the publisher, so both can use intra-process communication instead of an external CLI subscriber process.
The standard ros2 topic hz command runs as a separate ROS 2 process, not as a component inside the same container as the publisher. As a result, it does not benefit from the same-process composition model used by ROS 2 components.
When working with high-bandwidth image topics, this extra process and transport path can noticeably increase CPU and memory usage, while node composition is specifically designed to reduce that overhead by colocating components in one process.
Note
This package is meant for composable nodes or components, not as a general replacement for every ros2 topic hz use case.
This package provides a lightweight C++ subscriber component that:
- Subscribes to a target topic, typically an image topic.
- Computes average rate, minimum period, maximum period, standard deviation, and sample window.
- Prints an output similar to
ros2 topic hz, for example:
average rate: 59.978
min: 0.014s max: 0.019s std dev: 0.00056s window: 182
The component is intended to be loaded into the same rclcpp_components container as the composable publisher, with use_intra_process_comms:=true enabled on both components.
Both the publisher component and hz_dummy_subscriber must be available in the current ROS 2 environment before loading them into a container. In practice, that means their workspaces must be built and sourced in the current shell, whether the system is running natively or inside Docker.
ros2 run rclcpp_components component_container_mt --ros-args -r __node:=image_containerROS 2 supports running multiple components in the same process by loading them into a container process managed by rclcpp_components.[1][3]
ros2 component load /image_container your_image_pkg your_namespace::YourImageNode \
-e use_intra_process_comms:=trueros2 component load /image_container hz_subscriber hz_subscriber::HzDummySubscriber \
-p topic:=/image_raw \
-p report_period_sec:=1.0 \
-e use_intra_process_comms:=trueImportant
To get intra-process behavior, both components must be loaded into the same container, and both must enable use_intra_process_comms.