From 85a2bc3f0f943a63c71e88f53200828209d3e8dd Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 18 Jan 2023 22:52:54 +0000 Subject: [PATCH] Add a stat for blobs stored. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4133 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/client.js | 3 +++ src/ssb.c | 8 ++++++++ src/ssb.db.c | 8 ++++++-- src/ssb.h | 2 ++ src/task.c | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/client.js b/core/client.js index c24e2bde..9d6eb430 100644 --- a/core/client.js +++ b/core/client.js @@ -554,6 +554,9 @@ function _receive_websocket_message(message) { tls_malloc_percent: {group: 'memory', name: 'tls'}, uv_malloc_percent: {group: 'memory', name: 'uv'}, + messages_stored: {group: 'stored', name: 'messages'}, + blobs_stored: {group: 'stored', name: 'blobs'}, + socket_count: {group: 'socket', name: 'total'}, socket_open_count: {group: 'socket', name: 'open'}, diff --git a/src/ssb.c b/src/ssb.c index e8395cd2..83c1ab70 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -169,6 +169,7 @@ typedef struct _tf_ssb_t bool verbose; int messages_stored; + int blobs_stored; int rpc_in; int rpc_out; @@ -1951,6 +1952,7 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats) .connections = ssb->connections_count, .broadcasts = ssb->broadcasts_count, .messages_stored = ssb->messages_stored, + .blobs_stored = ssb->blobs_stored, .rpc_in = ssb->rpc_in, .rpc_out = ssb->rpc_out, .request_count = ssb->request_count, @@ -1964,6 +1966,7 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats) }, }; ssb->messages_stored = 0; + ssb->blobs_stored = 0; ssb->rpc_in = 0; ssb->rpc_out = 0; } @@ -3019,6 +3022,11 @@ void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_ca } } +void tf_ssb_notify_blob_stored(tf_ssb_t* ssb, const char* id) +{ + ssb->blobs_stored++; +} + void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id) { tf_ssb_message_added_callback_node_t* next = NULL; diff --git a/src/ssb.db.c b/src/ssb.db.c index 99b76666..dbe40a3c 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -455,9 +455,13 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* printf("prepare failed: %s\n", sqlite3_errmsg(db)); } - if (rows && !out_new) + if (rows) { - printf("blob stored %s %zd => %d\n", id, size, result); + tf_ssb_notify_blob_stored(ssb, id); + if (!out_new) + { + printf("blob stored %s %zd => %d\n", id, size, result); + } } if (result && out_id) diff --git a/src/ssb.h b/src/ssb.h index 5eb5b080..4052f980 100644 --- a/src/ssb.h +++ b/src/ssb.h @@ -44,6 +44,7 @@ typedef struct _tf_ssb_stats_t int connections; int broadcasts; int messages_stored; + int blobs_stored; int rpc_in; int rpc_out; int request_count; @@ -136,6 +137,7 @@ typedef void (tf_ssb_message_added_callback_t)(tf_ssb_t* ssb, const char* id, vo void tf_ssb_add_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data); void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, void* user_data); void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id); +void tf_ssb_notify_blob_stored(tf_ssb_t* ssb, const char* id); typedef void (tf_ssb_blob_want_added_callback_t)(tf_ssb_t* ssb, const char* id, void* user_data); void tf_ssb_add_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data); diff --git a/src/task.c b/src/task.c index a5164c0f..087a14ec 100644 --- a/src/task.c +++ b/src/task.c @@ -738,6 +738,7 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int tf_ssb_get_stats(task->_ssb, &ssb_stats); JS_SetPropertyStr(context, result, "messages_stored", JS_NewInt32(context, ssb_stats.messages_stored)); + JS_SetPropertyStr(context, result, "blobs_stored", JS_NewInt32(context, ssb_stats.blobs_stored)); JS_SetPropertyStr(context, result, "rpc_in", JS_NewInt32(context, ssb_stats.rpc_in)); JS_SetPropertyStr(context, result, "rpc_out", JS_NewInt32(context, ssb_stats.rpc_out)); JS_SetPropertyStr(context, result, "requests", JS_NewInt32(context, ssb_stats.request_count));