plugins/sql: print times taken to do list comand, populate table, and create index.
What changed, and why it matters
This commit adds debug-only timing messages to the SQL plugin. It records how long table refresh and index creation take, and prints those durations to the log at the LOG_DBG (debug) level. There is no change to network behavior, cryptography, authentication, data handling, or any security-sensitive logic.
No security action required. Treat as normal observability/logging improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff in plugins/sql.c introduces a struct timemono refresh_start field on table_desc, captures time_mono() at the start of refresh_tables(), and emits plugin_log(LOG_DBG, …) messages in process_json_result(), one_refresh_done(), and after init_indices(). It also adds #include
Changed components
plugins/sql.cInspect captured patch +23 / −0
diff --git a/plugins/sql.c b/plugins/sql.c
index f116f7e1..660ac85c 100644
--- a/plugins/sql.c
+++ b/plugins/sql.c
@@ -12,6 +12,7 @@
#include <errno.h>
#include <fcntl.h>
#include <gossipd/gossip_store_wiregen.h>
+#include <inttypes.h>
#include <plugins/libplugin.h>
#include <sqlite3.h>
#include <stdio.h>
@@ -129,6 +130,8 @@ struct table_desc {
u64 last_created_index;
/* Are we refreshing now? */
bool refreshing;
+ /* When did we start refreshing? */
+ struct timemono refresh_start;
/* Any other commands waiting for the refresh completion */
struct list_head refresh_waiters;
};
@@ -513,14 +516,27 @@ static struct command_result *one_refresh_done(struct command *cmd,
struct table_desc *td = dbq->tables[0];
struct list_head waiters;
struct refresh_waiter *rw;
+ struct timerel refresh_duration = timemono_since(td->refresh_start);
/* We are no longer refreshing */
assert(td->refreshing);
td->refreshing = false;
+ plugin_log(cmd->plugin, LOG_DBG,
+ "Time to refresh %s: %"PRIu64".%09"PRIu64" seconds (last=%"PRIu64")",
+ td->name,
+ (u64)refresh_duration.ts.tv_sec,
+ (u64)refresh_duration.ts.tv_nsec,
+ td->last_created_index);
if (!td->indices_created) {
init_indices(cmd->plugin, td);
td->indices_created = 1;
+ refresh_duration = timemono_since(td->refresh_start);
+ plugin_log(cmd->plugin, LOG_DBG,
+ "Time to refresh + create indices for %s: %"PRIu64".%09"PRIu64" seconds",
+ td->name,
+ (u64)refresh_duration.ts.tv_sec,
+ (u64)refresh_duration.ts.tv_nsec);
}
/* Transfer refresh waiters onto local list */
@@ -801,6 +817,12 @@ static struct command_result *process_json_result(struct command *cmd,
const struct table_desc *td,
u64 *last_created_index)
{
+ struct timerel so_far = timemono_since(td->refresh_start);
+ plugin_log(cmd->plugin, LOG_DBG,
+ "Time to call %s: %"PRIu64".%09"PRIu64" seconds",
+ td->cmdname,
+ (u64)so_far.ts.tv_sec, (u64)so_far.ts.tv_nsec);
+
return process_json_list(cmd, buf,
json_get_member(buf, result, td->arrname),
NULL, td, last_created_index);
@@ -1147,6 +1169,7 @@ static struct command_result *refresh_tables(struct command *cmd,
dbq->last_created_index = &dbq->tables[0]->last_created_index;
td->refreshing = true;
+ td->refresh_start = time_mono();
return td->refresh(cmd, dbq->tables[0], dbq);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.