Path: blob/master/samples/trace_events/trace-events-sample.h
10818 views
/*1* If TRACE_SYSTEM is defined, that will be the directory created2* in the ftrace directory under /sys/kernel/debug/tracing/events/<system>3*4* The define_trace.h below will also look for a file name of5* TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.6* In this case, it would look for sample.h7*8* If the header name will be different than the system name9* (as in this case), then you can override the header name that10* define_trace.h will look up by defining TRACE_INCLUDE_FILE11*12* This file is called trace-events-sample.h but we want the system13* to be called "sample". Therefore we must define the name of this14* file:15*16* #define TRACE_INCLUDE_FILE trace-events-sample17*18* As we do an the bottom of this file.19*20* Notice that TRACE_SYSTEM should be defined outside of #if21* protection, just like TRACE_INCLUDE_FILE.22*/23#undef TRACE_SYSTEM24#define TRACE_SYSTEM sample2526/*27* Notice that this file is not protected like a normal header.28* We also must allow for rereading of this file. The29*30* || defined(TRACE_HEADER_MULTI_READ)31*32* serves this purpose.33*/34#if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)35#define _TRACE_EVENT_SAMPLE_H3637/*38* All trace headers should include tracepoint.h, until we finally39* make it into a standard header.40*/41#include <linux/tracepoint.h>4243/*44* The TRACE_EVENT macro is broken up into 5 parts.45*46* name: name of the trace point. This is also how to enable the tracepoint.47* A function called trace_foo_bar() will be created.48*49* proto: the prototype of the function trace_foo_bar()50* Here it is trace_foo_bar(char *foo, int bar).51*52* args: must match the arguments in the prototype.53* Here it is simply "foo, bar".54*55* struct: This defines the way the data will be stored in the ring buffer.56* There are currently two types of elements. __field and __array.57* a __field is broken up into (type, name). Where type can be any58* type but an array.59* For an array. there are three fields. (type, name, size). The60* type of elements in the array, the name of the field and the size61* of the array.62*63* __array( char, foo, 10) is the same as saying char foo[10].64*65* fast_assign: This is a C like function that is used to store the items66* into the ring buffer.67*68* printk: This is a way to print out the data in pretty print. This is69* useful if the system crashes and you are logging via a serial line,70* the data can be printed to the console using this "printk" method.71*72* Note, that for both the assign and the printk, __entry is the handler73* to the data structure in the ring buffer, and is defined by the74* TP_STRUCT__entry.75*/76TRACE_EVENT(foo_bar,7778TP_PROTO(char *foo, int bar),7980TP_ARGS(foo, bar),8182TP_STRUCT__entry(83__array( char, foo, 10 )84__field( int, bar )85),8687TP_fast_assign(88strncpy(__entry->foo, foo, 10);89__entry->bar = bar;90),9192TP_printk("foo %s %d", __entry->foo, __entry->bar)93);94#endif9596/***** NOTICE! The #if protection ends here. *****/979899/*100* There are several ways I could have done this. If I left out the101* TRACE_INCLUDE_PATH, then it would default to the kernel source102* include/trace/events directory.103*104* I could specify a path from the define_trace.h file back to this105* file.106*107* #define TRACE_INCLUDE_PATH ../../samples/trace_events108*109* But the safest and easiest way to simply make it use the directory110* that the file is in is to add in the Makefile:111*112* CFLAGS_trace-events-sample.o := -I$(src)113*114* This will make sure the current path is part of the include115* structure for our file so that define_trace.h can find it.116*117* I could have made only the top level directory the include:118*119* CFLAGS_trace-events-sample.o := -I$(PWD)120*121* And then let the path to this directory be the TRACE_INCLUDE_PATH:122*123* #define TRACE_INCLUDE_PATH samples/trace_events124*125* But then if something defines "samples" or "trace_events" as a macro126* then we could risk that being converted too, and give us an unexpected127* result.128*/129#undef TRACE_INCLUDE_PATH130#undef TRACE_INCLUDE_FILE131#define TRACE_INCLUDE_PATH .132/*133* TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal134*/135#define TRACE_INCLUDE_FILE trace-events-sample136#include <trace/define_trace.h>137138139