2 * Notice that this file is not protected like a normal header.
3 * We also must allow for rereading of this file. The
5 * || defined(TRACE_HEADER_MULTI_READ)
9 #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
10 #define _TRACE_EVENT_SAMPLE_H
13 * All trace headers should include tracepoint.h, until we finally
14 * make it into a standard header.
16 #include <linux/tracepoint.h>
19 * If TRACE_SYSTEM is defined, that will be the directory created
20 * in the ftrace directory under /debugfs/tracing/events/<system>
22 * The define_trace.h belowe will also look for a file name of
23 * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
25 * If you want a different system than file name, you can override
26 * the header name by defining TRACE_INCLUDE_FILE
28 * If this file was called, goofy.h, then we would define:
30 * #define TRACE_INCLUDE_FILE goofy
34 #define TRACE_SYSTEM sample
37 * The TRACE_EVENT macro is broken up into 5 parts.
39 * name: name of the trace point. This is also how to enable the tracepoint.
40 * A function called trace_foo_bar() will be created.
42 * proto: the prototype of the function trace_foo_bar()
43 * Here it is trace_foo_bar(char *foo, int bar).
45 * args: must match the arguments in the prototype.
46 * Here it is simply "foo, bar".
48 * struct: This defines the way the data will be stored in the ring buffer.
49 * There are currently two types of elements. __field and __array.
50 * a __field is broken up into (type, name). Where type can be any
52 * For an array. there are three fields. (type, name, size). The
53 * type of elements in the array, the name of the field and the size
56 * __array( char, foo, 10) is the same as saying char foo[10].
58 * fast_assign: This is a C like function that is used to store the items
59 * into the ring buffer.
61 * printk: This is a way to print out the data in pretty print. This is
62 * useful if the system crashes and you are logging via a serial line,
63 * the data can be printed to the console using this "printk" method.
65 * Note, that for both the assign and the printk, __entry is the handler
66 * to the data structure in the ring buffer, and is defined by the
71 TP_PROTO(char *foo
, int bar
),
76 __array( char, foo
, 10 )
81 strncpy(__entry
->foo
, foo
, 10);
85 TP_printk("foo %s %d", __entry
->foo
, __entry
->bar
)
89 /***** NOTICE! The #if protection ends here. *****/
93 * There are several ways I could have done this. If I left out the
94 * TRACE_INCLUDE_PATH, then it would default to the kernel source
95 * include/trace/events directory.
97 * I could specify a path from the define_trace.h file back to this
100 * #define TRACE_INCLUDE_PATH ../../samples/trace_events
102 * But I chose to simply make it use the current directory and then in
103 * the Makefile I added:
105 * CFLAGS_trace-events-sample.o := -I$(PWD)/samples/trace_events/
107 * This will make sure the current path is part of the include
108 * structure for our file so that we can find it.
110 * I could have made only the top level directory the include:
112 * CFLAGS_trace-events-sample.o := -I$(PWD)
114 * And then let the path to this directory be the TRACE_INCLUDE_PATH:
116 * #define TRACE_INCLUDE_PATH samples/trace_events
118 * But then if something defines "samples" or "trace_events" then we
119 * could risk that being converted too, and give us an unexpected
122 #undef TRACE_INCLUDE_PATH
123 #undef TRACE_INCLUDE_FILE
124 #define TRACE_INCLUDE_PATH .
126 * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
128 #define TRACE_INCLUDE_FILE trace-events-sample
129 #include <trace/define_trace.h>