Path: blob/master/samples/trace_events/trace_custom_sched.c
26278 views
// SPDX-License-Identifier: GPL-2.01/*2* event tracer3*4* Copyright (C) 2022 Google Inc, Steven Rostedt <[email protected]>5*/67#define pr_fmt(fmt) fmt89#include <linux/trace_events.h>10#include <linux/module.h>11#include <linux/sched.h>1213/*14* Must include the event header that the custom event will attach to,15* from the C file, and not in the custom header file.16*/17#include <trace/events/sched.h>1819/* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */20#define CREATE_CUSTOM_TRACE_EVENTS2122#include "trace_custom_sched.h"2324/*25* As the trace events are not exported to modules, the use of26* for_each_kernel_tracepoint() is needed to find the trace event27* to attach to. The fct() function below, is a callback that28* will be called for every event.29*30* Helper functions are created by the TRACE_CUSTOM_EVENT() macro31* update the event. Those are of the form:32*33* trace_custom_event_<event>_update()34*35* Where <event> is the event to attach.36*/37static void fct(struct tracepoint *tp, void *priv)38{39trace_custom_event_sched_switch_update(tp);40trace_custom_event_sched_waking_update(tp);41}4243static int __init trace_sched_init(void)44{45for_each_kernel_tracepoint(fct, NULL);46return 0;47}4849static void __exit trace_sched_exit(void)50{51}5253module_init(trace_sched_init);54module_exit(trace_sched_exit);5556MODULE_AUTHOR("Steven Rostedt");57MODULE_DESCRIPTION("Custom scheduling events");58MODULE_LICENSE("GPL");596061