Centralize default trace location
This commit is contained in:
parent
078ebc411a
commit
1eacc66c97
7 changed files with 69 additions and 23 deletions
|
@ -14,10 +14,9 @@
|
|||
|
||||
"""API functions for the ROS 2 trace command."""
|
||||
|
||||
import os
|
||||
|
||||
from tracetools_trace.tools import args
|
||||
from tracetools_trace.tools import lttng
|
||||
from tracetools_trace.tools import path
|
||||
|
||||
|
||||
def add_trace_arguments(parser):
|
||||
|
@ -32,7 +31,6 @@ def init(args):
|
|||
"""
|
||||
session_name = args.session_name
|
||||
base_path = args.path
|
||||
full_path = os.path.join(base_path, session_name)
|
||||
ros_events = args.events_ust
|
||||
kernel_events = args.events_kernel
|
||||
|
||||
|
@ -51,9 +49,14 @@ def init(args):
|
|||
else:
|
||||
print('kernel tracing disabled')
|
||||
|
||||
print(f'writting tracing session to: {full_path}')
|
||||
full_session_path = path.get_full_session_path(session_name, base_path)
|
||||
print(f'writting tracing session to: {full_session_path}')
|
||||
input('press enter to start...')
|
||||
lttng.lttng_init(session_name, full_path, ros_events=ros_events, kernel_events=kernel_events)
|
||||
lttng.lttng_init(
|
||||
session_name,
|
||||
base_path=base_path,
|
||||
ros_events=ros_events,
|
||||
kernel_events=kernel_events)
|
||||
|
||||
|
||||
def fini(args):
|
||||
|
|
|
@ -22,8 +22,7 @@ from tracetools_launch.action import Trace
|
|||
def generate_launch_description():
|
||||
return LaunchDescription([
|
||||
Trace(
|
||||
session_name='my-tracing-session',
|
||||
base_path='/tmp'),
|
||||
session_name='my-tracing-session'),
|
||||
Node(
|
||||
package='tracetools_test',
|
||||
node_executable='test_ping',
|
||||
|
|
|
@ -24,6 +24,7 @@ from launch.event_handlers import OnShutdown
|
|||
from launch.launch_context import LaunchContext
|
||||
from tracetools_trace.tools import lttng
|
||||
from tracetools_trace.tools import names
|
||||
from tracetools_trace.tools import path
|
||||
|
||||
|
||||
class Trace(Action):
|
||||
|
@ -37,7 +38,7 @@ class Trace(Action):
|
|||
self,
|
||||
*,
|
||||
session_name: str,
|
||||
base_path: str = '/tmp',
|
||||
base_path: str = path.DEFAULT_BASE_PATH,
|
||||
events_ust: List[str] = names.DEFAULT_EVENTS_ROS,
|
||||
events_kernel: List[str] = names.DEFAULT_EVENTS_KERNEL,
|
||||
**kwargs,
|
||||
|
@ -46,13 +47,13 @@ class Trace(Action):
|
|||
Constructor.
|
||||
|
||||
:param session_name: the name of the tracing session
|
||||
:param base_path: the base directory in which to create the trace directory
|
||||
:param base_path: the path to the base directory in which to create the tracing session directory
|
||||
:param events_ust: the list of ROS UST events to enable
|
||||
:param events_kernel: the list of kernel events to enable
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self.__session_name = session_name
|
||||
self.__path = os.path.join(base_path, session_name)
|
||||
self.__base_path = base_path
|
||||
self.__events_ust = events_ust
|
||||
self.__events_kernel = events_kernel
|
||||
|
||||
|
@ -65,7 +66,7 @@ class Trace(Action):
|
|||
def _setup(self) -> None:
|
||||
lttng.lttng_init(
|
||||
self.__session_name,
|
||||
self.__path,
|
||||
self.__base_path,
|
||||
ros_events=self.__events_ust,
|
||||
kernel_events=self.__events_kernel)
|
||||
|
||||
|
@ -76,7 +77,7 @@ class Trace(Action):
|
|||
return (
|
||||
"Trace("
|
||||
f"session_name='{self.__session_name}', "
|
||||
f"path='{self.__path}', "
|
||||
f"base_path='{self.__base_path}', "
|
||||
f"num_events_ust={len(self.__events_ust)}, "
|
||||
f"num_events_kernel={len(self.__events_kernel)})"
|
||||
)
|
||||
|
|
|
@ -18,6 +18,7 @@ import argparse
|
|||
import time
|
||||
|
||||
from . import names
|
||||
from . import path
|
||||
|
||||
|
||||
class DefaultArgValueCompleter:
|
||||
|
@ -45,7 +46,7 @@ def add_arguments(parser):
|
|||
help='the name of the tracing session (default: session-YYYYMMDDHHMMSS)')
|
||||
parser.add_argument(
|
||||
'--path', '-p', dest='path',
|
||||
default='/tmp',
|
||||
default=path.DEFAULT_BASE_PATH,
|
||||
help='path of the base directory for trace data (default: %(default)s)')
|
||||
arg = parser.add_argument(
|
||||
'--ust', '-u', nargs='*', dest='events_ust', default=names.DEFAULT_EVENTS_ROS,
|
||||
|
|
|
@ -21,11 +21,13 @@ import lttng
|
|||
from .names import DEFAULT_CONTEXT
|
||||
from .names import DEFAULT_EVENTS_KERNEL
|
||||
from .names import DEFAULT_EVENTS_ROS
|
||||
from .path import DEFAULT_BASE_PATH
|
||||
from .path import get_full_session_path
|
||||
|
||||
|
||||
def lttng_init(
|
||||
session_name: str,
|
||||
full_path: str,
|
||||
base_path: str = DEFAULT_BASE_PATH,
|
||||
ros_events: List[str] = DEFAULT_EVENTS_ROS,
|
||||
kernel_events: List[str] = DEFAULT_EVENTS_KERNEL,
|
||||
context_names: List[str] = DEFAULT_CONTEXT
|
||||
|
@ -34,12 +36,12 @@ def lttng_init(
|
|||
Set up and start LTTng session.
|
||||
|
||||
:param session_name: the name of the session
|
||||
:param full_path: the full path to the main directory to write trace data to
|
||||
:param base_path: the path to the directory in which to create the tracing session directory
|
||||
:param ros_events: list of ROS events to enable
|
||||
:param kernel_events: list of kernel events to enable
|
||||
:param context_names: list of context elements to enable
|
||||
"""
|
||||
_lttng_setup(session_name, full_path, ros_events, kernel_events, context_names)
|
||||
_lttng_setup(session_name, base_path, ros_events, kernel_events, context_names)
|
||||
_lttng_start(session_name)
|
||||
|
||||
|
||||
|
@ -55,7 +57,7 @@ def lttng_fini(session_name: str) -> None:
|
|||
|
||||
def _lttng_setup(
|
||||
session_name: str,
|
||||
full_path: str,
|
||||
base_path: str = DEFAULT_BASE_PATH,
|
||||
ros_events: List[str] = DEFAULT_EVENTS_ROS,
|
||||
kernel_events: List[str] = DEFAULT_EVENTS_KERNEL,
|
||||
context_names: List[str] = DEFAULT_CONTEXT,
|
||||
|
@ -68,13 +70,16 @@ def _lttng_setup(
|
|||
See: https://lttng.org/docs/#doc-core-concepts
|
||||
|
||||
:param session_name: the name of the session
|
||||
:param full_path: the full path to the main directory to write trace data to
|
||||
:param base_path: the path to the directory in which to create the tracing session directory
|
||||
:param ros_events: list of ROS events to enable
|
||||
:param kernel_events: list of kernel events to enable
|
||||
:param context_names: list of context elements to enable
|
||||
:param channel_name_ust: the UST channel name
|
||||
:param channel_name_kernel: the kernel channel name
|
||||
"""
|
||||
# Resolve full tracing directory path
|
||||
full_path = get_full_session_path(session_name, base_path=base_path)
|
||||
|
||||
ust_enabled = ros_events is not None and len(ros_events) > 0
|
||||
kernel_enabled = kernel_events is not None and len(kernel_events) > 0
|
||||
|
||||
|
|
34
tracetools_trace/tracetools_trace/tools/path.py
Normal file
34
tracetools_trace/tracetools_trace/tools/path.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Copyright 2019 Robert Bosch GmbH
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
|
||||
DEFAULT_BASE_PATH = '~/.ros/tracing/'
|
||||
|
||||
|
||||
def get_full_session_path(
|
||||
session_name: str,
|
||||
base_path: str = DEFAULT_BASE_PATH
|
||||
) -> str:
|
||||
"""
|
||||
Get the full path to the trace directory of a given session.
|
||||
|
||||
:param session_name: the name of the tracing session
|
||||
:param base_path: the path to the directory containing the trace directory
|
||||
:return: the full path to the tracing session directory
|
||||
"""
|
||||
if base_path is None:
|
||||
base_path = DEFAULT_BASE_PATH
|
||||
return os.path.expanduser(os.path.join(base_path, session_name))
|
|
@ -15,10 +15,9 @@
|
|||
|
||||
"""Entrypoint/script to setup and start an LTTng tracing session."""
|
||||
|
||||
import os
|
||||
|
||||
from tracetools_trace.tools import args
|
||||
from tracetools_trace.tools import lttng
|
||||
from tracetools_trace.tools import path
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -26,7 +25,6 @@ def main():
|
|||
|
||||
session_name = params.session_name
|
||||
base_path = params.path
|
||||
full_path = os.path.join(base_path, session_name)
|
||||
ros_events = params.events_ust
|
||||
kernel_events = params.events_kernel
|
||||
|
||||
|
@ -45,9 +43,14 @@ def main():
|
|||
else:
|
||||
print('kernel tracing disabled')
|
||||
|
||||
print(f'writting tracing session to: {full_path}')
|
||||
full_session_path = path.get_full_session_path(session_name, base_path)
|
||||
print(f'writting tracing session to: {full_session_path}')
|
||||
input('press enter to start...')
|
||||
lttng.lttng_init(session_name, full_path, ros_events=ros_events, kernel_events=kernel_events)
|
||||
lttng.lttng_init(
|
||||
session_name,
|
||||
base_path=base_path,
|
||||
ros_events=ros_events,
|
||||
kernel_events=kernel_events)
|
||||
input('press enter to stop...')
|
||||
|
||||
print('stopping & destroying tracing session')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue