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

feat(hooked_trace_point.cpp): add tracepoint to cyclonedds for serialized_publish #228

Merged
merged 7 commits into from
Nov 14, 2023
Merged
Changes from 5 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
44 changes: 43 additions & 1 deletion CARET_trace/src/hooked_trace_points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

// #define DEBUG_OUTPUT

#include "dds/ddsi/ddsi_serdata.h"
#include "fastdds/rtps/common/CacheChange.h"

#define STRINGIFY_(s) #s
Expand All @@ -48,15 +49,18 @@
#define SYMBOL_CONCAT_2(x, y) x##y
#define SYMBOL_CONCAT_3(x, y, z) x##y##z

thread_local const void * serialized_message_addr;
ymski marked this conversation as resolved.
Show resolved Hide resolved
extern thread_local bool trace_filter_is_rcl_publish_recorded;

// Declare a prototype in order to use the functions implemented in cyclonedds.
rmw_ret_t rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid);

// cspell: ignore WRITECDR
namespace CYCLONEDDS
{
void * DDS_WRITE_IMPL;
}
void * DDS_WRITECDR_IMPL;
} // namespace CYCLONEDDS

// For FastDDS
namespace FASTDDS
Expand Down Expand Up @@ -206,6 +210,7 @@
// clang-format on
} else if (env_var == "rmw_cyclonedds_cpp") {
CYCLONEDDS::DDS_WRITE_IMPL = lib->get_symbol("dds_write_impl");
CYCLONEDDS::DDS_WRITECDR_IMPL = lib->get_symbol("dds_writecdr_impl");
}
}

Expand Down Expand Up @@ -233,6 +238,30 @@
return dds_return;
}

// for cyclonedds
// bind : &ros_message -> source_timestamp
// cspell: ignore ddsi, serdata, dinp
int dds_writecdr_impl(void * wr, void * xp, struct ddsi_serdata * dinp, bool flush) // NOLINT
isp-uetsuki marked this conversation as resolved.
Show resolved Hide resolved
{
static auto & context = Singleton<Context>::get_instance();
using functionT = int (*)(void *, void *, struct ddsi_serdata *, bool); // NOLINT

// clang-format on
if (CYCLONEDDS::DDS_WRITECDR_IMPL == nullptr) {
update_dds_function_addr();
}
int dds_return = ((functionT)CYCLONEDDS::DDS_WRITECDR_IMPL)(wr, xp, dinp, flush);

if (context.is_recording_allowed()) {
tracepoint(
TRACEPOINT_PROVIDER, dds_bind_addr_to_stamp, serialized_message_addr, dinp->timestamp.v);
#ifdef DEBUG_OUTPUT
std::cerr << "dds_bind_addr_to_stamp," << data << "," << tstamp << std::endl;
#endif
}
return dds_return;
}

// for fastdds
// bind : &ros_message -> source_timestamp
void _ZN8eprosima8fastrtps4rtps13WriterHistory13set_fragmentsEPNS1_13CacheChange_tE(
Expand All @@ -254,8 +283,21 @@
}
}

// for rmw_cyclonedds_cpp
// store message address in tread local memory
rmw_ret_t rmw_publish_serialized_message(
const rmw_publisher_t * publisher, const rmw_serialized_message_t * serialized_message,
rmw_publisher_allocation_t * allocation)
{
serialized_message_addr = static_cast<const void *>(serialized_message);
using functionT = int (*)(const void *, const void *, const void *);
static void * orig_func = dlsym(RTLD_NEXT, __func__);
int dds_return = ((functionT)orig_func)(publisher, serialized_message, allocation);
return dds_return;
ymski marked this conversation as resolved.
Show resolved Hide resolved
}

// rclcpp::executors::SingleThreadedExecutor::SingleThreadedExecutor(rclcpp::ExecutorOptions const&)
void _ZN6rclcpp9executors22SingleThreadedExecutorC1ERKNS_15ExecutorOptionsE(

Check warning on line 300 in CARET_trace/src/hooked_trace_points.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (ERKNS)
void * obj, const void * option)
{
static void * orig_func = dlsym(RTLD_NEXT, __func__);
Expand Down Expand Up @@ -288,7 +330,7 @@
// std::chrono::duration<long, std::ratio<1l, 1000000000l> >)
void SYMBOL_CONCAT_2(
_ZN6rclcpp9executors21MultiThreadedExecutor,
C1ERKNS_15ExecutorOptionsEmbNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE)(

Check warning on line 333 in CARET_trace/src/hooked_trace_points.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (ERKNS)
void * obj, const void * option, size_t number_of_thread, bool yield_before_execute,
const void * timeout)
{
Expand Down Expand Up @@ -319,7 +361,7 @@

// rclcpp::executors::StaticSingleThreadedExecutor::StaticSingleThreadedExecutor(
// rclcpp::ExecutorOptions const&)
void _ZN6rclcpp9executors28StaticSingleThreadedExecutorC1ERKNS_15ExecutorOptionsE(

Check warning on line 364 in CARET_trace/src/hooked_trace_points.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (ERKNS)
void * obj, const void * option)
{
static void * orig_func = dlsym(RTLD_NEXT, __func__);
Expand Down Expand Up @@ -423,7 +465,7 @@
bool SYMBOL_CONCAT_3(
_ZN6rclcpp9executors31StaticExecutorEntitiesCollector18add_callback_groupESt10shared_ptr,
INS_13CallbackGroupEES2_INS_15node_interfaces17NodeBaseInterface,
EERSt3mapISt8weak_ptrIS3_ES9_IS6_ESt10owner_lessISA_ESaISt4pairIKSA_SB_EEE)(

Check warning on line 468 in CARET_trace/src/hooked_trace_points.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (IKSA)
void * obj, rclcpp::CallbackGroup::SharedPtr group_ptr,
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
Expand Down
Loading