Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/trace.h |
| 3 | * This file provides definitions for runtime tracing |
| 4 | * |
| 5 | * Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _TYPES_TRACE_H |
| 23 | #define _TYPES_TRACE_H |
| 24 | |
| 25 | #include <common/buffer.h> |
| 26 | #include <common/compat.h> |
| 27 | #include <common/config.h> |
| 28 | #include <common/ist.h> |
| 29 | #include <common/mini-clist.h> |
| 30 | #include <types/sink.h> |
| 31 | |
Willy Tarreau | 17a51c6 | 2019-08-20 18:42:52 +0200 | [diff] [blame] | 32 | /* the macros below define an optional type for each of the 4 args passed to |
| 33 | * the trace() call. When such a type is set, the caller commits to exclusively |
| 34 | * using a valid pointer when this argument is not null. This allows the trace() |
| 35 | * function to automatically start or stop the lock-on mechanism when it detects |
| 36 | * a type that it can dereference such as a connection or a stream. Each value |
| 37 | * is represented as an exclusive bit and each arg is represented by a distinct |
| 38 | * byte. The reason for using a single bit per value is to speed up tests using |
| 39 | * bitmasks. Users must not declare args with multiple bits set for the same arg. |
| 40 | * By default arguments are private, corresponding to value 0. |
| 41 | */ |
| 42 | |
| 43 | /* for use only in macro definitions above */ |
| 44 | #define TRC_ARG_PRIV (0) |
| 45 | #define TRC_ARG_CONN (1 << 0) |
| 46 | #define TRC_ARG_SESS (1 << 1) |
| 47 | #define TRC_ARG_STRM (1 << 2) |
| 48 | |
| 49 | #define TRC_ARG1_PRIV (TRC_ARG_PRIV << 0) |
| 50 | #define TRC_ARG1_CONN (TRC_ARG_CONN << 0) |
| 51 | #define TRC_ARG1_SESS (TRC_ARG_SESS << 0) |
| 52 | #define TRC_ARG1_STRM (TRC_ARG_STRM << 0) |
| 53 | |
| 54 | #define TRC_ARG2_PRIV (TRC_ARG_PRIV << 8) |
| 55 | #define TRC_ARG2_CONN (TRC_ARG_CONN << 8) |
| 56 | #define TRC_ARG2_SESS (TRC_ARG_SESS << 8) |
| 57 | #define TRC_ARG2_STRM (TRC_ARG_STRM << 8) |
| 58 | |
| 59 | #define TRC_ARG3_PRIV (TRC_ARG_PRIV << 16) |
| 60 | #define TRC_ARG3_CONN (TRC_ARG_CONN << 16) |
| 61 | #define TRC_ARG3_SESS (TRC_ARG_SESS << 16) |
| 62 | #define TRC_ARG3_STRM (TRC_ARG_STRM << 16) |
| 63 | |
| 64 | #define TRC_ARG4_PRIV (TRC_ARG_PRIV << 24) |
| 65 | #define TRC_ARG4_CONN (TRC_ARG_CONN << 24) |
| 66 | #define TRC_ARG4_SESS (TRC_ARG_SESS << 24) |
| 67 | #define TRC_ARG4_STRM (TRC_ARG_STRM << 24) |
| 68 | |
| 69 | /* usable to detect the presence of any arg of the desired type */ |
| 70 | #define TRC_ARGS_CONN (TRC_ARG_CONN * 0x01010101U) |
| 71 | #define TRC_ARGS_SESS (TRC_ARG_SESS * 0x01010101U) |
| 72 | #define TRC_ARGS_STRM (TRC_ARG_STRM * 0x01010101U) |
| 73 | |
| 74 | |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 75 | enum trace_state { |
| 76 | TRACE_STATE_STOPPED = 0, // completely disabled |
| 77 | TRACE_STATE_WAITING, // waiting for the start condition to happen |
| 78 | TRACE_STATE_RUNNING, // waiting for the stop or pause conditions |
| 79 | }; |
| 80 | |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 81 | /* trace levels, from least detailed to most detailed. Traces emitted at a |
| 82 | * lower level are always reported at higher levels. |
| 83 | */ |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 84 | enum trace_level { |
| 85 | TRACE_LEVEL_USER = 0, // info useful to the end user |
Willy Tarreau | 2ea549b | 2019-08-29 08:01:48 +0200 | [diff] [blame] | 86 | TRACE_LEVEL_PROTO, // also report protocol-level updates |
| 87 | TRACE_LEVEL_STATE, // also report state changes |
| 88 | TRACE_LEVEL_DATA, // also report data exchanges |
| 89 | TRACE_LEVEL_DEVELOPER, // functions entry/exit and any other developer info |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | enum trace_lockon { |
| 93 | TRACE_LOCKON_NOTHING = 0, // don't lock on anything |
| 94 | TRACE_LOCKON_THREAD, // lock on the thread that started the trace |
| 95 | TRACE_LOCKON_LISTENER, // lock on the listener that started the trace |
| 96 | TRACE_LOCKON_FRONTEND, // lock on the frontend that started the trace |
| 97 | TRACE_LOCKON_BACKEND, // lock on the backend that started the trace |
| 98 | TRACE_LOCKON_SERVER, // lock on the server that started the trace |
| 99 | TRACE_LOCKON_CONNECTION, // lock on the connection that started the trace |
| 100 | TRACE_LOCKON_SESSION, // lock on the session that started the trace |
| 101 | TRACE_LOCKON_STREAM, // lock on the stream that started the trace |
Willy Tarreau | c14eea4 | 2019-08-20 19:22:53 +0200 | [diff] [blame] | 102 | TRACE_LOCKON_ARG1, // lock on arg1, totally source-dependent |
| 103 | TRACE_LOCKON_ARG2, // lock on arg2, totally source-dependent |
| 104 | TRACE_LOCKON_ARG3, // lock on arg3, totally source-dependent |
| 105 | TRACE_LOCKON_ARG4, // lock on arg4, totally source-dependent |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | /* Each trace event maps a name to a mask in an uint64_t. Multiple bits are |
| 109 | * permitted to have composite events. This is supposed to be stored into an |
| 110 | * array terminated by mask 0 (name and desc are then ignored). Names "now", |
| 111 | * "any" and "none" are reserved by the CLI parser for start/pause/stop |
| 112 | * operations.. |
| 113 | */ |
| 114 | struct trace_event { |
| 115 | uint64_t mask; |
| 116 | const char *name; |
| 117 | const char *desc; |
| 118 | }; |
| 119 | |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 120 | /* Regarding the verbosity, if <decoding> is not NULL, it must point to a NULL- |
| 121 | * terminated array of name:description, which will define verbosity levels |
| 122 | * implemented by the decoding callback. The verbosity value will default to |
| 123 | * 1. When verbosity levels are defined, levels 1 and above are described by |
| 124 | * these levels. At level zero, the callback is never called. |
| 125 | */ |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 126 | struct trace_source { |
| 127 | /* source definition */ |
| 128 | const struct ist name; |
| 129 | const char *desc; |
| 130 | const struct trace_event *known_events; |
| 131 | struct list source_link; // element in list of known trace sources |
Willy Tarreau | 3da0026 | 2019-08-28 07:03:58 +0200 | [diff] [blame] | 132 | void (*default_cb)(enum trace_level level, uint64_t mask, |
Willy Tarreau | 09fb0df | 2019-08-29 08:40:59 +0200 | [diff] [blame] | 133 | const struct trace_source *src, |
| 134 | const struct ist where, const struct ist func, |
Willy Tarreau | 3da0026 | 2019-08-28 07:03:58 +0200 | [diff] [blame] | 135 | const void *a1, const void *a2, const void *a3, const void *a4); |
Willy Tarreau | 17a51c6 | 2019-08-20 18:42:52 +0200 | [diff] [blame] | 136 | uint32_t arg_def; // argument definitions (sum of TRC_ARG{1..4}_*) |
Willy Tarreau | be5a288 | 2019-08-29 09:33:42 +0200 | [diff] [blame] | 137 | const struct name_desc *lockon_args; // must be 4 entries if not NULL |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 138 | const struct name_desc *decoding; // null-terminated if not NULL |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 139 | /* trace configuration, adjusted by "trace <module>" on CLI */ |
| 140 | enum trace_lockon lockon; |
| 141 | uint64_t start_events; // what will start the trace. default: 0=nothing |
| 142 | uint64_t pause_events; // what will pause the trace. default: 0=nothing |
| 143 | uint64_t stop_events; // what will stop the trace. default: 0=nothing |
| 144 | uint64_t report_events; // mask of which events need to be reported. |
| 145 | enum trace_level level; // report traces up to this level of info |
Willy Tarreau | 370a694 | 2019-08-29 08:24:16 +0200 | [diff] [blame] | 146 | unsigned int verbosity; // decoder's level of detail among <decoding> (0=no cb) |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 147 | struct sink *sink; // where to send the trace |
| 148 | /* trace state part below */ |
| 149 | enum trace_state state; |
Willy Tarreau | e40f274 | 2019-08-22 20:26:28 +0200 | [diff] [blame] | 150 | const void *lockon_ptr; // what to lockon when lockon is set |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | #endif /* _TYPES_TRACE_H */ |
| 154 | |
| 155 | /* |
| 156 | * Local variables: |
| 157 | * c-indent-level: 8 |
| 158 | * c-basic-offset: 8 |
| 159 | * End: |
| 160 | */ |