From af69745110cab1bf19543831449fc4de53593e3c Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Fri, 16 Aug 2019 12:00:37 +0200 Subject: [PATCH] Extract empty lttng interface functions to another file --- .../tracetools_trace/tools/lttng.py | 34 +++++-------------- .../tracetools_trace/tools/lttng_impl.py | 10 +++--- .../tracetools_trace/tools/lttng_stub.py | 31 +++++++++++++++++ 3 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 tracetools_trace/tracetools_trace/tools/lttng_stub.py diff --git a/tracetools_trace/tracetools_trace/tools/lttng.py b/tracetools_trace/tracetools_trace/tools/lttng.py index cfe20e1..de22fd5 100644 --- a/tracetools_trace/tracetools_trace/tools/lttng.py +++ b/tracetools_trace/tracetools_trace/tools/lttng.py @@ -17,26 +17,14 @@ from typing import List try: - import lttng + from . import lttng_impl - from .lttng_impl import _lttng_destroy - from .lttng_impl import _lttng_setup - from .lttng_impl import _lttng_start - from .lttng_impl import _lttng_stop + _lttng = lttng_impl except ImportError: - lttng = None + # Fall back on empty functions + from . import lttng_stub - def _lttng_destroy(*args, **kwargs) -> None: - pass - - def _lttng_setup(*args, **kwargs) -> None: - pass - - def _lttng_start(*args, **kwargs) -> None: - pass - - def _lttng_stop(*args, **kwargs) -> None: - pass + _lttng = lttng_stub from .names import DEFAULT_CONTEXT from .names import DEFAULT_EVENTS_KERNEL @@ -60,10 +48,8 @@ def lttng_init( :param kernel_events: list of kernel events to enable :param context_names: list of context elements to enable """ - if lttng is None: - return None - _lttng_setup(session_name, base_path, ros_events, kernel_events, context_names) - _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: @@ -72,7 +58,5 @@ def lttng_fini(session_name: str) -> None: :param session_name: the name of the session """ - if lttng is None: - return None - _lttng_stop(session_name) - _lttng_destroy(session_name) + _lttng.stop(session_name) + _lttng.destroy(session_name) diff --git a/tracetools_trace/tracetools_trace/tools/lttng_impl.py b/tracetools_trace/tracetools_trace/tools/lttng_impl.py index d3a64e5..c47ed1b 100644 --- a/tracetools_trace/tracetools_trace/tools/lttng_impl.py +++ b/tracetools_trace/tracetools_trace/tools/lttng_impl.py @@ -25,7 +25,7 @@ from .path import DEFAULT_BASE_PATH from .path import get_full_session_path -def _lttng_setup( +def setup( session_name: str, base_path: str = DEFAULT_BASE_PATH, ros_events: List[str] = DEFAULT_EVENTS_ROS, @@ -113,7 +113,7 @@ def _lttng_setup( _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. @@ -124,7 +124,7 @@ def _lttng_start(session_name: str) -> None: 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. @@ -135,7 +135,7 @@ def _lttng_stop(session_name: str) -> None: 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. @@ -175,7 +175,7 @@ def _create_session(session_name: str, full_path: str) -> None: if result == -LTTNG_ERR_EXIST_SESS: # Sessions seem to persist, so if it already exists, # just destroy it and try again - _lttng_destroy(session_name) + destroy(session_name) result = lttng.create(session_name, full_path) if result < 0: raise RuntimeError(f'session creation failed: {lttng.strerror(result)}') diff --git a/tracetools_trace/tracetools_trace/tools/lttng_stub.py b/tracetools_trace/tracetools_trace/tools/lttng_stub.py new file mode 100644 index 0000000..47c0c63 --- /dev/null +++ b/tracetools_trace/tracetools_trace/tools/lttng_stub.py @@ -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