Minor cleanup. Missing traces.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4356 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-07-20 02:20:38 +00:00
parent fb73fd0afc
commit 6889e11fd1
3 changed files with 27 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "mem.h"
#include "task.h"
#include "trace.h"
#include "util.js.h"
#include "unzip.h"
@ -256,11 +257,14 @@ typedef struct _zip_read_work_t
static void _file_read_file_zip_work(uv_work_t* work)
{
zip_read_work_t* data = work->data;
tf_trace_t* trace = tf_task_get_trace(data->task);
tf_trace_begin(trace, "file_read_zip_work");
unzFile zip = unzOpen(tf_task_get_zip_path(data->task));
bool is_file_open = false;
if (!zip)
{
data->result = errno;
tf_trace_end(trace);
return;
}
@ -291,6 +295,7 @@ static void _file_read_file_zip_work(uv_work_t* work)
tf_free(data->buffer);
data->buffer = NULL;
}
tf_trace_end(trace);
done:
if (is_file_open)
@ -303,6 +308,8 @@ done:
static void _file_read_file_zip_after_work(uv_work_t* work, int status)
{
zip_read_work_t* data = work->data;
tf_trace_t* trace = tf_task_get_trace(data->task);
tf_trace_begin(trace, "file_read_zip_after_work");
if (data->result >= 0)
{
tf_task_resolve_promise(data->task, data->promise, tf_util_new_uint8_array(data->context, data->buffer, data->result));
@ -314,11 +321,12 @@ static void _file_read_file_zip_after_work(uv_work_t* work, int status)
tf_free(data->buffer);
tf_free((void*)data->file_path);
tf_free(data);
tf_trace_end(trace);
}
static JSValue _file_read_file_zip(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
void* task = JS_GetContextOpaque(context);
tf_task_t* task = JS_GetContextOpaque(context);
const char* file_name = JS_ToCString(context, argv[0]);
zip_read_work_t* work = tf_malloc(sizeof(zip_read_work_t));

View File

@ -19,6 +19,11 @@
#include <unistd.h>
typedef struct _message_store_t message_store_t;
static void _tf_ssb_db_store_message_work_finish(message_store_t* store);
static void _tf_ssb_db_store_message_after_work(uv_work_t* work, int status);
static void _tf_ssb_db_exec(sqlite3* db, const char* statement)
{
char* error = NULL;
@ -290,7 +295,6 @@ static int64_t _tf_ssb_db_store_message_raw(
if (r != SQLITE_DONE)
{
tf_printf("_tf_ssb_db_store_message_raw: %s\n", sqlite3_errmsg(db));
abort();
}
if (r == SQLITE_DONE && sqlite3_changes(db) != 0)
{
@ -355,7 +359,6 @@ static char* _tf_ssb_db_get_message_blob_wants(tf_ssb_t* ssb, int64_t rowid)
return result;
}
typedef struct _message_store_t message_store_t;
typedef struct _message_store_t
{
uv_work_t work;
@ -382,17 +385,17 @@ typedef struct _message_store_t
static void _tf_ssb_db_store_message_work(uv_work_t* work)
{
message_store_t* store = work->data;
tf_trace_t* trace = tf_ssb_get_trace(store->ssb);
tf_trace_begin(trace, "message_store_work");
int64_t last_row_id = _tf_ssb_db_store_message_raw(store->ssb, store->id, *store->previous ? store->previous : NULL, store->author, store->sequence, store->timestamp, store->content, store->length, store->signature, store->sequence_before_author);
if (last_row_id != -1)
{
store->out_stored = true;
store->out_blob_wants = _tf_ssb_db_get_message_blob_wants(store->ssb, last_row_id);
}
tf_trace_end(trace);
}
static void _tf_ssb_db_store_message_work_finish(message_store_t* store);
static void _tf_ssb_db_store_message_after_work(uv_work_t* work, int status);
static void _wake_up_queue(tf_ssb_t* ssb, tf_ssb_store_queue_t* queue)
{
if (!queue->running)
@ -433,6 +436,8 @@ static void _tf_ssb_db_store_message_work_finish(message_store_t* store)
static void _tf_ssb_db_store_message_after_work(uv_work_t* work, int status)
{
message_store_t* store = work->data;
tf_trace_t* trace = tf_ssb_get_trace(store->ssb);
tf_trace_begin(trace, "message_store_after_work");
if (store->out_stored)
{
tf_ssb_notify_message_added(store->ssb, store->id);
@ -446,6 +451,7 @@ static void _tf_ssb_db_store_message_after_work(uv_work_t* work, int status)
tf_free(store->out_blob_wants);
}
_tf_ssb_db_store_message_work_finish(store);
tf_trace_end(trace);
}
void tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, bool sequence_before_author, tf_ssb_db_store_message_callback_t* callback, void* user_data)

View File

@ -5,6 +5,7 @@
#include "mem.h"
#include "ssb.db.h"
#include "ssb.h"
#include "trace.h"
#include "util.js.h"
#include "sodium/crypto_hash_sha256.h"
@ -396,6 +397,8 @@ static void _tf_ssb_sql_append(uint8_t** rows, size_t* rows_count, const void* d
static void _tf_ssb_sqlAsync_work(uv_work_t* work)
{
sql_work_t* sql_work = work->data;
tf_trace_t* trace = tf_ssb_get_trace(sql_work->ssb);
tf_trace_begin(trace, "sql_async_work");
sql_work->start_time = uv_hrtime();
sql_work->thread_id = uv_thread_self();
sqlite3* db = tf_ssb_acquire_db_reader(sql_work->ssb);
@ -494,11 +497,14 @@ static void _tf_ssb_sqlAsync_work(uv_work_t* work)
}
tf_ssb_release_db_reader(sql_work->ssb, db);
sql_work->end_time = uv_hrtime();
tf_trace_end(trace);
}
static void _tf_ssb_sqlAsync_after_work(uv_work_t* work, int status)
{
sql_work_t* sql_work = work->data;
tf_trace_t* trace = tf_ssb_get_trace(sql_work->ssb);
tf_trace_begin(trace, "sql_async_after_work");
tf_ssb_record_thread_time(sql_work->ssb, (int64_t)sql_work->thread_id, sql_work->end_time - sql_work->start_time);
JSContext* context = tf_ssb_get_context(sql_work->ssb);
uint8_t* p = sql_work->rows;
@ -585,6 +591,7 @@ static void _tf_ssb_sqlAsync_after_work(uv_work_t* work, int status)
tf_free(sql_work->error);
tf_free(sql_work);
tf_trace_end(trace);
}
static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)