Extract empty lttng interface functions to another file
This commit is contained in:
parent
33e56b9513
commit
af69745110
3 changed files with 45 additions and 30 deletions
|
@ -17,26 +17,14 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import lttng
|
from . import lttng_impl
|
||||||
|
|
||||||
from .lttng_impl import _lttng_destroy
|
_lttng = lttng_impl
|
||||||
from .lttng_impl import _lttng_setup
|
|
||||||
from .lttng_impl import _lttng_start
|
|
||||||
from .lttng_impl import _lttng_stop
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
lttng = None
|
# Fall back on empty functions
|
||||||
|
from . import lttng_stub
|
||||||
|
|
||||||
def _lttng_destroy(*args, **kwargs) -> None:
|
_lttng = lttng_stub
|
||||||
pass
|
|
||||||
|
|
||||||
def _lttng_setup(*args, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _lttng_start(*args, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _lttng_stop(*args, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from .names import DEFAULT_CONTEXT
|
from .names import DEFAULT_CONTEXT
|
||||||
from .names import DEFAULT_EVENTS_KERNEL
|
from .names import DEFAULT_EVENTS_KERNEL
|
||||||
|
@ -60,10 +48,8 @@ def lttng_init(
|
||||||
:param kernel_events: list of kernel events to enable
|
:param kernel_events: list of kernel events to enable
|
||||||
:param context_names: list of context elements to enable
|
:param context_names: list of context elements to enable
|
||||||
"""
|
"""
|
||||||
if lttng is None:
|
_lttng.setup(session_name, base_path, ros_events, kernel_events, context_names)
|
||||||
return None
|
_lttng.start(session_name)
|
||||||
_lttng_setup(session_name, base_path, ros_events, kernel_events, context_names)
|
|
||||||
_lttng_start(session_name)
|
|
||||||
|
|
||||||
|
|
||||||
def lttng_fini(session_name: str) -> None:
|
def lttng_fini(session_name: str) -> None:
|
||||||
|
@ -72,7 +58,5 @@ def lttng_fini(session_name: str) -> None:
|
||||||
|
|
||||||
:param session_name: the name of the session
|
:param session_name: the name of the session
|
||||||
"""
|
"""
|
||||||
if lttng is None:
|
_lttng.stop(session_name)
|
||||||
return None
|
_lttng.destroy(session_name)
|
||||||
_lttng_stop(session_name)
|
|
||||||
_lttng_destroy(session_name)
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ from .path import DEFAULT_BASE_PATH
|
||||||
from .path import get_full_session_path
|
from .path import get_full_session_path
|
||||||
|
|
||||||
|
|
||||||
def _lttng_setup(
|
def setup(
|
||||||
session_name: str,
|
session_name: str,
|
||||||
base_path: str = DEFAULT_BASE_PATH,
|
base_path: str = DEFAULT_BASE_PATH,
|
||||||
ros_events: List[str] = DEFAULT_EVENTS_ROS,
|
ros_events: List[str] = DEFAULT_EVENTS_ROS,
|
||||||
|
@ -113,7 +113,7 @@ def _lttng_setup(
|
||||||
_add_context(enabled_handles, context_list)
|
_add_context(enabled_handles, context_list)
|
||||||
|
|
||||||
|
|
||||||
def _lttng_start(session_name: str) -> None:
|
def start(session_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Start LTTng session, and check for errors.
|
Start LTTng session, and check for errors.
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ def _lttng_start(session_name: str) -> None:
|
||||||
raise RuntimeError(f'failed to start tracing: {lttng.strerror(result)}')
|
raise RuntimeError(f'failed to start tracing: {lttng.strerror(result)}')
|
||||||
|
|
||||||
|
|
||||||
def _lttng_stop(session_name: str) -> None:
|
def stop(session_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Stop LTTng session, and check for errors.
|
Stop LTTng session, and check for errors.
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ def _lttng_stop(session_name: str) -> None:
|
||||||
raise RuntimeError(f'failed to stop tracing: {lttng.strerror(result)}')
|
raise RuntimeError(f'failed to stop tracing: {lttng.strerror(result)}')
|
||||||
|
|
||||||
|
|
||||||
def _lttng_destroy(session_name: str) -> None:
|
def destroy(session_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Destroy LTTng session, and check for errors.
|
Destroy LTTng session, and check for errors.
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ def _create_session(session_name: str, full_path: str) -> None:
|
||||||
if result == -LTTNG_ERR_EXIST_SESS:
|
if result == -LTTNG_ERR_EXIST_SESS:
|
||||||
# Sessions seem to persist, so if it already exists,
|
# Sessions seem to persist, so if it already exists,
|
||||||
# just destroy it and try again
|
# just destroy it and try again
|
||||||
_lttng_destroy(session_name)
|
destroy(session_name)
|
||||||
result = lttng.create(session_name, full_path)
|
result = lttng.create(session_name, full_path)
|
||||||
if result < 0:
|
if result < 0:
|
||||||
raise RuntimeError(f'session creation failed: {lttng.strerror(result)}')
|
raise RuntimeError(f'session creation failed: {lttng.strerror(result)}')
|
||||||
|
|
31
tracetools_trace/tracetools_trace/tools/lttng_stub.py
Normal file
31
tracetools_trace/tracetools_trace/tools/lttng_stub.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""Stub version of the interface for tracing with LTTng."""
|
||||||
|
|
||||||
|
|
||||||
|
def setup(*args, **kwargs) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def start(*args, **kwargs) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def stop(*args, **kwargs) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def destroy(*args, **kwargs) -> None:
|
||||||
|
pass
|
Loading…
Add table
Add a link
Reference in a new issue