Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
trace-events-sample.h
Go to the documentation of this file.
1 /*
2  * If TRACE_SYSTEM is defined, that will be the directory created
3  * in the ftrace directory under /sys/kernel/debug/tracing/events/<system>
4  *
5  * The define_trace.h below will also look for a file name of
6  * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
7  * In this case, it would look for sample.h
8  *
9  * If the header name will be different than the system name
10  * (as in this case), then you can override the header name that
11  * define_trace.h will look up by defining TRACE_INCLUDE_FILE
12  *
13  * This file is called trace-events-sample.h but we want the system
14  * to be called "sample". Therefore we must define the name of this
15  * file:
16  *
17  * #define TRACE_INCLUDE_FILE trace-events-sample
18  *
19  * As we do an the bottom of this file.
20  *
21  * Notice that TRACE_SYSTEM should be defined outside of #if
22  * protection, just like TRACE_INCLUDE_FILE.
23  */
24 #undef TRACE_SYSTEM
25 #define TRACE_SYSTEM sample
26 
27 /*
28  * Notice that this file is not protected like a normal header.
29  * We also must allow for rereading of this file. The
30  *
31  * || defined(TRACE_HEADER_MULTI_READ)
32  *
33  * serves this purpose.
34  */
35 #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
36 #define _TRACE_EVENT_SAMPLE_H
37 
38 /*
39  * All trace headers should include tracepoint.h, until we finally
40  * make it into a standard header.
41  */
42 #include <linux/tracepoint.h>
43 
44 /*
45  * The TRACE_EVENT macro is broken up into 5 parts.
46  *
47  * name: name of the trace point. This is also how to enable the tracepoint.
48  * A function called trace_foo_bar() will be created.
49  *
50  * proto: the prototype of the function trace_foo_bar()
51  * Here it is trace_foo_bar(char *foo, int bar).
52  *
53  * args: must match the arguments in the prototype.
54  * Here it is simply "foo, bar".
55  *
56  * struct: This defines the way the data will be stored in the ring buffer.
57  * There are currently two types of elements. __field and __array.
58  * a __field is broken up into (type, name). Where type can be any
59  * type but an array.
60  * For an array. there are three fields. (type, name, size). The
61  * type of elements in the array, the name of the field and the size
62  * of the array.
63  *
64  * __array( char, foo, 10) is the same as saying char foo[10].
65  *
66  * fast_assign: This is a C like function that is used to store the items
67  * into the ring buffer.
68  *
69  * printk: This is a way to print out the data in pretty print. This is
70  * useful if the system crashes and you are logging via a serial line,
71  * the data can be printed to the console using this "printk" method.
72  *
73  * Note, that for both the assign and the printk, __entry is the handler
74  * to the data structure in the ring buffer, and is defined by the
75  * TP_STRUCT__entry.
76  */
77 TRACE_EVENT(foo_bar,
78 
79  TP_PROTO(char *foo, int bar),
80 
81  TP_ARGS(foo, bar),
82 
84  __array( char, foo, 10 )
85  __field( int, bar )
86  ),
87 
89  strncpy(__entry->foo, foo, 10);
90  __entry->bar = bar;
91  ),
92 
93  TP_printk("foo %s %d", __entry->foo, __entry->bar)
94 );
95 #endif
96 
97 /***** NOTICE! The #if protection ends here. *****/
98 
99 
100 /*
101  * There are several ways I could have done this. If I left out the
102  * TRACE_INCLUDE_PATH, then it would default to the kernel source
103  * include/trace/events directory.
104  *
105  * I could specify a path from the define_trace.h file back to this
106  * file.
107  *
108  * #define TRACE_INCLUDE_PATH ../../samples/trace_events
109  *
110  * But the safest and easiest way to simply make it use the directory
111  * that the file is in is to add in the Makefile:
112  *
113  * CFLAGS_trace-events-sample.o := -I$(src)
114  *
115  * This will make sure the current path is part of the include
116  * structure for our file so that define_trace.h can find it.
117  *
118  * I could have made only the top level directory the include:
119  *
120  * CFLAGS_trace-events-sample.o := -I$(PWD)
121  *
122  * And then let the path to this directory be the TRACE_INCLUDE_PATH:
123  *
124  * #define TRACE_INCLUDE_PATH samples/trace_events
125  *
126  * But then if something defines "samples" or "trace_events" as a macro
127  * then we could risk that being converted too, and give us an unexpected
128  * result.
129  */
130 #undef TRACE_INCLUDE_PATH
131 #undef TRACE_INCLUDE_FILE
132 #define TRACE_INCLUDE_PATH .
133 /*
134  * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
135  */
136 #define TRACE_INCLUDE_FILE trace-events-sample
137 #include <trace/define_trace.h>