libtracefs: APIs for inspecting hist/synth objects
v2 cover libtracefs: APIs for inspecting hist/synth objects
Changes in v2:
- Dropping patch 'libtracefs: New API for getting the raw format of a histogram'. This patch must be redesigned.
- Adding patch 'libtracefs: New APIs for getting the raw format of synth event'.
- Number of fixes suggested by Steven in his review.
Yordan Karadzhov (VMware) (3):
libtracefs: Rename the 'tracefs_get_hist_*()' APIs
libtracefs: Add new API for getting synth event name
libtracefs: New APIs for getting the raw format of synth event
Documentation/libtracefs-hist.txt | 24 ++++- Documentation/libtracefs-synth2.txt | 14 ++- include/tracefs.h | 12 ++- src/tracefs-hist.c | 132 +++++++++++++++++++++++----- 4 files changed, 154 insertions(+), 28 deletions(-)
Signature · 1 line
2.32.0
PATCH v2 1/3 libtracefs: Rename the 'tracefs_get_hist_*()' APIs
The following APIs are renamed:tracefs_get_hist_name() -> tracefs_hist_get_name()tracefs_get_hist_event() -> tracefs_hist_get_event() tracefs_get_hist_system() -> tracefs_hist_get_system()
This is done in order to match the naming convention used in the library. The patch adds documentation as well.
--- Documentation/libtracefs-hist.txt | 24 +++++++++++++++++++++++- include/tracefs.h | 6 +++--- src/tracefs-hist.c | 24 +++++++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-)
Documentation/libtracefs-hist.txt +23 -1
@@ -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_get_name, tracefs_hist_get_event, tracefs_hist_get_system - Create, update and describe event histograms SYNOPSIS --------
@@ -69,6 +70,12 @@ int tracefs_hist_command(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist, enum tracefs_hist_command command); +const char *tracefs_hist_get_name(struct tracefs_hist pass:[*]hist); + +const char *tracefs_hist_get_event(struct tracefs_hist pass:[*]hist); + +const char *tracefs_hist_get_system(struct tracefs_hist pass:[*]hist); + -- DESCRIPTION
@@ -229,12 +236,27 @@ instead of showing the number, show the name of the running task. *TRACEFS_HIST_KEY_USECS* for use with "common_timestamp" or TRACEFS_HIST_TIMESTAMP, in which case it will show the timestamp in microseconds instead of nanoseconds. +*tracefs_hist_get_name*() returns the name of the histogram or NULL on error. +The returned string belongs to the histogram object and is freed with the histogram +by *tracefs_hist_free*(). + +*tracefs_hist_get_event*() returns the event name of the histogram or NULL on error. +The returned string belongs to the histogram object and is freed with the histogram +by *tracefs_hist_free*(). + +*tracefs_hist_get_system*() returns the system name of the histogram or NULL on error. +The returned string belongs to the histogram object and is freed with the histogram +by *tracefs_hist_free*(). + RETURN VALUE ------------ *tracefs_hist_alloc_nd*() returns an allocated histogram descriptor which must be freed by *tracefs_hist_free*() or NULL on error. +*tracefs_hist_get_name*(), *tracefs_hist_get_event*() and *tracefs_hist_get_system*() +return strings owned by the histogram object. + All the other functions return zero on success or -1 on error. If *tracefs_hist_start*() returns an error, a message may be displayed
include/tracefs.h +3 -3
@@ -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
@@ -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 owned by @hist on success, 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 owned by @hist on success, 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 owned by @hist on success, 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
PATCH v2 2/3 libtracefs: Add new API for getting synth event name
In reply to Yordan Karadzhov (VMware)We add:
const char *tracefs_synth_get_name(struct tracefs_synth *)
The new API can be valuable in a number of different scenarios. For example, when the user works with multiple synth events and wants to print an adequate error message in a case of a failure.
--- Documentation/libtracefs-synth2.txt | 14 +++++++++++--- include/tracefs.h | 1 + src/tracefs-hist.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-)
Documentation/libtracefs-synth2.txt +11 -3
@@ -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); +const char *tracefs_synth_get_name(struct tracefs_synth pass:[*]synth); -- DESCRIPTION
@@ -87,9 +89,15 @@ 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*() returns the name of 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 ------------ -Returns zero on success or -1 on error. +*tracefs_synth_get_name*() returns a string owned by the synth event object. + +All other functions return zero on success or -1 on error. ERRORS ------
include/tracefs.h +1 -0
@@ -502,6 +502,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
@@ -702,6 +702,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 owned by @synth on success, 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
PATCH v2 3/3 libtracefs: New APIs for getting the raw format of synth event
In reply to 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_row(struct tracefs_synth *) const char *tracefs_synth_show_start_hist_row(struct tracefs_synth *) const char *tracefs_synth_show_end_hist_row(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.
--- include/tracefs.h | 5 +++ src/tracefs-hist.c | 97 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 84 insertions(+), 18 deletions(-)
include/tracefs.h +5 -0
@@ -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_row (struct tracefs_synth *synth); +const char *tracefs_synth_show_start_hist_row (struct tracefs_synth *synth); +const char *tracefs_synth_show_end_hist_row (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 +79 -18
145 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH v2 3/3] libtracefs: New APIs for getting the raw format of synth event
Quoted 5 lines · On Thu, 9 Dec 2021 12:45:24 +0200 "Yordan Karadzhov (VMware)"…
The following APIs are added:
inttracefs_synth_echo_fmt(struct trace_seq *, struct tracefs_synth *)const char *tracefs_synth_show_event_row(structtracefs_synth*) const char *tracefs_synth_show_start_hist_row(structtracefs_synth*) const char *tracefs_synth_show_end_hist_row(structtracefs_synth*)
OK, I'm going to do a little bikeshedding here ;-)
The word "row" seems off. I wonder if it would be better to just drop it.
tracefs_synth_show_event()
tracefs_synth_show_start_hist()
tracefs_synth_show_end_hist()
As to me "row" means this is a table and related somehow to the tracefs_sql() that can create a synthetic event. But these have nothing to do with the rows of those tables.
Quoted 75 lines
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.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 5 +++ src/tracefs-hist.c | 97 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 84 insertions(+), 18 deletions(-)include/tracefs.h +5
-0@@ -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_row (struct tracefs_synth *synth); +const char *tracefs_synth_show_start_hist_row (struct tracefs_synth *synth); +const char *tracefs_synth_show_end_hist_row (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 +19
-0@@ -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,70 @@ static char *create_end_hist(struct tracefs_synth *synth)return create_actions (end_hist, synth); } +/* +* 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) +{ +if (!synth->dyn_event) +return -1 ; +
src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1833
Quoted 10 lines
src/tracefs-hist.c +10
-0+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); + +return 0 ; +} + +/* +* tracefs_synth_show_event_row - show the dynamic event used by a synthetic +* event
FYI, this should be on a single line. A "kernel-doc" starts with "a one line description". Either shorten it, or just keep it on one line. Linux has extended the "max line chars" to 100 from 80.
Quoted 4 lines
src/tracefs-hist.c +4
-0+* @synth: The synthetic event to read format from +* +* This shows the raw format of the dynamic event used by the synthetic event. +*
src/tracefs-hist.c static char *create_end_hist(struct tracefs_synth *synth) · line 1847
Quoted 10 lines
src/tracefs-hist.c +10
-0+* Returns format string owned by @synth on success, or NULL on error. +*/ +const char *tracefs_synth_show_event_row (struct tracefs_synth *synth) +{ +return synth->dyn_event ? synth->dyn_event->format :NULL ; +} + +/* +* tracefs_synth_show_start_hist_row - show the start histogram used by a +* synthetic event
Here too.
And if we get rid of "_row" it should make it shorter anyway.
-- Steve
Quoted 11 lines
src/tracefs-hist.c +11
-0+* @synth: The synthetic event to read format from +* +* This shows the raw format of the start histogram used by the synthetic event. +* +* Returns format string owned by @synth on success, or NULL on error. +*/ +const char *tracefs_synth_show_start_hist_row (struct tracefs_synth *synth) +{ +return synth->start_hist; +} +
Quoted 7 lines · On Thu, 9 Dec 2021 12:45:21 +0200 "Yordan Karadzhov (VMware)"…
Changes in v2:
- Dropping patch 'libtracefs: New API for getting the raw format of a histogram'. This patch must be redesigned.- Adding patch 'libtracefs: New APIs for getting the raw format of synth event'.
Quoted 6 lines
- Number of fixes suggested by Steven in his review.
Yordan Karadzhov (VMware) (3):
libtracefs: Rename the 'tracefs_get_hist_*()' APIs
libtracefs: Add new API for getting synth event name
I pulled in the above two patches.
Quoted 1 line
libtracefs: New APIs for getting the raw format of synth event
You only need to resend an update to the above.
Thanks!
-- Steve
Quoted 7 lines
Documentation/libtracefs-hist.txt | 24 ++++- Documentation/libtracefs-synth2.txt | 14 ++- include/tracefs.h | 12 ++- src/tracefs-hist.c | 132 +++++++++++++++++++++++----- 4 files changed, 154 insertions(+), 28 deletions(-)
Quoted 17 lines · Steven Rostedt
Quoted 7 lines · On Thu, 9 Dec 2021 12:45:21 +0200 "Yordan Karadzhov (VMware)"…
Changes in v2:
- Dropping patch 'libtracefs: New API for getting the raw format of a histogram'. This patch must be redesigned.- Adding patch 'libtracefs: New APIs for getting the raw format of synth event'.
Quoted 6 lines
- Number of fixes suggested by Steven in his review.
Yordan Karadzhov (VMware) (3):
libtracefs: Rename the 'tracefs_get_hist_*()' APIs
libtracefs: Add new API for getting synth event name
Quoted 5 lines
I pulled in the above two patches.
Quoted 1 line
libtracefs: New APIs for getting the raw format of synth event
You only need to resend an update to the above.
OK, thanks!
Y.
Quoted 13 lines
Thanks!
-- Steve
Quoted 7 lines
Documentation/libtracefs-hist.txt | 24 ++++- Documentation/libtracefs-synth2.txt | 14 ++- include/tracefs.h | 12 ++- src/tracefs-hist.c | 132 +++++++++++++++++++++++----- 4 files changed, 154 insertions(+), 28 deletions(-)