13a73333fSSteven Rostedt (Google) /* SPDX-License-Identifier: GPL-2.0 */ 23a73333fSSteven Rostedt (Google) 33a73333fSSteven Rostedt (Google) /* 43a73333fSSteven Rostedt (Google) * Like the headers that use TRACE_EVENT(), the TRACE_CUSTOM_EVENT() 53a73333fSSteven Rostedt (Google) * needs a header that allows for multiple inclusions. 63a73333fSSteven Rostedt (Google) * 73a73333fSSteven Rostedt (Google) * Test for a unique name (here we have _TRACE_CUSTOM_SCHED_H), 83a73333fSSteven Rostedt (Google) * also allowing to continue if TRACE_CUSTOM_MULTI_READ is defined. 93a73333fSSteven Rostedt (Google) */ 103a73333fSSteven Rostedt (Google) #if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ) 113a73333fSSteven Rostedt (Google) #define _TRACE_CUSTOM_SCHED_H 123a73333fSSteven Rostedt (Google) 133a73333fSSteven Rostedt (Google) /* Include linux/trace_events.h for initial defines of TRACE_CUSTOM_EVENT() */ 143a73333fSSteven Rostedt (Google) #include <linux/trace_events.h> 153a73333fSSteven Rostedt (Google) 163a73333fSSteven Rostedt (Google) /* 173a73333fSSteven Rostedt (Google) * TRACE_CUSTOM_EVENT() is just like TRACE_EVENT(). The first parameter 183a73333fSSteven Rostedt (Google) * is the event name of an existing event where the TRACE_EVENT has been included 193a73333fSSteven Rostedt (Google) * in the C file before including this file. 203a73333fSSteven Rostedt (Google) */ 213a73333fSSteven Rostedt (Google) TRACE_CUSTOM_EVENT(sched_switch, 223a73333fSSteven Rostedt (Google) 233a73333fSSteven Rostedt (Google) /* 243a73333fSSteven Rostedt (Google) * The TP_PROTO() and TP_ARGS must match the trace event 253a73333fSSteven Rostedt (Google) * that the custom event is using. 263a73333fSSteven Rostedt (Google) */ 273a73333fSSteven Rostedt (Google) TP_PROTO(bool preempt, 283a73333fSSteven Rostedt (Google) struct task_struct *prev, 29*9c2136beSDelyan Kratunov struct task_struct *next, 30*9c2136beSDelyan Kratunov unsigned int prev_state), 313a73333fSSteven Rostedt (Google) 32*9c2136beSDelyan Kratunov TP_ARGS(preempt, prev, next, prev_state), 333a73333fSSteven Rostedt (Google) 343a73333fSSteven Rostedt (Google) /* 353a73333fSSteven Rostedt (Google) * The next fields are where the customization happens. 363a73333fSSteven Rostedt (Google) * The TP_STRUCT__entry() defines what will be recorded 373a73333fSSteven Rostedt (Google) * in the ring buffer when the custom event triggers. 383a73333fSSteven Rostedt (Google) * 393a73333fSSteven Rostedt (Google) * The rest is just like the TRACE_EVENT() macro except that 403a73333fSSteven Rostedt (Google) * it uses the custom entry. 413a73333fSSteven Rostedt (Google) */ 423a73333fSSteven Rostedt (Google) TP_STRUCT__entry( 433a73333fSSteven Rostedt (Google) __field( unsigned short, prev_prio ) 443a73333fSSteven Rostedt (Google) __field( unsigned short, next_prio ) 453a73333fSSteven Rostedt (Google) __field( pid_t, next_pid ) 463a73333fSSteven Rostedt (Google) ), 473a73333fSSteven Rostedt (Google) 483a73333fSSteven Rostedt (Google) TP_fast_assign( 493a73333fSSteven Rostedt (Google) __entry->prev_prio = prev->prio; 503a73333fSSteven Rostedt (Google) __entry->next_pid = next->pid; 513a73333fSSteven Rostedt (Google) __entry->next_prio = next->prio; 523a73333fSSteven Rostedt (Google) ), 533a73333fSSteven Rostedt (Google) 543a73333fSSteven Rostedt (Google) TP_printk("prev_prio=%d next_pid=%d next_prio=%d", 553a73333fSSteven Rostedt (Google) __entry->prev_prio, __entry->next_pid, __entry->next_prio) 563a73333fSSteven Rostedt (Google) ) 573a73333fSSteven Rostedt (Google) 583a73333fSSteven Rostedt (Google) 593a73333fSSteven Rostedt (Google) TRACE_CUSTOM_EVENT(sched_waking, 603a73333fSSteven Rostedt (Google) 613a73333fSSteven Rostedt (Google) TP_PROTO(struct task_struct *p), 623a73333fSSteven Rostedt (Google) 633a73333fSSteven Rostedt (Google) TP_ARGS(p), 643a73333fSSteven Rostedt (Google) 653a73333fSSteven Rostedt (Google) TP_STRUCT__entry( 663a73333fSSteven Rostedt (Google) __field( pid_t, pid ) 673a73333fSSteven Rostedt (Google) __field( unsigned short, prio ) 683a73333fSSteven Rostedt (Google) ), 693a73333fSSteven Rostedt (Google) 703a73333fSSteven Rostedt (Google) TP_fast_assign( 713a73333fSSteven Rostedt (Google) __entry->pid = p->pid; 723a73333fSSteven Rostedt (Google) __entry->prio = p->prio; 733a73333fSSteven Rostedt (Google) ), 743a73333fSSteven Rostedt (Google) 753a73333fSSteven Rostedt (Google) TP_printk("pid=%d prio=%d", __entry->pid, __entry->prio) 763a73333fSSteven Rostedt (Google) ) 773a73333fSSteven Rostedt (Google) #endif 783a73333fSSteven Rostedt (Google) /* 793a73333fSSteven Rostedt (Google) * Just like the headers that create TRACE_EVENTs, the below must 803a73333fSSteven Rostedt (Google) * be outside the protection of the above #if block. 813a73333fSSteven Rostedt (Google) */ 823a73333fSSteven Rostedt (Google) 833a73333fSSteven Rostedt (Google) /* 843a73333fSSteven Rostedt (Google) * It is required that the Makefile includes: 853a73333fSSteven Rostedt (Google) * CFLAGS_<c_file>.o := -I$(src) 863a73333fSSteven Rostedt (Google) */ 873a73333fSSteven Rostedt (Google) #undef TRACE_INCLUDE_PATH 883a73333fSSteven Rostedt (Google) #undef TRACE_INCLUDE_FILE 893a73333fSSteven Rostedt (Google) #define TRACE_INCLUDE_PATH . 903a73333fSSteven Rostedt (Google) 913a73333fSSteven Rostedt (Google) /* 923a73333fSSteven Rostedt (Google) * It is requred that the TRACE_INCLUDE_FILE be the same 933a73333fSSteven Rostedt (Google) * as this file without the ".h". 943a73333fSSteven Rostedt (Google) */ 953a73333fSSteven Rostedt (Google) #define TRACE_INCLUDE_FILE trace_custom_sched 963a73333fSSteven Rostedt (Google) #include <trace/define_custom_trace.h> 97