Tracing these list lengths sometimes dominates performance, so manually keep count for now.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3756 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-13 01:08:17 +00:00
parent 7ba1e6980f
commit e1f868730f

View File

@ -145,19 +145,28 @@ typedef struct _tf_ssb_t {
uint8_t pub[crypto_sign_PUBLICKEYBYTES]; uint8_t pub[crypto_sign_PUBLICKEYBYTES];
uint8_t priv[crypto_sign_SECRETKEYBYTES]; uint8_t priv[crypto_sign_SECRETKEYBYTES];
int connections_changed_count;
tf_ssb_connection_t* connections; tf_ssb_connection_t* connections;
int connections_count;
tf_ssb_connections_t* connections_tracker; tf_ssb_connections_t* connections_tracker;
tf_ssb_broadcast_t* broadcasts; tf_ssb_broadcast_t* broadcasts;
int broadcasts_count;
tf_ssb_rpc_callback_node_t* rpc; tf_ssb_rpc_callback_node_t* rpc;
int rpc_count;
tf_ssb_connections_changed_callback_node_t* connections_changed; tf_ssb_connections_changed_callback_node_t* connections_changed;
int connections_changed_count;
tf_ssb_message_added_callback_node_t* message_added; tf_ssb_message_added_callback_node_t* message_added;
int message_added_count;
tf_ssb_blob_want_added_callback_node_t* blob_want_added; tf_ssb_blob_want_added_callback_node_t* blob_want_added;
int blob_want_added_count;
tf_ssb_broadcasts_changed_callback_node_t* broadcasts_changed; tf_ssb_broadcasts_changed_callback_node_t* broadcasts_changed;
int broadcasts_changed_count;
} tf_ssb_t; } tf_ssb_t;
typedef struct _tf_ssb_connection_t { typedef struct _tf_ssb_connection_t {
@ -1201,6 +1210,7 @@ static void _tf_ssb_connection_on_close(uv_handle_t* handle)
{ {
*it = connection->next; *it = connection->next;
connection->next = NULL; connection->next = NULL;
ssb->connections_count--;
break; break;
} }
} }
@ -1484,29 +1494,6 @@ static bool _tf_ssb_save_keys(tf_ssb_t* ssb)
static void _tf_ssb_trace_timer(uv_timer_t* timer) static void _tf_ssb_trace_timer(uv_timer_t* timer)
{ {
tf_ssb_t* ssb = timer->data; tf_ssb_t* ssb = timer->data;
int connections = 0;
int broadcasts = 0;
int rpc = 0;
int connections_changed = 0;
int message_added = 0;
int blob_want_added = 0;
int broadcasts_changed = 0;
#define COUNT(type, name) \
for (type* it = ssb->name; it; it = it->next) \
{ \
name++; \
}
COUNT(tf_ssb_connection_t, connections);
COUNT(tf_ssb_broadcast_t, broadcasts);
COUNT(tf_ssb_rpc_callback_node_t, rpc);
COUNT(tf_ssb_connections_changed_callback_node_t, connections_changed);
COUNT(tf_ssb_message_added_callback_node_t, message_added);
COUNT(tf_ssb_blob_want_added_callback_node_t, blob_want_added);
COUNT(tf_ssb_broadcasts_changed_callback_node_t, broadcasts_changed);
#undef COUNT
const char* names[] = const char* names[] =
{ {
@ -1520,13 +1507,13 @@ static void _tf_ssb_trace_timer(uv_timer_t* timer)
}; };
int64_t values[] = int64_t values[] =
{ {
connections, ssb->connections_count,
broadcasts, ssb->broadcasts_count,
rpc, ssb->rpc_count,
connections_changed, ssb->connections_changed_count,
message_added, ssb->message_added_count,
blob_want_added, ssb->blob_want_added_count,
broadcasts_changed, ssb->broadcasts_changed_count,
}; };
tf_trace_counter(ssb->trace, "lists", _countof(values), names, values); tf_trace_counter(ssb->trace, "lists", _countof(values), names, values);
@ -1692,6 +1679,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_rpc_callback_node_t* node = ssb->rpc; tf_ssb_rpc_callback_node_t* node = ssb->rpc;
ssb->rpc = node->next; ssb->rpc = node->next;
ssb->rpc_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -1703,6 +1691,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_connections_changed_callback_node_t* node = ssb->connections_changed; tf_ssb_connections_changed_callback_node_t* node = ssb->connections_changed;
ssb->connections_changed = node->next; ssb->connections_changed = node->next;
ssb->connections_changed_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -1713,6 +1702,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_message_added_callback_node_t* node = ssb->message_added; tf_ssb_message_added_callback_node_t* node = ssb->message_added;
ssb->message_added = node->next; ssb->message_added = node->next;
ssb->message_added_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -1723,6 +1713,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_blob_want_added_callback_node_t* node = ssb->blob_want_added; tf_ssb_blob_want_added_callback_node_t* node = ssb->blob_want_added;
ssb->blob_want_added = node->next; ssb->blob_want_added = node->next;
ssb->blob_want_added_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -1733,6 +1724,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_broadcasts_changed_callback_node_t* node = ssb->broadcasts_changed; tf_ssb_broadcasts_changed_callback_node_t* node = ssb->broadcasts_changed;
ssb->broadcasts_changed = node->next; ssb->broadcasts_changed = node->next;
ssb->broadcasts_changed_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -1752,6 +1744,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{ {
tf_ssb_broadcast_t* broadcast = ssb->broadcasts; tf_ssb_broadcast_t* broadcast = ssb->broadcasts;
ssb->broadcasts = broadcast->next; ssb->broadcasts = broadcast->next;
ssb->broadcasts_count--;
free(broadcast); free(broadcast);
} }
free(ssb); free(ssb);
@ -1835,6 +1828,7 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
connection->next = ssb->connections; connection->next = ssb->connections;
ssb->connections = connection; ssb->connections = connection;
ssb->connections_count++;
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_create, connection); _tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_create, connection);
return connection; return connection;
} }
@ -1930,6 +1924,7 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
connection->next = ssb->connections; connection->next = ssb->connections;
ssb->connections = connection; ssb->connections = connection;
ssb->connections_count++;
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_create, connection); _tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_create, connection);
connection->state = k_tf_ssb_state_server_wait_hello; connection->state = k_tf_ssb_state_server_wait_hello;
@ -2133,6 +2128,7 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
node->ctime = time(NULL); node->ctime = time(NULL);
node->mtime = node->ctime; node->mtime = node->ctime;
ssb->broadcasts = node; ssb->broadcasts = node;
ssb->broadcasts_count++;
_tf_ssb_notify_broadcasts_changed(ssb); _tf_ssb_notify_broadcasts_changed(ssb);
} }
@ -2269,6 +2265,7 @@ void tf_ssb_add_broadcasts_changed_callback(tf_ssb_t* ssb, tf_ssb_broadcasts_cha
.next = ssb->broadcasts_changed, .next = ssb->broadcasts_changed,
}; };
ssb->broadcasts_changed = node; ssb->broadcasts_changed = node;
ssb->broadcasts_changed_count++;
} }
void tf_ssb_remove_broadcasts_changed_callback(tf_ssb_t* ssb, tf_ssb_broadcasts_changed_callback_t* callback, void* user_data) void tf_ssb_remove_broadcasts_changed_callback(tf_ssb_t* ssb, tf_ssb_broadcasts_changed_callback_t* callback, void* user_data)
@ -2281,6 +2278,7 @@ void tf_ssb_remove_broadcasts_changed_callback(tf_ssb_t* ssb, tf_ssb_broadcasts_
{ {
tf_ssb_broadcasts_changed_callback_node_t* node = *it; tf_ssb_broadcasts_changed_callback_node_t* node = *it;
*it = node->next; *it = node->next;
ssb->broadcasts_changed_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -2305,6 +2303,7 @@ void tf_ssb_add_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_connections_c
.next = ssb->connections_changed, .next = ssb->connections_changed,
}; };
ssb->connections_changed = node; ssb->connections_changed = node;
ssb->connections_changed_count++;
} }
void tf_ssb_remove_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_connections_changed_callback_t* callback, void* user_data) void tf_ssb_remove_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_connections_changed_callback_t* callback, void* user_data)
@ -2317,6 +2316,7 @@ void tf_ssb_remove_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_connection
{ {
tf_ssb_connections_changed_callback_node_t* node = *it; tf_ssb_connections_changed_callback_node_t* node = *it;
*it = node->next; *it = node->next;
ssb->connections_changed_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -2358,6 +2358,7 @@ void tf_ssb_add_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_callba
} }
node->name[name_count] = NULL; node->name[name_count] = NULL;
ssb->rpc = node; ssb->rpc = node;
ssb->rpc_count++;
} }
JSContext* tf_ssb_connection_get_context(tf_ssb_connection_t* connection) JSContext* tf_ssb_connection_get_context(tf_ssb_connection_t* connection)
@ -2396,6 +2397,7 @@ void tf_ssb_add_message_added_callback(tf_ssb_t* ssb, void (*callback)(tf_ssb_t*
.next = ssb->message_added, .next = ssb->message_added,
}; };
ssb->message_added = node; ssb->message_added = node;
ssb->message_added_count++;
} }
void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, void* user_data) void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, void* user_data)
@ -2408,6 +2410,7 @@ void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_ca
{ {
tf_ssb_message_added_callback_node_t* node = *it; tf_ssb_message_added_callback_node_t* node = *it;
*it = node->next; *it = node->next;
ssb->message_added_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);
@ -2442,6 +2445,7 @@ void tf_ssb_add_blob_want_added_callback(tf_ssb_t* ssb, void (*callback)(tf_ssb_
.next = ssb->blob_want_added, .next = ssb->blob_want_added,
}; };
ssb->blob_want_added = node; ssb->blob_want_added = node;
ssb->blob_want_added_count++;
} }
void tf_ssb_remove_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_added_callback_t* callback, void* user_data) void tf_ssb_remove_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_added_callback_t* callback, void* user_data)
@ -2454,6 +2458,7 @@ void tf_ssb_remove_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_adde
{ {
tf_ssb_blob_want_added_callback_node_t* node = *it; tf_ssb_blob_want_added_callback_node_t* node = *it;
*it = node->next; *it = node->next;
ssb->blob_want_added_count--;
if (node->cleanup) if (node->cleanup)
{ {
node->cleanup(ssb, node->user_data); node->cleanup(ssb, node->user_data);