blob: b99d9ab7db858f8e309980bee271f6b40c6a06c7 [file] [log] [blame]
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -05001// SPDX-License-Identifier: GPL-2.0
2/*
3 * event tracer
4 *
5 * Copyright (C) 2022 Google Inc, Steven Rostedt <rostedt@goodmis.org>
6 */
7
8#define pr_fmt(fmt) fmt
9
10#include <linux/trace_events.h>
11#include <linux/version.h>
12#include <linux/module.h>
13#include <linux/sched.h>
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050014
15/*
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.
18 */
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050019#include <trace/events/sched.h>
20
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050021/* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */
22#define CREATE_CUSTOM_TRACE_EVENTS
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050023
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050024#include "trace_custom_sched.h"
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050025
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050026/*
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.
31 *
32 * Helper functions are created by the TRACE_CUSTOM_EVENT() macro
33 * update the event. Those are of the form:
34 *
35 * trace_custom_event_<event>_update()
36 *
37 * Where <event> is the event to attach.
38 */
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050039static void fct(struct tracepoint *tp, void *priv)
40{
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050041 trace_custom_event_sched_switch_update(tp);
42 trace_custom_event_sched_waking_update(tp);
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050043}
44
45static int __init trace_sched_init(void)
46{
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050047 for_each_kernel_tracepoint(fct, NULL);
Steven Rostedt (Google)3a733332022-03-03 17:05:34 -050048 return 0;
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050049}
50
51static void __exit trace_sched_exit(void)
52{
Steven Rostedt (Google)953c2f02022-03-03 17:05:32 -050053}
54
55module_init(trace_sched_init);
56module_exit(trace_sched_exit);
57
58MODULE_AUTHOR("Steven Rostedt");
59MODULE_DESCRIPTION("Custom scheduling events");
60MODULE_LICENSE("GPL");