tracing: Add TRACE_CUSTOM_EVENT() macro
[linux-2.6-block.git] / samples / trace_events / trace_custom_sched.h
CommitLineData
3a73333f
SRG
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/*
4 * Like the headers that use TRACE_EVENT(), the TRACE_CUSTOM_EVENT()
5 * needs a header that allows for multiple inclusions.
6 *
7 * Test for a unique name (here we have _TRACE_CUSTOM_SCHED_H),
8 * also allowing to continue if TRACE_CUSTOM_MULTI_READ is defined.
9 */
10#if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ)
11#define _TRACE_CUSTOM_SCHED_H
12
13/* Include linux/trace_events.h for initial defines of TRACE_CUSTOM_EVENT() */
14#include <linux/trace_events.h>
15
16/*
17 * TRACE_CUSTOM_EVENT() is just like TRACE_EVENT(). The first parameter
18 * is the event name of an existing event where the TRACE_EVENT has been included
19 * in the C file before including this file.
20 */
21TRACE_CUSTOM_EVENT(sched_switch,
22
23 /*
24 * The TP_PROTO() and TP_ARGS must match the trace event
25 * that the custom event is using.
26 */
27 TP_PROTO(bool preempt,
28 struct task_struct *prev,
29 struct task_struct *next),
30
31 TP_ARGS(preempt, prev, next),
32
33 /*
34 * The next fields are where the customization happens.
35 * The TP_STRUCT__entry() defines what will be recorded
36 * in the ring buffer when the custom event triggers.
37 *
38 * The rest is just like the TRACE_EVENT() macro except that
39 * it uses the custom entry.
40 */
41 TP_STRUCT__entry(
42 __field( unsigned short, prev_prio )
43 __field( unsigned short, next_prio )
44 __field( pid_t, next_pid )
45 ),
46
47 TP_fast_assign(
48 __entry->prev_prio = prev->prio;
49 __entry->next_pid = next->pid;
50 __entry->next_prio = next->prio;
51 ),
52
53 TP_printk("prev_prio=%d next_pid=%d next_prio=%d",
54 __entry->prev_prio, __entry->next_pid, __entry->next_prio)
55)
56
57
58TRACE_CUSTOM_EVENT(sched_waking,
59
60 TP_PROTO(struct task_struct *p),
61
62 TP_ARGS(p),
63
64 TP_STRUCT__entry(
65 __field( pid_t, pid )
66 __field( unsigned short, prio )
67 ),
68
69 TP_fast_assign(
70 __entry->pid = p->pid;
71 __entry->prio = p->prio;
72 ),
73
74 TP_printk("pid=%d prio=%d", __entry->pid, __entry->prio)
75)
76#endif
77/*
78 * Just like the headers that create TRACE_EVENTs, the below must
79 * be outside the protection of the above #if block.
80 */
81
82/*
83 * It is required that the Makefile includes:
84 * CFLAGS_<c_file>.o := -I$(src)
85 */
86#undef TRACE_INCLUDE_PATH
87#undef TRACE_INCLUDE_FILE
88#define TRACE_INCLUDE_PATH .
89
90/*
91 * It is requred that the TRACE_INCLUDE_FILE be the same
92 * as this file without the ".h".
93 */
94#define TRACE_INCLUDE_FILE trace_custom_sched
95#include <trace/define_custom_trace.h>