Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,28 @@ void trace_span_suspend_(const void *key, const char *lbl)
DTRACE_PROBE1(lightningd, span_suspend, span->id);
}

static void destroy_trace_span(const void *key)
{
size_t numkey = trace_key(key);
struct span *span = trace_span_find(numkey);

/* It's usually ended normally. */
if (!span)
return;

/* Otherwise resume so we can terminate it */
trace_span_resume(key);
trace_span_end(key);
}

void trace_span_suspend_may_free_(const void *key, const char *lbl)
{
if (disable_trace)
return;
trace_span_suspend_(key, lbl);
tal_add_destructor(key, destroy_trace_span);
}

void trace_span_resume_(const void *key, const char *lbl)
{
if (disable_trace)
Expand All @@ -395,6 +417,7 @@ void trace_cleanup(void)
void trace_span_start(const char *name, const void *key) {}
void trace_span_end(const void *key) {}
void trace_span_suspend_(const void *key, const char *lbl) {}
void trace_span_suspend_may_free_(const void *key, const char *lbl) {}
void trace_span_resume_(const void *key, const char *lbl) {}
void trace_span_tag(const void *key, const char *name, const char *value) {}
void trace_cleanup(void) {}
Expand Down
2 changes: 2 additions & 0 deletions common/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ void trace_span_remote(u8 trace_id[TRACE_ID_SIZE], u8 span_id[SPAN_ID_SIZE]);

#define TRACE_LBL __FILE__ ":" stringify(__LINE__)
void trace_span_suspend_(const void *key, const char *lbl);
void trace_span_suspend_may_free_(const void *key, const char *lbl);
void trace_span_resume_(const void *key, const char *lbl);
#define trace_span_suspend(key) trace_span_suspend_(key, TRACE_LBL)
#define trace_span_suspend_may_free(key) trace_span_suspend_may_free_(key, TRACE_LBL)
#define trace_span_resume(key) trace_span_resume_(key, TRACE_LBL)

#endif /* LIGHTNING_COMMON_TRACE_H */
2 changes: 1 addition & 1 deletion plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ send_outreq(const struct out_req *req)
* callback. */
trace_span_start("jsonrpc", req);
trace_span_tag(req, "id", req->id);
trace_span_suspend(req);
trace_span_suspend_may_free(req);

ld_rpc_send(req->cmd->plugin, req->js);
notleak_with_children(req->cmd);
Expand Down