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

Add initial skeleton for LTTng tracing in navigation2 #2788

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions nav2_tracetools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc_output/
.DS_Store
8 changes: 8 additions & 0 deletions nav2_tracetools/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package nav2_tracetools
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0.1.0 (2021-12-22)
------------------
* Fork tracetools and shape it as nav2_tracetools to avoid external
dependencies.
153 changes: 153 additions & 0 deletions nav2_tracetools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
cmake_minimum_required(VERSION 3.5)
project(nav2_tracetools)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4)
endif()

find_package(ament_cmake_ros REQUIRED)

if(WIN32)
set(DISABLED_DEFAULT ON)
else()
set(DISABLED_DEFAULT OFF)
endif()
option(TRACETOOLS_DISABLED "Explicitly disable support for tracing" ${DISABLED_DEFAULT})
option(TRACETOOLS_NO_RDYNAMIC "Disable export of -rdynamic link flag" OFF)
option(TRACETOOLS_STATUS_CHECKING_TOOL "Enable the status checking tool" ON)

if(NOT TRACETOOLS_DISABLED)
# Set TRACETOOLS_LTTNG_ENABLED if we can find lttng-ust
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(LTTNG lttng-ust)
if(LTTNG_FOUND)
set(TRACETOOLS_LTTNG_ENABLED TRUE)
message("LTTng found: tracing enabled")
endif()
endif()
endif()

# Store configuration variables for runtime use
# TRACETOOLS_DISABLED
# TRACETOOLS_LTTNG_ENABLED
configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h)

# nav2_tracetools lib
set(SOURCES
src/tracetools.c
src/utils.cpp
)
set(HEADERS
include/${PROJECT_NAME}/tracetools.h
include/${PROJECT_NAME}/utils.hpp
include/${PROJECT_NAME}/visibility_control.hpp
)
if(TRACETOOLS_LTTNG_ENABLED)
# We only need these if we're using LTTng
list(APPEND SOURCES
src/tp_call.c
)
list(APPEND HEADERS
include/${PROJECT_NAME}/tp_call.h
)
endif()

# Copy select headers to the actual include/ directory that we will use and export
foreach(_header ${HEADERS})
configure_file(
${PROJECT_SOURCE_DIR}/${_header}
${PROJECT_BINARY_DIR}/${_header}
COPYONLY
)
endforeach()

add_library(${PROJECT_NAME} ${SOURCES})
if(TRACETOOLS_LTTNG_ENABLED)
target_link_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
# Export -rdynamic for downtream packages to use when calling
# ament_target_dependencies()
# which is needed to resolve function addresses to symbols when
# using function pointers directly/without std::bind()
# (the flag should not be used on Windows, but TRACETOOLS_LTTNG_ENABLED
# should never be true on Windows anyway, so there is no need to check)
if(NOT TRACETOOLS_NO_RDYNAMIC)
target_link_libraries(${PROJECT_NAME} "-rdynamic")
endif()
endif()
if(WIN32)
# Causes the visibility macros to use dllexport rather than dllimport
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "TRACETOOLS_BUILDING_DLL")
endif()

# Only use output/binary include directory
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
ament_export_targets(${PROJECT_NAME}_export HAS_LIBRARY_TARGET)

if(TRACETOOLS_STATUS_CHECKING_TOOL)
# Status checking tool
add_executable(status
src/status.c
)
target_link_libraries(status
${PROJECT_NAME}
)
install(TARGETS
status
DESTINATION lib/${PROJECT_NAME}
)
endif()

install(
DIRECTORY ${PROJECT_BINARY_DIR}/include/
DESTINATION include
)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_export
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_export_include_directories(include)
if(TRACETOOLS_LTTNG_ENABLED)
ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
# Export -rdynamic for downstream packages using classic CMake variables
if(NOT TRACETOOLS_NO_RDYNAMIC)
ament_export_link_flags("-rdynamic")
endif()
else()
ament_export_libraries(${PROJECT_NAME})
endif()

if(BUILD_TESTING)
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${LTTNG_INCLUDE_DIRS})
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

if(TRACETOOLS_STATUS_CHECKING_TOOL)
# Run status tool executable as test and set pass/fail expectation appropriately
add_test(test_status_tool status)
if(NOT TRACETOOLS_LTTNG_ENABLED)
set_tests_properties(test_status_tool PROPERTIES WILL_FAIL TRUE)
endif()
endif()

endif()

ament_package()

target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_VERSION="${${PROJECT_NAME}_VERSION}")
32 changes: 32 additions & 0 deletions nav2_tracetools/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# All settings not listed here will use the Doxygen default values.

PROJECT_NAME = "nav2_tracetools"
PROJECT_NUMBER = master
PROJECT_BRIEF = "LTTng tracing provider wrapper for navigation2 ROS 2 meta-package."

INPUT = ./include

RECURSIVE = YES
OUTPUT_DIRECTORY = doc_output

EXTRACT_ALL = YES
SORT_MEMBER_DOCS = NO

GENERATE_LATEX = NO

ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
PREDEFINED = \
"TRACETOOLS_PUBLIC="

EXCLUDE_SYMBOLS = \
"DECLARE_TRACEPOINT" \
"_demangle_symbol" \
"_get_symbol_funcptr"

# Tag files that do not exist will produce a warning and cross-project linking will not work.
TAGFILES += "../../../../../doxygen_tag_files/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/"
# Uncomment to generate tag files for cross-project linking.
# (path relative to workspace dir: doxygen_tag_files/$PACKAGE_NAME.tag)
#GENERATE_TAGFILE = "../../../../../doxygen_tag_files/tracetools.tag"
7 changes: 7 additions & 0 deletions nav2_tracetools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# nav2_tracetools

LTTng tracing provider wrapper for navigation2 ROS 2 meta-package. `nav2_tracetools` is a fork of [tracetools](https://gitlab.com/ros-tracing/ros2_tracing/-/tree/master/tracetools), refer to this package for the original work.

### Quality Declaration

No quality is claimed according to [REP-2004](https://www.ros.org/reps/rep-2004.html).
22 changes: 22 additions & 0 deletions nav2_tracetools/include/nav2_tracetools/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 Víctor Mayoral-Vilches
// 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.

#ifndef NAV2_TRACETOOLS__CONFIG_H_
#define NAV2_TRACETOOLS__CONFIG_H_

#cmakedefine TRACETOOLS_DISABLED
#cmakedefine TRACETOOLS_LTTNG_ENABLED

#endif // NAV2_TRACETOOLS__CONFIG_H_
40 changes: 40 additions & 0 deletions nav2_tracetools/include/nav2_tracetools/tp_call.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2021 Víctor Mayoral-Vilches
//
// 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.

// Provide fake header guard for cpplint
#undef NAV2_TRACETOOLS__TP_CALL_H_
#ifndef NAV2_TRACETOOLS__TP_CALL_H_
#define NAV2_TRACETOOLS__TP_CALL_H_

#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER ros2_navigation2

#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "nav2_tracetools/tp_call.h"

#if !defined(_NAV2_TRACETOOLS__TP_CALL_H_) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define _NAV2_TRACETOOLS__TP_CALL_H_

#include <lttng/tracepoint.h>

#include <stdint.h>
#include <stdbool.h>

// Add tracepoints

#endif // _NAV2_TRACETOOLS__TP_CALL_H_

#include <lttng/tracepoint-event.h>

#endif // NAV2_TRACETOOLS__TP_CALL_H_
68 changes: 68 additions & 0 deletions nav2_tracetools/include/nav2_tracetools/tracetools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2021 Víctor Mayoral-Vilches
//
// 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.


/** \mainpage nav2_tracetools: tracing tools and instrumentation for
* for image_pipeline ROS 2 meta-package.
*
* `nav2_tracetools` provides utilities to instrument ROS image_pipeline.
* It provides two main headers:
*
* - tracetools/tracetools.h
* - instrumentation functions
* - tracetools/utils.hpp
* - utility functions
*/

#ifndef NAV2_TRACETOOLS__TRACETOOLS_H_
#define NAV2_TRACETOOLS__TRACETOOLS_H_

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "nav2_tracetools/config.h"
#include "nav2_tracetools/visibility_control.hpp"

#ifndef TRACETOOLS_DISABLED
/// Call a tracepoint.
/**
* This is the preferred method over calling the actual function directly.
*/
# define TRACEPOINT(event_name, ...) \
(ros_trace_ ## event_name)(__VA_ARGS__)
# define DECLARE_TRACEPOINT(event_name, ...) \
TRACETOOLS_PUBLIC void ros_trace_ ## event_name(__VA_ARGS__);
#else
# define TRACEPOINT(event_name, ...) ((void) (0))
# define DECLARE_TRACEPOINT(event_name, ...)
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/// Get tracing compilation status.
/**
* \return `true` if tracing is enabled, `false` otherwise
*/
TRACETOOLS_PUBLIC bool ros_trace_compile_status();

// Add tracepoints

#ifdef __cplusplus
}
#endif

#endif // NAV2_TRACETOOLS__TRACETOOLS_H_
Loading