ros-controls / realtime_tools

Contains a set of tools that can be used from a hard realtime thread, without breaking the realtime behavior.
https://control.ros.org
BSD 3-Clause "New" or "Revised" License
140 stars 76 forks source link

Allow to rename thread in `RealtimePublisher` #176

Open roncapat opened 1 month ago

roncapat commented 1 month ago

At least in Linux, it is possible to rename a thread, via calls like ptrhead_setname_np.

For application featuring many RealtimePublishers and many other threads, diving into perf record outputs (e.g. via hotspot tool) is difficult because by default all threads have the same name (First 15 characters of the process name), and thread renaming is a powerful tool to discriminate at a glance which thread does what.

To allow this, either the implementation of RealtimePublisher shall permit to obtain the native handle (see this) or may enable for Linux only an additional method that uses pthread_setname_np.

I can submit a PR depending on maintainers feedback of course 👍🏻

christophfroehlich commented 1 week ago

@saikishor what do you think?

firesurfer commented 3 days ago

As I just spent some time with that class: I would recommend against both suggestions and make an alternative proposal:

We make the thread_ field protected and you can inherit from the RealtimePublisher and add whatever functionality you need.

I think this is the cleanest approach as we keep the RealtimePublisher itself free from platform specific code and avoid exposing internals.

roncapat commented 3 days ago

Fine for me, as long as I have a way to access the thread handle :)

firesurfer commented 3 days ago

@roncapat I suggest you create a PR for that ;)