Make sure platform is Linux before checking if LTTng is installed

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
Christophe Bedard 2020-05-14 10:25:30 -04:00
parent 8a11eed4de
commit a915fa55f0

View file

@ -14,6 +14,7 @@
"""Interface for tracing with LTTng.""" """Interface for tracing with LTTng."""
import platform
import subprocess import subprocess
import sys import sys
from typing import List from typing import List
@ -89,10 +90,19 @@ def is_lttng_installed() -> bool:
""" """
Check if LTTng is installed. Check if LTTng is installed.
Simply checks for the 'lttng' command. It first checks if the OS can support LTTng.
If so, it then simply checks if LTTng is installed using the 'lttng' command.
:return: True if it is installed, False otherwise :return: True if it is installed, False otherwise
""" """
message_doc = (
'Cannot trace. See documentation at: '
'https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing'
)
system = platform.system()
if 'Linux' != system:
print(f"System '{system}' does not support LTTng.\n{message_doc}", file=sys.stderr)
return False
try: try:
process = subprocess.Popen( process = subprocess.Popen(
['lttng', '--version'], ['lttng', '--version'],
@ -104,12 +114,5 @@ def is_lttng_installed() -> bool:
raise RuntimeError(stderr.decode()) raise RuntimeError(stderr.decode())
return True return True
except Exception as e: except Exception as e:
print( print(f'LTTng not found: {e}\n{message_doc}', file=sys.stderr)
(
f'LTTng not found: {e}\n'
'Cannot trace. See documentation at: '
'https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing'
),
file=sys.stderr,
)
return False return False