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 1/4] libtracefs: Add new constructors for histograms
Date: Fri, 10 Sep 2021 19:38:54 +0300 [thread overview]
Message-ID: <20210910163857.324696-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com>
The current way to create an N-dimensional histogram is bit
counterintuitive. We first have to call tracefs_hist_alloc()
which is essentially a constructor of 1d histogram. Then we
have to call tracefs_hist_add_key() N-1 times in order to
increase the dimentions of the histogram. Here we transform
tracefs_hist_alloc() into a constructor of N-dimensional
histogram and we also add 2 helper constructors for 1d and
2d histograms.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
include/tracefs.h | 17 +++++++++-
src/tracefs-hist.c | 82 ++++++++++++++++++++++++++++++++++++++--------
2 files changed, 85 insertions(+), 14 deletions(-)
diff --git a/include/tracefs.h b/include/tracefs.h
index b4aa75d..64fbb3f 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -280,10 +280,25 @@ enum tracefs_hist_sort_direction {
struct tracefs_hist;
void tracefs_hist_free(struct tracefs_hist *hist);
+struct tracefs_hist *
+tracefs_hist1d_alloc(struct tracefs_instance * instance,
+ const char *system, const char *event,
+ const char *key, enum tracefs_hist_key_type type);
+struct tracefs_hist *
+tracefs_hist2d_alloc(struct tracefs_instance * instance,
+ const char *system, const char *event,
+ const char *key1, enum tracefs_hist_key_type type1,
+ const char *key2, enum tracefs_hist_key_type type2);
+
+struct tracefs_hist_axis {
+ const char *key;
+ enum tracefs_hist_key_type type;
+};
+
struct tracefs_hist *
tracefs_hist_alloc(struct tracefs_instance * instance,
const char *system, const char *event,
- const char *key, enum tracefs_hist_key_type type);
+ struct tracefs_hist_axis *axes);
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);
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 6519f7e..8501d64 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -141,7 +141,7 @@ void tracefs_hist_free(struct tracefs_hist *hist)
}
/**
- * tracefs_hist_alloc - Initialize a histogram
+ * tracefs_hist1d_alloc - Initialize one-dimensional histogram
* @instance: The instance the histogram will be in (NULL for toplevel)
* @system: The system the histogram event is in.
* @event: The event that the histogram will be attached to.
@@ -157,14 +157,69 @@ void tracefs_hist_free(struct tracefs_hist *hist)
* NULL on failure.
*/
struct tracefs_hist *
+tracefs_hist1d_alloc(struct tracefs_instance * instance,
+ const char *system, const char *event,
+ const char *key, enum tracefs_hist_key_type type)
+{
+ struct tracefs_hist_axis axis[] = {{key, type}, {NULL, 0}};
+
+ return tracefs_hist_alloc(instance, system, event, axis);
+}
+
+/**
+ * tracefs_hist2d_alloc - Initialize two-dimensional histogram
+ * @instance: The instance the histogram will be in (NULL for toplevel)
+ * @system: The system the histogram event is in.
+ * @event: The event that the histogram will be attached to.
+ * @key1: The first primary key the histogram will use
+ * @type1: The format type of the first key.
+ * @key2: The second primary key the histogram will use
+ * @type2: The format type of the second key.
+ *
+ * Will initialize a histogram descriptor that will be attached to
+ * the @system/@event with the given @key1 and @key2 as the primaries.
+ * This only initializes the descriptor, it does not start the histogram
+ * in the kernel.
+ *
+ * Returns an initialized histogram on success.
+ * NULL on failure.
+ */
+struct tracefs_hist *
+tracefs_hist2d_alloc(struct tracefs_instance * instance,
+ const char *system, const char *event,
+ const char *key1, enum tracefs_hist_key_type type1,
+ const char *key2, enum tracefs_hist_key_type type2)
+{
+ struct tracefs_hist_axis axis[] = {{key1, type1},
+ {key2, type2},
+ {NULL, 0}};
+
+ return tracefs_hist_alloc(instance, system, event, axis);
+}
+
+/**
+ * tracefs_hist_alloc - Initialize N-dimensional histogram
+ * @instance: The instance the histogram will be in (NULL for toplevel)
+ * @system: The system the histogram event is in
+ * @event: The event that the histogram will be attached to
+ * @axes: An array of histogram axes, terminated by a {NULL, 0} entry
+ *
+ * Will initialize a histogram descriptor that will be attached to
+ * the @system/@event. This only initializes the descriptor with the given
+ * @axes keys as primaries. This only initializes the descriptor, it does
+ * not start the histogram in the kernel.
+ *
+ * Returns an initialized histogram on success.
+ * NULL on failure.
+ */
+struct tracefs_hist *
tracefs_hist_alloc(struct tracefs_instance * instance,
const char *system, const char *event,
- const char *key, enum tracefs_hist_key_type type)
+ struct tracefs_hist_axis *axes)
{
struct tracefs_hist *hist;
- int ret;
- if (!system || !event || !key)
+ if (!system || !event)
return NULL;
if (!tracefs_event_file_exists(instance, system, event, HIST_FILE))
@@ -174,8 +229,7 @@ tracefs_hist_alloc(struct tracefs_instance * instance,
if (!hist)
return NULL;
- ret = trace_get_instance(instance);
- if (ret < 0) {
+ if (trace_get_instance(instance) < 0) {
free(hist);
return NULL;
}
@@ -184,16 +238,18 @@ tracefs_hist_alloc(struct tracefs_instance * instance,
hist->system = strdup(system);
hist->event = strdup(event);
+ if (!hist->system || !hist->event)
+ goto fail;
- ret = tracefs_hist_add_key(hist, key, type);
-
- if (!hist->system || !hist->event || ret < 0) {
- tracefs_hist_free(hist);
- return NULL;
- }
-
+ for (; axes && axes->key; axes++)
+ if (tracefs_hist_add_key(hist, axes->key, axes->type) < 0)
+ goto fail;
return hist;
+
+ fail:
+ tracefs_hist_free(hist);
+ return NULL;
}
/**
--
2.30.2
next prev 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 ` Yordan Karadzhov (VMware) [this message]
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 ` [RFC PATCH 4/4] libtracefs: Remove tracefs_hist_add_key() Yordan Karadzhov (VMware)
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-2-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).