From f6742bebf3b1e3d066dfde4e5967e121e1e93472 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 3 Feb 2023 15:06:18 +0000 Subject: [PATCH] Tracing will continue until performance improves. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4169 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/ssb.c b/src/ssb.c index e9e9503f..ad34b1a9 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -120,6 +120,7 @@ typedef struct _tf_ssb_rpc_callback_node_t tf_ssb_rpc_callback_node_t; typedef struct _tf_ssb_rpc_callback_node_t { const char** name; + const char* flattened_name; tf_ssb_rpc_callback_t* callback; tf_ssb_callback_cleanup_t* cleanup; void* user_data; @@ -1040,7 +1041,9 @@ static void _tf_ssb_notify_connections_changed(tf_ssb_t* ssb, tf_ssb_change_t ch for (tf_ssb_connections_changed_callback_node_t* node = ssb->connections_changed; node; node = next) { next = node->next; + tf_trace_begin(ssb->trace, "connections_changed"); node->callback(ssb, change, connection, node->user_data); + tf_trace_end(ssb->trace); } } @@ -1474,7 +1477,9 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t { if (_tf_ssb_name_equals(context, val, it->name)) { + tf_trace_begin(connection->ssb->trace, it->flattened_name); it->callback(connection, flags, request_number, val, message, size, it->user_data); + tf_trace_end(connection->ssb->trace); found = true; break; } @@ -1488,7 +1493,11 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t { if (callback) { + char buffer[64]; + snprintf(buffer, sizeof(buffer), "request %d", request_number); + tf_trace_begin(connection->ssb->trace, buffer); callback(connection, flags, request_number, val, message, size, user_data); + tf_trace_end(connection->ssb->trace); } } else if (!_tf_ssb_name_equals(context, val, (const char*[]) { "Error", NULL })) @@ -1516,7 +1525,11 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t { if (callback) { + char buffer[64]; + snprintf(buffer, sizeof(buffer), "request %d", request_number); + tf_trace_begin(connection->ssb->trace, buffer); callback(connection, flags, request_number, JS_UNDEFINED, message, size, user_data); + tf_trace_end(connection->ssb->trace); } } else @@ -1714,7 +1727,9 @@ static void _tf_ssb_connection_dispatch_scheduled(tf_ssb_connection_t* connectio tf_ssb_connection_scheduled_t scheduled = connection->scheduled[0]; memmove(connection->scheduled, connection->scheduled + 1, sizeof(tf_ssb_connection_scheduled_t) * (connection->scheduled_count - 1)); connection->scheduled_count--; + tf_trace_begin(connection->ssb->trace, "scheduled callback"); scheduled.callback(connection, scheduled.user_data); + tf_trace_end(connection->ssb->trace); } } @@ -2695,7 +2710,9 @@ static void _tf_ssb_notify_broadcasts_changed(tf_ssb_t* ssb) next = node->next; if (node->callback) { + tf_trace_begin(ssb->trace, "broadcasts changed"); node->callback(ssb, node->user_data); + tf_trace_end(ssb->trace); } } } @@ -2786,7 +2803,9 @@ void tf_ssb_visit_broadcasts(tf_ssb_t* ssb, void (*callback)(const char* host, c next = node->next; if (node->mtime - now < 60) { + tf_trace_begin(ssb->trace, "broadcast"); callback(node->host, &node->addr, node->tunnel_connection, node->pub, user_data); + tf_trace_end(ssb->trace); } } } @@ -3028,10 +3047,15 @@ void tf_ssb_add_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_callba name_count++; name_len += strlen(name[i]) + 1; } - tf_ssb_rpc_callback_node_t* node = tf_malloc(sizeof(tf_ssb_rpc_callback_node_t) + (name_count + 1) * sizeof(const char*) + name_len); + tf_ssb_rpc_callback_node_t* node = tf_malloc( + sizeof(tf_ssb_rpc_callback_node_t) + + (name_count + 1) * sizeof(const char*) + + name_len + + name_len + 3); *node = (tf_ssb_rpc_callback_node_t) { .name = (const char**)(node + 1), + .flattened_name = (const char*)(node + 1) + (name_count + 1) * sizeof(const char*) + name_len, .callback = callback, .cleanup = cleanup, .user_data = user_data, @@ -3045,6 +3069,20 @@ void tf_ssb_add_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_callba node->name[i] = p; p += len + 1; } + char* flattened_name = (char*)node->flattened_name; + for (int i = 0; i < name_count; i++) + { + size_t length = strlen(name[i]); + memcpy(flattened_name, name[i], length); + flattened_name += length; + if (i != name_count - 1) + { + *flattened_name++ = '.'; + } + } + *flattened_name++ = '('; + *flattened_name++ = ')'; + *flattened_name++ = '\0'; node->name[name_count] = NULL; ssb->rpc = node; ssb->rpc_count++; @@ -3125,7 +3163,9 @@ void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id) for (tf_ssb_message_added_callback_node_t* node = ssb->message_added; node; node = next) { next = node->next; + tf_trace_begin(ssb->trace, "message added callback"); node->callback(ssb, id, node->user_data); + tf_trace_end(ssb->trace); } JSContext* context = ssb->context; @@ -3210,7 +3250,9 @@ void tf_ssb_notify_blob_want_added(tf_ssb_t* ssb, const char* id) for (tf_ssb_blob_want_added_callback_node_t* node = ssb->blob_want_added; node; node = next) { next = node->next; + tf_trace_begin(ssb->trace, "blob want added callback"); node->callback(ssb, id, node->user_data); + tf_trace_end(ssb->trace); } }