library mass rename: add lttng- prefix
[lttng-ust.git] / include / lttng / marker.h
CommitLineData
535b0d0a
MD
1#ifndef _UST_MARKER_H
2#define _UST_MARKER_H
3
a72ca31a
PMF
4/*
5 * Code markup for dynamic and static tracing.
6 *
7 * See Documentation/marker.txt.
8 *
9 * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
59b161cd 10 * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca>
fe566790 11 * (C) Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
a72ca31a 12 *
8fc2d8db
PMF
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
f37142a4
MD
15 * License as published by the Free Software Foundation;
16 * version 2.1 of the License.
8fc2d8db
PMF
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a72ca31a
PMF
26 */
27
28#include <stdarg.h>
9edd34bd
MD
29#include <stdint.h>
30#include <stddef.h>
535b0d0a 31#include <bits/wordsize.h>
22d9080d 32#include <urcu/list.h>
59b161cd 33
1ea2c2df
MD
34#ifdef __cplusplus
35extern "C" {
36#endif
37
b521931e 38struct ust_marker;
fd0a1aea 39struct ust_marker_probe_array;
a72ca31a
PMF
40
41/**
b521931e 42 * ust_marker_probe_func - Type of a marker probe function
a72ca31a
PMF
43 * @mdata: marker data
44 * @probe_private: probe private data
45 * @call_private: call site private data
46 * @fmt: format string
47 * @args: variable argument list pointer. Use a pointer to overcome C's
48 * inability to pass this around as a pointer in a portable manner in
49 * the callee otherwise.
50 *
51 * Type of marker probe functions. They receive the mdata and need to parse the
52 * format string to recover the variable argument list.
53 */
b521931e 54typedef void ust_marker_probe_func(const struct ust_marker *mdata,
fe566790 55 void *probe_private, void *call_private,
a72ca31a
PMF
56 const char *fmt, va_list *args);
57
b521931e
MD
58struct ust_marker_probe_closure {
59 ust_marker_probe_func *func; /* Callback */
a72ca31a
PMF
60 void *probe_private; /* Private probe data */
61};
62
b521931e 63struct ust_marker {
a72ca31a
PMF
64 const char *channel; /* Name of channel where to send data */
65 const char *name; /* Marker name */
66 const char *format; /* Marker format string, describing the
67 * variable argument list.
68 */
f36c12ab 69 char state; /* State. */
a72ca31a
PMF
70 char ptype; /* probe type : 0 : single, 1 : multi */
71 /* Probe wrapper */
9edd34bd
MD
72 uint16_t channel_id; /* Numeric channel identifier, dynamic */
73 uint16_t event_id; /* Numeric event identifier, dynamic */
fe566790 74 void (*call)(const struct ust_marker *mdata, void *call_private, ...);
b521931e 75 struct ust_marker_probe_closure single;
fd0a1aea 76 struct ust_marker_probe_array *multi;
a72ca31a
PMF
77 const char *tp_name; /* Optional tracepoint name */
78 void *tp_cb; /* Optional tracepoint callback */
eb5d20c6 79};
a72ca31a 80
fe566790
MD
81/*
82 * We keep the "channel" as internal field for marker.c *only*. It will be
83 * removed soon.
84 */
7166e240 85
fe566790
MD
86/*
87 * __ust_marker_ptrs section is not const (read-only) because it needs to be
88 * read-write to let the linker apply relocations and keep the object PIC.
89 */
90#define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format) \
7166e240 91 static const char __mstrtab_##channel##_##name[] \
fe566790 92 __attribute__((section("__ust_markers_strings"))) \
7166e240 93 = #channel "\0" #name "\0" format; \
fe566790
MD
94 static struct ust_marker __ust_marker_def_##name \
95 __attribute__((section("__ust_markers"))) = \
7166e240 96 { __mstrtab_##channel##_##name, \
fe566790
MD
97 &__mstrtab_##channel##_##name[sizeof(#channel)], \
98 &__mstrtab_##channel##_##name[sizeof(#channel) + \
99 sizeof(#name)], \
100 0, 0, 0, 0, ust_marker_probe_cb, \
101 { __ust_marker_empty_function, NULL}, \
102 NULL, tp_name_str, tp_cb }; \
103 static struct ust_marker * __ust_marker_ptr_##name \
535b0d0a 104 __attribute__((used, section("__ust_marker_ptrs"))) = \
fe566790
MD
105 &__ust_marker_def_##name
106
a72ca31a 107/*
b521931e 108 * Make sure the alignment of the structure in the __ust_marker section will
a72ca31a
PMF
109 * not add unwanted padding between the beginning of the section and the
110 * structure. Force alignment to the same alignment as the section start.
a72ca31a 111 */
bb9ade29 112
fe566790 113#define __ust_marker(channel, name, call_private, format, args...) \
a72ca31a 114 do { \
fe566790 115 _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \
b521931e 116 __ust_marker_check_format(format, ## args); \
9edd34bd 117 if (__builtin_expect(!!(__ust_marker_def_##name.state), 0)) \
fe566790
MD
118 (__ust_marker_def_##name.call) \
119 (&__ust_marker_def_##name, call_private,\
120 ## args); \
a72ca31a
PMF
121 } while (0)
122
a72ca31a 123/**
686debc3 124 * ust_marker - Marker using code patching
a72ca31a
PMF
125 * @name: marker name, not quoted.
126 * @format: format string
127 * @args...: variable argument list
128 *
f36c12ab 129 * Places a marker at caller site.
a72ca31a 130 */
686debc3 131#define ust_marker(name, format, args...) \
f36c12ab 132 __ust_marker(ust, name, NULL, format, ## args)
a72ca31a 133
67a61c67
MD
134static inline __attribute__((deprecated))
135void __trace_mark_is_deprecated()
136{
137}
5389de4d 138
a72ca31a 139/**
b521931e 140 * UST_MARKER_NOARGS - Format string for a marker with no argument.
a72ca31a 141 */
b521931e 142#define UST_MARKER_NOARGS " "
a72ca31a 143
a72ca31a 144/* To be used for string format validity checking with gcc */
535b0d0a 145static inline
9edd34bd
MD
146void __attribute__((format(printf, 1, 2)))
147 ___ust_marker_check_format(const char *fmt, ...)
a72ca31a
PMF
148{
149}
150
b521931e 151#define __ust_marker_check_format(format, args...) \
a72ca31a
PMF
152 do { \
153 if (0) \
b521931e 154 ___ust_marker_check_format(format, ## args); \
a72ca31a
PMF
155 } while (0)
156
b521931e 157extern ust_marker_probe_func __ust_marker_empty_function;
a72ca31a 158
b521931e 159extern void ust_marker_probe_cb(const struct ust_marker *mdata,
fe566790 160 void *call_private, ...);
a72ca31a 161
b521931e
MD
162struct ust_marker_lib {
163 struct ust_marker * const *ust_marker_start;
b521931e 164 int ust_marker_count;
0222e121 165 struct cds_list_head list;
98963de4
PMF
166};
167
b521931e
MD
168#define UST_MARKER_LIB \
169 extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
170 extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
fe566790
MD
171 static struct ust_marker * __ust_marker_ptr_dummy \
172 __attribute__((used, section("__ust_marker_ptrs"))); \
55994a67 173 \
535b0d0a 174 static void __attribute__((constructor)) __ust_marker__init(void) \
55994a67 175 { \
b521931e
MD
176 ust_marker_register_lib(__start___ust_marker_ptrs, \
177 __stop___ust_marker_ptrs \
535b0d0a 178 - __start___ust_marker_ptrs); \
900e307e
MD
179 } \
180 \
535b0d0a 181 static void __attribute__((destructor)) __ust_marker__destroy(void) \
24b6668c 182 { \
b521931e 183 ust_marker_unregister_lib(__start___ust_marker_ptrs); \
55994a67 184 }
98963de4 185
535b0d0a
MD
186extern
187int ust_marker_register_lib(struct ust_marker * const *ust_marker_start,
188 int ust_marker_count);
189extern
190int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start);
67a61c67
MD
191
192/*
535b0d0a 193 * trace_mark() -- DEPRECATED
67a61c67
MD
194 * @channel: name prefix, not quoted. Ignored.
195 * @name: marker name, not quoted.
196 * @format: format string
197 * @args...: variable argument list
198 *
535b0d0a 199 * Kept as a compatibility API and is *DEPRECATED* in favor of
67a61c67
MD
200 * ust_marker().
201 */
202#define trace_mark(channel, name, format, args...) \
203 __trace_mark_is_deprecated(); \
204 ust_marker(name, format, ## args)
205
206static inline __attribute__((deprecated))
207void __MARKER_LIB_IS_DEPRECATED()
208{
209}
210
7a05c99d 211/*
535b0d0a
MD
212 * MARKER_LIB is kept for backward compatibility and is *DEPRECATED*.
213 * Use UST_MARKER_LIB instead.
7a05c99d 214 */
67a61c67
MD
215#define MARKER_LIB \
216 __MARKER_LIB_IS_DEPRECATED(); \
217 UST_MARKER_LIB
7a05c99d 218
67a61c67 219/**
535b0d0a 220 * MARKER_NOARGS - Compatibility API. *DEPRECATED*. Use
67a61c67
MD
221 * UST_MARKER_NOARGS instead.
222 */
223#define MARK_NOARGS UST_MARKER_NOARGS
9160b4e4 224
1ea2c2df
MD
225#ifdef __cplusplus
226}
227#endif
228
defa46a7 229#endif /* _UST_MARKER_H */
This page took 0.038569 seconds and 4 git commands to generate.