2626#include " rclcpp/allocator/allocator_common.hpp"
2727#include " rclcpp/function_traits.hpp"
2828#include " rclcpp/visibility_control.hpp"
29+ #include " tracetools/tracetools.h"
30+ #include " tracetools/utils.hpp"
2931
3032namespace rclcpp
3133{
@@ -155,6 +157,7 @@ class AnySubscriptionCallback
155157 void dispatch (
156158 std::shared_ptr<MessageT> message, const rmw_message_info_t & message_info)
157159 {
160+ TRACEPOINT (callback_start, (const void *)this , false );
158161 if (shared_ptr_callback_) {
159162 shared_ptr_callback_ (message);
160163 } else if (shared_ptr_with_info_callback_) {
@@ -174,11 +177,13 @@ class AnySubscriptionCallback
174177 } else {
175178 throw std::runtime_error (" unexpected message without any callback set" );
176179 }
180+ TRACEPOINT (callback_end, (const void *)this );
177181 }
178182
179183 void dispatch_intra_process (
180184 ConstMessageSharedPtr message, const rmw_message_info_t & message_info)
181185 {
186+ TRACEPOINT (callback_start, (const void *)this , true );
182187 if (const_shared_ptr_callback_) {
183188 const_shared_ptr_callback_ (message);
184189 } else if (const_shared_ptr_with_info_callback_) {
@@ -195,11 +200,13 @@ class AnySubscriptionCallback
195200 throw std::runtime_error (" unexpected message without any callback set" );
196201 }
197202 }
203+ TRACEPOINT (callback_end, (const void *)this );
198204 }
199205
200206 void dispatch_intra_process (
201207 MessageUniquePtr message, const rmw_message_info_t & message_info)
202208 {
209+ TRACEPOINT (callback_start, (const void *)this , true );
203210 if (shared_ptr_callback_) {
204211 typename std::shared_ptr<MessageT> shared_message = std::move (message);
205212 shared_ptr_callback_ (shared_message);
@@ -217,13 +224,39 @@ class AnySubscriptionCallback
217224 } else {
218225 throw std::runtime_error (" unexpected message without any callback set" );
219226 }
227+ TRACEPOINT (callback_end, (const void *)this );
220228 }
221229
222230 bool use_take_shared_method ()
223231 {
224232 return const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_;
225233 }
226234
235+ void register_callback_for_tracing ()
236+ {
237+ if (shared_ptr_callback_) {
238+ TRACEPOINT (
239+ rclcpp_callback_register,
240+ (const void *)this ,
241+ get_symbol (shared_ptr_callback_));
242+ } else if (shared_ptr_with_info_callback_) {
243+ TRACEPOINT (
244+ rclcpp_callback_register,
245+ (const void *)this ,
246+ get_symbol (shared_ptr_with_info_callback_));
247+ } else if (unique_ptr_callback_) {
248+ TRACEPOINT (
249+ rclcpp_callback_register,
250+ (const void *)this ,
251+ get_symbol (unique_ptr_callback_));
252+ } else if (unique_ptr_with_info_callback_) {
253+ TRACEPOINT (
254+ rclcpp_callback_register,
255+ (const void *)this ,
256+ get_symbol (unique_ptr_with_info_callback_));
257+ }
258+ }
259+
227260private:
228261 std::shared_ptr<MessageAlloc> message_allocator_;
229262 MessageDeleter message_deleter_;
0 commit comments