162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/*
462306a36Sopenharmony_ci * If TRACE_SYSTEM is defined, that will be the directory created
562306a36Sopenharmony_ci * in the ftrace directory under /sys/kernel/tracing/events/<system>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * The define_trace.h below will also look for a file name of
862306a36Sopenharmony_ci * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
962306a36Sopenharmony_ci * In this case, it would look for sample-trace.h
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * If the header name will be different than the system name
1262306a36Sopenharmony_ci * (as in this case), then you can override the header name that
1362306a36Sopenharmony_ci * define_trace.h will look up by defining TRACE_INCLUDE_FILE
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * This file is called sample-trace-array.h but we want the system
1662306a36Sopenharmony_ci * to be called "sample-subsystem". Therefore we must define the name of this
1762306a36Sopenharmony_ci * file:
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * #define TRACE_INCLUDE_FILE sample-trace-array
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * As we do in the bottom of this file.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * Notice that TRACE_SYSTEM should be defined outside of #if
2462306a36Sopenharmony_ci * protection, just like TRACE_INCLUDE_FILE.
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_ci#undef TRACE_SYSTEM
2762306a36Sopenharmony_ci#define TRACE_SYSTEM sample-subsystem
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/*
3062306a36Sopenharmony_ci * TRACE_SYSTEM is expected to be a C valid variable (alpha-numeric
3162306a36Sopenharmony_ci * and underscore), although it may start with numbers. If for some
3262306a36Sopenharmony_ci * reason it is not, you need to add the following lines:
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci#undef TRACE_SYSTEM_VAR
3562306a36Sopenharmony_ci#define TRACE_SYSTEM_VAR sample_subsystem
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci/*
3862306a36Sopenharmony_ci * But the above is only needed if TRACE_SYSTEM is not alpha-numeric
3962306a36Sopenharmony_ci * and underscored. By default, TRACE_SYSTEM_VAR will be equal to
4062306a36Sopenharmony_ci * TRACE_SYSTEM. As TRACE_SYSTEM_VAR must be alpha-numeric, if
4162306a36Sopenharmony_ci * TRACE_SYSTEM is not, then TRACE_SYSTEM_VAR must be defined with
4262306a36Sopenharmony_ci * only alpha-numeric and underscores.
4362306a36Sopenharmony_ci *
4462306a36Sopenharmony_ci * The TRACE_SYSTEM_VAR is only used internally and not visible to
4562306a36Sopenharmony_ci * user space.
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/*
4962306a36Sopenharmony_ci * Notice that this file is not protected like a normal header.
5062306a36Sopenharmony_ci * We also must allow for rereading of this file. The
5162306a36Sopenharmony_ci *
5262306a36Sopenharmony_ci *  || defined(TRACE_HEADER_MULTI_READ)
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * serves this purpose.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci#if !defined(_SAMPLE_TRACE_ARRAY_H) || defined(TRACE_HEADER_MULTI_READ)
5762306a36Sopenharmony_ci#define _SAMPLE_TRACE_ARRAY_H
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#include <linux/tracepoint.h>
6062306a36Sopenharmony_ciTRACE_EVENT(sample_event,
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	TP_PROTO(int count, unsigned long time),
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	TP_ARGS(count, time),
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci	TP_STRUCT__entry(
6762306a36Sopenharmony_ci		__field(int, count)
6862306a36Sopenharmony_ci		__field(unsigned long, time)
6962306a36Sopenharmony_ci	),
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	TP_fast_assign(
7262306a36Sopenharmony_ci		__entry->count = count;
7362306a36Sopenharmony_ci		__entry->time = time;
7462306a36Sopenharmony_ci	),
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	TP_printk("count value=%d at jiffies=%lu", __entry->count,
7762306a36Sopenharmony_ci		__entry->time)
7862306a36Sopenharmony_ci	);
7962306a36Sopenharmony_ci#endif
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#undef TRACE_INCLUDE_PATH
8262306a36Sopenharmony_ci#define TRACE_INCLUDE_PATH .
8362306a36Sopenharmony_ci#define TRACE_INCLUDE_FILE sample-trace-array
8462306a36Sopenharmony_ci#include <trace/define_trace.h>
85