Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/trace.h |
| 3 | * This file provides functions 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 _PROTO_TRACE_H |
| 23 | #define _PROTO_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/log.h> |
| 31 | #include <types/sink.h> |
| 32 | #include <types/trace.h> |
| 33 | |
| 34 | extern struct list trace_sources; |
Willy Tarreau | 88ebd40 | 2019-08-19 15:55:34 +0200 | [diff] [blame] | 35 | extern THREAD_LOCAL struct buffer trace_buf; |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 36 | |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame^] | 37 | void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where, |
| 38 | const void *a1, const void *a2, const void *a3, const void *a4, |
| 39 | void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where, |
| 40 | const void *a1, const void *a2, const void *a3, const void *a4), |
| 41 | const struct ist msg); |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 42 | |
Willy Tarreau | 864e880 | 2019-08-08 18:48:12 +0200 | [diff] [blame] | 43 | /* return a single char to describe a trace state */ |
| 44 | static inline char trace_state_char(enum trace_state st) |
| 45 | { |
| 46 | return (st == TRACE_STATE_RUNNING) ? 'R' : |
| 47 | (st == TRACE_STATE_WAITING) ? 'w' : |
| 48 | '.'; |
| 49 | } |
| 50 | |
| 51 | /* return a single char to describe an event state */ |
| 52 | static inline char trace_event_char(uint64_t conf, uint64_t ev) |
| 53 | { |
| 54 | return (conf & ev) ? '+' : '-'; |
| 55 | } |
| 56 | |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 57 | /* registers trace source <source>. Modifies the list element! |
| 58 | * The {start,pause,stop,report} events are not changed so the source may |
| 59 | * preset them. |
| 60 | */ |
| 61 | static inline void trace_register_source(struct trace_source *source) |
| 62 | { |
| 63 | source->lockon = TRACE_LOCKON_NOTHING; |
| 64 | source->level = TRACE_LEVEL_USER; |
| 65 | source->detail_level = LOG_NOTICE; |
| 66 | source->sink = NULL; |
| 67 | source->state = TRACE_STATE_STOPPED; |
| 68 | source->lockon_ptr = NULL; |
| 69 | LIST_ADDQ(&trace_sources, &source->source_link); |
| 70 | } |
| 71 | |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 72 | /* sends a trace for the given source */ |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame^] | 73 | static inline void trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where, |
| 74 | const void *a1, const void *a2, const void *a3, const void *a4, |
| 75 | void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where, |
| 76 | const void *a1, const void *a2, const void *a3, const void *a4), |
| 77 | const struct ist msg) |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 78 | { |
| 79 | if (unlikely(src->state != TRACE_STATE_STOPPED)) |
Willy Tarreau | bfd14fc | 2019-08-19 16:28:07 +0200 | [diff] [blame^] | 80 | __trace(level, mask, src, where, a1, a2, a3, a4, cb, msg); |
Willy Tarreau | 4c2ae48 | 2019-08-12 15:51:58 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Willy Tarreau | 4151c75 | 2019-08-08 18:21:26 +0200 | [diff] [blame] | 83 | #endif /* _PROTO_TRACE_H */ |
| 84 | |
| 85 | /* |
| 86 | * Local variables: |
| 87 | * c-indent-level: 8 |
| 88 | * c-basic-offset: 8 |
| 89 | * End: |
| 90 | */ |