From d1073ae9005b0139936c2ddc5d6aed23428cfba5 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 25 Apr 2021 13:58:02 -0400 Subject: [PATCH] Add read/write instrumentation with LTTng Signed-off-by: Christophe Bedard --- src/CMakeLists.txt | 14 ++++ src/core/ddsc/CMakeLists.txt | 12 ++++ src/core/ddsc/src/dds_read.c | 2 + src/core/ddsc/src/dds_reader.c | 7 ++ src/core/ddsc/src/dds_write.c | 3 + src/core/ddsc/src/dds_writer.c | 7 ++ src/core/ddsc/src/tracing_lttng.c | 16 +++++ src/core/ddsc/src/tracing_lttng.h | 113 ++++++++++++++++++++++++++++++ src/features.h.in | 3 + 9 files changed, 177 insertions(+) create mode 100644 src/core/ddsc/src/tracing_lttng.c create mode 100644 src/core/ddsc/src/tracing_lttng.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c193c578bf..94b58fe959 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -111,6 +111,20 @@ if(NOT ENABLE_SECURITY) message(STATUS "Building without OMG DDS Security support") endif() +option(CYCLONE_ENABLE_TRACING "Enable building with static tracepoints with LTTng." OFF) +if(CYCLONE_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 "CYCLONE_ENABLE_TRACING requires lttng-ust") + endif() + endif() +endif() + configure_file(features.h.in "${CMAKE_CURRENT_BINARY_DIR}/core/include/dds/features.h") add_subdirectory(tools) diff --git a/src/core/ddsc/CMakeLists.txt b/src/core/ddsc/CMakeLists.txt index cb6ef0b2d9..e6090cf518 100644 --- a/src/core/ddsc/CMakeLists.txt +++ b/src/core/ddsc/CMakeLists.txt @@ -47,6 +47,10 @@ if (DDS_HAS_SHM) list(APPEND srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/shm_monitor.c") endif() +if (DDS_HAS_LTTNG_TRACING) + list(APPEND srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/tracing_lttng.c") +endif() + prepend(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/" dds__alloc.h dds__builtin.h @@ -75,6 +79,10 @@ prepend(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/" dds__get_status.h dds__data_allocator.h) +if (DDS_HAS_LTTNG_TRACING) + list(APPEND hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/tracing_lttng.h") +endif() + prepend(hdrs_public_ddsc "$$/dds/" dds.h ddsc/dds_public_error.h @@ -115,6 +123,10 @@ target_include_directories(ddsc INTERFACE $) +if (DDS_HAS_LTTNG_TRACING) + target_link_libraries(ddsc PRIVATE ${LTTNG_LIBRARIES} "-rdynamic") +endif() + install( DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/" diff --git a/src/core/ddsc/src/dds_read.c b/src/core/ddsc/src/dds_read.c index 7c5d614794..0abfd327bd 100644 --- a/src/core/ddsc/src/dds_read.c +++ b/src/core/ddsc/src/dds_read.c @@ -21,6 +21,7 @@ #include "dds/ddsi/ddsi_domaingv.h" #include "dds/ddsi/ddsi_sertype.h" #include "dds/ddsi/ddsi_sertopic.h" // for extern ddsi_sertopic_serdata_ops_wrap +#include "tracing_lttng.h" /* dds_read_impl: Core read/take function. Usually maxs is size of buf and si @@ -128,6 +129,7 @@ static dds_return_t dds_read_impl (bool take, dds_entity_t reader_or_condition, } dds_entity_unpin (entity); thread_state_asleep (ts1); + TRACEPOINT(read, (const void *)rd, (const void *)*buf); return ret; #undef NC_CLEAR_LOAN_OUT diff --git a/src/core/ddsc/src/dds_reader.c b/src/core/ddsc/src/dds_reader.c index 996317c4ea..a8c591f92c 100644 --- a/src/core/ddsc/src/dds_reader.c +++ b/src/core/ddsc/src/dds_reader.c @@ -35,6 +35,7 @@ #include "dds/ddsi/ddsi_entity_index.h" #include "dds/ddsi/ddsi_security_omg.h" #include "dds/ddsi/ddsi_statistics.h" +#include "tracing_lttng.h" #ifdef DDS_HAS_SHM #include "shm__monitor.h" @@ -645,6 +646,12 @@ static dds_entity_t dds_create_reader_int (dds_entity_t participant_or_subscribe dds_topic_allow_set_qos (tp); dds_topic_unpin (tp); dds_subscriber_unlock (sub); + +#ifdef DDS_HAS_LTTNG_TRACING + dds_guid_t guid; + (void)dds_get_guid(reader, &guid); + TRACEPOINT(create_reader, (const void *)rd, rd->m_topic->m_name, guid.v); +#endif return reader; #ifdef DDS_HAS_SECURITY diff --git a/src/core/ddsc/src/dds_write.c b/src/core/ddsc/src/dds_write.c index b2afa1373b..188d599fbf 100644 --- a/src/core/ddsc/src/dds_write.c +++ b/src/core/ddsc/src/dds_write.c @@ -26,6 +26,7 @@ #include "dds/ddsi/q_radmin.h" #include "dds/ddsi/ddsi_domaingv.h" #include "dds/ddsi/ddsi_deliver_locally.h" +#include "tracing_lttng.h" #ifdef DDS_HAS_SHM #include "dds/ddsi/shm_sync.h" @@ -333,6 +334,8 @@ dds_return_t dds_write_impl (dds_writer *wr, const void * data, dds_time_t tstam if (data == NULL) return DDS_RETCODE_BAD_PARAMETER; + TRACEPOINT(write, (const void *)wr, data, tstamp); + /* Check for topic filter */ if (!writekey && wr->m_topic->m_filter.mode != DDS_TOPIC_FILTER_NONE) { diff --git a/src/core/ddsc/src/dds_writer.c b/src/core/ddsc/src/dds_writer.c index 05c480f7cf..dbef246bf5 100644 --- a/src/core/ddsc/src/dds_writer.c +++ b/src/core/ddsc/src/dds_writer.c @@ -34,6 +34,7 @@ #include "dds__statistics.h" #include "dds__data_allocator.h" #include "dds/ddsi/ddsi_statistics.h" +#include "tracing_lttng.h" DECL_ENTITY_LOCK_UNLOCK (extern inline, dds_writer) @@ -458,6 +459,12 @@ dds_entity_t dds_create_writer (dds_entity_t participant_or_publisher, dds_entit nn_xpack_sendq_start(gv); } ddsrt_mutex_unlock (&gv->sendq_running_lock); + +#ifdef DDS_HAS_LTTNG_TRACING + dds_guid_t guid; + (void)dds_get_guid(writer, &guid); + TRACEPOINT(create_writer, (const void *)wr, wr->m_topic->m_name, guid.v); +#endif return writer; #ifdef DDS_HAS_SECURITY diff --git a/src/core/ddsc/src/tracing_lttng.c b/src/core/ddsc/src/tracing_lttng.c new file mode 100644 index 0000000000..5deca530ce --- /dev/null +++ b/src/core/ddsc/src/tracing_lttng.c @@ -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 "tracing_lttng.h" diff --git a/src/core/ddsc/src/tracing_lttng.h b/src/core/ddsc/src/tracing_lttng.h new file mode 100644 index 0000000000..dc22e8c250 --- /dev/null +++ b/src/core/ddsc/src/tracing_lttng.h @@ -0,0 +1,113 @@ +/* + * 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_ + +#include "dds/features.h" + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER dds + +#ifdef DDS_HAS_LTTNG_TRACING +# define TRACEPOINT(event_name, ...) \ + tracepoint(TRACEPOINT_PROVIDER, event_name, __VA_ARGS__) +#else +# define TRACEPOINT(event_name, ...) ((void) (0)) +#endif // DDS_HAS_LTTNG_TRACING + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "tracing_lttng.h" + +#if !defined(__DDS_LTTNG_H_) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define __DDS_LTTNG_H_ + +#include + +#if defined(DDS_HAS_LTTNG_TRACING) && !defined(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 +#include + +#define DDS_GID_STORAGE_SIZE 16u + +TRACEPOINT_EVENT( + TRACEPOINT_PROVIDER, + create_writer, + TP_ARGS( + const void *, writer_arg, + 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, + 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 + +#endif // _DDS_LTTNG_H_ diff --git a/src/features.h.in b/src/features.h.in index 0350bb05f1..532e4f8626 100644 --- a/src/features.h.in +++ b/src/features.h.in @@ -39,4 +39,7 @@ /* Whether or not support for Iceoryx support is included */ #cmakedefine DDS_HAS_SHM @DDS_HAS_SHM@ +/* Whether or not support for LTTng tracing instrumentation is included */ +#cmakedefine DDS_HAS_LTTNG_TRACING @DDS_HAS_LTTNG_TRACING@ + #endif