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  *
229cfe06f8SSteven Rostedt  * The define_trace.h belowe will also look for a file name of
239cfe06f8SSteven Rostedt  * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
249cfe06f8SSteven Rostedt  *
259cfe06f8SSteven Rostedt  * If you want a different system than file name, you can override
269cfe06f8SSteven Rostedt  * the header name by defining TRACE_INCLUDE_FILE
279cfe06f8SSteven Rostedt  *
289cfe06f8SSteven Rostedt  * If this file was called, goofy.h, then we would define:
299cfe06f8SSteven Rostedt  *
309cfe06f8SSteven Rostedt  * #define TRACE_INCLUDE_FILE goofy
319cfe06f8SSteven Rostedt  *
329cfe06f8SSteven Rostedt  */
339cfe06f8SSteven Rostedt #undef TRACE_SYSTEM
3471e1c8acSSteven Rostedt #define TRACE_SYSTEM sample
359cfe06f8SSteven Rostedt 
369cfe06f8SSteven Rostedt /*
379cfe06f8SSteven Rostedt  * The TRACE_EVENT macro is broken up into 5 parts.
389cfe06f8SSteven Rostedt  *
399cfe06f8SSteven Rostedt  * name: name of the trace point. This is also how to enable the tracepoint.
409cfe06f8SSteven Rostedt  *   A function called trace_foo_bar() will be created.
419cfe06f8SSteven Rostedt  *
429cfe06f8SSteven Rostedt  * proto: the prototype of the function trace_foo_bar()
439cfe06f8SSteven Rostedt  *   Here it is trace_foo_bar(char *foo, int bar).
449cfe06f8SSteven Rostedt  *
459cfe06f8SSteven Rostedt  * args:  must match the arguments in the prototype.
469cfe06f8SSteven Rostedt  *    Here it is simply "foo, bar".
479cfe06f8SSteven Rostedt  *
489cfe06f8SSteven Rostedt  * struct:  This defines the way the data will be stored in the ring buffer.
499cfe06f8SSteven Rostedt  *    There are currently two types of elements. __field and __array.
509cfe06f8SSteven Rostedt  *    a __field is broken up into (type, name). Where type can be any
519cfe06f8SSteven Rostedt  *    type but an array.
529cfe06f8SSteven Rostedt  *    For an array. there are three fields. (type, name, size). The
539cfe06f8SSteven Rostedt  *    type of elements in the array, the name of the field and the size
549cfe06f8SSteven Rostedt  *    of the array.
559cfe06f8SSteven Rostedt  *
569cfe06f8SSteven Rostedt  *    __array( char, foo, 10) is the same as saying   char foo[10].
579cfe06f8SSteven Rostedt  *
589cfe06f8SSteven Rostedt  * fast_assign: This is a C like function that is used to store the items
599cfe06f8SSteven Rostedt  *    into the ring buffer.
609cfe06f8SSteven Rostedt  *
619cfe06f8SSteven Rostedt  * printk: This is a way to print out the data in pretty print. This is
629cfe06f8SSteven Rostedt  *    useful if the system crashes and you are logging via a serial line,
639cfe06f8SSteven Rostedt  *    the data can be printed to the console using this "printk" method.
649cfe06f8SSteven Rostedt  *
659cfe06f8SSteven Rostedt  * Note, that for both the assign and the printk, __entry is the handler
669cfe06f8SSteven Rostedt  * to the data structure in the ring buffer, and is defined by the
679cfe06f8SSteven Rostedt  * TP_STRUCT__entry.
689cfe06f8SSteven Rostedt  */
699cfe06f8SSteven Rostedt TRACE_EVENT(foo_bar,
709cfe06f8SSteven Rostedt 
719cfe06f8SSteven Rostedt 	TP_PROTO(char *foo, int bar),
729cfe06f8SSteven Rostedt 
739cfe06f8SSteven Rostedt 	TP_ARGS(foo, bar),
749cfe06f8SSteven Rostedt 
759cfe06f8SSteven Rostedt 	TP_STRUCT__entry(
769cfe06f8SSteven Rostedt 		__array(	char,	foo,    10		)
779cfe06f8SSteven Rostedt 		__field(	int,	bar			)
789cfe06f8SSteven Rostedt 	),
799cfe06f8SSteven Rostedt 
809cfe06f8SSteven Rostedt 	TP_fast_assign(
819cfe06f8SSteven Rostedt 		strncpy(__entry->foo, foo, 10);
829cfe06f8SSteven Rostedt 		__entry->bar	= bar;
839cfe06f8SSteven Rostedt 	),
849cfe06f8SSteven Rostedt 
859cfe06f8SSteven Rostedt 	TP_printk("foo %s %d", __entry->foo, __entry->bar)
869cfe06f8SSteven Rostedt );
879cfe06f8SSteven Rostedt #endif
889cfe06f8SSteven Rostedt 
899cfe06f8SSteven Rostedt /***** NOTICE! The #if protection ends here. *****/
909cfe06f8SSteven Rostedt 
919cfe06f8SSteven Rostedt 
929cfe06f8SSteven Rostedt /*
939cfe06f8SSteven Rostedt  * There are several ways I could have done this. If I left out the
949cfe06f8SSteven Rostedt  * TRACE_INCLUDE_PATH, then it would default to the kernel source
959cfe06f8SSteven Rostedt  * include/trace/events directory.
969cfe06f8SSteven Rostedt  *
979cfe06f8SSteven Rostedt  * I could specify a path from the define_trace.h file back to this
989cfe06f8SSteven Rostedt  * file.
999cfe06f8SSteven Rostedt  *
1009cfe06f8SSteven Rostedt  * #define TRACE_INCLUDE_PATH ../../samples/trace_events
1019cfe06f8SSteven Rostedt  *
1029cfe06f8SSteven Rostedt  * But I chose to simply make it use the current directory and then in
1039cfe06f8SSteven Rostedt  * the Makefile I added:
1049cfe06f8SSteven Rostedt  *
1059cfe06f8SSteven Rostedt  * CFLAGS_trace-events-sample.o := -I$(PWD)/samples/trace_events/
1069cfe06f8SSteven Rostedt  *
1079cfe06f8SSteven Rostedt  * This will make sure the current path is part of the include
1089cfe06f8SSteven Rostedt  * structure for our file so that we can find it.
1099cfe06f8SSteven Rostedt  *
1109cfe06f8SSteven Rostedt  * I could have made only the top level directory the include:
1119cfe06f8SSteven Rostedt  *
1129cfe06f8SSteven Rostedt  * CFLAGS_trace-events-sample.o := -I$(PWD)
1139cfe06f8SSteven Rostedt  *
1149cfe06f8SSteven Rostedt  * And then let the path to this directory be the TRACE_INCLUDE_PATH:
1159cfe06f8SSteven Rostedt  *
1169cfe06f8SSteven Rostedt  * #define TRACE_INCLUDE_PATH samples/trace_events
1179cfe06f8SSteven Rostedt  *
1189cfe06f8SSteven Rostedt  * But then if something defines "samples" or "trace_events" then we
1199cfe06f8SSteven Rostedt  * could risk that being converted too, and give us an unexpected
1209cfe06f8SSteven Rostedt  * result.
1219cfe06f8SSteven Rostedt  */
1229cfe06f8SSteven Rostedt #undef TRACE_INCLUDE_PATH
12371e1c8acSSteven Rostedt #undef TRACE_INCLUDE_FILE
1249cfe06f8SSteven Rostedt #define TRACE_INCLUDE_PATH .
12571e1c8acSSteven Rostedt /*
12671e1c8acSSteven Rostedt  * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
12771e1c8acSSteven Rostedt  */
12871e1c8acSSteven Rostedt #define TRACE_INCLUDE_FILE trace-events-sample
1299cfe06f8SSteven Rostedt #include <trace/define_trace.h>
130