# Simple C++ node to get more accurate topic frequency

**URL:** <https://discourse.openrobotics.org/t/simple-c-node-to-get-more-accurate-topic-frequency/57741>\
**Category:** Projects\
**Tags:** ros2\
**Created:** [August 29, 2026, 4:06pm UTC](https://discourse.openrobotics.org/t/simple-c-node-to-get-more-accurate-topic-frequency/57741 "2026-08-29T16:06:00Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![TanayK07](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/tanayk07/32/35152_2.png) [@TanayK07](https://discourse.openrobotics.org/u/TanayK07)\
**Post date:** [September 28, 2026, 4:35pm UTC](https://discourse.openrobotics.org/t/simple-c-node-to-get-more-accurate-topic-frequency/57741/8 "2026-09-28T16:35:56Z")

</div>

A data point for #6 and #7, since the observer cost can be measured. On Humble with CycloneDDS, attaching `ros2 topic hz` to one of fifteen intra-process topics raised the watched process’s CPU from 0.303 s to 0.460 s per 10 s run (+52 %, higher in 10 of 10 trials), because the first out-of-process subscriber makes the publisher serialize every message. `hz` itself cost 7.1 % of a core on a 100 KB topic at 50 Hz, and `echo` 31.3 %. Method, CSV and plots: [Watching a ROS 2 topic changes it - ros2\_pulse](https://tanayk07.github.io/ros2_pulse/blog/2026-09-18-watching-a-ros2-topic-changes-it/)

One way around the question of how to subscribe carefully is not to subscribe at all. The tracetools hooks in stock binaries already fire on publish (`rclcpp_publish`, `rclcpp_intra_publish`) and on callback start, so counting there gives rates, intra-process included, with no endpoint on the graph and nothing for a publisher to adapt to. I did that as an LD\_PRELOAD shim (ros2\_pulse, [Ros2\_pulse: per-topic rates and node liveness, including intra-process, on stock binaries](https://discourse.openrobotics.org/t/57637)); the measured cost was +1.9 % ± 0.7 % CPU.

The tradeoffs: it has to be loaded into the processes you want to see, so it is not a drop-in for pointing `hz` at an arbitrary running system, and it only counts, it never sees message contents. For the buffer-aware case in #6 that could be useful, since nothing subscribes there is nothing to trigger a CPU fallback, but I have not tested it with rosidl::Buffer publishers.

---

_[View the full topic](https://discourse.openrobotics.org/t/simple-c-node-to-get-more-accurate-topic-frequency/57741)._
