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