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