2019-06-06 09:28:25 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-06-24 10:36:39 +02:00
|
|
|
# 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.
|
|
|
|
|
2019-06-24 10:45:29 +02:00
|
|
|
"""Entrypoint/script to setup and start an LTTng tracing session."""
|
2019-06-06 09:28:25 +02:00
|
|
|
|
2020-05-14 09:32:20 -04:00
|
|
|
import sys
|
2019-12-08 14:01:57 -08:00
|
|
|
from typing import List
|
|
|
|
|
2019-06-23 16:02:48 +02:00
|
|
|
from tracetools_trace.tools import args
|
2019-06-07 10:42:40 +02:00
|
|
|
from tracetools_trace.tools import lttng
|
2019-07-05 14:46:02 +02:00
|
|
|
from tracetools_trace.tools import path
|
2020-01-01 14:10:51 -05:00
|
|
|
from tracetools_trace.tools import print_names_list
|
2019-06-06 09:28:25 +02:00
|
|
|
|
2019-06-06 09:39:02 +02:00
|
|
|
|
2019-12-08 14:01:57 -08:00
|
|
|
def init(
|
|
|
|
session_name: str,
|
|
|
|
base_path: str,
|
|
|
|
ros_events: List[str],
|
|
|
|
kernel_events: List[str],
|
2020-01-01 14:12:23 -05:00
|
|
|
context_names: List[str],
|
2019-12-08 14:01:57 -08:00
|
|
|
display_list: bool = False,
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
Init and start tracing.
|
2019-06-06 09:28:25 +02:00
|
|
|
|
2019-12-08 14:01:57 -08:00
|
|
|
:param session_name: the name of the session
|
|
|
|
: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
|
2020-01-01 14:12:23 -05:00
|
|
|
:param context_names: list of context names to enable
|
|
|
|
:param display_list: whether to display list(s) of enabled events and context names
|
2019-12-08 14:01:57 -08:00
|
|
|
"""
|
2020-05-14 09:32:20 -04:00
|
|
|
if not lttng.is_lttng_installed():
|
|
|
|
sys.exit(2)
|
|
|
|
|
2019-06-06 09:30:48 +02:00
|
|
|
ust_enabled = len(ros_events) > 0
|
|
|
|
kernel_enabled = len(kernel_events) > 0
|
2019-06-06 09:39:02 +02:00
|
|
|
if ust_enabled:
|
|
|
|
print(f'UST tracing enabled ({len(ros_events)} events)')
|
2019-12-08 14:01:57 -08:00
|
|
|
if display_list:
|
2020-01-01 14:10:51 -05:00
|
|
|
print_names_list(ros_events)
|
2019-06-06 09:39:02 +02:00
|
|
|
else:
|
|
|
|
print('UST tracing disabled')
|
|
|
|
if kernel_enabled:
|
|
|
|
print(f'kernel tracing enabled ({len(kernel_events)} events)')
|
2019-12-08 14:01:57 -08:00
|
|
|
if display_list:
|
2020-01-01 14:10:51 -05:00
|
|
|
print_names_list(kernel_events)
|
2019-06-06 09:39:02 +02:00
|
|
|
else:
|
|
|
|
print('kernel tracing disabled')
|
2020-01-01 14:12:23 -05:00
|
|
|
if len(context_names) > 0:
|
|
|
|
print(f'context ({len(context_names)} names)')
|
|
|
|
if display_list:
|
|
|
|
print_names_list(context_names)
|
2019-06-06 09:30:48 +02:00
|
|
|
|
2019-07-05 14:46:02 +02:00
|
|
|
full_session_path = path.get_full_session_path(session_name, base_path)
|
2019-07-05 14:47:01 +02:00
|
|
|
print(f'writing tracing session to: {full_session_path}')
|
2019-06-06 09:29:38 +02:00
|
|
|
input('press enter to start...')
|
2019-07-05 14:46:02 +02:00
|
|
|
lttng.lttng_init(
|
|
|
|
session_name,
|
|
|
|
base_path=base_path,
|
|
|
|
ros_events=ros_events,
|
2020-01-01 14:12:23 -05:00
|
|
|
kernel_events=kernel_events,
|
|
|
|
context_names=context_names,
|
|
|
|
)
|
2019-06-06 09:28:25 +02:00
|
|
|
|
2019-12-08 14:01:57 -08:00
|
|
|
|
|
|
|
def fini(
|
|
|
|
session_name: str,
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
Stop and finalize tracing.
|
|
|
|
|
|
|
|
:param session_name: the name of the session
|
|
|
|
"""
|
|
|
|
input('press enter to stop...')
|
2019-06-06 09:28:25 +02:00
|
|
|
print('stopping & destroying tracing session')
|
2019-06-23 15:51:13 +02:00
|
|
|
lttng.lttng_fini(session_name)
|
2019-12-08 14:01:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
params = args.parse_args()
|
|
|
|
|
|
|
|
init(
|
|
|
|
params.session_name,
|
|
|
|
params.path,
|
|
|
|
params.events_ust,
|
|
|
|
params.events_kernel,
|
2020-01-01 14:12:23 -05:00
|
|
|
params.context_names,
|
2019-12-08 14:01:57 -08:00
|
|
|
params.list,
|
|
|
|
)
|
|
|
|
fini(
|
|
|
|
params.session_name,
|
|
|
|
)
|