From 039aaaf7772b84d911f948c521b3717f292f152d Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 27 Jul 2023 14:43:58 +0930 Subject: [PATCH] trace: Instrument topology functions --- lightningd/bitcoind.c | 6 ++++++ lightningd/chaintopology.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index e2ad1817c..910533362 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -464,6 +465,8 @@ getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks, const char *block_str, *err; struct bitcoin_blkid blkid; struct bitcoin_block *blk; + trace_span_resume(call); + trace_span_end(call); /* If block hash is `null`, this means not found! Call the callback * with NULL values. */ @@ -514,6 +517,9 @@ void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind, call->cb = cb; call->cb_arg = cb_arg; + trace_span_start("plugin/bitcoind", call); + trace_span_tag(call, "method", "getrawblockbyheight"); + trace_span_suspend(call); req = jsonrpc_request_start(bitcoind, "getrawblockbyheight", NULL, true, bitcoind->log, NULL, getrawblockbyheight_callback, diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 3c72da362..49be23683 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -971,13 +972,22 @@ static void add_tip(struct chain_topology *topo, struct block *b) b->prev = topo->tip; topo->tip->next = b; /* FIXME this doesn't seem to be used anywhere */ topo->tip = b; + trace_span_start("wallet_block_add", b); wallet_block_add(topo->ld->wallet, b); + trace_span_end(b); + trace_span_start("topo_add_utxo", b); topo_add_utxos(topo, b); + trace_span_end(b); + + trace_span_start("topo_update_spends", b); topo_update_spends(topo, b); + trace_span_end(b); /* Only keep the transactions we care about. */ + trace_span_start("filter_block_txs", b); filter_block_txs(topo, b); + trace_span_end(b); block_map_add(topo->block_map, b); topo->max_blockheight = b->height; @@ -1056,6 +1066,7 @@ static void get_new_block(struct bitcoind *bitcoind, if (!blkid && !blk) { /* No such block, we're done. */ updates_complete(topo); + trace_span_end(topo); return; } assert(blkid && blk); @@ -1075,6 +1086,7 @@ static void get_new_block(struct bitcoind *bitcoind, } /* Try for next one. */ + trace_span_end(topo); try_extend_tip(topo); } @@ -1083,6 +1095,7 @@ static void try_extend_tip(struct chain_topology *topo) topo->extend_timer = NULL; if (topo->stopping) return; + trace_span_start("extend_tip", topo); bitcoind_getrawblockbyheight(topo->bitcoind, topo->tip->height + 1, get_new_block, topo); }