diff mbox series

[3/9] libtracefs: Change hist_data_key type to flags

Message ID 20210810204818.880714-4-rostedt@goodmis.org (mailing list archive)
State New
Headers show
Series libtracefs: APIs to read a trace event hist file | expand

Commit Message

Steven Rostedt Aug. 10, 2021, 8:48 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

As the tracefs_hist_bucket_key will be exposed to users of the library,
have the type be flags, where it can be modified in the future, and not
break backward compatibility.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-hist-data.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/src/tracefs-hist-data.c b/src/tracefs-hist-data.c
index 6ec262e8b180..c7e110559ee8 100644
--- a/src/tracefs-hist-data.c
+++ b/src/tracefs-hist-data.c
@@ -113,10 +113,10 @@  static char *name_token(enum yytokentype type)
 	return NULL;
 }
 
-enum tracefs_bucket_key_type {
-	TRACEFS_BUCKET_KEY_UNDEF,
-	TRACEFS_BUCKET_KEY_SINGLE,
-	TRACEFS_BUCKET_KEY_RANGE,
+enum tracefs_bucket_key_flags {
+	TRACEFS_BUCKET_KEY_FL_UNDEF	= (1 << 29),
+	TRACEFS_BUCKET_KEY_FL_SINGLE	= (1 << 30),
+	TRACEFS_BUCKET_KEY_FL_RANGE	= (1 << 31),
 };
 
 struct tracefs_hist_bucket_key_single {
@@ -131,7 +131,7 @@  struct tracefs_hist_bucket_key_range {
 
 struct tracefs_hist_bucket_key {
 	struct tracefs_hist_bucket_key	*next;
-	enum tracefs_bucket_key_type	type;
+	unsigned int			flags;
 	union {
 		struct tracefs_hist_bucket_key_single	single;
 		struct tracefs_hist_bucket_key_range	range;
@@ -210,6 +210,8 @@  static int start_new_row(struct tracefs_hist_data *hdata)
 		return -1;
 	}
 
+	key->flags = TRACEFS_BUCKET_KEY_FL_UNDEF;
+
 	bucket->keys = key;
 	bucket->next_key = &key->next;
 
@@ -233,6 +235,8 @@  static int start_new_key(struct tracefs_hist_data *hdata)
 		return -1;
 	}
 
+	key->flags = TRACEFS_BUCKET_KEY_FL_UNDEF;
+
 	*bucket->next_key = key;
 	bucket->next_key = &key->next;
 
@@ -385,12 +389,13 @@  static int __do_key_val(struct tracefs_hist_data *hdata,
 	bucket = container_of(hdata->next_bucket, struct tracefs_hist_bucket, next);
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
-	if (!key->type)
-		key->type = TRACEFS_BUCKET_KEY_SINGLE;
-
-	if (key->type != TRACEFS_BUCKET_KEY_SINGLE)
+	if (!(key->flags &
+	      (TRACEFS_BUCKET_KEY_FL_UNDEF | TRACEFS_BUCKET_KEY_FL_SINGLE)))
 		return -1;
 
+	key->flags &= ~TRACEFS_BUCKET_KEY_FL_UNDEF;
+	key->flags |= TRACEFS_BUCKET_KEY_FL_SINGLE;
+
 	k = &key->single;
 
 	len = strlen(text);
@@ -455,7 +460,7 @@  static int do_key_raw(struct tracefs_hist_data *hdata, char *text)
 	bucket = container_of(hdata->next_bucket, struct tracefs_hist_bucket, next);
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
-	if (key->type != TRACEFS_BUCKET_KEY_SINGLE)
+	if (!(key->flags & TRACEFS_BUCKET_KEY_FL_SINGLE))
 		return -1;
 
 	k = &key->single;
@@ -487,12 +492,13 @@  static int do_key_range(struct tracefs_hist_data *hdata, long long start,
 
 	key = container_of(bucket->next_key, struct tracefs_hist_bucket_key, next);
 
-	if (!key->type)
-		key->type = TRACEFS_BUCKET_KEY_RANGE;
-
-	if (key->type != TRACEFS_BUCKET_KEY_RANGE)
+	if (!(key->flags &
+	      (TRACEFS_BUCKET_KEY_FL_UNDEF | TRACEFS_BUCKET_KEY_FL_RANGE)))
 		return -1;
 
+	key->flags &= ~TRACEFS_BUCKET_KEY_FL_UNDEF;
+	key->flags |= TRACEFS_BUCKET_KEY_FL_RANGE;
+
 	k = &key->range;
 
 	k->start = start;
@@ -698,13 +704,8 @@  void tracefs_hist_data_free(struct tracefs_hist_data *hdata)
 		hdata->buckets = bucket->next;
 		while ((key = bucket->keys)) {
 			bucket->keys = key->next;
-			switch (key->type) {
-			case TRACEFS_BUCKET_KEY_SINGLE:
+			if (key->flags & TRACEFS_BUCKET_KEY_FL_SINGLE)
 				free(key->single.sym);
-				break;
-			default:
-				break;
-			}
 			free(key);
 		}
 		while ((val = bucket->vals)) {