All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH v2 6/7] libtracefs: Add API tracefs_synth_get_start_hist()
Date: Tue,  3 Aug 2021 12:48:10 -0400	[thread overview]
Message-ID: <20210803164811.693731-7-rostedt@goodmis.org> (raw)
In-Reply-To: <20210803164811.693731-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add the API tracefs_synth_get_start_hist() that returns a tracefs_hist
descriptor describing the start event of a tracefs_synth.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-synth2.txt |  4 ++
 include/tracefs.h                   |  1 +
 src/tracefs-hist.c                  | 73 +++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)

diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
index 41680d5b9cba..5d34c4f60469 100644
--- a/Documentation/libtracefs-synth2.txt
+++ b/Documentation/libtracefs-synth2.txt
@@ -17,6 +17,7 @@ int tracefs_synth_destroy(struct tracefs_instance pass:[*]instance,
 			  struct tracefs_synth pass:[*]synth);
 int tracefs_synth_show(struct trace_seq pass:[*]seq, struct tracefs_instance pass:[*]instance,
 		       struct tracefs_synth pass:[*]synth);
+struct tracefs_hist pass:[*]tracefs_synth_get_start_hist(struct tracefs_synth pass:[*]synth);
 
 --
 
@@ -52,6 +53,9 @@ this may fail as busy.
 the synthetic event in the given _instance_, it will write the echo commands to
 manually create it in the _seq_ given.
 
+*tracefs_synth_get_start_hist*() returns a struct tracefs_hist descriptor describing
+the histogram used to create the synthetic event.
+
 RETURN VALUE
 ------------
 Returns zero on success or -1 on error.
diff --git a/include/tracefs.h b/include/tracefs.h
index ab781764b0ed..8148bd57224b 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -467,6 +467,7 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth,
 				    const char *field,
 				    enum tracefs_compare compare,
 				    const char *val);
+struct tracefs_hist *tracefs_synth_get_start_hist(struct tracefs_synth *synth);
 int tracefs_synth_create(struct tracefs_instance *instance,
 			 struct tracefs_synth *synth);
 int tracefs_synth_destroy(struct tracefs_instance *instance,
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 7c84e942d58b..379f75c7de24 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -543,6 +543,7 @@ struct tracefs_synth {
 	char			*name;
 	char			**synthetic_fields;
 	char			**synthetic_args;
+	char			**start_selection;
 	char			**start_keys;
 	char			**end_keys;
 	char			**start_vars;
@@ -1061,6 +1062,7 @@ int tracefs_synth_add_start_field(struct tracefs_synth *synth,
 {
 	const struct tep_format_field *field;
 	char *start_arg;
+	char **tmp;
 	int ret;
 
 	if (!synth || !start_field) {
@@ -1087,7 +1089,14 @@ int tracefs_synth_add_start_field(struct tracefs_synth *synth,
 		goto out_free;
 
 	ret = add_synth_fields(synth, field, name);
+	if (ret)
+		goto out_free;
 
+	tmp = tracefs_list_add(synth->start_selection, start_field);
+	if (tmp)
+		synth->start_selection = tmp;
+	else
+		ret = -1;
  out_free:
 	free(start_arg);
 	return ret;
@@ -1345,6 +1354,70 @@ static int verify_state(struct tracefs_synth *synth)
 	return 0;
 }
 
+/**
+ * tracefs_synth_get_start_hist - Return the histogram of the start event
+ * @synth: The synthetic event to get the start hist from.
+ *
+ * On success, returns a tracefs_hist descriptor that holds the
+ * histogram information of the start_event of the synthetic event
+ * structure. Returns NULL on failure.
+ */
+struct tracefs_hist *
+tracefs_synth_get_start_hist(struct tracefs_synth *synth)
+{
+	struct tracefs_hist *hist = NULL;
+	struct tep_handle *tep;
+	const char *system;
+	const char *event;
+	const char *key;
+	char **keys;
+	int ret;
+	int i;
+
+	if (!synth) {
+		errno = EINVAL;
+		return NULL;
+	}
+
+	system = synth->start_event->system;
+	event = synth->start_event->name;
+	keys = synth->start_keys;
+	tep = synth->tep;
+
+	if (!keys)
+		keys = synth->start_selection;
+
+	if (!keys)
+		return NULL;
+
+	for (i = 0; keys[i]; i++) {
+		key = keys[i];
+
+		if (i) {
+			ret = tracefs_hist_add_key(hist, key, 0);
+			if (ret < 0) {
+				tracefs_hist_free(hist);
+				return NULL;
+			}
+		} else {
+			hist = tracefs_hist_alloc(tep, system, event,
+						  key, 0);
+			if (!hist)
+				return NULL;
+		}
+	}
+
+	if (synth->start_filter) {
+		hist->filter = strdup(synth->start_filter);
+		if (!hist->filter) {
+			tracefs_hist_free(hist);
+			return NULL;
+		}
+	}
+
+	return hist;
+}
+
 /**
  * tracefs_synth_create - creates the synthetic event on the system
  * @instance: The instance to modify the start and end events
-- 
2.30.2


  parent reply	other threads:[~2021-08-03 16:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 16:48 [PATCH v2 0/7] libtracefs: Updates to the histograms for tracefs_sql() Steven Rostedt
2021-08-03 16:48 ` [PATCH v2 1/7] libtracefs: Change the tracefs_hist API to not take an instance immediately Steven Rostedt
2021-08-03 16:48 ` [PATCH v2 2/7] libtracefs: Expose tracefs_hist_command() as an API Steven Rostedt
2021-08-03 16:48 ` [PATCH v2 3/7] libtracefs: Add API tracefs_hist_append_filter() Steven Rostedt
2021-08-03 16:48 ` [PATCH v2 4/7] libtracefs: Add API tracefs_hist_show() Steven Rostedt
2021-08-03 16:48 ` [PATCH v2 5/7] libtracefs: Split up libtracefs-synth man page Steven Rostedt
2021-08-03 16:48 ` Steven Rostedt [this message]
2021-08-03 16:48 ` [PATCH v2 7/7] libtracefs: Add API tracefs_synth_complete() Steven Rostedt

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=20210803164811.693731-7-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.