1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2022 Google Inc, Steven Rostedt <rostedt@goodmis.org>
8 #define pr_fmt(fmt) fmt
10 #include <linux/trace_events.h>
11 #include <linux/version.h>
12 #include <linux/module.h>
13 #include <linux/sched.h>
16 * Must include the event header that the custom event will attach to,
17 * from the C file, and not in the custom header file.
19 #include <trace/events/sched.h>
21 /* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */
22 #define CREATE_CUSTOM_TRACE_EVENTS
24 #include "trace_custom_sched.h"
27 * As the trace events are not exported to modules, the use of
28 * for_each_kernel_tracepoint() is needed to find the trace event
29 * to attach to. The fct() function below, is a callback that
30 * will be called for every event.
32 * Helper functions are created by the TRACE_CUSTOM_EVENT() macro
33 * update the event. Those are of the form:
35 * trace_custom_event_<event>_update()
37 * Where <event> is the event to attach.
39 static void fct(struct tracepoint *tp, void *priv)
41 trace_custom_event_sched_switch_update(tp);
42 trace_custom_event_sched_waking_update(tp);
45 static int __init trace_sched_init(void)
47 for_each_kernel_tracepoint(fct, NULL);
51 static void __exit trace_sched_exit(void)
55 module_init(trace_sched_init);
56 module_exit(trace_sched_exit);
58 MODULE_AUTHOR("Steven Rostedt");
59 MODULE_DESCRIPTION("Custom scheduling events");
60 MODULE_LICENSE("GPL");