ros2 / rosbag2

Apache License 2.0
273 stars 245 forks source link

Message listener for recording #1075

Open emersonknapp opened 2 years ago

emersonknapp commented 2 years ago

Description

Allow user to register a callback with the Recorder that will be called on every new recorded message. This need comes out of rqt_bag workflows. See #558 for full discussion.

Related Issues

Split from #558

Completion Criteria

Implementation Notes / Suggestions

If you have ideas about how this feature might be accomplished, put them here. Note that this is just a suggestion to the implementer, so feel free to speculate.

Testing Notes / Suggestions

All features in this project need tests. Please give some input on cases that will need to be tested - and how the testing might be implemented.

MichaelOrlov commented 2 years ago

@emersonknapp I am afraid that callback from each new message to the python API and then to the rqt_bag will hit performance of the entire recording process.
I think it would be better to gather needed statistics inside recorder and provide getters API to it. Perhaps we can use atomic variables without mutexes. The idea is that rqt_bag will call statistic's getter API periodically instead of subscribing to the callbacks for each message write.

emersonknapp commented 2 years ago

Well, rqt_bag uses a much more inefficient method - when a message comes in, it triggers a separate thread to ask the actual open bagfile for messages in a timestamp range, and uses those results to populate the timeline. I'm not saying this is good, but a callback would be a strict improvement on running a read query on the bag that is being written, for every new message.

EDIT: note this is how ROS 1 version works - rosbag.Bag type supports making read queries into the bag while it is open for writing. rqt_bag calls Bag._get_entries in this case.