^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * If TRACE_SYSTEM is defined, that will be the directory created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * in the ftrace directory under /sys/kernel/tracing/events/<system>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * The define_trace.h below will also look for a file name of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * In this case, it would look for sample-trace.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * If the header name will be different than the system name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * (as in this case), then you can override the header name that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * define_trace.h will look up by defining TRACE_INCLUDE_FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This file is called trace-events-sample.h but we want the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * to be called "sample-trace". Therefore we must define the name of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * #define TRACE_INCLUDE_FILE trace-events-sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * As we do an the bottom of this file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Notice that TRACE_SYSTEM should be defined outside of #if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * protection, just like TRACE_INCLUDE_FILE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #undef TRACE_SYSTEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TRACE_SYSTEM sample-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * TRACE_SYSTEM is expected to be a C valid variable (alpha-numeric
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * and underscore), although it may start with numbers. If for some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * reason it is not, you need to add the following lines:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #undef TRACE_SYSTEM_VAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TRACE_SYSTEM_VAR sample_trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * But the above is only needed if TRACE_SYSTEM is not alpha-numeric
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * and underscored. By default, TRACE_SYSTEM_VAR will be equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * TRACE_SYSTEM. As TRACE_SYSTEM_VAR must be alpha-numeric, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * TRACE_SYSTEM is not, then TRACE_SYSTEM_VAR must be defined with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * only alpha-numeric and underscores.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * The TRACE_SYSTEM_VAR is only used internally and not visible to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Notice that this file is not protected like a normal header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * We also must allow for rereading of this file. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * || defined(TRACE_HEADER_MULTI_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * serves this purpose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define _TRACE_EVENT_SAMPLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * All trace headers should include tracepoint.h, until we finally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * make it into a standard header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/tracepoint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * The TRACE_EVENT macro is broken up into 5 parts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * name: name of the trace point. This is also how to enable the tracepoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * A function called trace_foo_bar() will be created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * proto: the prototype of the function trace_foo_bar()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * Here it is trace_foo_bar(char *foo, int bar).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * args: must match the arguments in the prototype.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Here it is simply "foo, bar".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * struct: This defines the way the data will be stored in the ring buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * The items declared here become part of a special structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * called "__entry", which can be used in the fast_assign part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * TRACE_EVENT macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Here are the currently defined types you can use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * __field : Is broken up into type and name. Where type can be any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * primitive type (integer, long or pointer).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * __field(int, foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * __entry->foo = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * __field_struct : This can be any static complex data type (struct, union
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * but not an array). Be careful using complex types, as each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * event is limited in size, and copying large amounts of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * into the ring buffer can slow things down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * __field_struct(struct bar, foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * __entry->bar.x = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * __array: There are three fields (type, name, size). The type is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * type of elements in the array, the name is the name of the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * size is the number of items in the array (not the total size).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * __array( char, foo, 10) is the same as saying: char foo[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Assigning arrays can be done like any array:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * __entry->foo[0] = 'a';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * memcpy(__entry->foo, bar, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * __dynamic_array: This is similar to array, but can vary its size from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * instance to instance of the tracepoint being called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * Like __array, this too has three elements (type, name, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * type is the type of the element, name is the name of the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * The size is different than __array. It is not a static number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * but the algorithm to figure out the length of the array for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * specific instance of tracepoint. Again, size is the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * items in the array, not the total length in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * __dynamic_array( int, foo, bar) is similar to: int foo[bar];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Note, unlike arrays, you must use the __get_dynamic_array() macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * to access the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * memcpy(__get_dynamic_array(foo), bar, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Notice, that "__entry" is not needed here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * __string: This is a special kind of __dynamic_array. It expects to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * have a null terminated character array passed to it (it allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * for NULL too, which would be converted into "(null)"). __string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * takes two parameter (name, src), where name is the name of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * the string saved, and src is the string to copy into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * ring buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * __string(foo, bar) is similar to: strcpy(foo, bar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * To assign a string, use the helper macro __assign_str().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * __assign_str(foo, bar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * In most cases, the __assign_str() macro will take the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * parameters as the __string() macro had to declare the string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * __bitmask: This is another kind of __dynamic_array, but it expects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * an array of longs, and the number of bits to parse. It takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * two parameters (name, nr_bits), where name is the name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * bitmask to save, and the nr_bits is the number of bits to record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * __bitmask(target_cpu, nr_cpumask_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * To assign a bitmask, use the __assign_bitmask() helper macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * __assign_bitmask(target_cpus, cpumask_bits(bar), nr_cpumask_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * fast_assign: This is a C like function that is used to store the items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * into the ring buffer. A special variable called "__entry" will be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * structure that points into the ring buffer and has the same fields as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * described by the struct part of TRACE_EVENT above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * printk: This is a way to print out the data in pretty print. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * useful if the system crashes and you are logging via a serial line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * the data can be printed to the console using this "printk" method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * This is also used to print out the data from the trace files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Again, the __entry macro is used to access the data from the ring buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * Note, __dynamic_array, __string, and __bitmask require special helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * to access the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * For __dynamic_array(int, foo, bar) use __get_dynamic_array(foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Use __get_dynamic_array_len(foo) to get the length of the array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * saved. Note, __get_dynamic_array_len() returns the total allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * length of the dynamic array; __print_array() expects the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * parameter to be the number of elements. To get that, the array length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * needs to be divided by the element size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * For __string(foo, bar) use __get_str(foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * For __bitmask(target_cpus, nr_cpumask_bits) use __get_bitmask(target_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Note, that for both the assign and the printk, __entry is the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * to the data structure in the ring buffer, and is defined by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * TP_STRUCT__entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * It is OK to have helper functions in the file, but they need to be protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * from being defined more than once. Remember, this file gets included more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #ifndef __TRACE_EVENT_SAMPLE_HELPER_FUNCTIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define __TRACE_EVENT_SAMPLE_HELPER_FUNCTIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static inline int __length_of(const int *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) for (i = 0; list[i]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) TRACE_SAMPLE_FOO = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) TRACE_SAMPLE_BAR = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) TRACE_SAMPLE_ZOO = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * If enums are used in the TP_printk(), their names will be shown in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * format files and not their values. This can cause problems with user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * space programs that parse the format files to know how to translate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * the raw binary trace output into human readable text.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * To help out user space programs, any enum that is used in the TP_printk()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * should be defined by TRACE_DEFINE_ENUM() macro. All that is needed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * be done is to add this macro with the enum within it in the trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * header file, and it will be converted in the output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) TRACE_EVENT(foo_bar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) TP_PROTO(const char *foo, int bar, const int *lst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) const char *string, const struct cpumask *mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) TP_ARGS(foo, bar, lst, string, mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) __array( char, foo, 10 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) __field( int, bar )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) __dynamic_array(int, list, __length_of(lst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __string( str, string )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) __bitmask( cpus, num_possible_cpus() )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) strlcpy(__entry->foo, foo, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) __entry->bar = bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) memcpy(__get_dynamic_array(list), lst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) __length_of(lst) * sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) __assign_str(str, string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) TP_printk("foo %s %d %s %s %s %s (%s)", __entry->foo, __entry->bar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * Notice here the use of some helper functions. This includes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * __print_symbolic( variable, { value, "string" }, ... ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * The variable is tested against each value of the { } pair. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * the variable matches one of the values, then it will print the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * string in that pair. If non are matched, it returns a string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * version of the number (if __entry->bar == 7 then "7" is returned).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) __print_symbolic(__entry->bar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) { 0, "zero" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) { TRACE_SAMPLE_FOO, "TWO" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) { TRACE_SAMPLE_BAR, "FOUR" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) { TRACE_SAMPLE_ZOO, "EIGHT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) { 10, "TEN" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * __print_flags( variable, "delim", { value, "flag" }, ... ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * This is similar to __print_symbolic, except that it tests the bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * of the value. If ((FLAG & variable) == FLAG) then the string is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * printed. If more than one flag matches, then each one that does is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * also printed with delim in between them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * If not all bits are accounted for, then the not found bits will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * added in hex format: 0x506 will show BIT2|BIT4|0x500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) __print_flags(__entry->bar, "|",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) { 1, "BIT1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) { 2, "BIT2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) { 4, "BIT3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) { 8, "BIT4" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * __print_array( array, len, element_size )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * This prints out the array that is defined by __array in a nice format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __print_array(__get_dynamic_array(list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) __get_dynamic_array_len(list) / sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) sizeof(int)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) __get_str(str), __get_bitmask(cpus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * There may be a case where a tracepoint should only be called if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * some condition is set. Otherwise the tracepoint should not be called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * But to do something like:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * if (cond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * trace_foo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * Would cause a little overhead when tracing is not enabled, and that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * overhead, even if small, is not something we want. As tracepoints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * use static branch (aka jump_labels), where no branch is taken to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * skip the tracepoint when not enabled, and a jmp is placed to jump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * to the tracepoint code when it is enabled, having a if statement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * nullifies that optimization. It would be nice to place that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * condition within the static branch. This is where TRACE_EVENT_CONDITION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * comes in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * TRACE_EVENT_CONDITION() is just like TRACE_EVENT, except it adds another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * parameter just after args. Where TRACE_EVENT has:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * TRACE_EVENT(name, proto, args, struct, assign, printk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * the CONDITION version has:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * TRACE_EVENT_CONDITION(name, proto, args, cond, struct, assign, printk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * Everything is the same as TRACE_EVENT except for the new cond. Think
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * of the cond variable as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * if (cond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * trace_foo_bar_with_cond();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * Except that the logic for the if branch is placed after the static branch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * That is, the if statement that processes the condition will not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * executed unless that traecpoint is enabled. Otherwise it still remains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * a nop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) TRACE_EVENT_CONDITION(foo_bar_with_cond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) TP_CONDITION(!(bar % 10)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) __string( foo, foo )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) __field( int, bar )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) __assign_str(foo, foo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) __entry->bar = bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) TP_printk("foo %s %d", __get_str(foo), __entry->bar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int foo_bar_reg(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) void foo_bar_unreg(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * Now in the case that some function needs to be called when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * tracepoint is enabled and/or when it is disabled, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * TRACE_EVENT_FN() serves this purpose. This is just like TRACE_EVENT()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * but adds two more parameters at the end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * TRACE_EVENT_FN( name, proto, args, struct, assign, printk, reg, unreg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * reg and unreg are functions with the prototype of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * void reg(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * The reg function gets called before the tracepoint is enabled, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * the unreg function gets called after the tracepoint is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * Note, reg and unreg are allowed to be NULL. If you only need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * call a function before enabling, or after disabling, just set one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * function and pass in NULL for the other parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) TRACE_EVENT_FN(foo_bar_with_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) __string( foo, foo )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) __field( int, bar )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) __assign_str(foo, foo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) __entry->bar = bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) TP_printk("foo %s %d", __get_str(foo), __entry->bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) foo_bar_reg, foo_bar_unreg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * Each TRACE_EVENT macro creates several helper functions to produce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * the code to add the tracepoint, create the files in the trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * directory, hook it to perf, assign the values and to print out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * the raw data from the ring buffer. To prevent too much bloat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * if there are more than one tracepoint that uses the same format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * for the proto, args, struct, assign and printk, and only the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * is different, it is highly recommended to use the DECLARE_EVENT_CLASS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * DECLARE_EVENT_CLASS() macro creates most of the functions for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * tracepoint. Then DEFINE_EVENT() is use to hook a tracepoint to those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * functions. This DEFINE_EVENT() is an instance of the class and can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * be enabled and disabled separately from other events (either TRACE_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * or other DEFINE_EVENT()s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * Note, TRACE_EVENT() itself is simply defined as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * #define TRACE_EVENT(name, proto, args, tstruct, assign, printk) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * DEFINE_EVENT(name, name, proto, args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * The DEFINE_EVENT() also can be declared with conditions and reg functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * DEFINE_EVENT_CONDITION(template, name, proto, args, cond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * DEFINE_EVENT_FN(template, name, proto, args, reg, unreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) DECLARE_EVENT_CLASS(foo_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) __string( foo, foo )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) __field( int, bar )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) __assign_str(foo, foo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) __entry->bar = bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) TP_printk("foo %s %d", __get_str(foo), __entry->bar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * Here's a better way for the previous samples (except, the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * example had more fields and could not be used here).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) DEFINE_EVENT(foo_template, foo_with_template_simple,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) TP_ARGS(foo, bar));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) DEFINE_EVENT_CONDITION(foo_template, foo_with_template_cond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) TP_CONDITION(!(bar % 8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) DEFINE_EVENT_FN(foo_template, foo_with_template_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) foo_bar_reg, foo_bar_unreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * Anytime two events share basically the same values and have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * the same output, use the DECLARE_EVENT_CLASS() and DEFINE_EVENT()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * when ever possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * If the event is similar to the DECLARE_EVENT_CLASS, but you need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * to have a different output, then use DEFINE_EVENT_PRINT() which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * lets you override the TP_printk() of the class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) DEFINE_EVENT_PRINT(foo_template, foo_with_template_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) TP_PROTO(const char *foo, int bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) TP_ARGS(foo, bar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) TP_printk("bar %s %d", __get_str(foo), __entry->bar));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /***** NOTICE! The #if protection ends here. *****/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * There are several ways I could have done this. If I left out the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * TRACE_INCLUDE_PATH, then it would default to the kernel source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * include/trace/events directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * I could specify a path from the define_trace.h file back to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * #define TRACE_INCLUDE_PATH ../../samples/trace_events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * But the safest and easiest way to simply make it use the directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * that the file is in is to add in the Makefile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * CFLAGS_trace-events-sample.o := -I$(src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * This will make sure the current path is part of the include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * structure for our file so that define_trace.h can find it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * I could have made only the top level directory the include:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * CFLAGS_trace-events-sample.o := -I$(PWD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * And then let the path to this directory be the TRACE_INCLUDE_PATH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * #define TRACE_INCLUDE_PATH samples/trace_events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * But then if something defines "samples" or "trace_events" as a macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * then we could risk that being converted too, and give us an unexpected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) #undef TRACE_INCLUDE_PATH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #undef TRACE_INCLUDE_FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #define TRACE_INCLUDE_PATH .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #define TRACE_INCLUDE_FILE trace-events-sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) #include <trace/define_trace.h>