aboutsummaryrefslogtreecommitdiffstats
path: root/samples/trace_events/trace-events-sample.h
diff options
context:
space:
mode:
Diffstat (limited to 'samples/trace_events/trace-events-sample.h')
-rw-r--r--samples/trace_events/trace-events-sample.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
new file mode 100644
index 000000000000..128a897687c5
--- /dev/null
+++ b/samples/trace_events/trace-events-sample.h
@@ -0,0 +1,129 @@
1/*
2 * Notice that this file is not protected like a normal header.
3 * We also must allow for rereading of this file. The
4 *
5 * || defined(TRACE_HEADER_MULTI_READ)
6 *
7 * serves this purpose.
8 */
9#if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
10#define _TRACE_EVENT_SAMPLE_H
11
12/*
13 * All trace headers should include tracepoint.h, until we finally
14 * make it into a standard header.
15 */
16#include <linux/tracepoint.h>
17
18/*
19 * If TRACE_SYSTEM is defined, that will be the directory created
20 * in the ftrace directory under /debugfs/tracing/events/<system>
21 *
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.
24 *
25 * If you want a different system than file name, you can override
26 * the header name by defining TRACE_INCLUDE_FILE
27 *
28 * If this file was called, goofy.h, then we would define:
29 *
30 * #define TRACE_INCLUDE_FILE goofy
31 *
32 */
33#undef TRACE_SYSTEM
34#define TRACE_SYSTEM sample
35
36/*
37 * The TRACE_EVENT macro is broken up into 5 parts.
38 *
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.
41 *
42 * proto: the prototype of the function trace_foo_bar()
43 * Here it is trace_foo_bar(char *foo, int bar).
44 *
45 * args: must match the arguments in the prototype.
46 * Here it is simply "foo, bar".
47 *
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
51 * type but an array.
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
54 * of the array.
55 *
56 * __array( char, foo, 10) is the same as saying char foo[10].
57 *
58 * fast_assign: This is a C like function that is used to store the items
59 * into the ring buffer.
60 *
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.
64 *
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
67 * TP_STRUCT__entry.
68 */
69TRACE_EVENT(foo_bar,
70
71 TP_PROTO(char *foo, int bar),
72
73 TP_ARGS(foo, bar),
74
75 TP_STRUCT__entry(
76 __array( char, foo, 10 )
77 __field( int, bar )
78 ),
79
80 TP_fast_assign(
81 strncpy(__entry->foo, foo, 10);
82 __entry->bar = bar;
83 ),
84
85 TP_printk("foo %s %d", __entry->foo, __entry->bar)
86);
87#endif
88
89/***** NOTICE! The #if protection ends here. *****/
90
91
92/*
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.
96 *
97 * I could specify a path from the define_trace.h file back to this
98 * file.
99 *
100 * #define TRACE_INCLUDE_PATH ../../samples/trace_events
101 *
102 * But I chose to simply make it use the current directory and then in
103 * the Makefile I added:
104 *
105 * CFLAGS_trace-events-sample.o := -I$(PWD)/samples/trace_events/
106 *
107 * This will make sure the current path is part of the include
108 * structure for our file so that we can find it.
109 *
110 * I could have made only the top level directory the include:
111 *
112 * CFLAGS_trace-events-sample.o := -I$(PWD)
113 *
114 * And then let the path to this directory be the TRACE_INCLUDE_PATH:
115 *
116 * #define TRACE_INCLUDE_PATH samples/trace_events
117 *
118 * But then if something defines "samples" or "trace_events" then we
119 * could risk that being converted too, and give us an unexpected
120 * result.
121 */
122#undef TRACE_INCLUDE_PATH
123#undef TRACE_INCLUDE_FILE
124#define TRACE_INCLUDE_PATH .
125/*
126 * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
127 */
128#define TRACE_INCLUDE_FILE trace-events-sample
129#include <trace/define_trace.h>