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. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- Documentation/libtracefs-synth2.txt | 14 +++++++++++--- include/tracefs.h | 1 + src/tracefs-hist.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt index 1cb07c8..569819a 100644 --- a/Documentation/libtracefs-synth2.txt +++ b/Documentation/libtracefs-synth2.txt @@ -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 ------ diff --git a/include/tracefs.h b/include/tracefs.h index b874d3f..967690f 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -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, diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 59ac5e4..6051ecc 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -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); -- 2.32.0