Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to custom lttng-ctl Python bindings #81

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
- uses: ros-tooling/action-ros-ci@master
with:
package-name: >
lttngpy
ros2trace
test_ros2trace
test_tracetools
Expand Down
9 changes: 7 additions & 2 deletions LTTng_QUALITY_DECLARATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,21 @@ Features are listed and well documented on the [LTTng website](https://lttng.org
LTTng packages have embedded API documentation.
It can be viewed on their man pages:

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

### License [3.iii]

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

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

### Copyright Statement [3.iv]

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ The LTTng kernel tracer has a similar implementation, but is separate from the u

## Packages

### lttngpy

Package containing `liblttng-ctl` Python bindings.

### ros2trace

Package containing a `ros2cli` extension to enable tracing.
Expand Down Expand Up @@ -246,6 +250,10 @@ Package containing tools for tracing-related tests.

Package containing tools to enable tracing.

### test_ros2trace

Package containing system tests for `ros2trace`.

### test_tracetools

Package containing unit and system tests for `tracetools`.
Expand Down
2 changes: 2 additions & 0 deletions lttngpy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.pyc
149 changes: 149 additions & 0 deletions lttngpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
cmake_minimum_required(VERSION 3.12)

project(lttngpy)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)

if(WIN32 OR APPLE OR ANDROID)
set(DISABLED_DEFAULT ON)
else()
set(DISABLED_DEFAULT OFF)
endif()
option(
LTTNGPY_DISABLED
"Explicitly disable support, don't link against liblttng-ctl"
${DISABLED_DEFAULT})

# Find python before pybind11
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)

find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)

if(NOT LTTNGPY_DISABLED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LTTNG_CTL REQUIRED lttng-ctl)
set(LTTNG_CTL_VERSION ${LTTNG_CTL_VERSION})

string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" dummy "${LTTNG_CTL_VERSION}")
set(LTTNG_CTL_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(LTTNG_CTL_VERSION_MINOR "${CMAKE_MATCH_2}")
set(LTTNG_CTL_VERSION_PATCH "${CMAKE_MATCH_3}")
else()
set(LTTNG_CTL_VERSION "")
set(LTTNG_CTL_VERSION_MAJOR "0")
set(LTTNG_CTL_VERSION_MINOR "0")
set(LTTNG_CTL_VERSION_PATCH "0")
endif()

# Store configuration variable for buildtime use
# LTTNGPY_DISABLED
# LTTNG_CTL_VERSION
# LTTNG_CTL_VERSION_MAJOR
# LTTNG_CTL_VERSION_MINOR
# LTTNG_CTL_VERSION_PATCH
configure_file(src/lttngpy/config.hpp.in src/lttngpy/config.hpp)

ament_python_install_package(${PROJECT_NAME})

set(SOURCES
src/lttngpy/_lttngpy_pybind11.cpp
src/lttngpy/status.cpp
)
if(NOT LTTNGPY_DISABLED)
list(APPEND SOURCES
src/lttngpy/channel.cpp
src/lttngpy/context_app.cpp
src/lttngpy/context_lttng.cpp
src/lttngpy/context_perf.cpp
src/lttngpy/event.cpp
src/lttngpy/lttng.cpp
src/lttngpy/session.cpp
)
endif()

pybind11_add_module(_lttngpy_pybind11 SHARED ${SOURCES})

if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
target_link_libraries(_lttngpy_pybind11 PRIVATE atomic)
endif()

target_include_directories(_lttngpy_pybind11 PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
)
if(NOT LTTNGPY_DISABLED)
target_link_libraries(_lttngpy_pybind11 PRIVATE ${LTTNG_CTL_LIBRARIES})
endif()

# Set the build location and install location for a CPython extension
install(TARGETS _lttngpy_pybind11
DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}"
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

if(NOT LTTNGPY_DISABLED)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_pytest REQUIRED)

# Using source files, because I can't seem to be able to link against _lttngpy_pybind11
ament_add_gtest(test_context_app test/test_context_app.cpp src/lttngpy/context_app.cpp)
if(TARGET test_context_app)
target_include_directories(test_context_app PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
)
endif()

ament_add_gtest(test_context_lttng test/test_context_lttng.cpp src/lttngpy/context_lttng.cpp)
if(TARGET test_context_lttng)
target_link_libraries(test_context_lttng ${LTTNG_CTL_LIBRARIES})
target_include_directories(test_context_lttng PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
)
endif()

ament_add_gtest(test_context_perf test/test_context_perf.cpp src/lttngpy/context_perf.cpp)
if(TARGET test_context_perf)
target_link_libraries(test_context_perf ${LTTNG_CTL_LIBRARIES})
target_include_directories(test_context_perf PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>"
)
endif()

set(_lttngpy_pytest_tests
test/test_constants.py
test/test_session.py
)

foreach(_test_path ${_lttngpy_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}
APPEND_ENV AMENT_PREFIX_PATH=${ament_index_build_path}
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 120
WERROR ON
)
endforeach()
endif()
endif()

ament_package()
20 changes: 20 additions & 0 deletions lttngpy/lttngpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Apex.AI, Inc.
#
# 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.

from .impl import impl


__all__ = [
'impl',
]
18 changes: 18 additions & 0 deletions lttngpy/lttngpy/impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Apex.AI, Inc.
#
# 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.

from rpyutils import import_c_library


impl = import_c_library('._lttngpy_pybind11', 'lttngpy')
31 changes: 31 additions & 0 deletions lttngpy/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>lttngpy</name>
<version>7.1.0</version>
<description>liblttng-ctl Python bindings</description>
<maintainer email="[email protected]">Christophe Bedard</maintainer>
<license>Apache License 2.0</license>
<url type="website">https://index.ros.org/p/lttngpy/</url>
<url type="repository">https://github.com/ros2/ros2_tracing</url>
<url type="bugtracker">https://github.com/ros2/ros2_tracing/issues</url>
<author email="[email protected]">Christophe Bedard</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>python_cmake_module</buildtool_depend>

<depend>liblttng-ctl-dev</depend>

<build_depend>pybind11_vendor</build_depend>

<exec_depend>rpyutils</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading
Loading