Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 1 | /* |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 2 | * If TRACE_SYSTEM is defined, that will be the directory created |
GeunSik Lim | 088a4ee | 2009-09-07 21:37:37 +0900 | [diff] [blame] | 3 | * in the ftrace directory under /sys/kernel/debug/tracing/events/<system> |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 4 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 5 | * The define_trace.h below will also look for a file name of |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 6 | * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here. |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 7 | * In this case, it would look for sample.h |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 8 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 9 | * If the header name will be different than the system name |
| 10 | * (as in this case), then you can override the header name that |
| 11 | * define_trace.h will look up by defining TRACE_INCLUDE_FILE |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 12 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 13 | * This file is called trace-events-sample.h but we want the system |
| 14 | * to be called "sample". Therefore we must define the name of this |
| 15 | * file: |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 16 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 17 | * #define TRACE_INCLUDE_FILE trace-events-sample |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 18 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 19 | * As we do an the bottom of this file. |
Li Zefan | d0b6e04 | 2009-07-13 10:33:21 +0800 | [diff] [blame] | 20 | * |
| 21 | * Notice that TRACE_SYSTEM should be defined outside of #if |
| 22 | * protection, just like TRACE_INCLUDE_FILE. |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 23 | */ |
| 24 | #undef TRACE_SYSTEM |
Steven Rostedt | 71e1c8a | 2009-05-06 21:20:39 -0400 | [diff] [blame] | 25 | #define TRACE_SYSTEM sample |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Li Zefan | d0b6e04 | 2009-07-13 10:33:21 +0800 | [diff] [blame] | 28 | * Notice that this file is not protected like a normal header. |
| 29 | * We also must allow for rereading of this file. The |
| 30 | * |
| 31 | * || defined(TRACE_HEADER_MULTI_READ) |
| 32 | * |
| 33 | * serves this purpose. |
| 34 | */ |
| 35 | #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ) |
| 36 | #define _TRACE_EVENT_SAMPLE_H |
| 37 | |
| 38 | /* |
| 39 | * All trace headers should include tracepoint.h, until we finally |
| 40 | * make it into a standard header. |
| 41 | */ |
| 42 | #include <linux/tracepoint.h> |
| 43 | |
| 44 | /* |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 45 | * The TRACE_EVENT macro is broken up into 5 parts. |
| 46 | * |
| 47 | * name: name of the trace point. This is also how to enable the tracepoint. |
| 48 | * A function called trace_foo_bar() will be created. |
| 49 | * |
| 50 | * proto: the prototype of the function trace_foo_bar() |
| 51 | * Here it is trace_foo_bar(char *foo, int bar). |
| 52 | * |
| 53 | * args: must match the arguments in the prototype. |
| 54 | * Here it is simply "foo, bar". |
| 55 | * |
| 56 | * struct: This defines the way the data will be stored in the ring buffer. |
| 57 | * There are currently two types of elements. __field and __array. |
| 58 | * a __field is broken up into (type, name). Where type can be any |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 59 | * primitive type (integer, long or pointer). __field_struct() can |
| 60 | * be any static complex data value (struct, union, but not an array). |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 61 | * For an array. there are three fields. (type, name, size). The |
| 62 | * type of elements in the array, the name of the field and the size |
| 63 | * of the array. |
| 64 | * |
| 65 | * __array( char, foo, 10) is the same as saying char foo[10]. |
| 66 | * |
| 67 | * fast_assign: This is a C like function that is used to store the items |
| 68 | * into the ring buffer. |
| 69 | * |
| 70 | * printk: This is a way to print out the data in pretty print. This is |
| 71 | * useful if the system crashes and you are logging via a serial line, |
| 72 | * the data can be printed to the console using this "printk" method. |
| 73 | * |
| 74 | * Note, that for both the assign and the printk, __entry is the handler |
| 75 | * to the data structure in the ring buffer, and is defined by the |
| 76 | * TP_STRUCT__entry. |
| 77 | */ |
| 78 | TRACE_EVENT(foo_bar, |
| 79 | |
| 80 | TP_PROTO(char *foo, int bar), |
| 81 | |
| 82 | TP_ARGS(foo, bar), |
| 83 | |
| 84 | TP_STRUCT__entry( |
| 85 | __array( char, foo, 10 ) |
| 86 | __field( int, bar ) |
| 87 | ), |
| 88 | |
| 89 | TP_fast_assign( |
Zhao Hongjiang | d8fae2f | 2013-06-20 19:05:40 +0800 | [diff] [blame] | 90 | strlcpy(__entry->foo, foo, 10); |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 91 | __entry->bar = bar; |
| 92 | ), |
| 93 | |
| 94 | TP_printk("foo %s %d", __entry->foo, __entry->bar) |
| 95 | ); |
| 96 | #endif |
| 97 | |
| 98 | /***** NOTICE! The #if protection ends here. *****/ |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | * There are several ways I could have done this. If I left out the |
| 103 | * TRACE_INCLUDE_PATH, then it would default to the kernel source |
| 104 | * include/trace/events directory. |
| 105 | * |
| 106 | * I could specify a path from the define_trace.h file back to this |
| 107 | * file. |
| 108 | * |
| 109 | * #define TRACE_INCLUDE_PATH ../../samples/trace_events |
| 110 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 111 | * But the safest and easiest way to simply make it use the directory |
| 112 | * that the file is in is to add in the Makefile: |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 113 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 114 | * CFLAGS_trace-events-sample.o := -I$(src) |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 115 | * |
| 116 | * This will make sure the current path is part of the include |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 117 | * structure for our file so that define_trace.h can find it. |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 118 | * |
| 119 | * I could have made only the top level directory the include: |
| 120 | * |
| 121 | * CFLAGS_trace-events-sample.o := -I$(PWD) |
| 122 | * |
| 123 | * And then let the path to this directory be the TRACE_INCLUDE_PATH: |
| 124 | * |
| 125 | * #define TRACE_INCLUDE_PATH samples/trace_events |
| 126 | * |
Steven Rostedt | 44ad18e | 2009-06-16 19:53:07 -0400 | [diff] [blame] | 127 | * But then if something defines "samples" or "trace_events" as a macro |
| 128 | * then we could risk that being converted too, and give us an unexpected |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 129 | * result. |
| 130 | */ |
| 131 | #undef TRACE_INCLUDE_PATH |
Steven Rostedt | 71e1c8a | 2009-05-06 21:20:39 -0400 | [diff] [blame] | 132 | #undef TRACE_INCLUDE_FILE |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 133 | #define TRACE_INCLUDE_PATH . |
Steven Rostedt | 71e1c8a | 2009-05-06 21:20:39 -0400 | [diff] [blame] | 134 | /* |
| 135 | * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal |
| 136 | */ |
| 137 | #define TRACE_INCLUDE_FILE trace-events-sample |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 138 | #include <trace/define_trace.h> |