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: add ignore processes filter #273

Merged
merged 6 commits into from
Mar 22, 2024
Merged
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
7 changes: 7 additions & 0 deletions CARET_trace/include/caret_trace/tracing_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class TracingController
/// @return True if the buffer is enabled, false otherwise.
bool is_allowed_buffer(const void * buffer);

/// @brief Check if current process is allowed to output trace events
/// @return True if the process is enabled, false otherwise.
bool is_allowed_process();

private:
void debug(std::string message) const;
void info(std::string message) const;
Expand All @@ -132,10 +136,13 @@ class TracingController
const std::unordered_set<std::string> ignored_node_names_;
const std::unordered_set<std::string> selected_topic_names_;
const std::unordered_set<std::string> ignored_topic_names_;
const std::unordered_set<std::string> ignored_process_names_;

const bool select_enabled_;
const bool ignore_enabled_;

bool is_ignored_process_;

const bool use_log_; // for test

std::unordered_map<const void *, const void *> subscription_handle_to_node_handles_;
Expand Down
67 changes: 59 additions & 8 deletions CARET_trace/src/hooked_trace_points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,19 @@
"Could not load library %s: %s", library_name.c_str(), e.what());
}

static auto record = [](const char * rmw_implementation, int64_t init_time) {
tracepoint(TRACEPOINT_PROVIDER, rmw_implementation, rmw_implementation, init_time);
};
if (context.get_controller().is_allowed_process()) {
static auto record = [](const char * rmw_implementation, int64_t init_time) {
tracepoint(TRACEPOINT_PROVIDER, rmw_implementation, rmw_implementation, init_time);
};

if (!data_container.is_assigned_rmw_implementation()) {
data_container.assign_rmw_implementation(record);
}
if (!data_container.is_assigned_rmw_implementation()) {
data_container.assign_rmw_implementation(record);
}

data_container.store_rmw_implementation(env_var.c_str(), now);
data_container.store_rmw_implementation(env_var.c_str(), now);

record(env_var.c_str(), now);
record(env_var.c_str(), now);
}

if (env_var == "rmw_fastrtps_cpp") {
// clang-format off
Expand Down Expand Up @@ -229,6 +231,10 @@
}
int dds_return = ((functionT)CYCLONEDDS::DDS_WRITE_IMPL)(wr, data, tstamp, action);

if (!context.get_controller().is_allowed_process()) {
return dds_return;
}

if (context.is_recording_allowed() && trace_filter_is_rcl_publish_recorded) {
tracepoint(TRACEPOINT_PROVIDER, dds_bind_addr_to_stamp, data, tstamp);
#ifdef DEBUG_OUTPUT
Expand All @@ -252,6 +258,10 @@
}
int dds_return = ((functionT)CYCLONEDDS::DDS_WRITECDR_IMPL)(wr, xp, dinp, flush);

if (!context.get_controller().is_allowed_process()) {
return dds_return;
}

if (context.is_recording_allowed()) {
tracepoint(
TRACEPOINT_PROVIDER, dds_bind_addr_to_stamp, serialized_message_addr, dinp->timestamp.v);
Expand All @@ -274,6 +284,11 @@
update_dds_function_addr();
}
((functionT)FASTDDS::SET_FRAGMENTS)(obj, change);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (context.is_recording_allowed()) {
tracepoint(
TRACEPOINT_PROVIDER, dds_bind_addr_to_stamp, nullptr, change->sourceTimestamp.to_ns());
Expand All @@ -297,7 +312,7 @@
}

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

Check warning on line 315 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 All @@ -315,6 +330,10 @@
using functionT = void (*)(void *, const void *);
((functionT)orig_func)(obj, option);

if (!context.get_controller().is_allowed_process()) {
return;
}

const std::string executor_type_name = "single_threaded_executor";

if (!data_container.is_assigned_construct_executor()) {
Expand All @@ -330,7 +349,7 @@
// std::chrono::duration<long, std::ratio<1l, 1000000000l> >)
void SYMBOL_CONCAT_2(
_ZN6rclcpp9executors21MultiThreadedExecutor,
C1ERKNS_15ExecutorOptionsEmbNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE)(

Check warning on line 352 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 All @@ -351,6 +370,10 @@
using functionT = void (*)(void *, const void *, size_t, bool, const void *);
((functionT)orig_func)(obj, option, number_of_thread, yield_before_execute, timeout);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_construct_executor()) {
data_container.assign_construct_executor(record);
}
Expand All @@ -361,7 +384,7 @@

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

Check warning on line 387 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 All @@ -386,6 +409,10 @@
using functionT = void (*)(void *, const void *);
((functionT)orig_func)(obj, option);

if (!context.get_controller().is_allowed_process()) {
return;
}

using StaticSingleThreadedExecutorPublic = rclcpp::executors::StaticSingleThreadedExecutorPublic;
auto exec_ptr = reinterpret_cast<StaticSingleThreadedExecutorPublic *>(obj);

Expand Down Expand Up @@ -437,6 +464,10 @@

((functionT)orig_func)(obj, group_ptr, node_ptr, weak_groups_to_nodes, notify);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_add_callback_group()) {
data_container.assign_add_callback_group(record);
}
Expand Down Expand Up @@ -465,7 +496,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 499 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 Expand Up @@ -501,6 +532,10 @@

auto ret = ((functionT)orig_func)(obj, group_ptr, node_ptr, weak_groups_to_nodes);

if (!context.get_controller().is_allowed_process()) {
return ret;
}

if (!data_container.is_assigned_add_callback_group_static_executor()) {
data_container.assign_add_callback_group_static_executor(record);
}
Expand Down Expand Up @@ -534,6 +569,10 @@
auto timer_handle = static_cast<const void *>(timer_ptr->get_timer_handle().get());
((functionT)orig_func)(obj, timer_ptr);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_callback_group_add_timer()) {
data_container.assign_callback_group_add_timer(record);
}
Expand Down Expand Up @@ -566,6 +605,10 @@
static_cast<const void *>(subscription_ptr->get_subscription_handle().get());
((functionT)orig_func)(obj, subscription_ptr);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_callback_group_add_subscription()) {
data_container.assign_callback_group_add_subscription(record);
}
Expand Down Expand Up @@ -595,6 +638,10 @@
auto service_handle = static_cast<const void *>(service_ptr->get_service_handle().get());
((functionT)orig_func)(obj, service_ptr);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_callback_group_add_service()) {
data_container.assign_callback_group_add_service(record);
}
Expand Down Expand Up @@ -624,6 +671,10 @@
auto client_handle = static_cast<const void *>(client_ptr->get_client_handle().get());
((functionT)orig_func)(obj, client_ptr);

if (!context.get_controller().is_allowed_process()) {
return;
}

if (!data_container.is_assigned_callback_group_add_client()) {
data_container.assign_callback_group_add_client(record);
}
Expand Down
Loading
Loading