34272053947bcc7017bb73d1ea25eb47762a16da
1 #ifndef _UST_TRACEPOINT_H
2 #define _UST_TRACEPOINT_H
5 * Copyright (C) 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 * Copyright (C) 2009 Pierre-Marc Fournier
7 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Heavily inspired from the Linux Kernel Markers.
25 * Ported to userspace by Pierre-Marc Fournier.
41 const char *name
; /* Tracepoint name */
42 char state
; /* State. */
46 #define PARAMS(args...) args
48 #define TP_PROTO(args...) args
49 #define TP_ARGS(args...) args
52 * Tracepoints should be added to the instrumented code using the
53 * "tracepoint()" macro.
55 #define tracepoint(name, args...) __trace_##name(args)
57 #define register_tracepoint(name, probe, data) \
58 __register_trace_##name(probe, data)
60 #define unregister_tracepoint(name, probe, data) \
61 __unregister_trace_##name(probe, data)
63 #define CONFIG_TRACEPOINTS
64 #ifdef CONFIG_TRACEPOINTS
67 * it_func[0] is never NULL because there is at least one element in the array
68 * when the array itself is non NULL.
70 #define __DO_TRACE(tp, proto, args) \
72 struct probe *it_probe_ptr; \
77 it_probe_ptr = rcu_dereference((tp)->probes); \
80 it_func = (it_probe_ptr)->func; \
81 __data = (it_probe_ptr)->data; \
82 ((void(*)(proto))(it_func))(args); \
83 } while ((++it_probe_ptr)->func); \
88 #define __CHECK_TRACE(name, proto, args) \
90 if (unlikely(__tracepoint_##name.state)) \
91 __DO_TRACE(&__tracepoint_##name, \
92 TP_PROTO(proto), TP_ARGS(args)); \
96 * Make sure the alignment of the structure in the __tracepoints section will
97 * not add unwanted padding between the beginning of the section and the
98 * structure. Force alignment to the same alignment as the section start.
100 #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
101 extern struct tracepoint __tracepoint_##name; \
102 static inline void __trace_##name(proto) \
104 __CHECK_TRACE(name, TP_PROTO(data_proto), \
105 TP_ARGS(data_args)); \
108 __register_trace_##name(void (*probe)(data_proto), void *data) \
110 return tracepoint_probe_register(#name, (void *)probe, \
115 __unregister_trace_##name(void (*probe)(data_proto), void *data)\
117 return tracepoint_probe_unregister(#name, (void *)probe, \
121 #define DEFINE_TRACE_FN(name, reg, unreg) \
122 static const char __tpstrtab_##name[] \
123 __attribute__((section("__tracepoints_strings"))) = #name; \
124 struct tracepoint __tracepoint_##name \
125 __attribute__((section("__tracepoints"))) = \
126 { __tpstrtab_##name, 0, NULL }; \
127 static struct tracepoint * const __tracepoint_ptr_##name \
128 __attribute__((used, section("__tracepoints_ptrs"))) = \
129 &__tracepoint_##name;
131 #define DEFINE_TRACE(name) \
132 DEFINE_TRACE_FN(name, NULL, NULL)
134 extern void tracepoint_update_probe_range(struct tracepoint
* const *begin
,
135 struct tracepoint
* const *end
);
137 #else /* !CONFIG_TRACEPOINTS */
138 #define __DECLARE_TRACE(name, proto, args) \
139 static inline void trace_##name(proto) \
141 static inline void _trace_##name(proto) \
143 static inline int __register_trace_##name(void (*probe)(proto), void *data) \
147 static inline int __unregister_trace_##name(void (*probe)(proto), void *data) \
152 #define DEFINE_TRACE(name)
153 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
154 #define EXPORT_TRACEPOINT_SYMBOL(name)
156 static inline void tracepoint_update_probe_range(struct tracepoint
*begin
,
157 struct tracepoint
*end
)
159 #endif /* CONFIG_TRACEPOINTS */
162 * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
163 * (void). "void" is a special value in a function prototype and can
164 * not be combined with other arguments. Since the DECLARE_TRACE()
165 * macro adds a data element at the beginning of the prototype,
166 * we need a way to differentiate "(void *data, proto)" from
167 * "(void *data, void)". The second prototype is invalid.
169 * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
170 * and "void *__data" as the callback prototype.
172 * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
173 * "void *__data, proto" as the callback prototype.
175 #define DECLARE_TRACE_NOARGS(name) \
176 __DECLARE_TRACE(name, void, , void *__data, __data)
178 #define DECLARE_TRACE(name, proto, args) \
179 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
180 PARAMS(void *__data, proto), \
181 PARAMS(__data, args))
184 * Connect a probe to a tracepoint.
185 * Internal API, should not be used directly.
187 extern int tracepoint_probe_register(const char *name
, void *probe
, void *data
);
190 * Disconnect a probe from a tracepoint.
191 * Internal API, should not be used directly.
193 extern int tracepoint_probe_unregister(const char *name
, void *probe
, void *data
);
195 extern int tracepoint_probe_register_noupdate(const char *name
, void *probe
,
197 extern int tracepoint_probe_unregister_noupdate(const char *name
, void *probe
,
199 extern void tracepoint_probe_update_all(void);
201 struct tracepoint_iter
{
202 //ust// struct module *module;
203 struct tracepoint_lib
*lib
;
204 struct tracepoint
* const *tracepoint
;
207 extern void tracepoint_iter_start(struct tracepoint_iter
*iter
);
208 extern void tracepoint_iter_next(struct tracepoint_iter
*iter
);
209 extern void tracepoint_iter_stop(struct tracepoint_iter
*iter
);
210 extern void tracepoint_iter_reset(struct tracepoint_iter
*iter
);
211 extern int tracepoint_get_iter_range(struct tracepoint
* const **tracepoint
,
212 struct tracepoint
* const *begin
, struct tracepoint
* const *end
);
215 * tracepoint_synchronize_unregister must be called between the last tracepoint
216 * probe unregistration and the end of module exit to make sure there is no
217 * caller executing a probe when it is freed.
219 static inline void tracepoint_synchronize_unregister(void)
221 //ust// synchronize_sched();
224 struct tracepoint_lib
{
225 struct tracepoint
* const *tracepoints_start
;
226 int tracepoints_count
;
227 struct cds_list_head list
;
230 extern int tracepoint_register_lib(struct tracepoint
* const *tracepoints_start
,
231 int tracepoints_count
);
232 extern int tracepoint_unregister_lib(struct tracepoint
* const *tracepoints_start
);
234 #define TRACEPOINT_LIB \
235 extern struct tracepoint * const __start___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
236 extern struct tracepoint * const __stop___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
237 static struct tracepoint * const __tracepoint_ptr_dummy \
238 __attribute__((used, section("__tracepoints_ptrs"))) = NULL; \
239 static void __attribute__((constructor)) __tracepoints__init(void) \
241 tracepoint_register_lib(__start___tracepoints_ptrs, \
242 __stop___tracepoints_ptrs - \
243 __start___tracepoints_ptrs); \
246 static void __attribute__((destructor)) __tracepoints__destroy(void) \
248 tracepoint_unregister_lib(__start___tracepoints_ptrs); \
254 * For use with the TRACE_EVENT macro:
256 * We define a tracepoint, its arguments, its printf format
257 * and its 'fast binary record' layout.
259 * Firstly, name your tracepoint via TRACE_EVENT(name : the
260 * 'subsystem_event' notation is fine.
262 * Think about this whole construct as the
263 * 'trace_sched_switch() function' from now on.
266 * TRACE_EVENT(sched_switch,
269 * * A function has a regular function arguments
270 * * prototype, declare it via TP_PROTO():
273 * TP_PROTO(struct rq *rq, struct task_struct *prev,
274 * struct task_struct *next),
277 * * Define the call signature of the 'function'.
278 * * (Design sidenote: we use this instead of a
279 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
282 * TP_ARGS(rq, prev, next),
285 * * Fast binary tracing: define the trace record via
286 * * TP_STRUCT__entry(). You can think about it like a
287 * * regular C structure local variable definition.
289 * * This is how the trace record is structured and will
290 * * be saved into the ring buffer. These are the fields
291 * * that will be exposed to readers.
293 * * The declared 'local variable' is called '__entry'
295 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
299 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
301 * * char prev_comm[TASK_COMM_LEN];
305 * __array( char, prev_comm, TASK_COMM_LEN )
306 * __field( pid_t, prev_pid )
307 * __field( int, prev_prio )
308 * __array( char, next_comm, TASK_COMM_LEN )
309 * __field( pid_t, next_pid )
310 * __field( int, next_prio )
314 * * Assign the entry into the trace record, by embedding
315 * * a full C statement block into TP_fast_assign(). You
316 * * can refer to the trace record as '__entry' -
317 * * otherwise you can put arbitrary C code in here.
319 * * Note: this C code will execute every time a trace event
320 * * happens, on an active tracepoint.
324 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
325 * __entry->prev_pid = prev->pid;
326 * __entry->prev_prio = prev->prio;
327 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
328 * __entry->next_pid = next->pid;
329 * __entry->next_prio = next->prio;
333 * * Formatted output of a trace record via TP_printf().
334 * * This is how the tracepoint will appear under debugging
337 * * (raw-binary tracing wont actually perform this step.)
340 * TP_printf("task %s:%d [%d] ==> %s:%d [%d]",
341 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
342 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
346 * This macro construct is thus used for the regular printf format
349 * A set of (un)registration functions can be passed to the variant
350 * TRACE_EVENT_FN to perform any (un)registration work.
355 int (*regfunc
)(void *data
);
356 int (*unregfunc
)(void *data
);
359 struct trace_event_lib
{
360 struct trace_event
* const *trace_events_start
;
361 int trace_events_count
;
362 struct cds_list_head list
;
365 struct trace_event_iter
{
366 struct trace_event_lib
*lib
;
367 struct trace_event
* const *trace_event
;
370 extern void lock_trace_events(void);
371 extern void unlock_trace_events(void);
373 extern void trace_event_iter_start(struct trace_event_iter
*iter
);
374 extern void trace_event_iter_next(struct trace_event_iter
*iter
);
375 extern void trace_event_iter_reset(struct trace_event_iter
*iter
);
377 extern int trace_event_get_iter_range(struct trace_event
* const **trace_event
,
378 struct trace_event
* const *begin
,
379 struct trace_event
* const *end
);
381 extern void trace_event_update_process(void);
382 extern int is_trace_event_enabled(const char *channel
, const char *name
);
384 extern int trace_event_register_lib(struct trace_event
* const *start_trace_events
,
385 int trace_event_count
);
387 extern int trace_event_unregister_lib(struct trace_event
* const *start_trace_events
);
389 #define TRACE_EVENT_LIB \
390 extern struct trace_event * const __start___trace_events_ptrs[] \
391 __attribute__((weak, visibility("hidden"))); \
392 extern struct trace_event * const __stop___trace_events_ptrs[] \
393 __attribute__((weak, visibility("hidden"))); \
394 static struct trace_event * const __event_ptrs_dummy \
395 __attribute__((used, section("__trace_events_ptrs"))) = NULL; \
396 static void __attribute__((constructor)) \
397 __trace_events__init(void) \
399 trace_event_register_lib(__start___trace_events_ptrs, \
400 __stop___trace_events_ptrs - \
401 __start___trace_events_ptrs); \
404 static void __attribute__((destructor)) \
405 __trace_event__destroy(void) \
407 trace_event_unregister_lib(__start___trace_events_ptrs);\
410 #define DECLARE_TRACE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
411 #define DEFINE_TRACE_EVENT(template, name, proto, args) \
412 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
413 #define DEFINE_TRACE_EVENT_PRINT(template, name, proto, args, print) \
414 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
416 #define TRACE_EVENT(name, proto, args, struct, assign, print) \
417 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
418 #define TRACE_EVENT_FN(name, proto, args, struct, \
419 assign, print, reg, unreg) \
420 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
422 #endif /* ifdef TRACE_EVENT (see note above) */
425 #endif /* _UST_TRACEPOINT_H */
This page took 0.039503 seconds and 3 git commands to generate.