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