blob: 6d85f9cbe4d1b7948e1eff3ba1e7f9b7c2c2c59a [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
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 Tarreau17a51c62019-08-20 18:42:52 +020032/* 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 Tarreau4151c752019-08-08 18:21:26 +020075enum 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
81enum trace_level {
82 TRACE_LEVEL_USER = 0, // info useful to the end user
83 TRACE_LEVEL_PAYLOAD, // add info relevant to the payload
84 TRACE_LEVEL_PROTO, // add info relevant to the protocol
85 TRACE_LEVEL_STATE, // add info relevant to the state machine
86 TRACE_LEVEL_DEVELOPER, // add info useful only to the developer
87};
88
89enum trace_lockon {
90 TRACE_LOCKON_NOTHING = 0, // don't lock on anything
91 TRACE_LOCKON_THREAD, // lock on the thread that started the trace
92 TRACE_LOCKON_LISTENER, // lock on the listener that started the trace
93 TRACE_LOCKON_FRONTEND, // lock on the frontend that started the trace
94 TRACE_LOCKON_BACKEND, // lock on the backend that started the trace
95 TRACE_LOCKON_SERVER, // lock on the server that started the trace
96 TRACE_LOCKON_CONNECTION, // lock on the connection that started the trace
97 TRACE_LOCKON_SESSION, // lock on the session that started the trace
98 TRACE_LOCKON_STREAM, // lock on the stream that started the trace
Willy Tarreauc14eea42019-08-20 19:22:53 +020099 TRACE_LOCKON_ARG1, // lock on arg1, totally source-dependent
100 TRACE_LOCKON_ARG2, // lock on arg2, totally source-dependent
101 TRACE_LOCKON_ARG3, // lock on arg3, totally source-dependent
102 TRACE_LOCKON_ARG4, // lock on arg4, totally source-dependent
Willy Tarreau4151c752019-08-08 18:21:26 +0200103};
104
105/* Each trace event maps a name to a mask in an uint64_t. Multiple bits are
106 * permitted to have composite events. This is supposed to be stored into an
107 * array terminated by mask 0 (name and desc are then ignored). Names "now",
108 * "any" and "none" are reserved by the CLI parser for start/pause/stop
109 * operations..
110 */
111struct trace_event {
112 uint64_t mask;
113 const char *name;
114 const char *desc;
115};
116
Willy Tarreauc14eea42019-08-20 19:22:53 +0200117/* add a name and description for each arg that we know we can track. Those
118 * with a non-null name will be presented in the menu and will be usable for
119 * trace lock-on.
120 */
121struct trace_lockon_arg {
122 const char *name;
123 const char *desc;
124};
125
Willy Tarreau4151c752019-08-08 18:21:26 +0200126struct 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 Tarreau17a51c62019-08-20 18:42:52 +0200132 uint32_t arg_def; // argument definitions (sum of TRC_ARG{1..4}_*)
Willy Tarreauc14eea42019-08-20 19:22:53 +0200133 const struct trace_lockon_arg *lockon_args; // must be 4 entries if not NULL
Willy Tarreau4151c752019-08-08 18:21:26 +0200134 /* trace configuration, adjusted by "trace <module>" on CLI */
135 enum trace_lockon lockon;
136 uint64_t start_events; // what will start the trace. default: 0=nothing
137 uint64_t pause_events; // what will pause the trace. default: 0=nothing
138 uint64_t stop_events; // what will stop the trace. default: 0=nothing
139 uint64_t report_events; // mask of which events need to be reported.
140 enum trace_level level; // report traces up to this level of info
141 int detail_level; // report events with this level of detail (LOG_*)
142 struct sink *sink; // where to send the trace
143 /* trace state part below */
144 enum trace_state state;
145 void *lockon_ptr; // what to lockon when lockon is set
146};
147
148#endif /* _TYPES_TRACE_H */
149
150/*
151 * Local variables:
152 * c-indent-level: 8
153 * c-basic-offset: 8
154 * End:
155 */