24 #include <sys/prctl.h> 36 void task_init(
const char* name,
const char* owner) {
38 std::ostringstream oss;
40 if (owner != NULL && strlen(owner) > 0) {
43 char thread_name[256];
44 prctl(PR_GET_NAME, thread_name, NULL, NULL, NULL);
47 std::string fqn(oss.str());
48 tracepoint(roscpp, task_start, fqn.c_str());
52 if (strlen(name) > 10) {
53 oss.str(fqn.substr(0, 8));
55 oss <<
"_" << fqn.substr(strlen(name));
58 prctl(PR_SET_NAME, fqn.c_str(), NULL, NULL, NULL);
61 void node_init(
const char* node_name,
unsigned int roscpp_version) {
63 tracepoint(roscpp, init_node, node_name, roscpp_version);
64 prctl(PR_SET_NAME, node_name, NULL, NULL, NULL);
68 const uint64_t trace_id) {
70 tracepoint(roscpp, callback_start, ptr_ref, data, trace_id);
73 void call_end(
const void* ptr_ref,
const void* data,
const uint64_t trace_id) {
75 tracepoint(roscpp, callback_end, ptr_ref, data, trace_id);
80 const uint32_t receipt_time_sec,
const uint32_t receipt_time_nsec) {
83 receipt_time_sec, receipt_time_nsec);
90 void* func_ptr =
const_cast<void*
>(const_ptr);
91 char** symbols = backtrace_symbols(&func_ptr, 1);
93 if (symbols[0][0] ==
'[') {
96 tracepoint(roscpp, ptr_name_info, symbols[0], ptr);
107 void timer_added(
const void* fun_ptr,
const char* type_info,
int period_sec,
112 period_sec, period_nsec);
122 void time_sleep(
const void* callback_ref,
int sleep_sec,
int sleep_nsec) {
124 tracepoint(roscpp,
time_sleep, callback_ref, sleep_sec, sleep_nsec);
128 void link_step(
const char* element_name,
const void* caller_ref,
129 const void* in_data_ref,
const void* out_data_ref,
130 const uint64_t trace_id) {
132 #ifdef NO_LINK_BACKTRACES 133 tracepoint(roscpp, trace_link, element_name, user_name,
134 in_data_ref, out_data_ref, trace_id, NULL);
136 tracepoint(roscpp, trace_link, element_name,
typeid(caller_ref).name(),
137 caller_ref, in_data_ref, out_data_ref, trace_id,
144 const char* remote_hostport_arg,
const void* channel_ref_arg,
145 const char* channel_type_arg,
const char* name_arg,
146 const char* data_type_arg) {
148 tracepoint(roscpp,
new_connection, local_hostport_arg, remote_hostport_arg,
149 channel_ref_arg, channel_type_arg, name_arg, data_type_arg);
153 const void* buffer_ref_arg) {
161 const void* buffer_ref_arg) {
167 const void* buffer_ref_arg) {
174 const void* channel_ref_arg) {
187 const void* buffer_ref_arg,
const void* queue_ref_arg,
188 const void* callback_ref_arg,
const void* message_ref_arg,
189 int receipt_time_sec_arg,
int receipt_time_nsec_arg) {
192 queue_ref_arg, callback_ref_arg, message_ref_arg,
193 receipt_time_sec_arg, receipt_time_nsec_arg);
197 const void* buffer_ref_arg,
198 const void* queue_ref_arg,
199 const void* callback_ref_arg,
200 const void* message_ref_arg,
201 int receipt_time_sec_arg,
202 int receipt_time_nsec_arg)
206 queue_ref_arg, callback_ref_arg, message_ref_arg,
207 receipt_time_sec_arg, receipt_time_nsec_arg);
211 const void* callback_ref_arg,
const char* type_info_arg,
212 const char* data_type_arg,
const char* source_name_arg,
213 int queue_size_arg) {
216 callback_ref_arg, type_info_arg, data_type_arg, source_name_arg,
222 const void* callback_ref,
const void* message_ref,
int receipt_time_sec,
223 int receipt_time_nsec) {
225 tracepoint(roscpp, subscriber_callback_start, topic.c_str(), 0, queue_ref,
226 callback_ref, message_ref, receipt_time_sec, receipt_time_nsec);
230 const void* callback_ref,
const void* message_ref,
int receipt_time_sec,
231 int receipt_time_nsec) {
233 tracepoint(roscpp, subscriber_callback_end, topic.c_str(), 0, queue_ref,
234 callback_ref, message_ref, receipt_time_sec, receipt_time_nsec);
238 void queue_delay(
const char* queue_name,
const void* ptr_ref,
const void* data,
239 const uint32_t entry_time_sec,
const uint32_t entry_time_nsec) {
241 tracepoint(roscpp,
queue_delay, queue_name, ptr_ref, data, entry_time_sec,
249 const int bufsize = 50;
250 void* bt_buffer[bufsize];
251 int size = backtrace(bt_buffer, bufsize);
252 char** symbols = backtrace_symbols(bt_buffer, size);
254 std::ostringstream oss;
259 for (
int i = 2; i < size; ++i) {
260 oss << symbols[i] <<
"|";
263 oss << symbols[index];
266 oss <<
"Invalid index " << index <<
" requested, only have " << size
267 <<
" backtrace entries";
279 char** symbols = backtrace_symbols(&funptr, 1);
280 std::string result(symbols[0]);
289 void* funptr =
const_cast<void*
>(func_ptr);
290 char** symbols = backtrace_symbols(&funptr, 1);
291 std::string result(symbols[0]);
293 return name + std::string(
" ") + result;
void subscriber_call_end(const std::string &topic, const void *queue_ref, const void *callback_ref, const void *message_ref, int receipt_time_sec, int receipt_time_nsec)
Marks the end of the call, same arguments as above.
std::string getCallbackInfo(const void *func_ptr, const char *name)
try to get a name for the function inside the CallbackInterfacePtr
void subscriber_callback_added(const void *queue_ref_arg, const void *callback_ref_arg, const char *type_info_arg, const char *data_type_arg, const char *source_name_arg, int queue_size_arg)
Trace metadata on a new subscription callback.
std::string get_backtrace(int index=-1)
void timer_added(const void *fun_ptr, const char *type_info, int period_sec, int period_nsec)
void node_init(const char *node_name, unsigned int roscpp_version)
also set's procname, but be aware that's limited to 16 chars
void fn_name_info(const void *fun_ptr, const void *ref)
Emit tracing information linking the function ptr's name to the given reference pointer.
std::string get_symbol(void *funptr)
void publisher_link_handle_message(const void *channel_ref_arg, const void *buffer_ref_arg)
Trace metadata on creation of a publisher link (incoming topic connection)
void publisher_message_queued(const char *topic_arg, const void *buffer_ref_arg)
Trace a message being queue for publishing.
void new_connection(const char *local_hostport_arg, const char *remote_hostport_arg, const void *channel_ref_arg, const char *channel_type_arg, const char *name_arg, const char *data_type_arg)
Trace metadata on creation of a new connection.
void subscriber_link_message_dropped(const void *message_ref_arg)
Trac on an incoming message being dropped (queue full, etc.)
void call_end(const void *ptr_ref, const void *data, const uint64_t trace_id)
Trace the end of a user-callback invocation.
void time_sleep(const void *callback_ref, int sleep_sec, int sleep_nsec)
void task_init(const char *task_name, const char *owner=NULL)
emit a tracepoint specifying a name for this thread.
void subscription_message_queued(const char *topic_arg, const void *buffer_ref_arg, const void *queue_ref_arg, const void *callback_ref_arg, const void *message_ref_arg, int receipt_time_sec_arg, int receipt_time_nsec_arg)
Trace on a message having been received and queued.
bool compile_status()
report whether tracing is compiled in
void queue_delay(const char *queue_name, const void *ptr_ref, const void *data, const uint32_t entry_time_sec, const uint32_t entry_time_nsec)
Trace queue delay experienced by the given function pointer.
void message_processed(const char *message_name, const void *callback_ref, const uint32_t receipt_time_sec, const uint32_t receipt_time_nsec)
Mark the processing of a given "message".
void subscription_message_dropped(const char *topic_arg, const void *buffer_arg, const void *queue_ref_arg, const void *callback_ref_arg, const void *message_ref_arg, int receipt_time_sec, int receipt_time_nsec)
void subscriber_call_start(const std::string &topic, const void *queue_ref, const void *callback_ref, const void *message_ref, int receipt_time_sec, int receipt_time_nsec)
Trace the invocation of a previously queued subscriber call.
void call_start(const void *ptr_ref, const void *data, const uint64_t trace_id)
Trace the start of a function call through a function pointer.
void timer_scheduled(const void *callback_ref, const void *timer_ref)
Emit tracing information that the timer identified by 'timer_ref' has been scheduled for invocation o...
void subscriber_link_message_write(const void *message_ref_arg, const void *channel_ref_arg)
Trace on a message being written to the socket.
void link_step(const char *element_name, const void *caller_name, const void *in_data_ref, const void *out_data_ref, const uint64_t trace_id)
Emit a trace message for a link in a processing chain.