Centralize default trace location

This commit is contained in:
Christophe Bedard 2019-07-05 14:46:02 +02:00
parent 078ebc411a
commit 1eacc66c97
7 changed files with 69 additions and 23 deletions

View file

@ -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,

View file

@ -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

View 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))

View file

@ -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')