[PATCH 3/5] samples/trace_event: Add '__rel_loc' using sample event

From: Masami Hiramatsu
Date: Mon Nov 15 2021 - 05:20:53 EST


Add '__rel_loc' using sample event for testing.
User can use this for testing purpose. There is
no reason to use this macro from the kernel.

Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
---
samples/trace_events/trace-events-sample.c | 2 ++
samples/trace_events/trace-events-sample.h | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)

diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c
index 1a72b7d95cdc..b43415c31da6 100644
--- a/samples/trace_events/trace-events-sample.c
+++ b/samples/trace_events/trace-events-sample.c
@@ -43,6 +43,8 @@ static void simple_thread_func(int cnt)
trace_foo_with_template_cond("prints other times", cnt);

trace_foo_with_template_print("I have to be different", cnt);
+
+ trace_foo_rel_loc("Hello __rel_loc", cnt);
}

static int simple_thread(void *arg)
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index e61471ab7d14..be6321d4b04a 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -506,6 +506,34 @@ DEFINE_EVENT_PRINT(foo_template, foo_with_template_print,
TP_ARGS(foo, bar),
TP_printk("bar %s %d", __get_str(foo), __entry->bar));

+/*
+ * There are yet another __rel_loc dynamic data attribute. If you
+ * use __rel_dynamic_array() and __rel_string() etc. macros, you
+ * can use this attribute. There is no difference from the viewpoint
+ * of functionality with/without 'rel' but the encoding is a bit
+ * different. This is expected to be used with user-space event,
+ * there is no reason that the kernel event use this, but only for
+ * testing.
+ */
+
+TRACE_EVENT(foo_rel_loc,
+
+ TP_PROTO(const char *foo, int bar),
+
+ TP_ARGS(foo, bar),
+
+ TP_STRUCT__entry(
+ __rel_string( foo, foo )
+ __field( int, bar )
+ ),
+
+ TP_fast_assign(
+ __assign_rel_str(foo, foo);
+ __entry->bar = bar;
+ ),
+
+ TP_printk("foo_rel_loc %s, %d", __get_rel_str(foo), __entry->bar)
+);
#endif

/***** NOTICE! The #if protection ends here. *****/