Skip to content

Commit ed6f435

Browse files
Switch to custom lttng-ctl Python bindings (#81)
* Add lttngpy * Replace python3-lttng with lttngpy * Support lttng-ctl 2.12 Signed-off-by: Christophe Bedard <[email protected]>
1 parent 408c54b commit ed6f435

40 files changed

+2458
-370
lines changed

Diff for: .github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
- uses: ros-tooling/action-ros-ci@master
5050
with:
5151
package-name: >
52+
lttngpy
5253
ros2trace
5354
test_ros2trace
5455
test_tracetools

Diff for: LTTng_QUALITY_DECLARATION.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,21 @@ Features are listed and well documented on the [LTTng website](https://lttng.org
8888
LTTng packages have embedded API documentation.
8989
It can be viewed on their man pages:
9090

91-
* [`lttng-ust`](https://lttng.org/man/3/lttng-ust/v2.11/)
91+
* [`lttng-ust`](https://lttng.org/man/3/lttng-ust/v2.13/)
9292

9393
### License [3.iii]
9494

9595
All repositories have a `LICENSE` file.
9696
All relevant files have a license identifier.
9797

98-
* `lttng-tools` is licensed under LGPLv2.1 and GPLv2, see [`LICENSE` file](https://github.com/lttng/lttng-tools/blob/master/LICENSE)
9998
* `lttng-ust` is licensed under LGPLv2.1, the MIT license and GPLv2, see [`LICENSE` file](https://github.com/lttng/lttng-ust/blob/master/LICENSE)
99+
* `liblttng-ust` (build dependency) is LGPLv2.1 and MIT
100+
* The rest (runtime tools, not dependencies) is GPLv2
101+
* `lttng-tools` is licensed under LGPLv2.1 and GPLv2, see [`LICENSE` file](https://github.com/lttng/lttng-tools/blob/master/LICENSE)
102+
* `liblttng-ctl` (build dependency) is LGPLv2.1
103+
* The rest (runtime tools, not dependencies) is GPLv2
100104
* `lttng-modules` is licensed under LGPLv2.1, GPLv2 and the MIT license, see [`LICENSE` file](https://github.com/lttng/lttng-modules/blob/master/LICENSE)
105+
* Not a dependency
101106

102107
### Copyright Statement [3.iv]
103108

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ The LTTng kernel tracer has a similar implementation, but is separate from the u
218218
219219
## Packages
220220
221+
### lttngpy
222+
223+
Package containing `liblttng-ctl` Python bindings.
224+
221225
### ros2trace
222226
223227
Package containing a `ros2cli` extension to enable tracing.
@@ -246,6 +250,10 @@ Package containing tools for tracing-related tests.
246250
247251
Package containing tools to enable tracing.
248252
253+
### test_ros2trace
254+
255+
Package containing system tests for `ros2trace`.
256+
249257
### test_tracetools
250258
251259
Package containing unit and system tests for `tracetools`.

Diff for: lttngpy/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
*.pyc

Diff for: lttngpy/CMakeLists.txt

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(lttngpy)
4+
5+
# Default to C++17
6+
if(NOT CMAKE_CXX_STANDARD)
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
endif()
10+
# Default to C11
11+
if(NOT CMAKE_C_STANDARD)
12+
set(CMAKE_C_STANDARD 11)
13+
endif()
14+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
15+
add_compile_options(-Wall -Wextra -Wpedantic)
16+
endif()
17+
18+
find_package(ament_cmake REQUIRED)
19+
20+
if(WIN32 OR APPLE OR ANDROID)
21+
set(DISABLED_DEFAULT ON)
22+
else()
23+
set(DISABLED_DEFAULT OFF)
24+
endif()
25+
option(
26+
LTTNGPY_DISABLED
27+
"Explicitly disable support, don't link against liblttng-ctl"
28+
${DISABLED_DEFAULT})
29+
30+
# Find python before pybind11
31+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
32+
33+
find_package(pybind11_vendor REQUIRED)
34+
find_package(pybind11 REQUIRED)
35+
36+
if(NOT LTTNGPY_DISABLED)
37+
find_package(PkgConfig REQUIRED)
38+
pkg_check_modules(LTTNG_CTL REQUIRED lttng-ctl)
39+
set(LTTNG_CTL_VERSION ${LTTNG_CTL_VERSION})
40+
41+
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" dummy "${LTTNG_CTL_VERSION}")
42+
set(LTTNG_CTL_VERSION_MAJOR "${CMAKE_MATCH_1}")
43+
set(LTTNG_CTL_VERSION_MINOR "${CMAKE_MATCH_2}")
44+
set(LTTNG_CTL_VERSION_PATCH "${CMAKE_MATCH_3}")
45+
else()
46+
set(LTTNG_CTL_VERSION "")
47+
set(LTTNG_CTL_VERSION_MAJOR "0")
48+
set(LTTNG_CTL_VERSION_MINOR "0")
49+
set(LTTNG_CTL_VERSION_PATCH "0")
50+
endif()
51+
52+
# Store configuration variable for buildtime use
53+
# LTTNGPY_DISABLED
54+
# LTTNG_CTL_VERSION
55+
# LTTNG_CTL_VERSION_MAJOR
56+
# LTTNG_CTL_VERSION_MINOR
57+
# LTTNG_CTL_VERSION_PATCH
58+
configure_file(src/lttngpy/config.hpp.in src/lttngpy/config.hpp)
59+
60+
ament_python_install_package(${PROJECT_NAME})
61+
62+
set(SOURCES
63+
src/lttngpy/_lttngpy_pybind11.cpp
64+
src/lttngpy/status.cpp
65+
)
66+
if(NOT LTTNGPY_DISABLED)
67+
list(APPEND SOURCES
68+
src/lttngpy/channel.cpp
69+
src/lttngpy/context_app.cpp
70+
src/lttngpy/context_lttng.cpp
71+
src/lttngpy/context_perf.cpp
72+
src/lttngpy/event.cpp
73+
src/lttngpy/lttng.cpp
74+
src/lttngpy/session.cpp
75+
)
76+
endif()
77+
78+
pybind11_add_module(_lttngpy_pybind11 SHARED ${SOURCES})
79+
80+
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
81+
target_link_libraries(_lttngpy_pybind11 PRIVATE atomic)
82+
endif()
83+
84+
target_include_directories(_lttngpy_pybind11 PRIVATE
85+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
86+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
87+
)
88+
if(NOT LTTNGPY_DISABLED)
89+
target_link_libraries(_lttngpy_pybind11 PRIVATE ${LTTNG_CTL_LIBRARIES})
90+
endif()
91+
92+
# Set the build location and install location for a CPython extension
93+
install(TARGETS _lttngpy_pybind11
94+
DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}"
95+
)
96+
97+
if(BUILD_TESTING)
98+
find_package(ament_lint_auto REQUIRED)
99+
ament_lint_auto_find_test_dependencies()
100+
101+
if(NOT LTTNGPY_DISABLED)
102+
find_package(ament_cmake_gtest REQUIRED)
103+
find_package(ament_cmake_pytest REQUIRED)
104+
105+
# Using source files, because I can't seem to be able to link against _lttngpy_pybind11
106+
ament_add_gtest(test_context_app test/test_context_app.cpp src/lttngpy/context_app.cpp)
107+
if(TARGET test_context_app)
108+
target_include_directories(test_context_app PRIVATE
109+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
110+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
111+
)
112+
endif()
113+
114+
ament_add_gtest(test_context_lttng test/test_context_lttng.cpp src/lttngpy/context_lttng.cpp)
115+
if(TARGET test_context_lttng)
116+
target_link_libraries(test_context_lttng ${LTTNG_CTL_LIBRARIES})
117+
target_include_directories(test_context_lttng PRIVATE
118+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
119+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
120+
)
121+
endif()
122+
123+
ament_add_gtest(test_context_perf test/test_context_perf.cpp src/lttngpy/context_perf.cpp)
124+
if(TARGET test_context_perf)
125+
target_link_libraries(test_context_perf ${LTTNG_CTL_LIBRARIES})
126+
target_include_directories(test_context_perf PRIVATE
127+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
128+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
129+
)
130+
endif()
131+
132+
set(_lttngpy_pytest_tests
133+
test/test_constants.py
134+
test/test_session.py
135+
)
136+
137+
foreach(_test_path ${_lttngpy_pytest_tests})
138+
get_filename_component(_test_name ${_test_path} NAME_WE)
139+
ament_add_pytest_test(${_test_name} ${_test_path}
140+
APPEND_ENV AMENT_PREFIX_PATH=${ament_index_build_path}
141+
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
142+
TIMEOUT 120
143+
WERROR ON
144+
)
145+
endforeach()
146+
endif()
147+
endif()
148+
149+
ament_package()

Diff for: lttngpy/lttngpy/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 Apex.AI, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .impl import impl
16+
17+
18+
__all__ = [
19+
'impl',
20+
]

Diff for: lttngpy/lttngpy/impl.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2023 Apex.AI, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from rpyutils import import_c_library
16+
17+
18+
impl = import_c_library('._lttngpy_pybind11', 'lttngpy')

Diff for: lttngpy/package.xml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>lttngpy</name>
5+
<version>7.1.0</version>
6+
<description>liblttng-ctl Python bindings</description>
7+
<maintainer email="[email protected]">Christophe Bedard</maintainer>
8+
<license>Apache License 2.0</license>
9+
<url type="website">https://index.ros.org/p/lttngpy/</url>
10+
<url type="repository">https://github.com/ros2/ros2_tracing</url>
11+
<url type="bugtracker">https://github.com/ros2/ros2_tracing/issues</url>
12+
<author email="[email protected]">Christophe Bedard</author>
13+
14+
<buildtool_depend>ament_cmake</buildtool_depend>
15+
<buildtool_depend>python_cmake_module</buildtool_depend>
16+
17+
<depend>liblttng-ctl-dev</depend>
18+
19+
<build_depend>pybind11_vendor</build_depend>
20+
21+
<exec_depend>rpyutils</exec_depend>
22+
23+
<test_depend>ament_cmake_gtest</test_depend>
24+
<test_depend>ament_cmake_pytest</test_depend>
25+
<test_depend>ament_lint_auto</test_depend>
26+
<test_depend>ament_lint_common</test_depend>
27+
28+
<export>
29+
<build_type>ament_cmake</build_type>
30+
</export>
31+
</package>

0 commit comments

Comments
 (0)