19cfe06f8SSteven Rostedt /*
29cfe06f8SSteven Rostedt  * Notice that this file is not protected like a normal header.
39cfe06f8SSteven Rostedt  * We also must allow for rereading of this file. The
49cfe06f8SSteven Rostedt  *
59cfe06f8SSteven Rostedt  *  || defined(TRACE_HEADER_MULTI_READ)
69cfe06f8SSteven Rostedt  *
79cfe06f8SSteven Rostedt  * serves this purpose.
89cfe06f8SSteven Rostedt  */
99cfe06f8SSteven Rostedt #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
109cfe06f8SSteven Rostedt #define _TRACE_EVENT_SAMPLE_H
119cfe06f8SSteven Rostedt 
129cfe06f8SSteven Rostedt /*
139cfe06f8SSteven Rostedt  * All trace headers should include tracepoint.h, until we finally
149cfe06f8SSteven Rostedt  * make it into a standard header.
159cfe06f8SSteven Rostedt  */
169cfe06f8SSteven Rostedt #include <linux/tracepoint.h>
179cfe06f8SSteven Rostedt 
189cfe06f8SSteven Rostedt /*
199cfe06f8SSteven Rostedt  * If TRACE_SYSTEM is defined, that will be the directory created
209cfe06f8SSteven Rostedt  * in the ftrace directory under /debugfs/tracing/events/<system>
219cfe06f8SSteven Rostedt  *
2244ad18e0SSteven Rostedt  * The define_trace.h below will also look for a file name of
239cfe06f8SSteven Rostedt  * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
2444ad18e0SSteven Rostedt  * In this case, it would look for sample.h
259cfe06f8SSteven Rostedt  *
2644ad18e0SSteven Rostedt  * If the header name will be different than the system name
2744ad18e0SSteven Rostedt  * (as in this case), then you can override the header name that
2844ad18e0SSteven Rostedt  * define_trace.h will look up by defining TRACE_INCLUDE_FILE
299cfe06f8SSteven Rostedt  *
3044ad18e0SSteven Rostedt  * This file is called trace-events-sample.h but we want the system
3144ad18e0SSteven Rostedt  * to be called "sample". Therefore we must define the name of this
3244ad18e0SSteven Rostedt  * file:
339cfe06f8SSteven Rostedt  *
3444ad18e0SSteven Rostedt  * #define TRACE_INCLUDE_FILE trace-events-sample
359cfe06f8SSteven Rostedt  *
3644ad18e0SSteven Rostedt  * As we do an the bottom of this file.
379cfe06f8SSteven Rostedt  */
389cfe06f8SSteven Rostedt #undef TRACE_SYSTEM
3971e1c8acSSteven Rostedt #define TRACE_SYSTEM sample
409cfe06f8SSteven Rostedt 
419cfe06f8SSteven Rostedt /*
429cfe06f8SSteven Rostedt  * The TRACE_EVENT macro is broken up into 5 parts.
439cfe06f8SSteven Rostedt  *
449cfe06f8SSteven Rostedt  * name: name of the trace point. This is also how to enable the tracepoint.
459cfe06f8SSteven Rostedt  *   A function called trace_foo_bar() will be created.
469cfe06f8SSteven Rostedt  *
479cfe06f8SSteven Rostedt  * proto: the prototype of the function trace_foo_bar()
489cfe06f8SSteven Rostedt  *   Here it is trace_foo_bar(char *foo, int bar).
499cfe06f8SSteven Rostedt  *
509cfe06f8SSteven Rostedt  * args:  must match the arguments in the prototype.
519cfe06f8SSteven Rostedt  *    Here it is simply "foo, bar".
529cfe06f8SSteven Rostedt  *
539cfe06f8SSteven Rostedt  * struct:  This defines the way the data will be stored in the ring buffer.
549cfe06f8SSteven Rostedt  *    There are currently two types of elements. __field and __array.
559cfe06f8SSteven Rostedt  *    a __field is broken up into (type, name). Where type can be any
569cfe06f8SSteven Rostedt  *    type but an array.
579cfe06f8SSteven Rostedt  *    For an array. there are three fields. (type, name, size). The
589cfe06f8SSteven Rostedt  *    type of elements in the array, the name of the field and the size
599cfe06f8SSteven Rostedt  *    of the array.
609cfe06f8SSteven Rostedt  *
619cfe06f8SSteven Rostedt  *    __array( char, foo, 10) is the same as saying   char foo[10].
629cfe06f8SSteven Rostedt  *
639cfe06f8SSteven Rostedt  * fast_assign: This is a C like function that is used to store the items
649cfe06f8SSteven Rostedt  *    into the ring buffer.
659cfe06f8SSteven Rostedt  *
669cfe06f8SSteven Rostedt  * printk: This is a way to print out the data in pretty print. This is
679cfe06f8SSteven Rostedt  *    useful if the system crashes and you are logging via a serial line,
689cfe06f8SSteven Rostedt  *    the data can be printed to the console using this "printk" method.
699cfe06f8SSteven Rostedt  *
709cfe06f8SSteven Rostedt  * Note, that for both the assign and the printk, __entry is the handler
719cfe06f8SSteven Rostedt  * to the data structure in the ring buffer, and is defined by the
729cfe06f8SSteven Rostedt  * TP_STRUCT__entry.
739cfe06f8SSteven Rostedt  */
749cfe06f8SSteven Rostedt TRACE_EVENT(foo_bar,
759cfe06f8SSteven Rostedt 
769cfe06f8SSteven Rostedt 	TP_PROTO(char *foo, int bar),
779cfe06f8SSteven Rostedt 
789cfe06f8SSteven Rostedt 	TP_ARGS(foo, bar),
799cfe06f8SSteven Rostedt 
809cfe06f8SSteven Rostedt 	TP_STRUCT__entry(
819cfe06f8SSteven Rostedt 		__array(	char,	foo,    10		)
829cfe06f8SSteven Rostedt 		__field(	int,	bar			)
839cfe06f8SSteven Rostedt 	),
849cfe06f8SSteven Rostedt 
859cfe06f8SSteven Rostedt 	TP_fast_assign(
869cfe06f8SSteven Rostedt 		strncpy(__entry->foo, foo, 10);
879cfe06f8SSteven Rostedt 		__entry->bar	= bar;
889cfe06f8SSteven Rostedt 	),
899cfe06f8SSteven Rostedt 
909cfe06f8SSteven Rostedt 	TP_printk("foo %s %d", __entry->foo, __entry->bar)
919cfe06f8SSteven Rostedt );
929cfe06f8SSteven Rostedt #endif
939cfe06f8SSteven Rostedt 
949cfe06f8SSteven Rostedt /***** NOTICE! The #if protection ends here. *****/
959cfe06f8SSteven Rostedt 
969cfe06f8SSteven Rostedt 
979cfe06f8SSteven Rostedt /*
989cfe06f8SSteven Rostedt  * There are several ways I could have done this. If I left out the
999cfe06f8SSteven Rostedt  * TRACE_INCLUDE_PATH, then it would default to the kernel source
1009cfe06f8SSteven Rostedt  * include/trace/events directory.
1019cfe06f8SSteven Rostedt  *
1029cfe06f8SSteven Rostedt  * I could specify a path from the define_trace.h file back to this
1039cfe06f8SSteven Rostedt  * file.
1049cfe06f8SSteven Rostedt  *
1059cfe06f8SSteven Rostedt  * #define TRACE_INCLUDE_PATH ../../samples/trace_events
1069cfe06f8SSteven Rostedt  *
10744ad18e0SSteven Rostedt  * But the safest and easiest way to simply make it use the directory
10844ad18e0SSteven Rostedt  * that the file is in is to add in the Makefile:
1099cfe06f8SSteven Rostedt  *
11044ad18e0SSteven Rostedt  * CFLAGS_trace-events-sample.o := -I$(src)
1119cfe06f8SSteven Rostedt  *
1129cfe06f8SSteven Rostedt  * This will make sure the current path is part of the include
11344ad18e0SSteven Rostedt  * structure for our file so that define_trace.h can find it.
1149cfe06f8SSteven Rostedt  *
1159cfe06f8SSteven Rostedt  * I could have made only the top level directory the include:
1169cfe06f8SSteven Rostedt  *
1179cfe06f8SSteven Rostedt  * CFLAGS_trace-events-sample.o := -I$(PWD)
1189cfe06f8SSteven Rostedt  *
1199cfe06f8SSteven Rostedt  * And then let the path to this directory be the TRACE_INCLUDE_PATH:
1209cfe06f8SSteven Rostedt  *
1219cfe06f8SSteven Rostedt  * #define TRACE_INCLUDE_PATH samples/trace_events
1229cfe06f8SSteven Rostedt  *
12344ad18e0SSteven Rostedt  * But then if something defines "samples" or "trace_events" as a macro
12444ad18e0SSteven Rostedt  * then we could risk that being converted too, and give us an unexpected
1259cfe06f8SSteven Rostedt  * result.
1269cfe06f8SSteven Rostedt  */
1279cfe06f8SSteven Rostedt #undef TRACE_INCLUDE_PATH
12871e1c8acSSteven Rostedt #undef TRACE_INCLUDE_FILE
1299cfe06f8SSteven Rostedt #define TRACE_INCLUDE_PATH .
13071e1c8acSSteven Rostedt /*
13171e1c8acSSteven Rostedt  * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
13271e1c8acSSteven Rostedt  */
13371e1c8acSSteven Rostedt #define TRACE_INCLUDE_FILE trace-events-sample
1349cfe06f8SSteven Rostedt #include <trace/define_trace.h>
135