Skip to content

Commit

Permalink
Add read/write instrumentation with LTTng
Browse files Browse the repository at this point in the history
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
  • Loading branch information
christophebedard committed Aug 2, 2021
1 parent f879dc0 commit d1073ae
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/core/ddsc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/dds/"
dds.h
ddsc/dds_public_error.h
Expand Down Expand Up @@ -115,6 +123,10 @@ target_include_directories(ddsc
INTERFACE
$<INSTALL_INTERFACE:include>)

if (DDS_HAS_LTTNG_TRACING)
target_link_libraries(ddsc PRIVATE ${LTTNG_LIBRARIES} "-rdynamic")
endif()

install(
DIRECTORY
"${CMAKE_CURRENT_LIST_DIR}/include/"
Expand Down
2 changes: 2 additions & 0 deletions src/core/ddsc/src/dds_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/core/ddsc/src/dds_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/ddsc/src/dds_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/ddsc/src/dds_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/core/ddsc/src/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 "tracing_lttng.h"
113 changes: 113 additions & 0 deletions src/core/ddsc/src/tracing_lttng.h
Original file line number Diff line number Diff line change
@@ -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 <lttng/tracepoint.h>

#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 <stdint.h>
#include <stdbool.h>

#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 <lttng/tracepoint-event.h>

#endif // _DDS_LTTNG_H_
3 changes: 3 additions & 0 deletions src/features.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d1073ae

Please sign in to comment.