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