Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Runtime tracing API |
| 3 | * |
| 4 | * Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation, version 2.1 |
| 9 | * exclusively. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
Willy Tarreau | eb6f701 | 2020-05-27 16:21:26 +0200 | [diff] [blame] | 21 | #include <import/ist.h> |
Willy Tarreau | 2741c8c | 2020-06-02 11:28:02 +0200 | [diff] [blame] | 22 | #include <haproxy/api.h> |
| 23 | #include <haproxy/buf.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 24 | #include <haproxy/cli.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 25 | #include <haproxy/errors.h> |
Willy Tarreau | 2741c8c | 2020-06-02 11:28:02 +0200 | [diff] [blame] | 26 | #include <haproxy/istbuf.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 27 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 28 | #include <haproxy/log.h> |
Willy Tarreau | ba2f73d | 2020-06-03 20:02:28 +0200 | [diff] [blame] | 29 | #include <haproxy/sink.h> |
Willy Tarreau | c6d61d7 | 2020-06-04 19:02:42 +0200 | [diff] [blame] | 30 | #include <haproxy/trace.h> |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 31 | |
| 32 | struct list trace_sources = LIST_HEAD_INIT(trace_sources); |
Willy Tarreau | 88ebd40 | 2019-08-19 15:55:34 +0200 | [diff] [blame] | 33 | THREAD_LOCAL struct buffer trace_buf = { }; |
| 34 | |
| 35 | /* allocates the trace buffers. Returns 0 in case of failure. It is safe to |
| 36 | * call to call this function multiple times if the size changes. |
| 37 | */ |
| 38 | static int alloc_trace_buffers_per_thread() |
| 39 | { |
| 40 | chunk_init(&trace_buf, my_realloc2(trace_buf.area, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2e7fdfc | 2019-11-25 19:43:31 +0100 | [diff] [blame] | 41 | return !!trace_buf.area; |
Willy Tarreau | 88ebd40 | 2019-08-19 15:55:34 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void free_trace_buffers_per_thread() |
| 45 | { |
| 46 | chunk_destroy(&trace_buf); |
| 47 | } |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 48 | |
Willy Tarreau | 88ebd40 | 2019-08-19 15:55:34 +0200 | [diff] [blame] | 49 | REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread); |
| 50 | REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread); |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 51 | |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 52 | /* pick the lowest non-null argument with a non-null arg_def mask */ |
| 53 | static inline const void *trace_pick_arg(uint32_t arg_def, const void *a1, const void *a2, const void *a3, const void *a4) |
| 54 | { |
| 55 | if (arg_def & 0x0000FFFF) { |
| 56 | if ((arg_def & 0x000000FF) && a1) |
| 57 | return a1; |
| 58 | if ((arg_def & 0x0000FF00) && a2) |
| 59 | return a2; |
| 60 | } |
| 61 | |
| 62 | if (arg_def & 0xFFFF0000) { |
| 63 | if ((arg_def & 0x00FF0000) && a3) |
| 64 | return a3; |
| 65 | if ((arg_def & 0xFF000000) && a4) |
| 66 | return a4; |
| 67 | } |
| 68 | |
| 69 | return NULL; |
| 70 | } |
| 71 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 72 | /* write a message for the given trace source */ |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 73 | void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, |
| 74 | const struct ist where, const char *func, |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame] | 75 | const void *a1, const void *a2, const void *a3, const void *a4, |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 76 | void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, |
| 77 | const struct ist where, const struct ist func, |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame] | 78 | const void *a1, const void *a2, const void *a3, const void *a4), |
| 79 | const struct ist msg) |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 80 | { |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 81 | const struct listener *li = NULL; |
| 82 | const struct proxy *fe = NULL; |
| 83 | const struct proxy *be = NULL; |
| 84 | const struct server *srv = NULL; |
| 85 | const struct session *sess = NULL; |
| 86 | const struct stream *strm = NULL; |
| 87 | const struct connection *conn = NULL; |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 88 | const struct check *check = NULL; |
Amaury Denoyelle | baea964 | 2021-12-21 11:26:02 +0100 | [diff] [blame] | 89 | #ifdef USE_QUIC |
| 90 | const struct quic_conn *qc = NULL; |
| 91 | #endif |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 92 | const void *lockon_ptr = NULL; |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 93 | struct ist ist_func = ist(func); |
Willy Tarreau | a9f5b96 | 2019-08-28 10:08:58 +0200 | [diff] [blame] | 94 | char tnum[4]; |
Willy Tarreau | 052ad36 | 2019-08-29 09:08:36 +0200 | [diff] [blame] | 95 | struct ist line[12]; |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 96 | int words = 0; |
Willy Tarreau | 419bd49 | 2019-08-12 17:27:09 +0200 | [diff] [blame] | 97 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 98 | if (likely(src->state == TRACE_STATE_STOPPED)) |
| 99 | return; |
| 100 | |
| 101 | /* check that at least one action is interested by this event */ |
| 102 | if (((src->report_events | src->start_events | src->pause_events | src->stop_events) & mask) == 0) |
| 103 | return; |
| 104 | |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 105 | /* retrieve available information from the caller's arguments */ |
| 106 | if (src->arg_def & TRC_ARGS_CONN) |
| 107 | conn = trace_pick_arg(src->arg_def & TRC_ARGS_CONN, a1, a2, a3, a4); |
| 108 | |
| 109 | if (src->arg_def & TRC_ARGS_SESS) |
| 110 | sess = trace_pick_arg(src->arg_def & TRC_ARGS_SESS, a1, a2, a3, a4); |
| 111 | |
| 112 | if (src->arg_def & TRC_ARGS_STRM) |
| 113 | strm = trace_pick_arg(src->arg_def & TRC_ARGS_STRM, a1, a2, a3, a4); |
| 114 | |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 115 | if (src->arg_def & TRC_ARGS_CHK) |
| 116 | check = trace_pick_arg(src->arg_def & TRC_ARGS_CHK, a1, a2, a3, a4); |
| 117 | |
Amaury Denoyelle | baea964 | 2021-12-21 11:26:02 +0100 | [diff] [blame] | 118 | #ifdef USE_QUIC |
| 119 | if (src->arg_def & TRC_ARGS_QCON) |
| 120 | qc = trace_pick_arg(src->arg_def & TRC_ARGS_QCON, a1, a2, a3, a4); |
| 121 | #endif |
| 122 | |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 123 | if (!sess && strm) |
| 124 | sess = strm->sess; |
Willy Tarreau | 6e805da | 2022-03-18 17:37:20 +0100 | [diff] [blame] | 125 | else if (!sess && conn && LIST_INLIST(&conn->session_list)) |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 126 | sess = conn->owner; |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 127 | else if (!sess && check) |
| 128 | sess = check->sess; |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 129 | |
| 130 | if (sess) { |
| 131 | fe = sess->fe; |
| 132 | li = sess->listener; |
| 133 | } |
| 134 | |
| 135 | if (!li && conn) |
| 136 | li = objt_listener(conn->target); |
| 137 | |
| 138 | if (li && !fe) |
| 139 | fe = li->bind_conf->frontend; |
| 140 | |
| 141 | if (strm) { |
| 142 | be = strm->be; |
| 143 | srv = strm->srv_conn; |
| 144 | } |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 145 | if (check) { |
| 146 | srv = check->server; |
| 147 | be = srv->proxy; |
| 148 | } |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 149 | |
| 150 | if (!srv && conn) |
| 151 | srv = objt_server(conn->target); |
| 152 | |
| 153 | if (srv && !be) |
| 154 | be = srv->proxy; |
| 155 | |
| 156 | if (!be && conn) |
| 157 | be = objt_proxy(conn->target); |
| 158 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 159 | /* TODO: add handling of filters here, return if no match (not even update states) */ |
| 160 | |
| 161 | /* check if we need to start the trace now */ |
| 162 | if (src->state == TRACE_STATE_WAITING) { |
| 163 | if ((src->start_events & mask) == 0) |
| 164 | return; |
| 165 | |
| 166 | /* TODO: add update of lockon+lockon_ptr here */ |
| 167 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_RUNNING); |
| 168 | } |
| 169 | |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 170 | /* we may want to lock on a particular object */ |
| 171 | if (src->lockon != TRACE_LOCKON_NOTHING) { |
| 172 | switch (src->lockon) { |
| 173 | case TRACE_LOCKON_BACKEND: lockon_ptr = be; break; |
| 174 | case TRACE_LOCKON_CONNECTION: lockon_ptr = conn; break; |
| 175 | case TRACE_LOCKON_FRONTEND: lockon_ptr = fe; break; |
| 176 | case TRACE_LOCKON_LISTENER: lockon_ptr = li; break; |
| 177 | case TRACE_LOCKON_SERVER: lockon_ptr = srv; break; |
| 178 | case TRACE_LOCKON_SESSION: lockon_ptr = sess; break; |
| 179 | case TRACE_LOCKON_STREAM: lockon_ptr = strm; break; |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 180 | case TRACE_LOCKON_CHECK: lockon_ptr = check; break; |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 181 | case TRACE_LOCKON_THREAD: lockon_ptr = ti; break; |
Amaury Denoyelle | baea964 | 2021-12-21 11:26:02 +0100 | [diff] [blame] | 182 | #ifdef USE_QUIC |
| 183 | case TRACE_LOCKON_QCON: lockon_ptr = qc; break; |
| 184 | #endif |
Willy Tarreau | d8b99ed | 2019-08-21 17:05:46 +0200 | [diff] [blame] | 185 | case TRACE_LOCKON_ARG1: lockon_ptr = a1; break; |
| 186 | case TRACE_LOCKON_ARG2: lockon_ptr = a2; break; |
| 187 | case TRACE_LOCKON_ARG3: lockon_ptr = a3; break; |
| 188 | case TRACE_LOCKON_ARG4: lockon_ptr = a4; break; |
| 189 | default: break; // silence stupid gcc -Wswitch |
| 190 | } |
| 191 | |
| 192 | if (src->lockon_ptr && src->lockon_ptr != lockon_ptr) |
| 193 | return; |
| 194 | |
| 195 | if (!src->lockon_ptr && lockon_ptr && src->state == TRACE_STATE_RUNNING) |
| 196 | HA_ATOMIC_STORE(&src->lockon_ptr, lockon_ptr); |
| 197 | } |
| 198 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 199 | /* here the trace is running and is tracking a desired item */ |
| 200 | |
Willy Tarreau | 5da4088 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 201 | if ((src->report_events & mask) == 0 || level > src->level) |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 202 | goto end; |
| 203 | |
Willy Tarreau | 419bd49 | 2019-08-12 17:27:09 +0200 | [diff] [blame] | 204 | /* log the logging location truncated to 10 chars from the right so that |
| 205 | * the line number and the end of the file name are there. |
| 206 | */ |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 207 | line[words++] = ist("["); |
Willy Tarreau | a9f5b96 | 2019-08-28 10:08:58 +0200 | [diff] [blame] | 208 | tnum[0] = '0' + tid / 10; |
| 209 | tnum[1] = '0' + tid % 10; |
| 210 | tnum[2] = '|'; |
| 211 | tnum[3] = 0; |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 212 | line[words++] = ist(tnum); |
| 213 | line[words++] = src->name; |
| 214 | line[words++] = ist("|"); |
Frédéric Lécaille | fd18314 | 2020-12-02 16:51:00 +0100 | [diff] [blame] | 215 | line[words++] = ist2("012345" + level, 1); // "0" to "5" |
Willy Tarreau | 052ad36 | 2019-08-29 09:08:36 +0200 | [diff] [blame] | 216 | line[words++] = ist("|"); |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 217 | line[words] = where; |
| 218 | if (line[words].len > 13) { |
| 219 | line[words].ptr += (line[words].len - 13); |
| 220 | line[words].len = 13; |
Willy Tarreau | 419bd49 | 2019-08-12 17:27:09 +0200 | [diff] [blame] | 221 | } |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 222 | words++; |
| 223 | line[words++] = ist("] "); |
| 224 | |
Tim Duesterhus | 7b5777d | 2021-03-02 18:57:28 +0100 | [diff] [blame] | 225 | if (isttest(ist_func)) { |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 226 | line[words++] = ist_func; |
| 227 | line[words++] = ist("(): "); |
| 228 | } |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame] | 229 | |
Willy Tarreau | 3da0026 | 2019-08-28 07:03:58 +0200 | [diff] [blame] | 230 | if (!cb) |
| 231 | cb = src->default_cb; |
| 232 | |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 233 | if (cb && src->verbosity) { |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame] | 234 | /* decode function passed, we want to pre-fill the |
| 235 | * buffer with the message and let the decode function |
| 236 | * do its job, possibly even overwriting it. |
| 237 | */ |
| 238 | b_reset(&trace_buf); |
| 239 | b_istput(&trace_buf, msg); |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 240 | cb(level, mask, src, where, ist_func, a1, a2, a3, a4); |
Tim Duesterhus | 92c696e | 2021-02-28 16:11:36 +0100 | [diff] [blame] | 241 | line[words] = ist2(trace_buf.area, trace_buf.data); |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 242 | words++; |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame] | 243 | } |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 244 | else { |
| 245 | /* Note that here we could decide to print some args whose type |
| 246 | * is known, when verbosity is above the quiet level, and even |
| 247 | * to print the name and values of those which are declared for |
| 248 | * lock-on. |
| 249 | */ |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 250 | line[words++] = msg; |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 251 | } |
Willy Tarreau | 419bd49 | 2019-08-12 17:27:09 +0200 | [diff] [blame] | 252 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 253 | if (src->sink) |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 254 | sink_write(src->sink, line, words, 0, 0, NULL); |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 255 | |
| 256 | end: |
| 257 | /* check if we need to stop the trace now */ |
| 258 | if ((src->stop_events & mask) != 0) { |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 259 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 260 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_STOPPED); |
| 261 | } |
| 262 | else if ((src->pause_events & mask) != 0) { |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 263 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 264 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_WAITING); |
| 265 | } |
| 266 | } |
| 267 | |
Willy Tarreau | 4de2cda | 2022-03-02 14:53:00 +0100 | [diff] [blame] | 268 | /* registers trace source <source>. Modifies the list element! |
| 269 | * The {start,pause,stop,report} events are not changed so the source may |
| 270 | * preset them. |
| 271 | */ |
| 272 | void trace_register_source(struct trace_source *source) |
| 273 | { |
| 274 | source->lockon = TRACE_LOCKON_NOTHING; |
| 275 | source->level = TRACE_LEVEL_USER; |
| 276 | source->verbosity = 1; |
| 277 | source->sink = NULL; |
| 278 | source->state = TRACE_STATE_STOPPED; |
| 279 | source->lockon_ptr = NULL; |
| 280 | LIST_APPEND(&trace_sources, &source->source_link); |
| 281 | } |
| 282 | |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 283 | struct trace_source *trace_find_source(const char *name) |
| 284 | { |
| 285 | struct trace_source *src; |
| 286 | const struct ist iname = ist(name); |
| 287 | |
| 288 | list_for_each_entry(src, &trace_sources, source_link) |
| 289 | if (isteq(src->name, iname)) |
| 290 | return src; |
| 291 | return NULL; |
| 292 | } |
| 293 | |
| 294 | const struct trace_event *trace_find_event(const struct trace_event *ev, const char *name) |
| 295 | { |
| 296 | for (; ev && ev->mask; ev++) |
| 297 | if (strcmp(ev->name, name) == 0) |
| 298 | return ev; |
| 299 | return NULL; |
| 300 | } |
| 301 | |
| 302 | /* parse the command, returns 1 if a message is returned, otherwise zero */ |
| 303 | static int cli_parse_trace(char **args, char *payload, struct appctx *appctx, void *private) |
| 304 | { |
| 305 | struct trace_source *src; |
| 306 | uint64_t *ev_ptr = NULL; |
| 307 | |
| 308 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 309 | return 1; |
| 310 | |
| 311 | if (!*args[1]) { |
| 312 | /* no arg => report the list of supported sources as a warning */ |
| 313 | chunk_printf(&trash, |
| 314 | "Supported trace sources and states (.=stopped, w=waiting, R=running) :\n" |
| 315 | " [.] 0 : not a source, will immediately stop all traces\n" |
| 316 | ); |
| 317 | |
| 318 | list_for_each_entry(src, &trace_sources, source_link) |
| 319 | chunk_appendf(&trash, " [%c] %-10s : %s\n", trace_state_char(src->state), src->name.ptr, src->desc); |
| 320 | |
| 321 | trash.area[trash.data] = 0; |
| 322 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 323 | } |
| 324 | |
| 325 | if (strcmp(args[1], "0") == 0) { |
| 326 | /* emergency stop of all traces */ |
| 327 | list_for_each_entry(src, &trace_sources, source_link) |
| 328 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_STOPPED); |
| 329 | return cli_msg(appctx, LOG_NOTICE, "All traces now stopped"); |
| 330 | } |
| 331 | |
| 332 | src = trace_find_source(args[1]); |
| 333 | if (!src) |
| 334 | return cli_err(appctx, "No such trace source"); |
| 335 | |
| 336 | if (!*args[2]) { |
| 337 | return cli_msg(appctx, LOG_WARNING, |
| 338 | "Supported commands:\n" |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 339 | " event : list/enable/disable source-specific event reporting\n" |
| 340 | //" filter : list/enable/disable generic filters\n" |
| 341 | " level : list/set trace reporting level\n" |
| 342 | " lock : automatic lock on thread/connection/stream/...\n" |
| 343 | " pause : pause and automatically restart after a specific event\n" |
| 344 | " sink : list/set event sinks\n" |
| 345 | " start : start immediately or after a specific event\n" |
| 346 | " stop : stop immediately or after a specific event\n" |
| 347 | " verbosity : list/set trace output verbosity\n" |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 348 | ); |
| 349 | } |
| 350 | else if ((strcmp(args[2], "event") == 0 && (ev_ptr = &src->report_events)) || |
| 351 | (strcmp(args[2], "pause") == 0 && (ev_ptr = &src->pause_events)) || |
| 352 | (strcmp(args[2], "start") == 0 && (ev_ptr = &src->start_events)) || |
| 353 | (strcmp(args[2], "stop") == 0 && (ev_ptr = &src->stop_events))) { |
| 354 | const struct trace_event *ev; |
| 355 | const char *name = args[3]; |
| 356 | int neg = 0; |
| 357 | int i; |
| 358 | |
| 359 | /* skip prefix '!', '-', '+' and remind negation */ |
| 360 | while (*name) { |
| 361 | if (*name == '!' || *name == '-') |
| 362 | neg = 1; |
| 363 | else if (*name == '+') |
| 364 | neg = 0; |
| 365 | else |
| 366 | break; |
| 367 | name++; |
| 368 | } |
| 369 | |
| 370 | if (!*name) { |
| 371 | chunk_printf(&trash, "Supported events for source %s (+=enabled, -=disabled):\n", src->name.ptr); |
| 372 | if (ev_ptr != &src->report_events) |
Willy Tarreau | 99282dd | 2019-08-30 07:37:32 +0200 | [diff] [blame] | 373 | chunk_appendf(&trash, " - now : don't wait for events, immediately change the state\n"); |
| 374 | chunk_appendf(&trash, " - none : disable all event types\n"); |
| 375 | chunk_appendf(&trash, " - any : enable all event types\n"); |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 376 | for (i = 0; src->known_events && src->known_events[i].mask; i++) { |
Willy Tarreau | 99282dd | 2019-08-30 07:37:32 +0200 | [diff] [blame] | 377 | chunk_appendf(&trash, " %c %-12s : %s\n", |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 378 | trace_event_char(*ev_ptr, src->known_events[i].mask), |
| 379 | src->known_events[i].name, src->known_events[i].desc); |
| 380 | } |
| 381 | trash.area[trash.data] = 0; |
| 382 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 383 | } |
| 384 | |
| 385 | if (strcmp(name, "now") == 0 && ev_ptr != &src->report_events) { |
| 386 | HA_ATOMIC_STORE(ev_ptr, 0); |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 387 | if (ev_ptr == &src->pause_events) { |
| 388 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 389 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_WAITING); |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 390 | } |
| 391 | else if (ev_ptr == &src->start_events) { |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 392 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_RUNNING); |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 393 | } |
| 394 | else if (ev_ptr == &src->stop_events) { |
| 395 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 396 | HA_ATOMIC_STORE(&src->state, TRACE_STATE_STOPPED); |
Willy Tarreau | beadb5c | 2019-08-20 18:57:48 +0200 | [diff] [blame] | 397 | } |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | if (strcmp(name, "none") == 0) |
| 402 | HA_ATOMIC_STORE(ev_ptr, 0); |
| 403 | else if (strcmp(name, "any") == 0) |
| 404 | HA_ATOMIC_STORE(ev_ptr, ~0); |
| 405 | else { |
| 406 | ev = trace_find_event(src->known_events, name); |
| 407 | if (!ev) |
| 408 | return cli_err(appctx, "No such trace event"); |
| 409 | |
| 410 | if (!neg) |
| 411 | HA_ATOMIC_OR(ev_ptr, ev->mask); |
| 412 | else |
| 413 | HA_ATOMIC_AND(ev_ptr, ~ev->mask); |
| 414 | } |
| 415 | } |
| 416 | else if (strcmp(args[2], "sink") == 0) { |
| 417 | const char *name = args[3]; |
| 418 | struct sink *sink; |
| 419 | |
| 420 | if (!*name) { |
| 421 | chunk_printf(&trash, "Supported sinks for source %s (*=current):\n", src->name.ptr); |
| 422 | chunk_appendf(&trash, " %c none : no sink\n", src->sink ? ' ' : '*'); |
| 423 | list_for_each_entry(sink, &sink_list, sink_list) { |
| 424 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 425 | src->sink == sink ? '*' : ' ', |
| 426 | sink->name, sink->desc); |
| 427 | } |
| 428 | trash.area[trash.data] = 0; |
| 429 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 430 | } |
| 431 | |
| 432 | if (strcmp(name, "none") == 0) |
| 433 | sink = NULL; |
| 434 | else { |
| 435 | sink = sink_find(name); |
| 436 | if (!sink) |
| 437 | return cli_err(appctx, "No such sink"); |
| 438 | } |
| 439 | |
| 440 | HA_ATOMIC_STORE(&src->sink, sink); |
| 441 | } |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 442 | else if (strcmp(args[2], "level") == 0) { |
| 443 | const char *name = args[3]; |
| 444 | |
| 445 | if (!*name) { |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 446 | chunk_printf(&trash, "Supported trace levels for source %s:\n", src->name.ptr); |
Willy Tarreau | a1f1274 | 2020-12-01 09:46:46 +0100 | [diff] [blame] | 447 | chunk_appendf(&trash, " %c error : report errors\n", |
| 448 | src->level == TRACE_LEVEL_ERROR ? '*' : ' '); |
| 449 | chunk_appendf(&trash, " %c user : also information useful to the end user\n", |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 450 | src->level == TRACE_LEVEL_USER ? '*' : ' '); |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 451 | chunk_appendf(&trash, " %c proto : also protocol-level updates\n", |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 452 | src->level == TRACE_LEVEL_PROTO ? '*' : ' '); |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 453 | chunk_appendf(&trash, " %c state : also report internal state changes\n", |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 454 | src->level == TRACE_LEVEL_STATE ? '*' : ' '); |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 455 | chunk_appendf(&trash, " %c data : also report data transfers\n", |
| 456 | src->level == TRACE_LEVEL_DATA ? '*' : ' '); |
| 457 | chunk_appendf(&trash, " %c developer : also report information useful only to the developer\n", |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 458 | src->level == TRACE_LEVEL_DEVELOPER ? '*' : ' '); |
| 459 | trash.area[trash.data] = 0; |
| 460 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 461 | } |
| 462 | |
Willy Tarreau | a1f1274 | 2020-12-01 09:46:46 +0100 | [diff] [blame] | 463 | if (strcmp(name, "error") == 0) |
| 464 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_ERROR); |
| 465 | else if (strcmp(name, "user") == 0) |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 466 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_USER); |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 467 | else if (strcmp(name, "proto") == 0) |
| 468 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_PROTO); |
| 469 | else if (strcmp(name, "state") == 0) |
| 470 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_STATE); |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 471 | else if (strcmp(name, "data") == 0) |
| 472 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_DATA); |
Willy Tarreau | aaaf411 | 2019-08-12 17:57:57 +0200 | [diff] [blame] | 473 | else if (strcmp(name, "developer") == 0) |
| 474 | HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_DEVELOPER); |
| 475 | else |
| 476 | return cli_err(appctx, "No such trace level"); |
| 477 | } |
Willy Tarreau | 60e4c9f | 2019-08-20 19:24:10 +0200 | [diff] [blame] | 478 | else if (strcmp(args[2], "lock") == 0) { |
| 479 | const char *name = args[3]; |
| 480 | |
| 481 | if (!*name) { |
| 482 | chunk_printf(&trash, "Supported lock-on criteria for source %s:\n", src->name.ptr); |
| 483 | if (src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_STRM)) |
| 484 | chunk_appendf(&trash, " %c backend : lock on the backend that started the trace\n", |
| 485 | src->lockon == TRACE_LOCKON_BACKEND ? '*' : ' '); |
| 486 | |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 487 | if (src->arg_def & TRC_ARGS_CHK) |
| 488 | chunk_appendf(&trash, " %c check : lock on the check that started the trace\n", |
| 489 | src->lockon == TRACE_LOCKON_CHECK ? '*' : ' '); |
| 490 | |
Willy Tarreau | 60e4c9f | 2019-08-20 19:24:10 +0200 | [diff] [blame] | 491 | if (src->arg_def & TRC_ARGS_CONN) |
| 492 | chunk_appendf(&trash, " %c connection : lock on the connection that started the trace\n", |
| 493 | src->lockon == TRACE_LOCKON_CONNECTION ? '*' : ' '); |
| 494 | |
| 495 | if (src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) |
| 496 | chunk_appendf(&trash, " %c frontend : lock on the frontend that started the trace\n", |
| 497 | src->lockon == TRACE_LOCKON_FRONTEND ? '*' : ' '); |
| 498 | |
| 499 | if (src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) |
| 500 | chunk_appendf(&trash, " %c listener : lock on the listener that started the trace\n", |
| 501 | src->lockon == TRACE_LOCKON_LISTENER ? '*' : ' '); |
| 502 | |
| 503 | chunk_appendf(&trash, " %c nothing : do not lock on anything\n", |
| 504 | src->lockon == TRACE_LOCKON_NOTHING ? '*' : ' '); |
| 505 | |
| 506 | if (src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_STRM)) |
| 507 | chunk_appendf(&trash, " %c server : lock on the server that started the trace\n", |
| 508 | src->lockon == TRACE_LOCKON_SERVER ? '*' : ' '); |
| 509 | |
| 510 | if (src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) |
| 511 | chunk_appendf(&trash, " %c session : lock on the session that started the trace\n", |
| 512 | src->lockon == TRACE_LOCKON_SESSION ? '*' : ' '); |
| 513 | |
| 514 | if (src->arg_def & TRC_ARGS_STRM) |
| 515 | chunk_appendf(&trash, " %c stream : lock on the stream that started the trace\n", |
| 516 | src->lockon == TRACE_LOCKON_STREAM ? '*' : ' '); |
| 517 | |
| 518 | chunk_appendf(&trash, " %c thread : lock on the thread that started the trace\n", |
| 519 | src->lockon == TRACE_LOCKON_THREAD ? '*' : ' '); |
| 520 | |
| 521 | if (src->lockon_args && src->lockon_args[0].name) |
| 522 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 523 | src->lockon == TRACE_LOCKON_ARG1 ? '*' : ' ', |
| 524 | src->lockon_args[0].name, src->lockon_args[0].desc); |
| 525 | |
| 526 | if (src->lockon_args && src->lockon_args[1].name) |
| 527 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 528 | src->lockon == TRACE_LOCKON_ARG2 ? '*' : ' ', |
| 529 | src->lockon_args[1].name, src->lockon_args[1].desc); |
| 530 | |
| 531 | if (src->lockon_args && src->lockon_args[2].name) |
| 532 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 533 | src->lockon == TRACE_LOCKON_ARG3 ? '*' : ' ', |
| 534 | src->lockon_args[2].name, src->lockon_args[2].desc); |
| 535 | |
| 536 | if (src->lockon_args && src->lockon_args[3].name) |
| 537 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 538 | src->lockon == TRACE_LOCKON_ARG4 ? '*' : ' ', |
| 539 | src->lockon_args[3].name, src->lockon_args[3].desc); |
| 540 | |
| 541 | trash.area[trash.data] = 0; |
| 542 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 543 | } |
| 544 | else if ((src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_STRM)) && strcmp(name, "backend") == 0) { |
| 545 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_BACKEND); |
| 546 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 547 | } |
Christopher Faulet | 6d80b63 | 2021-04-12 11:53:16 +0200 | [diff] [blame] | 548 | else if ((src->arg_def & TRC_ARGS_CHK) && strcmp(name, "check") == 0) { |
| 549 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_CHECK); |
| 550 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 551 | } |
Willy Tarreau | 60e4c9f | 2019-08-20 19:24:10 +0200 | [diff] [blame] | 552 | else if ((src->arg_def & TRC_ARGS_CONN) && strcmp(name, "connection") == 0) { |
| 553 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_CONNECTION); |
| 554 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 555 | } |
| 556 | else if ((src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) && strcmp(name, "frontend") == 0) { |
| 557 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_FRONTEND); |
| 558 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 559 | } |
| 560 | else if ((src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) && strcmp(name, "listener") == 0) { |
| 561 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_LISTENER); |
| 562 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 563 | } |
| 564 | else if (strcmp(name, "nothing") == 0) { |
| 565 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_NOTHING); |
| 566 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 567 | } |
| 568 | else if ((src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_STRM)) && strcmp(name, "server") == 0) { |
| 569 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_SERVER); |
| 570 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 571 | } |
| 572 | else if ((src->arg_def & (TRC_ARGS_CONN|TRC_ARGS_SESS|TRC_ARGS_STRM)) && strcmp(name, "session") == 0) { |
| 573 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_SESSION); |
| 574 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 575 | } |
| 576 | else if ((src->arg_def & TRC_ARGS_STRM) && strcmp(name, "stream") == 0) { |
| 577 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_STREAM); |
| 578 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 579 | } |
| 580 | else if (strcmp(name, "thread") == 0) { |
| 581 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_THREAD); |
| 582 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 583 | } |
| 584 | else if (src->lockon_args && src->lockon_args[0].name && strcmp(name, src->lockon_args[0].name) == 0) { |
| 585 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_ARG1); |
| 586 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 587 | } |
| 588 | else if (src->lockon_args && src->lockon_args[1].name && strcmp(name, src->lockon_args[1].name) == 0) { |
| 589 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_ARG2); |
| 590 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 591 | } |
| 592 | else if (src->lockon_args && src->lockon_args[2].name && strcmp(name, src->lockon_args[2].name) == 0) { |
| 593 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_ARG3); |
| 594 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 595 | } |
| 596 | else if (src->lockon_args && src->lockon_args[3].name && strcmp(name, src->lockon_args[3].name) == 0) { |
| 597 | HA_ATOMIC_STORE(&src->lockon, TRACE_LOCKON_ARG4); |
| 598 | HA_ATOMIC_STORE(&src->lockon_ptr, NULL); |
| 599 | } |
| 600 | else |
| 601 | return cli_err(appctx, "Unsupported lock-on criterion"); |
| 602 | } |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 603 | else if (strcmp(args[2], "verbosity") == 0) { |
| 604 | const char *name = args[3]; |
| 605 | const struct name_desc *nd; |
| 606 | |
| 607 | if (!*name) { |
| 608 | chunk_printf(&trash, "Supported trace verbosities for source %s:\n", src->name.ptr); |
| 609 | chunk_appendf(&trash, " %c quiet : only report basic information with no decoding\n", |
| 610 | src->verbosity == 0 ? '*' : ' '); |
| 611 | if (!src->decoding || !src->decoding[0].name) { |
| 612 | chunk_appendf(&trash, " %c default : report extra information when available\n", |
| 613 | src->verbosity > 0 ? '*' : ' '); |
| 614 | } else { |
| 615 | for (nd = src->decoding; nd->name && nd->desc; nd++) |
| 616 | chunk_appendf(&trash, " %c %-10s : %s\n", |
| 617 | nd == (src->decoding + src->verbosity - 1) ? '*' : ' ', |
| 618 | nd->name, nd->desc); |
| 619 | } |
| 620 | trash.area[trash.data] = 0; |
| 621 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 622 | } |
| 623 | |
| 624 | if (strcmp(name, "quiet") == 0) |
| 625 | HA_ATOMIC_STORE(&src->verbosity, 0); |
| 626 | else if (!src->decoding || !src->decoding[0].name) { |
| 627 | if (strcmp(name, "default") == 0) |
| 628 | HA_ATOMIC_STORE(&src->verbosity, 1); |
| 629 | else |
| 630 | return cli_err(appctx, "No such verbosity level"); |
| 631 | } else { |
| 632 | for (nd = src->decoding; nd->name && nd->desc; nd++) |
| 633 | if (strcmp(name, nd->name) == 0) |
| 634 | break; |
| 635 | |
| 636 | if (!nd->name || !nd->desc) |
| 637 | return cli_err(appctx, "No such verbosity level"); |
| 638 | |
| 639 | HA_ATOMIC_STORE(&src->verbosity, (nd - src->decoding) + 1); |
| 640 | } |
| 641 | } |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 642 | else |
| 643 | return cli_err(appctx, "Unknown trace keyword"); |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
Willy Tarreau | 85b1575 | 2019-08-12 16:44:33 +0200 | [diff] [blame] | 648 | /* parse the command, returns 1 if a message is returned, otherwise zero */ |
| 649 | static int cli_parse_show_trace(char **args, char *payload, struct appctx *appctx, void *private) |
| 650 | { |
| 651 | struct trace_source *src; |
| 652 | const struct sink *sink; |
| 653 | int i; |
| 654 | |
| 655 | args++; // make args[1] the 1st arg |
| 656 | |
| 657 | if (!*args[1]) { |
| 658 | /* no arg => report the list of supported sources */ |
| 659 | chunk_printf(&trash, |
| 660 | "Supported trace sources and states (.=stopped, w=waiting, R=running) :\n" |
| 661 | ); |
| 662 | |
| 663 | list_for_each_entry(src, &trace_sources, source_link) { |
| 664 | sink = src->sink; |
| 665 | chunk_appendf(&trash, " [%c] %-10s -> %s [drp %u] [%s]\n", |
| 666 | trace_state_char(src->state), src->name.ptr, |
| 667 | sink ? sink->name : "none", |
| 668 | sink ? sink->ctx.dropped : 0, |
| 669 | src->desc); |
| 670 | } |
| 671 | |
| 672 | trash.area[trash.data] = 0; |
| 673 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 674 | } |
| 675 | |
| 676 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 677 | return 1; |
| 678 | |
| 679 | src = trace_find_source(args[1]); |
| 680 | if (!src) |
| 681 | return cli_err(appctx, "No such trace source"); |
| 682 | |
| 683 | sink = src->sink; |
| 684 | chunk_printf(&trash, "Trace status for %s:\n", src->name.ptr); |
| 685 | chunk_appendf(&trash, " - sink: %s [%u dropped]\n", |
| 686 | sink ? sink->name : "none", sink ? sink->ctx.dropped : 0); |
| 687 | |
Willy Tarreau | 99282dd | 2019-08-30 07:37:32 +0200 | [diff] [blame] | 688 | chunk_appendf(&trash, " - event name : report start stop pause\n"); |
Willy Tarreau | 85b1575 | 2019-08-12 16:44:33 +0200 | [diff] [blame] | 689 | for (i = 0; src->known_events && src->known_events[i].mask; i++) { |
Willy Tarreau | 99282dd | 2019-08-30 07:37:32 +0200 | [diff] [blame] | 690 | chunk_appendf(&trash, " %-12s : %c %c %c %c\n", |
Willy Tarreau | 85b1575 | 2019-08-12 16:44:33 +0200 | [diff] [blame] | 691 | src->known_events[i].name, |
| 692 | trace_event_char(src->report_events, src->known_events[i].mask), |
| 693 | trace_event_char(src->start_events, src->known_events[i].mask), |
| 694 | trace_event_char(src->stop_events, src->known_events[i].mask), |
| 695 | trace_event_char(src->pause_events, src->known_events[i].mask)); |
| 696 | } |
| 697 | |
| 698 | trash.area[trash.data] = 0; |
| 699 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 700 | } |
| 701 | |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 702 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 703 | { { "trace", NULL }, "trace [<module>|0] [cmd [args...]] : manage live tracing (empty to list, 0 to stop all)", cli_parse_trace, NULL, NULL }, |
| 704 | { { "show", "trace", NULL }, "show trace [<module>] : show live tracing state", cli_parse_show_trace, NULL, NULL }, |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 705 | {{},} |
| 706 | }}; |
| 707 | |
| 708 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 709 | |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 710 | /* |
| 711 | * Local variables: |
| 712 | * c-indent-level: 8 |
| 713 | * c-basic-offset: 8 |
| 714 | * End: |
| 715 | */ |