diff mbox series

[3/4] libtraceevent: Add DECLARE_TRACEEVAL_<types>

Message ID 20241025074247.1157166-4-rostedt@goodmis.org (mailing list archive)
State New
Headers show
Series libtraceeval: Updates | expand

Commit Message

Steven Rostedt Oct. 25, 2024, 7:40 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Using the format of:

  {
	.type = TRACEEVAL_TYPE_NUMBER,
 	.name = "Schedule state"
  },
  {
	.type = TRACEEVAL_TYPE_STRING,
	.name = "COMM",
  },
  {
	.type = TRACEEVAL_TYPE_NUMBER,
	.name = "Prio",
  },

Is cumbersome, instead add macros that make it easier to assign these
values:

	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
	DECLARE_TRACEEVAL_STRING("COMM"),
	DECLARE_TRACEEVAL_NUMBER("Prio"),

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/traceeval.h |  19 +++++++
 samples/task-eval.c | 122 +++++++++-----------------------------------
 2 files changed, 43 insertions(+), 98 deletions(-)
diff mbox series

Patch

diff --git a/include/traceeval.h b/include/traceeval.h
index f02ecdd58ffb..7de59a302445 100644
--- a/include/traceeval.h
+++ b/include/traceeval.h
@@ -97,6 +97,24 @@  struct traceeval_data {
 	};
 };
 
+#define __TRACEEVAL_DECLARE(data_type, data_name)			\
+	{  .type = TRACEEVAL_TYPE_##data_type, .name = (data_name) }
+
+#define DECLARE_TRACEEVAL_NUMBER(data)	   __TRACEEVAL_DECLARE(NUMBER, data)
+#define DECLARE_TRACEEVAL_NUMBER_8(data)   __TRACEEVAL_DECLARE(NUMBER_8, data)
+#define DECLARE_TRACEEVAL_NUMBER_16(data)  __TRACEEVAL_DECLARE(NUMBER_16, data)
+#define DECLARE_TRACEEVAL_NUMBER_32(data)  __TRACEEVAL_DECLARE(NUMBER_32, data)
+#define DECLARE_TRACEEVAL_NUMBER_64(data)  __TRACEEVAL_DECLARE(NUMBER_64, data)
+#define DECLARE_TRACEEVAL_STRING(data)	   __TRACEEVAL_DECLARE(STRING, data)
+#define DECLARE_TRACEEVAL_CSTRING(data)	   __TRACEEVAL_DECLARE(STRING, data)
+#define DECLARE_TRACEEVAL_DELTA(data)	   __TRACEEVAL_DECLARE(DELTA, data)
+#define DECLARE_TRACEEVAL_POINTER(data_name, data_release, data_copy)	\
+	{								\
+		.type = TRACEEVAL_TYPE_POINTER,				\
+		.name = (data_name),					\
+		.release = data_release, .copy = data_copy,		\
+	}
+
 #define __TRACEEVAL_DATA(data_type, member, data)			\
 	{  .type = TRACEEVAL_TYPE_##data_type, .member = (data) }
 
@@ -362,6 +380,7 @@  int traceeval_iterator_query(struct traceeval_iterator *iter,
 			     const struct traceeval_data **results);
 void traceeval_iterator_results_release(struct traceeval_iterator *iter,
 					const struct traceeval_data *results);
+int traceeval_iterator_reset(struct traceeval_iterator *iter);
 struct traceeval_stat *traceeval_iterator_stat(struct traceeval_iterator *iter,
 					       const char *val_name);
 int traceeval_iterator_delta_stop(struct traceeval_iterator *iter,
diff --git a/samples/task-eval.c b/samples/task-eval.c
index 47ccce8e4737..26197385c91d 100644
--- a/samples/task-eval.c
+++ b/samples/task-eval.c
@@ -104,10 +104,7 @@  enum sched_state {
  * sched_switch event.
  */
 static struct traceeval_type cpu_delta_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "CPU",
-	},
+	DECLARE_TRACEEVAL_NUMBER("CPU"),
 };
 
 /*
@@ -117,10 +114,7 @@  static struct traceeval_type cpu_delta_keys[] = {
  * as RUNNING.
  */
 static struct traceeval_type cpu_delta_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Schedule state",
-	},
+	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
 };
 
 static void start_cpu_data(struct traceeval *teval, int cpu, int state,
@@ -190,14 +184,8 @@  int cpu_last_state(struct traceeval *teval, int cpu, int *state)
  * The output will show all the CPUs and their IDLE vs RUNNING states.
  */
 static struct traceeval_type cpu_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "CPU",
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Schedule state",
-	},
+	DECLARE_TRACEEVAL_NUMBER("CPU"),
+	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
 };
 
 /*
@@ -205,10 +193,7 @@  static struct traceeval_type cpu_keys[] = {
  * CPU was in that state.
  */
 static struct traceeval_type cpu_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_DELTA,
-		.name = DELTA_NAME,
-	},
+	DECLARE_TRACEEVAL_DELTA(DELTA_NAME),
 };
 
 static void insert_cpu_data(struct traceeval *teval, int cpu, int state,
@@ -229,24 +214,15 @@  static void insert_cpu_data(struct traceeval *teval, int cpu, int state,
  * When tracking tasks and threads wake up timings.
  */
 static struct traceeval_type wakeup_delta_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "PID",
-	},
+	DECLARE_TRACEEVAL_NUMBER("PID"),
 };
 
 /*
  * When finishing the timings of the task being woken up.
  */
 static struct traceeval_type wakeup_delta_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_STRING,
-		.name = "COMM",
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Prio",
-	},
+	DECLARE_TRACEEVAL_STRING("COMM"),
+	DECLARE_TRACEEVAL_NUMBER("Prio"),
 };
 
 static void start_wakeup_data(struct traceeval *teval, int pid,
@@ -292,10 +268,7 @@  static int stop_wakeup_data(struct traceeval *teval, int pid,
  * when scheduling out (for sleep state) or in (for running state).
  */
 static struct traceeval_type task_delta_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "PID",
-	},
+	DECLARE_TRACEEVAL_NUMBER("PID"),
 };
 
 /*
@@ -304,18 +277,9 @@  static struct traceeval_type task_delta_keys[] = {
  * and the priority it had. This will be saved for the output.
  */
 static struct traceeval_type task_delta_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Schedule state"
-	},
-	{
-		.type = TRACEEVAL_TYPE_STRING,
-		.name = "COMM",
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Prio",
-	},
+	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
+	DECLARE_TRACEEVAL_STRING("COMM"),
+	DECLARE_TRACEEVAL_NUMBER("Prio"),
 };
 
 static void start_task_data(struct traceeval *teval, int pid, int state,
@@ -367,14 +331,8 @@  static int stop_task_data(struct traceeval *teval, int pid, int *state,
  * they were in: RUNNING, BLOCKED, PREEMPTED, SLEEPING.
  */
 static struct traceeval_type task_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_STRING,
-		.name = "COMM"
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Schedule state"
-	},
+	DECLARE_TRACEEVAL_STRING("COMM"),
+	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
 };
 
 static void release_data(const struct traceeval_type *type,
@@ -400,16 +358,8 @@  static int copy_data(const struct traceeval_type *type,
  * that will be saved in the "data" field.
  */
 static struct traceeval_type task_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_POINTER,
-		.name = "data",
-		.release = release_data,
-		.copy = copy_data,
-	},
-	{
-		.type = TRACEEVAL_TYPE_DELTA,
-		.name = DELTA_NAME,
-	},
+	DECLARE_TRACEEVAL_POINTER("data", release_data, copy_data),
+	DECLARE_TRACEEVAL_DELTA(DELTA_NAME),
 };
 
 static int insert_task_data(struct traceeval *teval, const char *comm,
@@ -464,28 +414,16 @@  static bool task_data_exists(struct traceeval *teval, const char *comm, void **d
  * and their priority.
  */
 static struct traceeval_type thread_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "TID",
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Prio",
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Schedule state",
-	},
+	DECLARE_TRACEEVAL_NUMBER("TID"),
+	DECLARE_TRACEEVAL_NUMBER("Prio"),
+	DECLARE_TRACEEVAL_NUMBER("Schedule state"),
 };
 
 /*
  * Save the timings of the thread/state/prio keys.
  */
 static struct traceeval_type thread_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_DELTA,
-		.name = DELTA_NAME,
-	},
+	DECLARE_TRACEEVAL_DELTA(DELTA_NAME),
 };
 
 static void insert_thread_data(struct traceeval *teval,
@@ -506,28 +444,16 @@  static void insert_thread_data(struct traceeval *teval,
 }
 
 static struct traceeval_type wakeup_task_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_STRING,
-		.name = "COMM"
-	},
+	DECLARE_TRACEEVAL_STRING("COMM"),
 };
 
 static struct traceeval_type wakeup_thread_keys[] = {
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "PID"
-	},
-	{
-		.type = TRACEEVAL_TYPE_NUMBER,
-		.name = "Prio"
-	},
+	DECLARE_TRACEEVAL_NUMBER("PID"),
+	DECLARE_TRACEEVAL_NUMBER("Prio"),
 };
 
 static struct traceeval_type wakeup_vals[] = {
-	{
-		.type = TRACEEVAL_TYPE_DELTA,
-		.name = DELTA_NAME,
-	},
+	DECLARE_TRACEEVAL_DELTA(DELTA_NAME),
 };
 
 static void insert_wakeup_task_data(struct traceeval *teval,