linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [RFC PATCH 4/4] libtracefs: Remove tracefs_hist_add_key()
Date: Fri, 10 Sep 2021 19:38:57 +0300	[thread overview]
Message-ID: <20210910163857.324696-5-y.karadz@gmail.com> (raw)
In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com>

Since we have appropriate constructor for N-dimensional histograms,
this method is no longer needed.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 Documentation/libtracefs-hist-cont.txt |   8 +-
 Documentation/libtracefs-hist.txt      |   8 +-
 include/tracefs.h                      |   2 -
 src/tracefs-hist.c                     | 110 +++++++++++--------------
 4 files changed, 58 insertions(+), 70 deletions(-)

diff --git a/Documentation/libtracefs-hist-cont.txt b/Documentation/libtracefs-hist-cont.txt
index 1b0153c..d584b46 100644
--- a/Documentation/libtracefs-hist-cont.txt
+++ b/Documentation/libtracefs-hist-cont.txt
@@ -82,15 +82,15 @@ int main (int argc, char **argv, char **env)
 		exit(-1);
 	}
 
-	hist = tracefs_hist_alloc(instance, "kmem", "kmalloc",
-				  "call_site", TRACEFS_HIST_KEY_SYM);
+	hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc",
+				    "call_site", TRACEFS_HIST_KEY_SYM,
+				    "bytes_req", 0);
 	if (!hist) {
 		fprintf(stderr, "Failed hist create\n");
 		exit(-1);
 	}
 
-	ret = tracefs_hist_add_key(hist, "bytes_req", 0);
-	ret |= tracefs_hist_add_value(hist, "bytes_alloc");
+	ret = tracefs_hist_add_value(hist, "bytes_alloc");
 	ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL);
 
 	ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc",
diff --git a/Documentation/libtracefs-hist.txt b/Documentation/libtracefs-hist.txt
index 0254c5f..692f488 100644
--- a/Documentation/libtracefs-hist.txt
+++ b/Documentation/libtracefs-hist.txt
@@ -186,15 +186,15 @@ int main (int argc, char **argv, char **env)
 		exit(-1);
 	}
 
-	hist = tracefs_hist_alloc(instance, "kmem", "kmalloc",
-				  "call_site", TRACEFS_HIST_KEY_SYM);
+	hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc",
+				    "call_site", TRACEFS_HIST_KEY_SYM,
+				    "bytes_req", 0);
 	if (!hist) {
 		fprintf(stderr, "Failed hist create\n");
 		exit(-1);
 	}
 
-	ret = tracefs_hist_add_key(hist, "bytes_req", 0);
-	ret |= tracefs_hist_add_value(hist, "bytes_alloc");
+	ret = tracefs_hist_add_value(hist, "bytes_alloc");
 	ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL);
 
 	ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc",
diff --git a/include/tracefs.h b/include/tracefs.h
index 255be9b..5c193a2 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -303,8 +303,6 @@ const char *tracefs_get_hist_name(struct tracefs_hist *hist);
 const char *tracefs_get_hist_event(struct tracefs_hist *hist);
 const char *tracefs_get_hist_system(struct tracefs_hist *hist);
 struct tracefs_instance *tracefs_get_hist_instance(struct tracefs_hist *hist);
-int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key,
-			 enum tracefs_hist_key_type type);
 int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value);
 int tracefs_hist_add_sort_key(struct tracefs_hist *hist,
 			      char *sort_key);
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 175b627..b71b0e3 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -217,6 +217,55 @@ tracefs_hist2d_alloc(struct tracefs_instance * instance,
 	return tracefs_hist_alloc(instance, system, event, axis);
 }
 
+static int add_hist_key(struct tracefs_hist *hist, const char *key,
+			 enum tracefs_hist_key_type type)
+{
+	bool use_key = false;
+	char *key_type = NULL;
+	char **new_list;
+	int ret;
+
+	switch (type) {
+	case TRACEFS_HIST_KEY_NORMAL:
+		use_key = true;
+		ret = 0;
+		break;
+	case TRACEFS_HIST_KEY_HEX:
+		ret = asprintf(&key_type, "%s.hex", key);
+		break;
+	case TRACEFS_HIST_KEY_SYM:
+		ret = asprintf(&key_type, "%s.sym", key);
+		break;
+	case TRACEFS_HIST_KEY_SYM_OFFSET:
+		ret = asprintf(&key_type, "%s.sym-offset", key);
+		break;
+	case TRACEFS_HIST_KEY_SYSCALL:
+		ret = asprintf(&key_type, "%s.syscall", key);
+		break;
+	case TRACEFS_HIST_KEY_EXECNAME:
+		ret = asprintf(&key_type, "%s.execname", key);
+		break;
+	case TRACEFS_HIST_KEY_LOG:
+		ret = asprintf(&key_type, "%s.log2", key);
+		break;
+	case TRACEFS_HIST_KEY_USECS:
+		ret = asprintf(&key_type, "%s.usecs", key);
+		break;
+	}
+
+	if (ret < 0)
+		return -1;
+
+	new_list = tracefs_list_add(hist->keys, use_key ? key : key_type);
+	free(key_type);
+	if (!new_list)
+		return -1;
+
+	hist->keys = new_list;
+
+	return 0;
+}
+
 /**
  * tracefs_hist_alloc - Initialize N-dimensional histogram
  * @instance: The instance the histogram will be in (NULL for toplevel)
@@ -262,7 +311,7 @@ tracefs_hist_alloc(struct tracefs_instance * instance,
 		goto fail;
 
 	for (; axes && axes->key; axes++)
-		if (tracefs_hist_add_key(hist, axes->key, axes->type) < 0)
+		if (add_hist_key(hist, axes->key, axes->type) < 0)
 			goto fail;
 
 	return hist;
@@ -272,65 +321,6 @@ tracefs_hist_alloc(struct tracefs_instance * instance,
 	return NULL;
 }
 
-/**
- * tracefs_hist_add_key - add to a key to a histogram
- * @hist: The histogram to add the key to.
- * @key: The name of the key field.
- * @type: The type of the key format.
- *
- * This adds a secondary or tertiary key to the histogram.
- *
- * Returns 0 on success, -1 on error.
- */
-int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key,
-			 enum tracefs_hist_key_type type)
-{
-	bool use_key = false;
-	char *key_type = NULL;
-	char **new_list;
-	int ret;
-
-	switch (type) {
-	case TRACEFS_HIST_KEY_NORMAL:
-		use_key = true;
-		ret = 0;
-		break;
-	case TRACEFS_HIST_KEY_HEX:
-		ret = asprintf(&key_type, "%s.hex", key);
-		break;
-	case TRACEFS_HIST_KEY_SYM:
-		ret = asprintf(&key_type, "%s.sym", key);
-		break;
-	case TRACEFS_HIST_KEY_SYM_OFFSET:
-		ret = asprintf(&key_type, "%s.sym-offset", key);
-		break;
-	case TRACEFS_HIST_KEY_SYSCALL:
-		ret = asprintf(&key_type, "%s.syscall", key);
-		break;
-	case TRACEFS_HIST_KEY_EXECNAME:
-		ret = asprintf(&key_type, "%s.execname", key);
-		break;
-	case TRACEFS_HIST_KEY_LOG:
-		ret = asprintf(&key_type, "%s.log2", key);
-		break;
-	case TRACEFS_HIST_KEY_USECS:
-		ret = asprintf(&key_type, "%s.usecs", key);
-		break;
-	}
-
-	if (ret < 0)
-		return -1;
-
-	new_list = tracefs_list_add(hist->keys, use_key ? key : key_type);
-	free(key_type);
-	if (!new_list)
-		return -1;
-
-	hist->keys = new_list;
-
-	return 0;
-}
-
 /**
  * tracefs_hist_add_value - add to a value to a histogram
  * @hist: The histogram to add the value to.
-- 
2.30.2


      parent reply	other threads:[~2021-09-10 16:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 16:38 [RFC PATCH 0/4] Modifications of some 'hist' APIs Yordan Karadzhov (VMware)
2021-09-10 16:38 ` [RFC PATCH 1/4] libtracefs: Add new constructors for histograms Yordan Karadzhov (VMware)
2021-09-10 16:38 ` [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key() Yordan Karadzhov (VMware)
2021-09-10 20:01   ` Steven Rostedt
2021-09-13 12:26     ` Yordan Karadzhov
2021-09-13 17:56       ` Steven Rostedt
2021-09-10 20:04   ` Steven Rostedt
2021-09-13 12:28     ` Yordan Karadzhov
2021-09-10 16:38 ` [RFC PATCH 3/4] libtracefs: Add new 'hist' APIs Yordan Karadzhov (VMware)
2021-09-10 16:38 ` Yordan Karadzhov (VMware) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210910163857.324696-5-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).