blob: bbeec31e0ae3f03144684cfd5039a138497328e0 [file] [log] [blame]
Steven Rostedt770cb242009-03-05 21:35:29 -05001/*
2 * trace_export.c - export basic ftrace utilities to user space
3 *
4 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
5 */
6#include <linux/stringify.h>
7#include <linux/kallsyms.h>
8#include <linux/seq_file.h>
9#include <linux/debugfs.h>
10#include <linux/uaccess.h>
11#include <linux/ftrace.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/fs.h>
15
16#include "trace_output.h"
17
Steven Rostedt4e5292e2009-09-12 19:26:21 -040018#undef TRACE_SYSTEM
19#define TRACE_SYSTEM ftrace
Steven Rostedtda4d0302009-03-09 17:14:30 -040020
Steven Rostedt4e5292e2009-09-12 19:26:21 -040021/* not needed for this file */
22#undef __field_struct
23#define __field_struct(type, item)
Steven Rostedtda4d0302009-03-09 17:14:30 -040024
Steven Rostedt4e5292e2009-09-12 19:26:21 -040025#undef __field
Li Zefan05ffa2d2009-09-14 15:54:52 +080026#define __field(type, item) type item;
27
28#undef __field_desc
29#define __field_desc(type, container, item) type item;
30
31#undef __array
32#define __array(type, item, size) type item[size];
33
34#undef __array_desc
35#define __array_desc(type, container, item, size) type item[size];
36
37#undef __dynamic_array
38#define __dynamic_array(type, item) type item[];
39
40#undef F_STRUCT
41#define F_STRUCT(args...) args
42
43#undef F_printk
44#define F_printk(fmt, args...) fmt, args
45
46#undef FTRACE_ENTRY
47#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
48struct ____ftrace_##name { \
49 tstruct \
50}; \
Li Zefan5e9b3972009-11-02 08:51:13 +080051static void __always_unused ____ftrace_check_##name(void) \
Li Zefan05ffa2d2009-09-14 15:54:52 +080052{ \
53 struct ____ftrace_##name *__entry = NULL; \
54 \
Li Zefan5e9b3972009-11-02 08:51:13 +080055 /* force compile-time check on F_printk() */ \
Li Zefan05ffa2d2009-09-14 15:54:52 +080056 printk(print); \
57}
58
59#undef FTRACE_ENTRY_DUP
60#define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
61 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
62
63#include "trace_entries.h"
64
Steven Rostedt4e5292e2009-09-12 19:26:21 -040065#undef __field
66#define __field(type, item) \
67 ret = trace_define_field(event_call, #type, #item, \
68 offsetof(typeof(field), item), \
69 sizeof(field.item), \
70 is_signed_type(type), FILTER_OTHER); \
71 if (ret) \
72 return ret;
73
74#undef __field_desc
75#define __field_desc(type, container, item) \
76 ret = trace_define_field(event_call, #type, #item, \
77 offsetof(typeof(field), \
78 container.item), \
79 sizeof(field.container.item), \
80 is_signed_type(type), FILTER_OTHER); \
81 if (ret) \
82 return ret;
83
84#undef __array
85#define __array(type, item, len) \
Steven Rostedt04295782010-11-12 22:32:11 -050086 do { \
87 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
88 mutex_lock(&event_storage_mutex); \
89 snprintf(event_storage, sizeof(event_storage), \
90 "%s[%d]", #type, len); \
91 ret = trace_define_field(event_call, event_storage, #item, \
Steven Rostedt4e5292e2009-09-12 19:26:21 -040092 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +080093 sizeof(field.item), \
94 is_signed_type(type), FILTER_OTHER); \
Steven Rostedt04295782010-11-12 22:32:11 -050095 mutex_unlock(&event_storage_mutex); \
96 if (ret) \
97 return ret; \
98 } while (0);
Steven Rostedt4e5292e2009-09-12 19:26:21 -040099
100#undef __array_desc
101#define __array_desc(type, container, item, len) \
102 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
103 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
104 offsetof(typeof(field), \
105 container.item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +0800106 sizeof(field.container.item), \
107 is_signed_type(type), FILTER_OTHER); \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400108 if (ret) \
109 return ret;
110
111#undef __dynamic_array
Lai Jiangshan809826a2009-12-15 15:39:34 +0800112#define __dynamic_array(type, item) \
113 ret = trace_define_field(event_call, #type, #item, \
114 offsetof(typeof(field), item), \
115 0, is_signed_type(type), FILTER_OTHER);\
116 if (ret) \
117 return ret;
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400118
119#undef FTRACE_ENTRY
120#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
121int \
122ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500123{ \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400124 struct struct_name field; \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500125 int ret; \
126 \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400127 tstruct; \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500128 \
129 return ret; \
130}
131
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400132#include "trace_entries.h"
133
Lai Jiangshan509e7602009-12-15 15:39:42 +0800134#undef __entry
135#define __entry REC
136
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400137#undef __field
138#define __field(type, item)
139
140#undef __field_desc
141#define __field_desc(type, container, item)
142
143#undef __array
144#define __array(type, item, len)
145
146#undef __array_desc
147#define __array_desc(type, container, item, len)
148
149#undef __dynamic_array
150#define __dynamic_array(type, item)
151
Lai Jiangshan509e7602009-12-15 15:39:42 +0800152#undef F_printk
153#define F_printk(fmt, args...) #fmt ", " __stringify(args)
154
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400155#undef FTRACE_ENTRY
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400156#define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
Steven Rostedt770cb242009-03-05 21:35:29 -0500157 \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400158struct ftrace_event_class event_class_ftrace_##call = { \
159 .system = __stringify(TRACE_SYSTEM), \
160 .define_fields = ftrace_define_fields_##call, \
Li Zefanffb9f992010-05-24 16:24:52 +0800161 .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
Steven Rostedt2e33af02010-04-22 10:35:55 -0400162}; \
163 \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500164struct ftrace_event_call __used event_##call = { \
Steven Rostedtef180122009-03-10 14:10:56 -0400165 .name = #call, \
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400166 .event.type = etype, \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400167 .class = &event_class_ftrace_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800168 .print_fmt = print, \
Tom Zanussie1112b42009-03-31 00:48:49 -0500169}; \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500170struct ftrace_event_call __used \
171__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
Tom Zanussie1112b42009-03-31 00:48:49 -0500172
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400173#include "trace_entries.h"