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