diff --git a/ros2caret/verb/record.py b/ros2caret/verb/record.py index b70efedf..d237b9bc 100644 --- a/ros2caret/verb/record.py +++ b/ros2caret/verb/record.py @@ -13,6 +13,8 @@ # limitations under the License. import os +import signal +import subprocess from typing import Optional @@ -149,6 +151,9 @@ def add_arguments(self, parser, cli_name): parser.add_argument( '--immediate', dest='immediate', action='store_true', help='record immediately. ') + parser.add_argument( + '-c', '--record-clock', dest='record_clock', action='store_true', + help='launch the node where the /clock topic is stored to use ROS time. ') def main(self, *, args): if args.light_mode: @@ -217,9 +222,19 @@ def _run(): def _fini(): node.stop_progress() node.end() + if clock_recorder: + # cspell: ignore killpg, getpgid + os.killpg(os.getpgid(clock_recorder.pid), signal.SIGTERM) print('stopping & destroying tracing session') lttng.lttng_fini(session_name=args.session_name) + if args.record_clock: + # cspell: ignore preexec, setpgrp + clock_recorder = subprocess.Popen( + ['ros2', 'run', 'caret_trace', 'clock_recorder'], + preexec_fn=os.setpgrp) + else: + clock_recorder = None execute_and_handle_sigint(_run, _fini) return 0