From a9f5b96e029b71459e866427a0aad1e4ded8e50a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 28 Aug 2019 10:08:58 +0200 Subject: [PATCH] MINOR: trace: show thread number and source name in the trace Traces were missing the thread number and the source name, which was really annoying. Now the thread number is emitted on two digits inside the square brackets, followed by the source name then the line location, each delimited with a vertical bar, such as below : [00|h2|mux_h2.c:2651] Notifying stream about SID change : h2c=0x7f3284581ae0 st=3 h2s=0x7f3284297f00 id=523 st=4 [00|h2|mux_h2.c:2708] receiving H2 HEADERS frame : h2c=0x7f3284581ae0 st=3 dsi=525 (st=0) [02|h2|mux_h2.c:2194] Received H2 request : h2c=0x7f328d3d1ae0 st=2 : [525] H2 REQ: GET / HTTP/2.0 [02|h2|mux_h2.c:2561] Expecting H2 frame header : h2c=0x7f328d3d1ae0 st=2 --- src/trace.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/trace.c b/src/trace.c index 8d68b6642..e44fa8421 100644 --- a/src/trace.c +++ b/src/trace.c @@ -83,6 +83,7 @@ void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, co const struct stream *strm = NULL; const struct connection *conn = NULL; const void *lockon_ptr = NULL; + char tnum[4]; struct ist line[8]; if (likely(src->state == TRACE_STATE_STOPPED)) @@ -177,12 +178,19 @@ void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, co * the line number and the end of the file name are there. */ line[0] = ist("["); - line[1] = where; - if (line[1].len > 13) { - line[1].ptr += (line[1].len - 13); - line[1].len = 13; + tnum[0] = '0' + tid / 10; + tnum[1] = '0' + tid % 10; + tnum[2] = '|'; + tnum[3] = 0; + line[1] = ist(tnum); + line[2] = src->name; + line[3] = ist("|"); + line[4] = where; + if (line[4].len > 13) { + line[4].ptr += (line[4].len - 13); + line[4].len = 13; } - line[2] = ist("] "); + line[5] = ist("] "); if (!cb) cb = src->default_cb; @@ -195,14 +203,14 @@ void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, co b_reset(&trace_buf); b_istput(&trace_buf, msg); cb(level, mask, src, where, a1, a2, a3, a4); - line[3].ptr = trace_buf.area; - line[3].len = trace_buf.data; + line[6].ptr = trace_buf.area; + line[6].len = trace_buf.data; } else - line[3] = msg; + line[6] = msg; if (src->sink) - sink_write(src->sink, line, 4); + sink_write(src->sink, line, 7); end: /* check if we need to stop the trace now */