2009-04-15 09:37:03 +08:00
|
|
|
/*
|
|
|
|
* If TRACE_SYSTEM is defined, that will be the directory created
|
2009-09-07 20:37:37 +08:00
|
|
|
* in the ftrace directory under /sys/kernel/debug/tracing/events/<system>
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* The define_trace.h below will also look for a file name of
|
2009-04-15 09:37:03 +08:00
|
|
|
* TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
|
2009-06-17 07:53:07 +08:00
|
|
|
* In this case, it would look for sample.h
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* If the header name will be different than the system name
|
|
|
|
* (as in this case), then you can override the header name that
|
|
|
|
* define_trace.h will look up by defining TRACE_INCLUDE_FILE
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* This file is called trace-events-sample.h but we want the system
|
|
|
|
* to be called "sample". Therefore we must define the name of this
|
|
|
|
* file:
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* #define TRACE_INCLUDE_FILE trace-events-sample
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* As we do an the bottom of this file.
|
2009-07-13 10:33:21 +08:00
|
|
|
*
|
|
|
|
* Notice that TRACE_SYSTEM should be defined outside of #if
|
|
|
|
* protection, just like TRACE_INCLUDE_FILE.
|
2009-04-15 09:37:03 +08:00
|
|
|
*/
|
|
|
|
#undef TRACE_SYSTEM
|
2009-05-07 09:20:39 +08:00
|
|
|
#define TRACE_SYSTEM sample
|
2009-04-15 09:37:03 +08:00
|
|
|
|
2009-07-13 10:33:21 +08:00
|
|
|
/*
|
|
|
|
* Notice that this file is not protected like a normal header.
|
|
|
|
* We also must allow for rereading of this file. The
|
|
|
|
*
|
|
|
|
* || defined(TRACE_HEADER_MULTI_READ)
|
|
|
|
*
|
|
|
|
* serves this purpose.
|
|
|
|
*/
|
|
|
|
#if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
|
|
|
|
#define _TRACE_EVENT_SAMPLE_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All trace headers should include tracepoint.h, until we finally
|
|
|
|
* make it into a standard header.
|
|
|
|
*/
|
|
|
|
#include <linux/tracepoint.h>
|
|
|
|
|
2009-04-15 09:37:03 +08:00
|
|
|
/*
|
|
|
|
* The TRACE_EVENT macro is broken up into 5 parts.
|
|
|
|
*
|
|
|
|
* name: name of the trace point. This is also how to enable the tracepoint.
|
|
|
|
* A function called trace_foo_bar() will be created.
|
|
|
|
*
|
|
|
|
* proto: the prototype of the function trace_foo_bar()
|
|
|
|
* Here it is trace_foo_bar(char *foo, int bar).
|
|
|
|
*
|
|
|
|
* args: must match the arguments in the prototype.
|
|
|
|
* Here it is simply "foo, bar".
|
|
|
|
*
|
|
|
|
* struct: This defines the way the data will be stored in the ring buffer.
|
|
|
|
* There are currently two types of elements. __field and __array.
|
|
|
|
* a __field is broken up into (type, name). Where type can be any
|
2014-06-17 20:59:16 +08:00
|
|
|
* primitive type (integer, long or pointer). __field_struct() can
|
|
|
|
* be any static complex data value (struct, union, but not an array).
|
2009-04-15 09:37:03 +08:00
|
|
|
* For an array. there are three fields. (type, name, size). The
|
|
|
|
* type of elements in the array, the name of the field and the size
|
|
|
|
* of the array.
|
|
|
|
*
|
|
|
|
* __array( char, foo, 10) is the same as saying char foo[10].
|
|
|
|
*
|
|
|
|
* fast_assign: This is a C like function that is used to store the items
|
|
|
|
* into the ring buffer.
|
|
|
|
*
|
|
|
|
* printk: This is a way to print out the data in pretty print. This is
|
|
|
|
* useful if the system crashes and you are logging via a serial line,
|
|
|
|
* the data can be printed to the console using this "printk" method.
|
|
|
|
*
|
|
|
|
* Note, that for both the assign and the printk, __entry is the handler
|
|
|
|
* to the data structure in the ring buffer, and is defined by the
|
|
|
|
* TP_STRUCT__entry.
|
|
|
|
*/
|
|
|
|
TRACE_EVENT(foo_bar,
|
|
|
|
|
|
|
|
TP_PROTO(char *foo, int bar),
|
|
|
|
|
|
|
|
TP_ARGS(foo, bar),
|
|
|
|
|
|
|
|
TP_STRUCT__entry(
|
|
|
|
__array( char, foo, 10 )
|
|
|
|
__field( int, bar )
|
|
|
|
),
|
|
|
|
|
|
|
|
TP_fast_assign(
|
|
|
|
strncpy(__entry->foo, foo, 10);
|
|
|
|
__entry->bar = bar;
|
|
|
|
),
|
|
|
|
|
|
|
|
TP_printk("foo %s %d", __entry->foo, __entry->bar)
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***** NOTICE! The #if protection ends here. *****/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are several ways I could have done this. If I left out the
|
|
|
|
* TRACE_INCLUDE_PATH, then it would default to the kernel source
|
|
|
|
* include/trace/events directory.
|
|
|
|
*
|
|
|
|
* I could specify a path from the define_trace.h file back to this
|
|
|
|
* file.
|
|
|
|
*
|
|
|
|
* #define TRACE_INCLUDE_PATH ../../samples/trace_events
|
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* But the safest and easiest way to simply make it use the directory
|
|
|
|
* that the file is in is to add in the Makefile:
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* CFLAGS_trace-events-sample.o := -I$(src)
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
|
|
|
* This will make sure the current path is part of the include
|
2009-06-17 07:53:07 +08:00
|
|
|
* structure for our file so that define_trace.h can find it.
|
2009-04-15 09:37:03 +08:00
|
|
|
*
|
|
|
|
* I could have made only the top level directory the include:
|
|
|
|
*
|
|
|
|
* CFLAGS_trace-events-sample.o := -I$(PWD)
|
|
|
|
*
|
|
|
|
* And then let the path to this directory be the TRACE_INCLUDE_PATH:
|
|
|
|
*
|
|
|
|
* #define TRACE_INCLUDE_PATH samples/trace_events
|
|
|
|
*
|
2009-06-17 07:53:07 +08:00
|
|
|
* But then if something defines "samples" or "trace_events" as a macro
|
|
|
|
* then we could risk that being converted too, and give us an unexpected
|
2009-04-15 09:37:03 +08:00
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
#undef TRACE_INCLUDE_PATH
|
2009-05-07 09:20:39 +08:00
|
|
|
#undef TRACE_INCLUDE_FILE
|
2009-04-15 09:37:03 +08:00
|
|
|
#define TRACE_INCLUDE_PATH .
|
2009-05-07 09:20:39 +08:00
|
|
|
/*
|
|
|
|
* TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
|
|
|
|
*/
|
|
|
|
#define TRACE_INCLUDE_FILE trace-events-sample
|
2009-04-15 09:37:03 +08:00
|
|
|
#include <trace/define_trace.h>
|