Skip to content

Commit

Permalink
add tracepoints with LTTng
Browse files Browse the repository at this point in the history
  • Loading branch information
cwecht authored and kalle committed Feb 22, 2023
1 parent 1252ed8 commit 3facbce
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 5 deletions.
29 changes: 28 additions & 1 deletion rmw_connextdds_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ project(rmw_connextdds_common)

find_package(ament_cmake REQUIRED)

option(CONNEXT_ENABLE_TRACING "Enable building with static tracepoints with LTTng." OFF)
if(CONNEXT_ENABLE_TRACING AND CMAKE_SYSTEM_NAME MATCHES Linux)
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(LTTNG lttng-ust)
if(LTTNG_FOUND)
message(STATUS "Building with LTTng instrumentation support")
set(DDS_HAS_LTTNG_TRACING "1")
else()
message(FATAL_ERROR "CONNEXT_ENABLE_TRACING requires lttng-ust")
endif()
endif()
endif()


################################################################################
# rtirmw_add_library(
# NAME <library name>
Expand Down Expand Up @@ -59,6 +74,10 @@ function(rtirmw_add_library)
${_rti_build_LIBRARIES}
fastcdr)

if (DDS_HAS_LTTNG_TRACING)
target_link_libraries(${_rti_build_NAME} ${LTTNG_LIBRARIES})
endif()

ament_target_dependencies(${_rti_build_NAME}
${_rti_build_DEPS})

Expand Down Expand Up @@ -87,7 +106,11 @@ function(rtirmw_add_library)
CACHE INTERNAL "")
endif()

target_compile_definitions(${_rti_build_NAME} PRIVATE ${private_defines})
target_compile_definitions(${_rti_build_NAME}
PRIVATE
${private_defines}
DDS_HAS_LTTNG_TRACING=${DDS_HAS_LTTNG_TRACING}
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
Expand All @@ -111,6 +134,7 @@ set(RMW_CONNEXT_DEPS
rcpputils
rmw
rmw_dds_common
tracetools
fastcdr
rosidl_runtime_c
rosidl_runtime_cpp
Expand All @@ -127,6 +151,7 @@ endforeach()
################################################################################
# Common Source Configuration
################################################################################

set(RMW_CONNEXT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(RMW_CONNEXT_COMMON_SOURCE_CPP
Expand All @@ -148,6 +173,7 @@ set(RMW_CONNEXT_COMMON_SOURCE_CPP
src/common/rmw_subscription.cpp
src/common/rmw_waitset.cpp
src/common/rmw_type_support.cpp
$<$<BOOL:${CONNEXT_ENABLE_TRACING}>:src/common/tracing_lttng.c>
src/common/demangle.cpp)

set(RMW_CONNEXT_COMMON_SOURCE_HPP
Expand All @@ -171,6 +197,7 @@ set(RMW_CONNEXT_COMMON_SOURCE
${RMW_CONNEXT_COMMON_SOURCE_CPP}
${RMW_CONNEXT_COMMON_SOURCE_HPP})


################################################################################
# Check if additional Connext components are needed (e.g. security)
################################################################################
Expand Down
115 changes: 115 additions & 0 deletions rmw_connextdds_common/include/rmw_connextdds/tracing_lttng.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright(c) 2021 Christophe Bedard
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

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

#ifndef DDS_HAS_LTTNG_TRACING

#define TRACEPOINT_DDS(event_name, ...) ((void) (0))

#else // DDS_HAS_LTTNG_TRACING

#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER dds

#define TRACEPOINT_DDS(event_name, ...) \
tracepoint(TRACEPOINT_PROVIDER, event_name, __VA_ARGS__)

#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "rmw_connextdds/tracing_lttng.h"

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

#include <lttng/tracepoint.h>

#ifndef LTTNG_UST_HAVE_SDT_INTEGRATION
# ifdef _MSC_VER
# pragma message ("lttng-ust has not been configured & built with SDT integration (--with-sdt)")
# else
# warning lttng-ust has not been configured & built with SDT integration (--with-sdt)
# endif
#endif

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

#define DDS_GID_STORAGE_SIZE 16u

TRACEPOINT_EVENT(
TRACEPOINT_PROVIDER,
create_writer,
TP_ARGS(
const void *, writer_arg,
const char *, topic_name_arg,
const uint8_t *, gid_arg
),
TP_FIELDS(
ctf_integer_hex(const void *, writer, writer_arg)
ctf_string(topic_name, topic_name_arg)
ctf_array(uint8_t, gid, gid_arg, DDS_GID_STORAGE_SIZE)
)
)

TRACEPOINT_EVENT(
TRACEPOINT_PROVIDER,
create_reader,
TP_ARGS(
const void *, reader_arg,
const char *, topic_name_arg,
const uint8_t *, gid_arg
),
TP_FIELDS(
ctf_integer_hex(const void *, reader, reader_arg)
ctf_string(topic_name, topic_name_arg)
ctf_array(uint8_t, gid, gid_arg, DDS_GID_STORAGE_SIZE)
)
)

TRACEPOINT_EVENT(
TRACEPOINT_PROVIDER,
write,
TP_ARGS(
const void *, writer_arg,
const void *, data_arg,
int64_t, timestamp_arg
),
TP_FIELDS(
ctf_integer_hex(const void *, writer, writer_arg)
ctf_integer_hex(const void *, data, data_arg)
ctf_integer(int64_t, timestamp, timestamp_arg)
)
)

TRACEPOINT_EVENT(
TRACEPOINT_PROVIDER,
read,
TP_ARGS(
const void *, reader_arg,
const void *, buffer_arg
),
TP_FIELDS(
ctf_integer_hex(const void *, reader, reader_arg)
ctf_integer_hex(const void *, buffer, buffer_arg)
)
)

#endif // __DDS_LTTNG_H_

#include <lttng/tracepoint-event.h>

#endif // DDS_HAS_LTTNG_TRACING

#endif // _DDS_LTTNG_H_
1 change: 1 addition & 0 deletions rmw_connextdds_common/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<depend>rosidl_typesupport_fastrtps_cpp</depend>
<depend>rosidl_typesupport_introspection_c</depend>
<depend>rosidl_typesupport_introspection_cpp</depend>
<depend>tracetools</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
20 changes: 20 additions & 0 deletions rmw_connextdds_common/src/common/rmw_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
#include <vector>
#include <stdexcept>

#include "tracetools/tracetools.h"

#include "rmw_dds_common/time_utils.hpp"

#include "rmw_connextdds/graph_cache.hpp"

#include "rmw_connextdds/tracing_lttng.h"

#define ROS_SERVICE_REQUESTER_PREFIX_STR "rq"
#define ROS_SERVICE_RESPONSE_PREFIX_STR "rr"

Expand Down Expand Up @@ -811,6 +815,8 @@ RMW_Connext_Publisher::create(
scope_exit_topic_delete.cancel();
scope_exit_dds_writer_delete.cancel();

TRACEPOINT_DDS(create_writer, dds_writer, topic_name, rmw_pub_impl->gid()->data);

return rmw_pub_impl;
}

Expand Down Expand Up @@ -1090,6 +1096,10 @@ rmw_connextdds_create_publisher(
}
}

TRACEPOINT(
rmw_publisher_init,
static_cast<const void *>(rmw_publisher),
rmw_pub_impl->gid()->data);

scope_exit_rmw_writer_impl_delete.cancel();
scope_exit_rmw_writer_delete.cancel();
Expand Down Expand Up @@ -1375,10 +1385,13 @@ RMW_Connext_Subscriber::create(
RMW_CONNEXT_LOG_ERROR_SET("failed to allocate RMW subscriber")
return nullptr;
}

scope_exit_dds_reader_delete.cancel();
scope_exit_topic_delete.cancel();
scope_exit_type_unregister.cancel();

TRACEPOINT_DDS(create_reader, dds_reader, topic_name, rmw_sub_impl->gid()->data);

return rmw_sub_impl;
}

Expand Down Expand Up @@ -1776,6 +1789,8 @@ RMW_Connext_Subscriber::take_next(
rmw_connextdds_message_info_from_dds(message_info, info);
}

TRACEPOINT_DDS(read, this->reader(), ros_message);

*taken += 1;
continue;
}
Expand Down Expand Up @@ -1906,6 +1921,11 @@ rmw_connextdds_create_subscriber(
}
}

TRACEPOINT(
rmw_subscription_init,
static_cast<const void *>(rmw_subscriber),
rmw_sub_impl->gid()->data);

#if RMW_CONNEXT_DEBUG && RMW_CONNEXT_DDS_API == RMW_CONNEXT_DDS_API_PRO
scope_exit_enable_participant_on_error.cancel();
#endif // RMW_CONNEXT_DEBUG && RMW_CONNEXT_DDS_API == RMW_CONNEXT_DDS_API_PRO
Expand Down
4 changes: 4 additions & 0 deletions rmw_connextdds_common/src/common/rmw_publication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "rmw/validate_full_topic_name.h"

#include "tracetools/tracetools.h"

/******************************************************************************
* Publication functions
******************************************************************************/
Expand Down Expand Up @@ -45,6 +47,8 @@ rmw_api_connextdds_publish(
auto pub_impl = static_cast<RMW_Connext_Publisher *>(publisher->data);
RMW_CHECK_ARGUMENT_FOR_NULL(pub_impl, RMW_RET_INVALID_ARGUMENT);

TRACEPOINT(rmw_publish, ros_message);

return pub_impl->write(ros_message, false /* serialized */);
}

Expand Down
15 changes: 15 additions & 0 deletions rmw_connextdds_common/src/common/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "rmw/validate_full_topic_name.h"

#include "tracetools/tracetools.h"

/******************************************************************************
* Subscription functions
******************************************************************************/
Expand Down Expand Up @@ -272,6 +274,12 @@ rmw_api_connextdds_take(

rmw_ret_t rc = sub_impl->take_message(ros_message, nullptr, taken);

TRACEPOINT(
rmw_take,
static_cast<const void *>(subscription),
static_cast<const void *>(ros_message),
0LL,
*taken);
return rc;
}

Expand Down Expand Up @@ -301,6 +309,13 @@ rmw_api_connextdds_take_with_info(

rmw_ret_t rc = sub_impl->take_message(ros_message, message_info, taken);

TRACEPOINT(
rmw_take,
static_cast<const void *>(subscription),
static_cast<const void *>(ros_message),
(message_info ? message_info->source_timestamp : 0LL),
*taken);

return rc;
}

Expand Down
16 changes: 16 additions & 0 deletions rmw_connextdds_common/src/common/tracing_lttng.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright(c) 2021 Christophe Bedard
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

#define TRACEPOINT_CREATE_PROBES

#define TRACEPOINT_DEFINE
#include "rmw_connextdds/tracing_lttng.h"
Loading

0 comments on commit 3facbce

Please sign in to comment.