Skip to contentSkip to conversation

libtracefs: New APIs for getting the raw format of synth event

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 4 messages Dec 9, 2021 Documentation

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 libtracefs: New APIs for getting the raw format of synth event

The following APIs are added:
int tracefs_synth_echo_fmt(struct trace_seq *, struct tracefs_synth *) const char *tracefs_synth_show_event(struct tracefs_synth *) const char *tracefs_synth_show_start_hist(struct tracefs_synth *) const char *tracefs_synth_show_end_hist(struct tracefs_synth *)

The new APIs can be useful in the case whene the user wants to check what exactly gets passed to the kernel as definition of a synth event.

---
 Documentation/libtracefs-synth2.txt | 23 ++++++-
 include/tracefs.h                   |  5 ++
 src/tracefs-hist.c                  | 94 +++++++++++++++++++++++------
 3 files changed, 102 insertions(+), 20 deletions(-)
Documentation/libtracefs-synth2.txt +21 -2
index 569819a..e557bc9 100644
@@ -5,7 +5,8 @@ NAME
 ----
 tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_echo_cmd, tracefs_synth_complete,
 tracefs_synth_get_start_hist, tracefs_synth_trace, tracefs_synth_snapshot,
-tracefs_synth_get_name - Creation of synthetic events
+tracefs_synth_get_name, tracefs_synth_echo_fmt, tracefs_synth_show_event,
+tracefs_synth_show_start_hist, tracefs_synth_show_end_hist - Creation of synthetic events
 
 SYNOPSIS
 --------
@@ -27,6 +28,11 @@ int tracefs_synth_save(struct tracefs_synth pass:[*]synth,
 		       enum tracefs_synth_handler type, const char pass:[*]var,
 		       char pass:[**]save_fields);
 const char *tracefs_synth_get_name(struct tracefs_synth pass:[*]synth);
+int tracefs_synth_echo_fmt(struct trace_seq pass:[*]seq, struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_event(struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_start_hist(struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_end_hist(struct tracefs_synth pass:[*]synth);
+
 --
 
 DESCRIPTION
@@ -93,9 +99,22 @@ _var_ changes. _var_ must be one of the _name_ elements used in *tracefs_synth_a
 The returned string belongs to the synth event object and is freed with the event
 by *tracefs_synth_free*().
 
+*tracefs_synth_show_event*() returns the format of the dynamic event used by the synthetic
+event or NULL on error. The returned string belongs to the synth event object and is freed
+with the event by *tracefs_synth_free*().
+
+*tracefs_synth_show_start_hist*() returns the format of the start histogram used by the
+synthetic event or NULL on error. The returned string belongs to the synth event object
+and is freed with the event by *tracefs_synth_free*().
+
+*tracefs_synth_show_end_hist*() returns the format of the end histogram used by the
+synthetic event or NULL on error. The returned string belongs to the synth event object
+and is freed with the event by *tracefs_synth_free*().
+
 RETURN VALUE
 ------------
-*tracefs_synth_get_name*() returns a string owned by the synth event object.
+*tracefs_synth_get_name*(), *tracefs_synth_show_event*(), *tracefs_synth_show_start_hist*()
+and *tracefs_synth_show_end_hist*()  return a string owned by the synth event object.
 
 All other functions return zero on success or -1 on error.
 
include/tracefs.h +5 -0
index 967690f..b772f5a 100644
@@ -250,6 +250,7 @@ enum tracefs_dynevent_type {
 	TRACEFS_DYNEVENT_SYNTH		= 1 << 5,
 	TRACEFS_DYNEVENT_MAX		= 1 << 6,
 };
+
 int tracefs_dynevent_create(struct tracefs_dynevent *devent);
 int tracefs_dynevent_destroy(struct tracefs_dynevent *devent, bool force);
 int tracefs_dynevent_destroy_all(unsigned int types, bool force);
@@ -550,6 +551,10 @@ int tracefs_synth_create(struct tracefs_synth *synth);
 int tracefs_synth_destroy(struct tracefs_synth *synth);
 void tracefs_synth_free(struct tracefs_synth *synth);
 int tracefs_synth_echo_cmd(struct trace_seq *seq, struct tracefs_synth *synth);
+int tracefs_synth_echo_fmt(struct trace_seq *seq, struct tracefs_synth *synth);
+const char *tracefs_synth_show_event(struct tracefs_synth *synth);
+const char *tracefs_synth_show_start_hist(struct tracefs_synth *synth);
+const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
 
 struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
 				  const char *sql_buffer, char **err);
src/tracefs-hist.c +76 -18

142 lines not on this page · raw message

Signature · 1 line
2.32.0
#1 lore raw
Quoted 7 lines · On Thu, 9 Dec 2021 18:38:15 +0200 "Yordan Karadzhov (VMware)"…

The following APIs are added:
int tracefs_synth_echo_fmt(struct trace_seq *, struct tracefs_synth *) const char *tracefs_synth_show_event(struct tracefs_synth *) const char *tracefs_synth_show_start_hist(struct tracefs_synth *) const char *tracefs_synth_show_end_hist(struct tracefs_synth *)

The new APIs can be useful in the case whene the user wants to

                                        "where"
Quoted 110 lines

check what exactly gets passed to the kernel as definition of a synth event.

---
 Documentation/libtracefs-synth2.txt | 23 ++++++-
 include/tracefs.h                   |  5 ++
 src/tracefs-hist.c                  | 94 +++++++++++++++++++++++------
 3 files changed, 102 insertions(+), 20 deletions(-)
Documentation/libtracefs-synth2.txt +21 -2
index 569819a..e557bc9 100644
@@ -5,7 +5,8 @@ NAME
 ----
 tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_echo_cmd, tracefs_synth_complete,
 tracefs_synth_get_start_hist, tracefs_synth_trace, tracefs_synth_snapshot,
-tracefs_synth_get_name - Creation of synthetic events
+tracefs_synth_get_name, tracefs_synth_echo_fmt, tracefs_synth_show_event,
+tracefs_synth_show_start_hist, tracefs_synth_show_end_hist - Creation of synthetic events
 
 SYNOPSIS
 --------
@@ -27,6 +28,11 @@ int tracefs_synth_save(struct tracefs_synth pass:[*]synth,
 		       enum tracefs_synth_handler type, const char pass:[*]var,
 		       char pass:[**]save_fields);
 const char *tracefs_synth_get_name(struct tracefs_synth pass:[*]synth);
+int tracefs_synth_echo_fmt(struct trace_seq pass:[*]seq, struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_event(struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_start_hist(struct tracefs_synth pass:[*]synth);
+const char *tracefs_synth_show_end_hist(struct tracefs_synth pass:[*]synth);
+
 --
 
 DESCRIPTION
@@ -93,9 +99,22 @@ _var_ changes. _var_ must be one of the _name_ elements used in *tracefs_synth_a
 The returned string belongs to the synth event object and is freed with the event
 by *tracefs_synth_free*().
 
+*tracefs_synth_show_event*() returns the format of the dynamic event used by the synthetic
+event or NULL on error. The returned string belongs to the synth event object and is freed
+with the event by *tracefs_synth_free*().
+
+*tracefs_synth_show_start_hist*() returns the format of the start histogram used by the
+synthetic event or NULL on error. The returned string belongs to the synth event object
+and is freed with the event by *tracefs_synth_free*().
+
+*tracefs_synth_show_end_hist*() returns the format of the end histogram used by the
+synthetic event or NULL on error. The returned string belongs to the synth event object
+and is freed with the event by *tracefs_synth_free*().
+
 RETURN VALUE
 ------------
-*tracefs_synth_get_name*() returns a string owned by the synth event object.
+*tracefs_synth_get_name*(), *tracefs_synth_show_event*(), *tracefs_synth_show_start_hist*()
+and *tracefs_synth_show_end_hist*()  return a string owned by the synth event object.
 
 All other functions return zero on success or -1 on error.
 
include/tracefs.h +5 -0
index 967690f..b772f5a 100644
@@ -250,6 +250,7 @@ enum tracefs_dynevent_type {
 	TRACEFS_DYNEVENT_SYNTH		= 1 << 5,
 	TRACEFS_DYNEVENT_MAX		= 1 << 6,
 };
+
 int tracefs_dynevent_create(struct tracefs_dynevent *devent);
 int tracefs_dynevent_destroy(struct tracefs_dynevent *devent, bool force);
 int tracefs_dynevent_destroy_all(unsigned int types, bool force);
@@ -550,6 +551,10 @@ int tracefs_synth_create(struct tracefs_synth *synth);
 int tracefs_synth_destroy(struct tracefs_synth *synth);
 void tracefs_synth_free(struct tracefs_synth *synth);
 int tracefs_synth_echo_cmd(struct trace_seq *seq, struct tracefs_synth *synth);
+int tracefs_synth_echo_fmt(struct trace_seq *seq, struct tracefs_synth *synth);
+const char *tracefs_synth_show_event(struct tracefs_synth *synth);
+const char *tracefs_synth_show_start_hist(struct tracefs_synth *synth);
+const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
 
 struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
 				  const char *sql_buffer, char **err);
src/tracefs-hist.c +5 -0
index 6051ecc..f5359a5 100644
@@ -683,6 +683,8 @@ struct tracefs_synth {
 	struct action		*actions;
 	struct action		**next_action;
 	struct tracefs_dynevent	*dyn_event;
+	char			*start_hist;
+	char			*end_hist;
 	char			*name;
 	char			**synthetic_fields;
 	char			**synthetic_args;
@@ -737,6 +739,8 @@ void tracefs_synth_free(struct tracefs_synth *synth)
 		return;
 
 	free(synth->name);
+	free(synth->start_hist);
+	free(synth->end_hist);
 	tracefs_list_free(synth->synthetic_fields);
 	tracefs_list_free(synth->synthetic_args);
 	tracefs_list_free(synth->start_keys);
@@ -1802,6 +1806,67 @@ static char *create_end_hist(struct tracefs_synth *synth)
 	return create_actions(end_hist, synth);
 }
 
+/*

src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1819

Quoted 10 lines
src/tracefs-hist.c +10 -0
+ * tracefs_synth_echo_fmt - show the raw format of a synthetic event
+ * @seq: A trace_seq to store the format string
+ * @synth: The synthetic event to read format from
+ *
+ * This shows the raw format that describes the synthetic event, including
+ * the format of the dynamic event and the start / end histograms.
+ *
+ * Returns 0 on succes -1 on error.
+ */
+int tracefs_synth_echo_fmt(struct trace_seq *seq, struct tracefs_synth *synth)

Sorry to nitpick on the naming again, but perhaps we should call this

tracefs_synth_raw_fmt()

Because saying "echo_fmt" I would think it would include the "echo" command in the output.

src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1826

Quoted 7 lines
src/tracefs-hist.c +7 -0
+{
+	if (!synth->dyn_event)
+		return -1;
+
+	trace_seq_printf(seq, "%s", synth->dyn_event->format);
+	trace_seq_printf(seq, "\n%s", synth->start_hist);
+	trace_seq_printf(seq, "\n%s", synth->end_hist);

Hmm, shouldn't this end with a \n? Or is it to allow quoting?

-- Steve

Quoted 4 lines
src/tracefs-hist.c +4 -0
+
+	return 0;
+}
+
#2 lore raw
Quoted 14 lines · Steven Rostedt

src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1819

Quoted 11 lines
src/tracefs-hist.c +11 -0
+/*
+ * tracefs_synth_echo_fmt - show the raw format of a synthetic event
+ * @seq: A trace_seq to store the format string
+ * @synth: The synthetic event to read format from
+ *
+ * This shows the raw format that describes the synthetic event, including
+ * the format of the dynamic event and the start / end histograms.
+ *
+ * Returns 0 on succes -1 on error.
+ */
+int tracefs_synth_echo_fmt(struct trace_seq *seq, struct tracefs_synth *synth)

Sorry to nitpick on the naming again, but perhaps we should call this

Quoted 5 lines

tracefs_synth_raw_fmt()

Because saying "echo_fmt" I would think it would include the "echo" command in the output.

OK

Quoted 9 lines

src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1826

Quoted 8 lines
src/tracefs-hist.c +7 -0
+{
+	if (!synth->dyn_event)
+		return -1;
+
+	trace_seq_printf(seq, "%s", synth->dyn_event->format);
+	trace_seq_printf(seq, "\n%s", synth->start_hist);
+	trace_seq_printf(seq, "\n%s", synth->end_hist);

Hmm, shouldn't this end with a \n? Or is it to allow quoting?

The function returns string and the user is free to do anything with it. If this string ends with "\n" and you print this string with puts() you will get extra line (same problem printing it in Python).

Thanks!
Y.

Quoted 8 lines

-- Steve

Quoted 4 lines
src/tracefs-hist.c +4 -0
+
+	return 0;
+}
+
#3 lore raw
Quoted 4 lines · On Thu, 9 Dec 2021 21:07:28 +0200 Yordan Karadzhov <[email protected]> wrote:
Quoted 1 line

Hmm, shouldn't this end with a \n? Or is it to allow quoting?

The function returns string and the user is free to do anything with it. If this string ends with "\n" and you print this string with puts() you will get extra line (same problem printing it in Python).

OK, that's fine.

-- Steve