19cfe06f8SSteven Rostedt /* 29cfe06f8SSteven Rostedt * If TRACE_SYSTEM is defined, that will be the directory created 3088a4eedSGeunSik Lim * in the ftrace directory under /sys/kernel/debug/tracing/events/<system> 49cfe06f8SSteven Rostedt * 544ad18e0SSteven Rostedt * The define_trace.h below will also look for a file name of 69cfe06f8SSteven Rostedt * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here. 744ad18e0SSteven Rostedt * In this case, it would look for sample.h 89cfe06f8SSteven Rostedt * 944ad18e0SSteven Rostedt * If the header name will be different than the system name 1044ad18e0SSteven Rostedt * (as in this case), then you can override the header name that 1144ad18e0SSteven Rostedt * define_trace.h will look up by defining TRACE_INCLUDE_FILE 129cfe06f8SSteven Rostedt * 1344ad18e0SSteven Rostedt * This file is called trace-events-sample.h but we want the system 1444ad18e0SSteven Rostedt * to be called "sample". Therefore we must define the name of this 1544ad18e0SSteven Rostedt * file: 169cfe06f8SSteven Rostedt * 1744ad18e0SSteven Rostedt * #define TRACE_INCLUDE_FILE trace-events-sample 189cfe06f8SSteven Rostedt * 1944ad18e0SSteven Rostedt * As we do an the bottom of this file. 20d0b6e04aSLi Zefan * 21d0b6e04aSLi Zefan * Notice that TRACE_SYSTEM should be defined outside of #if 22d0b6e04aSLi Zefan * protection, just like TRACE_INCLUDE_FILE. 239cfe06f8SSteven Rostedt */ 249cfe06f8SSteven Rostedt #undef TRACE_SYSTEM 2571e1c8acSSteven Rostedt #define TRACE_SYSTEM sample 269cfe06f8SSteven Rostedt 279cfe06f8SSteven Rostedt /* 28d0b6e04aSLi Zefan * Notice that this file is not protected like a normal header. 29d0b6e04aSLi Zefan * We also must allow for rereading of this file. The 30d0b6e04aSLi Zefan * 31d0b6e04aSLi Zefan * || defined(TRACE_HEADER_MULTI_READ) 32d0b6e04aSLi Zefan * 33d0b6e04aSLi Zefan * serves this purpose. 34d0b6e04aSLi Zefan */ 35d0b6e04aSLi Zefan #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ) 36d0b6e04aSLi Zefan #define _TRACE_EVENT_SAMPLE_H 37d0b6e04aSLi Zefan 38d0b6e04aSLi Zefan /* 39d0b6e04aSLi Zefan * All trace headers should include tracepoint.h, until we finally 40d0b6e04aSLi Zefan * make it into a standard header. 41d0b6e04aSLi Zefan */ 42d0b6e04aSLi Zefan #include <linux/tracepoint.h> 43d0b6e04aSLi Zefan 44d0b6e04aSLi Zefan /* 459cfe06f8SSteven Rostedt * The TRACE_EVENT macro is broken up into 5 parts. 469cfe06f8SSteven Rostedt * 479cfe06f8SSteven Rostedt * name: name of the trace point. This is also how to enable the tracepoint. 489cfe06f8SSteven Rostedt * A function called trace_foo_bar() will be created. 499cfe06f8SSteven Rostedt * 509cfe06f8SSteven Rostedt * proto: the prototype of the function trace_foo_bar() 519cfe06f8SSteven Rostedt * Here it is trace_foo_bar(char *foo, int bar). 529cfe06f8SSteven Rostedt * 539cfe06f8SSteven Rostedt * args: must match the arguments in the prototype. 549cfe06f8SSteven Rostedt * Here it is simply "foo, bar". 559cfe06f8SSteven Rostedt * 569cfe06f8SSteven Rostedt * struct: This defines the way the data will be stored in the ring buffer. 579cfe06f8SSteven Rostedt * There are currently two types of elements. __field and __array. 589cfe06f8SSteven Rostedt * a __field is broken up into (type, name). Where type can be any 599cfe06f8SSteven Rostedt * type but an array. 609cfe06f8SSteven Rostedt * For an array. there are three fields. (type, name, size). The 619cfe06f8SSteven Rostedt * type of elements in the array, the name of the field and the size 629cfe06f8SSteven Rostedt * of the array. 639cfe06f8SSteven Rostedt * 649cfe06f8SSteven Rostedt * __array( char, foo, 10) is the same as saying char foo[10]. 659cfe06f8SSteven Rostedt * 669cfe06f8SSteven Rostedt * fast_assign: This is a C like function that is used to store the items 679cfe06f8SSteven Rostedt * into the ring buffer. 689cfe06f8SSteven Rostedt * 699cfe06f8SSteven Rostedt * printk: This is a way to print out the data in pretty print. This is 709cfe06f8SSteven Rostedt * useful if the system crashes and you are logging via a serial line, 719cfe06f8SSteven Rostedt * the data can be printed to the console using this "printk" method. 729cfe06f8SSteven Rostedt * 739cfe06f8SSteven Rostedt * Note, that for both the assign and the printk, __entry is the handler 749cfe06f8SSteven Rostedt * to the data structure in the ring buffer, and is defined by the 759cfe06f8SSteven Rostedt * TP_STRUCT__entry. 769cfe06f8SSteven Rostedt */ 779cfe06f8SSteven Rostedt TRACE_EVENT(foo_bar, 789cfe06f8SSteven Rostedt 799cfe06f8SSteven Rostedt TP_PROTO(char *foo, int bar), 809cfe06f8SSteven Rostedt 819cfe06f8SSteven Rostedt TP_ARGS(foo, bar), 829cfe06f8SSteven Rostedt 839cfe06f8SSteven Rostedt TP_STRUCT__entry( 849cfe06f8SSteven Rostedt __array( char, foo, 10 ) 859cfe06f8SSteven Rostedt __field( int, bar ) 869cfe06f8SSteven Rostedt ), 879cfe06f8SSteven Rostedt 889cfe06f8SSteven Rostedt TP_fast_assign( 899cfe06f8SSteven Rostedt strncpy(__entry->foo, foo, 10); 909cfe06f8SSteven Rostedt __entry->bar = bar; 919cfe06f8SSteven Rostedt ), 929cfe06f8SSteven Rostedt 939cfe06f8SSteven Rostedt TP_printk("foo %s %d", __entry->foo, __entry->bar) 949cfe06f8SSteven Rostedt ); 959cfe06f8SSteven Rostedt #endif 969cfe06f8SSteven Rostedt 979cfe06f8SSteven Rostedt /***** NOTICE! The #if protection ends here. *****/ 989cfe06f8SSteven Rostedt 999cfe06f8SSteven Rostedt 1009cfe06f8SSteven Rostedt /* 1019cfe06f8SSteven Rostedt * There are several ways I could have done this. If I left out the 1029cfe06f8SSteven Rostedt * TRACE_INCLUDE_PATH, then it would default to the kernel source 1039cfe06f8SSteven Rostedt * include/trace/events directory. 1049cfe06f8SSteven Rostedt * 1059cfe06f8SSteven Rostedt * I could specify a path from the define_trace.h file back to this 1069cfe06f8SSteven Rostedt * file. 1079cfe06f8SSteven Rostedt * 1089cfe06f8SSteven Rostedt * #define TRACE_INCLUDE_PATH ../../samples/trace_events 1099cfe06f8SSteven Rostedt * 11044ad18e0SSteven Rostedt * But the safest and easiest way to simply make it use the directory 11144ad18e0SSteven Rostedt * that the file is in is to add in the Makefile: 1129cfe06f8SSteven Rostedt * 11344ad18e0SSteven Rostedt * CFLAGS_trace-events-sample.o := -I$(src) 1149cfe06f8SSteven Rostedt * 1159cfe06f8SSteven Rostedt * This will make sure the current path is part of the include 11644ad18e0SSteven Rostedt * structure for our file so that define_trace.h can find it. 1179cfe06f8SSteven Rostedt * 1189cfe06f8SSteven Rostedt * I could have made only the top level directory the include: 1199cfe06f8SSteven Rostedt * 1209cfe06f8SSteven Rostedt * CFLAGS_trace-events-sample.o := -I$(PWD) 1219cfe06f8SSteven Rostedt * 1229cfe06f8SSteven Rostedt * And then let the path to this directory be the TRACE_INCLUDE_PATH: 1239cfe06f8SSteven Rostedt * 1249cfe06f8SSteven Rostedt * #define TRACE_INCLUDE_PATH samples/trace_events 1259cfe06f8SSteven Rostedt * 12644ad18e0SSteven Rostedt * But then if something defines "samples" or "trace_events" as a macro 12744ad18e0SSteven Rostedt * then we could risk that being converted too, and give us an unexpected 1289cfe06f8SSteven Rostedt * result. 1299cfe06f8SSteven Rostedt */ 1309cfe06f8SSteven Rostedt #undef TRACE_INCLUDE_PATH 13171e1c8acSSteven Rostedt #undef TRACE_INCLUDE_FILE 1329cfe06f8SSteven Rostedt #define TRACE_INCLUDE_PATH . 13371e1c8acSSteven Rostedt /* 13471e1c8acSSteven Rostedt * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal 13571e1c8acSSteven Rostedt */ 13671e1c8acSSteven Rostedt #define TRACE_INCLUDE_FILE trace-events-sample 1379cfe06f8SSteven Rostedt #include <trace/define_trace.h> 138