Skip to content

Commit

Permalink
Add lttngpy
Browse files Browse the repository at this point in the history
Signed-off-by: Christophe Bedard <[email protected]>
  • Loading branch information
christophebedard committed Oct 26, 2023
1 parent 0041e07 commit 4bc0ecd
Show file tree
Hide file tree
Showing 30 changed files with 2,177 additions and 0 deletions.
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
2 changes: 2 additions & 0 deletions lttngpy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.pyc
129 changes: 129 additions & 0 deletions lttngpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
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})
else()
set(LTTNG_CTL_VERSION "")
endif()

# Store configuration variable for buildtime use
# LTTNGPY_DISABLED
# LTTNG_CTL_VERSION
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 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 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 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

0 comments on commit 4bc0ecd

Please sign in to comment.