diff --git a/tracetools_launch/destroy.py b/tracetools_launch/destroy.py deleted file mode 100644 index 8b4a456..0000000 --- a/tracetools_launch/destroy.py +++ /dev/null @@ -1,24 +0,0 @@ - -from typing import List -from typing import Optional -from typing import Text - -from launch.action import Action -from launch_context import LaunchContext -from launch_description_entity import LaunchDescriptionEntity - - -class Destroy(Action): - """ - Action for launch that destroys a tracing session. - - It finalizes and destroys a tracing session that was setup with the Trace action. - """ - - def __init__(self, session_name: str, **kwargs) -> None: - """Constructor.""" - super().__init__(**kwargs) - self.__session_name = session_name - - def execute(self, context: LaunchContext) -> Optional[List[Action]]: - pass \ No newline at end of file diff --git a/tracetools_launch/trace.py b/tracetools_launch/trace.py index 5d847bd..c032a4f 100644 --- a/tracetools_launch/trace.py +++ b/tracetools_launch/trace.py @@ -1,11 +1,14 @@ +import os from typing import List from typing import Optional from typing import Text from launch.action import Action -from launch_context import LaunchContext -from launch_description_entity import LaunchDescriptionEntity +from launch.event import Event +from launch.event_handlers import OnShutdown +from launch.launch_context import LaunchContext +from tracetools_trace.tools import names class Trace(Action): @@ -15,15 +18,32 @@ class Trace(Action): Sets up and enables tracing through a launch file description. """ - def __init__(self, *, + def __init__( + self, *, session_name: str, - base_path: str, - events_ust: List[str], - events_kernel: List[str], + base_path: str = '/tmp', + events_ust: List[str] = names.DEFAULT_EVENTS_ROS, + events_kernel: List[str] = names.DEFAULT_EVENTS_KERNEL, **kwargs) -> None: """Constructor.""" super().__init__(**kwargs) + self.__session_name = session_name + self.__path = os.path.join(base_path, session_name) + self.__events_ust = events_ust + self.__events_kernel = events_kernel def execute(self, context: LaunchContext) -> Optional[List[Action]]: + # TODO make sure this is done as late as possible + context.register_event_handler(OnShutdown( + on_shutdown=self._destroy, + )) + # TODO make sure this is done as early as possible + self._setup() + + def _setup(self): # TODO - pass + print('setting up tracing!') + + def _destroy(self, event: Event, context: LaunchContext): + # TODO + print('destroying tracing session!')