blob: 537ac32c7c948a061ca2878c2357515b88a13293 [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 Tarreaueb6f7012020-05-27 16:21:26 +020026#include <import/ist.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020027#include <haproxy/list-t.h>
Willy Tarreauba2f73d2020-06-03 20:02:28 +020028#include <haproxy/sink-t.h>
Willy Tarreau4151c752019-08-08 18:21:26 +020029
Willy Tarreau17a51c62019-08-20 18:42:52 +020030/* 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 Tarreau4151c752019-08-08 18:21:26 +020073enum 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 Tarreau2ea549b2019-08-29 08:01:48 +020079/* trace levels, from least detailed to most detailed. Traces emitted at a
80 * lower level are always reported at higher levels.
81 */
Willy Tarreau4151c752019-08-08 18:21:26 +020082enum trace_level {
83 TRACE_LEVEL_USER = 0, // info useful to the end user
Willy Tarreau2ea549b2019-08-29 08:01:48 +020084 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 Tarreau4151c752019-08-08 18:21:26 +020088};
89
90enum 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 Tarreauc14eea42019-08-20 19:22:53 +0200100 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 Tarreau4151c752019-08-08 18:21:26 +0200104};
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 */
112struct trace_event {
113 uint64_t mask;
114 const char *name;
115 const char *desc;
116};
117
Willy Tarreau370a6942019-08-29 08:24:16 +0200118/* 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 Tarreau4151c752019-08-08 18:21:26 +0200124struct 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 Tarreau3da00262019-08-28 07:03:58 +0200130 void (*default_cb)(enum trace_level level, uint64_t mask,
Willy Tarreau09fb0df2019-08-29 08:40:59 +0200131 const struct trace_source *src,
132 const struct ist where, const struct ist func,
Willy Tarreau3da00262019-08-28 07:03:58 +0200133 const void *a1, const void *a2, const void *a3, const void *a4);
Willy Tarreau17a51c62019-08-20 18:42:52 +0200134 uint32_t arg_def; // argument definitions (sum of TRC_ARG{1..4}_*)
Willy Tarreaube5a2882019-08-29 09:33:42 +0200135 const struct name_desc *lockon_args; // must be 4 entries if not NULL
Willy Tarreau370a6942019-08-29 08:24:16 +0200136 const struct name_desc *decoding; // null-terminated if not NULL
Willy Tarreau4151c752019-08-08 18:21:26 +0200137 /* 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 Tarreau370a6942019-08-29 08:24:16 +0200144 unsigned int verbosity; // decoder's level of detail among <decoding> (0=no cb)
Willy Tarreau4151c752019-08-08 18:21:26 +0200145 struct sink *sink; // where to send the trace
146 /* trace state part below */
147 enum trace_state state;
Willy Tarreaue40f2742019-08-22 20:26:28 +0200148 const void *lockon_ptr; // what to lockon when lockon is set
Willy Tarreau4151c752019-08-08 18:21:26 +0200149};
150
151#endif /* _TYPES_TRACE_H */
152
153/*
154 * Local variables:
155 * c-indent-level: 8
156 * c-basic-offset: 8
157 * End:
158 */