Skip to contentSkip to conversation

libtracefs: APIs for inspecting of hist and synth objects

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 9 messages Dec 6, 2021 – Dec 8, 2021 Documentation

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover libtracefs: APIs for inspecting of hist and synth objects

I hope this minor changes can go in before tagging new version.

Thanks!
Yordan

Yordan Karadzhov (VMware) (3):
libtracefs: New API for getting the raw format of a histogram
libtracefs: Rename the 'tracefs_get_hist_*()' APIs
libtracefs: Add new API for getting synth event name WiP

 Documentation/libtracefs-hist.txt   | 24 +++++++++-
 Documentation/libtracefs-synth2.txt |  8 +++-
 include/tracefs.h                   | 10 +++--
 src/tracefs-hist.c                  | 69 +++++++++++++++++++++++++++--
 4 files changed, 101 insertions(+), 10 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/3 libtracefs: New API for getting the raw format of a histogram

The new API is similar to tracefs_hist_echo_cmd(), but prints just the raw format descriptor of the histogram. It can be useful in the case whene the user wants to check what exactly gets passed to the kernel as definition of the histogram.

---
 Documentation/libtracefs-hist.txt | 11 ++++++++--
 include/tracefs.h                 |  3 +++
 src/tracefs-hist.c                | 34 +++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 2 deletions(-)
Documentation/libtracefs-hist.txt +9 -2
index 2eef718..c8230e5 100644
@@ -4,7 +4,8 @@ libtracefs(3)
 NAME
 ----
 tracefs_hist_alloc, tracefs_hist_free, tracefs_hist_add_key, tracefs_hist_add_value, tracefs_hist_add_name, tracefs_hist_start,
-tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_set_sort_key,tracefs_hist_sort_key_direction - Create and update event histograms
+tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_set_sort_key, tracefs_hist_sort_key_direction
+tracefs_hist_echo_cmd, tracefs_hist_echo_fmt - Create and update event histograms
 
 SYNOPSIS
 --------
@@ -69,6 +70,9 @@ int tracefs_hist_command(struct tracefs_instance pass:[*]instance,
 			 struct tracefs_hist pass:[*]hist,
 			 enum tracefs_hist_command command);
 
+int tracefs_hist_echo_fmt(struct trace_seq pass:[*]s, struct tracefs_instance pass:[*]instance,
+			  struct tracefs_hist pass:[*]hist);
+
 --
 
 DESCRIPTION
@@ -178,11 +182,14 @@ _field_, _compare_, and _val_ are ignored unless _type_ is equal to
 
 *TRACEFS_COMPARE_AND* - _field_ & _val_ : where _field_ is a flags field.
 
-*trace_hist_echo_cmd*() prints the commands needed to create the given histogram
+*tracefs_hist_echo_cmd*() prints the commands needed to create the given histogram
 in the given _instance_, or NULL for the top level, into the _seq_.
 The command that is printed is described by _command_ and shows the functionality
 that would be done by *tracefs_hist_command*(3).
 
+*tracefs_hist_echo_fmt*() prints the raw format that describes the state of the
+histogram in the given _instance_, or NULL for the top level, into the _seq_.
+
 *tracefs_hist_command*() is called to process a command on the histogram
 _hist_ for its event in the given _instance_, or NULL for the top level.
 The _cmd_ can be one of:
include/tracefs.h +3 -0
index 3ac3d9c..c2a6db7 100644
@@ -377,6 +377,9 @@ int tracefs_hist_echo_cmd(struct trace_seq *seq,  struct tracefs_instance *insta
 			  struct tracefs_hist *hist, enum tracefs_hist_command command);
 int tracefs_hist_command(struct tracefs_instance *instance,
 			 struct tracefs_hist *hist, enum tracefs_hist_command cmd);
+int tracefs_hist_echo_fmt(struct trace_seq *seq,
+			  struct tracefs_instance *instance,
+			  struct tracefs_hist *hist);
 
 /**
  * tracefs_hist_start - enable a histogram
src/tracefs-hist.c +34 -0
index ea9e127..9beafe0 100644
@@ -142,6 +142,40 @@ tracefs_hist_echo_cmd(struct trace_seq *seq, struct tracefs_instance *instance,
 	return 0;
 }
 
+/*
+ * tracefs_hist_echo_fmt - show the raw format of the histogram
+ * @seq: A trace_seq to store the format string
+ * @hist: The histogram to read format from
+ *
+ * This show the raw format that describes the state of the histogram.
+ *
+ * Returns the size of the format string on succes -1 on error.
+ */
+int tracefs_hist_echo_fmt(struct trace_seq *seq,
+			  struct tracefs_instance *instance,
+			  struct tracefs_hist *hist)
+{
+	const char *event = hist->event_name;
+	const char *system = hist->system;
+	int fmt_size;
+	char *path;
+	char *fmt;
+
+	path = tracefs_event_get_file(instance, system, event, "trigger");
+	if (!path)
+		return -1;
+
+	fmt = tracefs_event_file_read(instance, system, event, path,
+				      &fmt_size);
+	if (!fmt)
+		return -1;
+
+	trace_seq_puts(seq, fmt);
+	tracefs_put_tracing_file(path);
+
+	return fmt_size;
+}
+
 /*
  * tracefs_hist_command - Create, start, pause, destroy a histogram for an event
  * @instance: The instance the histogram will be in (NULL for toplevel)
Signature · 1 line
2.32.0
#2 lore raw

Re: [PATCH 1/3] libtracefs: New API for getting the raw format of a histogram

Quoted 15 lines · On Mon, 6 Dec 2021 17:08:53 +0200 "Yordan Karadzhov (VMware)"…
src/tracefs-hist.c +15 -0
+/*
+ * tracefs_hist_echo_fmt - show the raw format of the histogram
+ * @seq: A trace_seq to store the format string
+ * @hist: The histogram to read format from
+ *
+ * This show the raw format that describes the state of the histogram.
+ *
+ * Returns the size of the format string on succes -1 on error.
+ */
+int tracefs_hist_echo_fmt(struct trace_seq *seq,
+			  struct tracefs_instance *instance,
+			  struct tracefs_hist *hist)
+{
+	const char *event = hist->event_name;
+	const char *system = hist->system;

src/tracefs-hist.c tracefs_hist_echo_cmd(struct trace_seq *seq, struct tracefs_instance *instance, · line 169

Quoted 10 lines
src/tracefs-hist.c +10 -0
+	int fmt_size;
+	char *path;
+	char *fmt;
+
+	path = tracefs_event_get_file(instance, system, event, "trigger");
+	if (!path)
+		return -1;
+
+	fmt = tracefs_event_file_read(instance, system, event, path,
+				      &fmt_size);

First, path should just be "trigger" as tracefs_event_file_read() is a short cut to get to the files for the event. I'm surprised that this even worked.

src/tracefs-hist.c tracefs_hist_echo_cmd(struct trace_seq *seq, struct tracefs_instance *instance, · line 173

Quoted 4 lines
src/tracefs-hist.c +4 -0
+	if (!fmt)
+		return -1;
+
+	trace_seq_puts(seq, fmt);

Second, just reading the trigger file is not useful, as the trigger file holds triggers, not just histograms. And you can have more than one histogram in the trigger file. For instance, I could do:

 # cd /sys/kernel/debug/tracing/events/sched/sched_switch
 # echo stacktrace > trigger
 # echo 'hist:keys=prev_pid' >> trigger
 # echo 'hist:keys=next_pid' >> trigger
 # cat trigger
stacktrace:unlimited
hist:keys=prev_pid:vals=hitcount:sort=hitcount:size=2048 [active]
hist:keys=next_pid:vals=hitcount:sort=hitcount:size=2048 [active]

Is this really what you want?

-- Steve

Quoted 8 lines
src/tracefs-hist.c +5 -0
+	tracefs_put_tracing_file(path);
+
+	return fmt_size;
+}
+
 /*
  * tracefs_hist_command - Create, start, pause, destroy a histogram for an event
  * @instance: The instance the histogram will be in (NULL for toplevel)
#3 lore raw

Re: [PATCH 1/3] libtracefs: New API for getting the raw format of a histogram

Quoted 51 lines · Steven Rostedt
Quoted 15 lines · On Mon, 6 Dec 2021 17:08:53 +0200 "Yordan Karadzhov (VMware)"…
src/tracefs-hist.c +15 -0
+/*
+ * tracefs_hist_echo_fmt - show the raw format of the histogram
+ * @seq: A trace_seq to store the format string
+ * @hist: The histogram to read format from
+ *
+ * This show the raw format that describes the state of the histogram.
+ *
+ * Returns the size of the format string on succes -1 on error.
+ */
+int tracefs_hist_echo_fmt(struct trace_seq *seq,
+			  struct tracefs_instance *instance,
+			  struct tracefs_hist *hist)
+{
+	const char *event = hist->event_name;
+	const char *system = hist->system;

src/tracefs-hist.c tracefs_hist_echo_cmd(struct trace_seq *seq, struct tracefs_instance *instance, · line 169

Quoted 10 lines
src/tracefs-hist.c +10 -0
+	int fmt_size;
+	char *path;
+	char *fmt;
+
+	path = tracefs_event_get_file(instance, system, event, "trigger");
+	if (!path)
+		return -1;
+
+	fmt = tracefs_event_file_read(instance, system, event, path,
+				      &fmt_size);

First, path should just be "trigger" as tracefs_event_file_read() is a short cut to get to the files for the event. I'm surprised that this even worked.

src/tracefs-hist.c tracefs_hist_echo_cmd(struct trace_seq *seq, struct tracefs_instance *instance, · line 173

Quoted 4 lines
src/tracefs-hist.c +4 -0
+	if (!fmt)
+		return -1;
+
+	trace_seq_puts(seq, fmt);

Second, just reading the trigger file is not useful, as the trigger file holds triggers, not just histograms. And you can have more than one histogram in the trigger file. For instance, I could do:

  # cd /sys/kernel/debug/tracing/events/sched/sched_switch
  # echo stacktrace > trigger
  # echo 'hist:keys=prev_pid' >> trigger
  # echo 'hist:keys=next_pid' >> trigger
  # cat trigger
stacktrace:unlimited
hist:keys=prev_pid:vals=hitcount:sort=hitcount:size=2048 [active]
hist:keys=next_pid:vals=hitcount:sort=hitcount:size=2048 [active]
Quoted 2 lines

Is this really what you want?

No, it isn’t :( I have to rethink this.

Thanks a lot!
Y.

Quoted 11 lines

-- Steve

Quoted 8 lines
src/tracefs-hist.c +5 -0
+	tracefs_put_tracing_file(path);
+
+	return fmt_size;
+}
+
  /*
   * tracefs_hist_command - Create, start, pause, destroy a histogram for an event
   * @instance: The instance the histogram will be in (NULL for toplevel)
#4 lore raw

PATCH 2/3 libtracefs: Rename the 'tracefs_get_hist_*()' APIs

In reply to Yordan Karadzhov (VMware)

The APIs are renamed in order to match the naming convention used in the library. The patch adds documentation add well.

---
 Documentation/libtracefs-hist.txt | 15 ++++++++++++++-
 include/tracefs.h                 |  6 +++---
 src/tracefs-hist.c                | 24 +++++++++++++++++++++---
 3 files changed, 38 insertions(+), 7 deletions(-)
Documentation/libtracefs-hist.txt +14 -1
index c8230e5..e3145c9 100644
@@ -5,7 +5,8 @@ NAME
 ----
 tracefs_hist_alloc, tracefs_hist_free, tracefs_hist_add_key, tracefs_hist_add_value, tracefs_hist_add_name, tracefs_hist_start,
 tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_set_sort_key, tracefs_hist_sort_key_direction
-tracefs_hist_echo_cmd, tracefs_hist_echo_fmt - Create and update event histograms
+tracefs_hist_echo_cmd, tracefs_hist_echo_fmt, tracefs_hist_get_name, tracefs_hist_get_event,
+tracefs_hist_get_system - Create, update and describe event histograms
 
 SYNOPSIS
 --------
@@ -73,6 +74,12 @@ int tracefs_hist_command(struct tracefs_instance pass:[*]instance,
 int tracefs_hist_echo_fmt(struct trace_seq pass:[*]s, struct tracefs_instance pass:[*]instance,
 			  struct tracefs_hist pass:[*]hist);
 
+tracefs_hist_get_name(struct tracefs_hist pass:[*]hist);
+
+tracefs_hist_get_event(struct tracefs_hist pass:[*]hist);
+
+tracefs_hist_get_system(struct tracefs_hist pass:[*]hist);
+
 --
 
 DESCRIPTION
@@ -190,6 +197,12 @@ that would be done by *tracefs_hist_command*(3).
 *tracefs_hist_echo_fmt*() prints the raw format that describes the state of the
 histogram in the given _instance_, or NULL for the top level, into the _seq_.
 
+*tracefs_hist_get_name*() prints the name of the histogram.
+
+*tracefs_hist_get_event*() prints the event name of the histogram.
+
+*tracefs_hist_get_system*() prints the system name of the histogram.
+
 *tracefs_hist_command*() is called to process a command on the histogram
 _hist_ for its event in the given _instance_, or NULL for the top level.
 The _cmd_ can be one of:
include/tracefs.h +3 -3
index c2a6db7..7c03086 100644
@@ -354,9 +354,9 @@ struct tracefs_hist *
 tracefs_hist_alloc_nd(struct tep_handle *tep,
 		      const char *system, const char *event_name,
 		      struct tracefs_hist_axis *axes);
-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);
+const char *tracefs_hist_get_name(struct tracefs_hist *hist);
+const char *tracefs_hist_get_event(struct tracefs_hist *hist);
+const char *tracefs_hist_get_system(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);
src/tracefs-hist.c +21 -3
index 9beafe0..837d4e1 100644
@@ -41,17 +41,35 @@ struct tracefs_hist {
 	unsigned int		filter_state;
 };
 
-const char *tracefs_get_hist_name(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_name - get the name of the histogram
+ * @hist: The histogram to get the name for
+ *
+ * Returns name string on succes or NULL on error.
+ */
+const char *tracefs_hist_get_name(struct tracefs_hist *hist)
 {
 	return hist ? hist->name : NULL;
 }
 
-const char *tracefs_get_hist_event(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_event - get the event name of the histogram
+ * @hist: The histogram to get the event name for
+ *
+ * Returns event name string on succes or NULL on error.
+ */
+const char *tracefs_hist_get_event(struct tracefs_hist *hist)
 {
 	return hist ? hist->event_name : NULL;
 }
 
-const char *tracefs_get_hist_system(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_system - get the system name of the histogram
+ * @hist: The histogram to get the system name for
+ *
+ * Returns system name string on succes or NULL on error.
+ */
+const char *tracefs_hist_get_system(struct tracefs_hist *hist)
 {
 	return hist ? hist->system : NULL;
 }
Signature · 1 line
2.32.0
#5 lore raw

Re: [PATCH 2/3] libtracefs: Rename the 'tracefs_get_hist_*()' APIs

On Mon, 6 Dec 2021 17:08:54 +0200
"Yordan Karadzhov (VMware)" <[email protected]> wrote:

Please specify what is being renamed and to what it's new name is.

Quoted 2 lines

The APIs are renamed in order to match the naming convention used in the library. The patch adds documentation add well.

     "as well".
Quoted 23 lines
---
 Documentation/libtracefs-hist.txt | 15 ++++++++++++++-
 include/tracefs.h                 |  6 +++---
 src/tracefs-hist.c                | 24 +++++++++++++++++++++---
 3 files changed, 38 insertions(+), 7 deletions(-)
Documentation/libtracefs-hist.txt +2 -1
index c8230e5..e3145c9 100644
@@ -5,7 +5,8 @@ NAME
 ----
 tracefs_hist_alloc, tracefs_hist_free, tracefs_hist_add_key, tracefs_hist_add_value, tracefs_hist_add_name, tracefs_hist_start,
 tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_set_sort_key, tracefs_hist_sort_key_direction
-tracefs_hist_echo_cmd, tracefs_hist_echo_fmt - Create and update event histograms
+tracefs_hist_echo_cmd, tracefs_hist_echo_fmt, tracefs_hist_get_name, tracefs_hist_get_event,
+tracefs_hist_get_system - Create, update and describe event histograms
 
 SYNOPSIS
 --------

Documentation/libtracefs-hist.txt int tracefs_hist_command(struct tracefs_instance pass:[*]instance, · line 82

Quoted 9 lines
Documentation/libtracefs-hist.txt +6 -0
@@ -73,6 +74,12 @@ int tracefs_hist_command(struct tracefs_instance pass:[*]instance,
 int tracefs_hist_echo_fmt(struct trace_seq pass:[*]s, struct tracefs_instance pass:[*]instance,
 			  struct tracefs_hist pass:[*]hist);
 
+tracefs_hist_get_name(struct tracefs_hist pass:[*]hist);
+
+tracefs_hist_get_event(struct tracefs_hist pass:[*]hist);
+
+tracefs_hist_get_system(struct tracefs_hist pass:[*]hist);
+

The above three need to also show the return value.

Documentation/libtracefs-hist.txt that would be done by *tracefs_hist_command*(3). · line 200

Quoted 8 lines
Documentation/libtracefs-hist.txt +1 -0
 --
 
 DESCRIPTION
@@ -190,6 +197,12 @@ that would be done by *tracefs_hist_command*(3).
 *tracefs_hist_echo_fmt*() prints the raw format that describes the state of the
 histogram in the given _instance_, or NULL for the top level, into the _seq_.
 
+*tracefs_hist_get_name*() prints the name of the histogram.

It doesn't print anything. It returns the name, and it needs to be stated that the returned string belongs to the histogram and is freed with the histogram. That is, its scope is the same as the histogram, and the returned string should not be freed.

Documentation/libtracefs-hist.txt that would be done by *tracefs_hist_command*(3). · line 204

Quoted 4 lines
Documentation/libtracefs-hist.txt +4 -0
+
+*tracefs_hist_get_event*() prints the event name of the histogram.
+
+*tracefs_hist_get_system*() prints the system name of the histogram.

Same for these two.

Quoted 26 lines
Documentation/libtracefs-hist.txt +1 -0
+
 *tracefs_hist_command*() is called to process a command on the histogram
 _hist_ for its event in the given _instance_, or NULL for the top level.
 The _cmd_ can be one of:
include/tracefs.h +3 -3
index c2a6db7..7c03086 100644
@@ -354,9 +354,9 @@ struct tracefs_hist *
 tracefs_hist_alloc_nd(struct tep_handle *tep,
 		      const char *system, const char *event_name,
 		      struct tracefs_hist_axis *axes);
-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);
+const char *tracefs_hist_get_name(struct tracefs_hist *hist);
+const char *tracefs_hist_get_event(struct tracefs_hist *hist);
+const char *tracefs_hist_get_system(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);
src/tracefs-hist.c +0 -0
index 9beafe0..837d4e1 100644

src/tracefs-hist.c struct tracefs_hist { · line 48

Quoted 9 lines
src/tracefs-hist.c +5 -1
@@ -41,17 +41,35 @@ struct tracefs_hist {
 	unsigned int		filter_state;
 };
 
-const char *tracefs_get_hist_name(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_name - get the name of the histogram
+ * @hist: The histogram to get the name for
+ *
+ * Returns name string on succes or NULL on error.

Should state that the name returned belongs to the histogram and should not be freed.

Quoted 14 lines
src/tracefs-hist.c +9 -1
+ */
+const char *tracefs_hist_get_name(struct tracefs_hist *hist)
 {
 	return hist ? hist->name : NULL;
 }
 
-const char *tracefs_get_hist_event(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_event - get the event name of the histogram
+ * @hist: The histogram to get the event name for
+ *
+ * Returns event name string on succes or NULL on error.
+ */
+const char *tracefs_hist_get_event(struct tracefs_hist *hist)

src/tracefs-hist.c struct tracefs_hist { · line 70

Quoted 10 lines
src/tracefs-hist.c +5 -1
 {
 	return hist ? hist->event_name : NULL;
 }
 
-const char *tracefs_get_hist_system(struct tracefs_hist *hist)
+/*
+ * tracefs_hist_get_system - get the system name of the histogram
+ * @hist: The histogram to get the system name for
+ *
+ * Returns system name string on succes or NULL on error.

Same for these as well.

-- Steve

Quoted 5 lines
src/tracefs-hist.c +2 -0
+ */
+const char *tracefs_hist_get_system(struct tracefs_hist *hist)
 {
 	return hist ? hist->system : NULL;
 }
#6 lore raw

PATCH 3/3 libtracefs: Add new API for getting synth event name WiP

In reply to Yordan Karadzhov (VMware)
---
 Documentation/libtracefs-synth2.txt |  8 ++++++--
 include/tracefs.h                   |  1 +
 src/tracefs-hist.c                  | 11 +++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
Documentation/libtracefs-synth2.txt +6 -2
index 1cb07c8..2439a54 100644
@@ -3,8 +3,9 @@ libtracefs(3)
 
 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 - Creation of synthetic events
+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
 
 SYNOPSIS
 --------
@@ -25,6 +26,7 @@ int tracefs_synth_snapshot(struct tracefs_synth pass:[*]synth,
 int tracefs_synth_save(struct tracefs_synth pass:[*]synth,
 		       enum tracefs_synth_handler type, const char pass:[*]var,
 		       char pass:[**]save_fields);
+tracefs_synth_get_name(struct tracefs_synth pass:[*]synth);
 --
 
 DESCRIPTION
@@ -87,6 +89,8 @@ then saven the given _save_fields_ list. The fields will be stored in the histog
 "hist" file of the event that can be retrieved with *tracefs_event_file_read*(3).
 _var_ changes. _var_ must be one of the _name_ elements used in *tracefs_synth_add_end_field*(3).
 
+*tracefs_synth_get_name*() get the name of the synthetic event.
+
 RETURN VALUE
 ------------
 Returns zero on success or -1 on error.
include/tracefs.h +1 -0
index 7c03086..804d738 100644
@@ -505,6 +505,7 @@ enum tracefs_synth_handler {
 	TRACEFS_SYNTH_HANDLE_CHANGE,
 };
 
+const char *tracefs_synth_get_name(struct tracefs_synth *synth);
 struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep,
 					  const char *name,
 					  const char *start_system,
src/tracefs-hist.c +11 -0
index 837d4e1..41c88d1 100644
@@ -736,6 +736,17 @@ struct tracefs_synth {
 	int			arg_cnt;
 };
 
+ /*
+ * tracefs_synth_get_name - get the name of the synthetic event
+ * @synth: The synthetic event to get the name for
+ *
+ * Returns name string on succes or NULL on error.
+ */
+const char *tracefs_synth_get_name(struct tracefs_synth *synth)
+{
+	return synth ? synth->name : NULL;
+}
+
 static void action_free(struct action *action)
 {
 	free(action->handle_field);
Signature · 1 line
2.32.0
#7 lore raw

Re: [PATCH 3/3] libtracefs: Add new API for getting synth event name WiP

On Mon, 6 Dec 2021 17:08:55 +0200
"Yordan Karadzhov (VMware)" <[email protected]> wrote:

I'm guessing for the lack of change log, that this is really an RFC?

Quoted 24 lines
---
 Documentation/libtracefs-synth2.txt |  8 ++++++--
 include/tracefs.h                   |  1 +
 src/tracefs-hist.c                  | 11 +++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
Documentation/libtracefs-synth2.txt +3 -2
index 1cb07c8..2439a54 100644
@@ -3,8 +3,9 @@ libtracefs(3)
 
 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 - Creation of synthetic events
+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
 
 SYNOPSIS
 --------

Documentation/libtracefs-synth2.txt int tracefs_synth_snapshot(struct tracefs_synth pass:[*]synth, · line 29

Quoted 4 lines
Documentation/libtracefs-synth2.txt +1 -0
@@ -25,6 +26,7 @@ int tracefs_synth_snapshot(struct tracefs_synth pass:[*]synth,
 int tracefs_synth_save(struct tracefs_synth pass:[*]synth,
 		       enum tracefs_synth_handler type, const char pass:[*]var,
 		       char pass:[**]save_fields);
+tracefs_synth_get_name(struct tracefs_synth pass:[*]synth);

Need return value.

Documentation/libtracefs-synth2.txt then saven the given _save_fields_ list. The fields will be stored in the histog · line 92

Quoted 8 lines
Documentation/libtracefs-synth2.txt +1 -0
 --
 
 DESCRIPTION
@@ -87,6 +89,8 @@ then saven the given _save_fields_ list. The fields will be stored in the histog
 "hist" file of the event that can be retrieved with *tracefs_event_file_read*(3).
 _var_ changes. _var_ must be one of the _name_ elements used in *tracefs_synth_add_end_field*(3).
 
+*tracefs_synth_get_name*() get the name of the synthetic event.

And state that the string returned belongs to the synthetic event descriptor and lives only as long as it does. The value returned should not be freed.

Quoted 21 lines
Documentation/libtracefs-synth2.txt +1 -0
+
 RETURN VALUE
 ------------
 Returns zero on success or -1 on error.
include/tracefs.h +1 -0
index 7c03086..804d738 100644
@@ -505,6 +505,7 @@ enum tracefs_synth_handler {
 	TRACEFS_SYNTH_HANDLE_CHANGE,
 };
 
+const char *tracefs_synth_get_name(struct tracefs_synth *synth);
 struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep,
 					  const char *name,
 					  const char *start_system,
src/tracefs-hist.c +0 -0
index 837d4e1..41c88d1 100644

src/tracefs-hist.c struct tracefs_synth { · line 743

Quoted 8 lines
src/tracefs-hist.c +5 -0
@@ -736,6 +736,17 @@ struct tracefs_synth {
 	int			arg_cnt;
 };
 
+ /*
+ * tracefs_synth_get_name - get the name of the synthetic event
+ * @synth: The synthetic event to get the name for
+ *
+ * Returns name string on succes or NULL on error.

And this needs to state its scope as well.

-- Steve

Quoted 9 lines
src/tracefs-hist.c +6 -0
+ */
+const char *tracefs_synth_get_name(struct tracefs_synth *synth)
+{
+	return synth ? synth->name : NULL;
+}
+
 static void action_free(struct action *action)
 {
 	free(action->handle_field);
#8 lore raw

Re: [PATCH 3/3] libtracefs: Add new API for getting synth event name WiP

Quoted 4 lines · Steven Rostedt

On Mon, 6 Dec 2021 17:08:55 +0200
"Yordan Karadzhov (VMware)"<[email protected]> wrote:

I'm guessing for the lack of change log, that this is really an RFC?

This patch-set is a disaster :( Sorry about that!

The name of this patch (WiP) makes me think that I screwed up the 'git send-mail' command and somehow sent you an old version of the patches. Any way, a lot of the mistakes you pointed out are present also in the version that was supposed to be sent. I will try to do better with v2.

Thanks a lot!
Yordan