Skip to content

Commit

Permalink
Add ifdefs to remove tracing-related calls if tracing is disabled
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 Feb 25, 2020
1 parent 72083a1 commit 8b17de4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rclcpp/include/rclcpp/any_service_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AnyServiceCallback
TRACEPOINT(callback_end, (const void *)this);
}

#ifndef TRACETOOLS_DISABLED
void register_callback_for_tracing()
{
if (shared_ptr_callback_) {
Expand All @@ -114,6 +115,7 @@ class AnyServiceCallback
get_symbol(shared_ptr_with_request_header_callback_));
}
}
#endif // TRACETOOLS_DISABLED
};

} // namespace rclcpp
Expand Down
2 changes: 2 additions & 0 deletions rclcpp/include/rclcpp/any_subscription_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class AnySubscriptionCallback
return const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_;
}

#ifndef TRACETOOLS_DISABLED
void register_callback_for_tracing()
{
if (shared_ptr_callback_) {
Expand All @@ -256,6 +257,7 @@ class AnySubscriptionCallback
get_symbol(unique_ptr_with_info_callback_));
}
}
#endif // TRACETOOLS_DISABLED

private:
std::shared_ptr<MessageAlloc> message_allocator_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase
// The callback object gets copied, so if registration is done too early/before this point
// (e.g. in `AnySubscriptionCallback::set()`), its address won't match any address used later
// in subsequent tracepoints.
#ifndef TRACETOOLS_DISABLED
any_callback_.register_callback_for_tracing();
#endif
}

bool
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/include/rclcpp/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class Service : public ServiceBase
rclcpp_service_callback_added,
(const void *)get_service_handle().get(),
(const void *)&any_callback_);
#ifndef TRACETOOLS_DISABLED
any_callback_.register_callback_for_tracing();
#endif
}

Service(
Expand All @@ -182,7 +184,9 @@ class Service : public ServiceBase
rclcpp_service_callback_added,
(const void *)get_service_handle().get(),
(const void *)&any_callback_);
#ifndef TRACETOOLS_DISABLED
any_callback_.register_callback_for_tracing();
#endif
}

Service(
Expand All @@ -207,7 +211,9 @@ class Service : public ServiceBase
rclcpp_service_callback_added,
(const void *)get_service_handle().get(),
(const void *)&any_callback_);
#ifndef TRACETOOLS_DISABLED
any_callback_.register_callback_for_tracing();
#endif
}

Service() = delete;
Expand Down
2 changes: 2 additions & 0 deletions rclcpp/include/rclcpp/subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ class Subscription : public SubscriptionBase
// The callback object gets copied, so if registration is done too early/before this point
// (e.g. in `AnySubscriptionCallback::set()`), its address won't match any address used later
// in subsequent tracepoints.
#ifndef TRACETOOLS_DISABLED
any_callback_.register_callback_for_tracing();
#endif
}

/// Called after construction to continue setup that requires shared_from_this().
Expand Down

0 comments on commit 8b17de4

Please sign in to comment.