Modifications of some 'hist' APIs
v2 cover Modifications of some 'hist' APIs
The patch-set contains various minor modifications inspired by my first experience using the 'hist' APIs of libtracefs.
This patch-set applies on top of patches
'libtracefs: Fix code indentation' and
'libtracefs: Fix add_sort_key()'
Yordan Karadzhov (VMware) (4):
libtracefs: Add new constructors for histograms
libtracefs: Transform tracefs_hist_add_sort_key()
libtracefs: Add new 'hist' APIs
libtracefs: Update 'hist' documentation
Documentation/libtracefs-hist-cont.txt | 30 ++++-- Documentation/libtracefs-hist.txt | 80 ++++++++------- include/tracefs.h | 26 ++++- src/tracefs-hist.c | 132 +++++++++++++++++++++---- 4 files changed, 207 insertions(+), 61 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/4 libtracefs: Add new constructors for histograms
The current way to create an N-dimensional histogram is bit counterintuitive. We first have to call tracefs_hist_alloc() which is essentially a constructor of 1d histogram. Then we have to call tracefs_hist_add_key() N-1 times in order to increase the dimentions of the histogram. Here we transform tracefs_hist_alloc() into a constructor of N-dimensional histogram and we also add 2 helper constructors for 1d and 2d histograms.
--- include/tracefs.h | 19 +++++++++-- src/tracefs-hist.c | 84 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 87 insertions(+), 16 deletions(-)
include/tracefs.h +17 -2
@@ -310,10 +310,25 @@ enum tracefs_compare { };void tracefs_hist_free (struct tracefs_hist *hist); +struct tracefs_hist * +tracefs_hist1d_alloc (struct tep_handle *tep, +const char *system,const char *event_name, +const char *key,enum tracefs_hist_key_type type); +struct tracefs_hist * +tracefs_hist2d_alloc (struct tep_handle *tep, +const char *system,const char *event_name, +const char *key1,enum tracefs_hist_key_type type1, +const char *key2,enum tracefs_hist_key_type type2); + +struct tracefs_hist_axis { +const char *key; +enum tracefs_hist_key_type type; +}; +struct tracefs_hist *tracefs_hist_alloc (struct tep_handle *tep, -const char *system,const char *event, -const char *key,enum tracefs_hist_key_type type); +const char *system,const char *event_name, +struct tracefs_hist_axis *axes);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 +70 -14
120 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v2 1/4] libtracefs: Add new constructors for histograms
Quoted 31 lines · Yordan Karadzhov (VMware)
The current way to create an N-dimensional histogram is bit counterintuitive. We first have to call
tracefs_hist_alloc()which is essentially a constructor of 1d histogram. Then we have to calltracefs_hist_add_key()N-1 times in order to increase the dimentions of the histogram. Here we transformtracefs_hist_alloc()into a constructor of N-dimensional histogram and we also add 2 helper constructors for 1d and 2d histograms.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 19 +++++++++-- src/tracefs-hist.c | 84 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 87 insertions(+), 16 deletions(-)include/tracefs.h +7
-0@@ -310,10 +310,25 @@ enum tracefs_compare { };void tracefs_hist_free (struct tracefs_hist *hist); +struct tracefs_hist * +tracefs_hist1d_alloc (struct tep_handle *tep, +const char *system,const char *event_name, +const char *key,enum tracefs_hist_key_type type); +struct tracefs_hist * +tracefs_hist2d_alloc(struct tep_handle *tep, + const char *system, const char *event_name,
include/tracefs.h enum tracefs_compare { · line 329
Quoted 10 lines
include/tracefs.h +8
-0+ const char *key1, enum tracefs_hist_key_type type1, + const char *key2, enum tracefs_hist_key_type type2); + +struct tracefs_hist_axis { +const char *key; +enum tracefs_hist_key_type type; +}; +struct tracefs_hist * tracefs_hist_alloc(struct tep_handle *tep,
For consistency with the newly added "alloc" APIs, this should be renamed. The dimensions of the histogram are part of the name, this one is for N dimensions:
tracefs_hist_alloc_1d()
tracefs_hist_alloc_2d()
tracefs_hist_alloc_nd()
or something like that.
src/tracefs-hist.c void tracefs_hist_free(struct tracefs_hist *hist) · line 189
Quoted 13 lines
include/tracefs.h +2
-2- const char *system, const char *event, - const char *key, enum tracefs_hist_key_type type); + const char *system, const char *event_name, + struct tracefs_hist_axis *axes);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@@ -189,7 +189,7 @@ void tracefs_hist_free(struct tracefs_hist *hist) }
[...]
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Re: [PATCH v2 1/4] libtracefs: Add new constructors for histograms
Quoted 10 lines · On Fri, 24 Sep 2021 18:51:38 +0300 Tzvetomir Stoyanov <[email protected]>…
Quoted 2 lines
struct
tracefs_hist*
tracefs_hist_alloc(structtep_handle*tep,For consistency with the newly added "alloc" APIs, this should be renamed. The dimensions of the histogram are part of the name, this one is for N dimensions:
tracefs_hist_alloc_1d()
tracefs_hist_alloc_2d()
tracefs_hist_alloc_nd()
or something like that.
I rather not have the _nd().
tracefs_hist_alloc_1d()
tracefs_hist_alloc_2d() are more just helper handlers for specific cases.
tracefs_hist_alloc() should be the "main" function, and hence doesn't need
any extra annotation.
-- Steve
Re: [PATCH v2 1/4] libtracefs: Add new constructors for histograms
Quoted 14 lines · Steven Rostedt
Quoted 10 lines · On Fri, 24 Sep 2021 18:51:38 +0300 Tzvetomir Stoyanov <[email protected]>…
Quoted 2 lines
struct
tracefs_hist*
tracefs_hist_alloc(structtep_handle*tep,For consistency with the newly added "alloc" APIs, this should be renamed. The dimensions of the histogram are part of the name, this one is for N dimensions:
tracefs_hist_alloc_1d() tracefs_hist_alloc_2d() tracefs_hist_alloc_nd()or something like that.
Quoted 8 lines
I rather not have the
_nd().
tracefs_hist_alloc_1d()
tracefs_hist_alloc_2d()are more just helper handlers for specific cases.
tracefs_hist_alloc()should be the "main" function, and hence doesn't need
any extra annotation.
My idea was the same.
Thanks!
Yordan
Quoted 2 lines
-- Steve
PATCH v2 2/4 libtracefs: Transform tracefs_hist_add_sort_key()
In reply to Yordan Karadzhov (VMware)The current version of the API makes it hard to add multiple sort keys to a histogram. The only way to do this is to use the variadic arguments, however in order to do this the caller has to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by creating a tracefs_hist_add_sort_key() into two methods - one that overwrite and one that does not. The current version of 'tracefs_hist_add_sort_key()' gets renamed to 'tracefs_hist_set_sort_key()' without introducing any functional changes. In the same time a new 'tracefs_hist_add_sort_key()' function is defined. The new function can add one new sort key to the list of previously added sort keys.
--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-)
include/tracefs.h +3 -1
@@ -333,7 +333,9 @@ 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);int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...); +const char *sort_key); +int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...);int tracefs_hist_sort_key_direction (struct tracefs_hist *hist,const char *sort_key,enum tracefs_hist_sort_direction dir);
src/tracefs-hist.c +30 -3
@@ -437,16 +437,43 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)/** * tracefs_hist_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to +* @sort_key: The key to sort +* +* Call the function to add to the list of sort keys of the histohram in +* the order of priority that the keys would be sorted on output. +* +* Returns 0 on success, -1 on error. +*/ +int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +const char *sort_key) +{ +char **list = hist->sort; + +if (!hist || !sort_key) +return -1 ; + + list =add_sort_key (hist, sort_key, hist->sort); +if (!list) +return -1 ; + + hist->sort = list; + +return 0 ; +} + +/** +* tracefs_hist_reset_sort_key - set a key for sorting the histogram +* @hist: The histogram to set the sort key to * @sort_key: The key to sort (and the strings after it) * Last one must be NULL. * -* Add a list of sort keys in the order of priority that the +* Set a list of sort keys in the order of priority that the * keys would be sorted on output. Keys must be added first. * * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...) {char **list =NULL ;char **tmp;
Signature · 1 line
2.30.2
Re: [PATCH v2 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 24 lines · Yordan Karadzhov (VMware)
The current version of the API makes it hard to add multiple sort keys to a histogram. The only way to do this is to use the variadic arguments, however in order to do this the caller has to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by creating a
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not. The current version of 'tracefs_hist_add_sort_key()' gets renamed to 'tracefs_hist_set_sort_key()' without introducing any functional changes. In the same time a new 'tracefs_hist_add_sort_key()' function is defined. The new function can add one new sort key to the list of previously added sort keys.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-)include/tracefs.h +0
-0
include/tracefs.h int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, · line 338
Quoted 7 lines
include/tracefs.h +3
-1@@ -333,7 +333,9 @@ 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);int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...); +const char *sort_key); +int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...);
The new name of the function, mentioned in the patch description, is
tracefs_hist_set_sort_key()
I like the name with "set" instead of "reset". The behaviour of the function should be described in the function comments - to stress that the old keys are overwritten.
Quoted 55 lines
include/tracefs.h +0
-0int tracefs_hist_sort_key_direction (struct tracefs_hist *hist,const char *sort_key,enum tracefs_hist_sort_direction dir);src/tracefs-hist.c +30
-4@@ -437,16 +437,43 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)/** * tracefs_hist_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to +* @sort_key: The key to sort +* +* Call the function to add to the list of sort keys of the histohram in +* the order of priority that the keys would be sorted on output. +* +* Returns 0 on success, -1 on error. +*/ +int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +const char *sort_key) +{ +char **list = hist->sort; + +if (!hist || !sort_key) +return -1 ; + + list =add_sort_key (hist, sort_key, hist->sort); +if (!list) +return -1 ; + + hist->sort = list; + +return 0 ; +} + +/** +* tracefs_hist_reset_sort_key - set a key for sorting the histogram +* @hist: The histogram to set the sort key to * @sort_key: The key to sort (and the strings after it) * Last one must be NULL. * -* Add a list of sort keys in the order of priority that the +* Set a list of sort keys in the order of priority that the * keys would be sorted on output. Keys must be added first. * * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...) {char **list =NULL ;char **tmp; --
Quoted 2 lines
2.30.2
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Re: [PATCH v2 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 31 lines · Tzvetomir Stoyanov
Quoted 29 lines · Yordan Karadzhov (VMware)
The current version of the API makes it hard to add multiple sort keys to a histogram. The only way to do this is to use the variadic arguments, however in order to do this the caller has to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by creating a
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not. The current version of 'tracefs_hist_add_sort_key()' gets renamed to 'tracefs_hist_set_sort_key()' without introducing any functional changes. In the same time a new 'tracefs_hist_add_sort_key()' function is defined. The new function can add one new sort key to the list of previously added sort keys.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-)include/tracefs.h +1
-1@@ -333,7 +333,9 @@ 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);int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...); +const char *sort_key);
Quoted 9 lines
include/tracefs.h int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, · line 338
Quoted 2 lines
include/tracefs.h +2
-0+int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...);The new name of the function, mentioned in the patch description, is
tracefs_hist_set_sort_key()
I like the name with "set" instead of "reset". The behaviour of the function should be described in the function comments - to stress that the old keys are overwritten.
Steven suggested to name it 'reset' in the review of the first version. Both 'set' and 'reset' are OK for me.
Thanks!
Yordan
Quoted 63 lines
Quoted 55 lines
include/tracefs.h +0
-0int tracefs_hist_sort_key_direction (struct tracefs_hist *hist,const char *sort_key,enum tracefs_hist_sort_direction dir);src/tracefs-hist.c +30
-4@@ -437,16 +437,43 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)/** * tracefs_hist_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to +* @sort_key: The key to sort +* +* Call the function to add to the list of sort keys of the histohram in +* the order of priority that the keys would be sorted on output. +* +* Returns 0 on success, -1 on error. +*/ +int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +const char *sort_key) +{ +char **list = hist->sort; + +if (!hist || !sort_key) +return -1 ; + + list =add_sort_key (hist, sort_key, hist->sort); +if (!list) +return -1 ; + + hist->sort = list; + +return 0 ; +} + +/** +* tracefs_hist_reset_sort_key - set a key for sorting the histogram +* @hist: The histogram to set the sort key to * @sort_key: The key to sort (and the strings after it) * Last one must be NULL. * -* Add a list of sort keys in the order of priority that the +* Set a list of sort keys in the order of priority that the * keys would be sorted on output. Keys must be added first. * * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_reset_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...) {char **list =NULL ;char **tmp; --Quoted 2 lines
2.30.2
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Re: [PATCH v2 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 9 lines · On Fri, 24 Sep 2021 19:56:41 +0300 Yordan Karadzhov <[email protected]> wrote:
Quoted 6 lines
The new name of the function, mentioned in the patch description, is
tracefs_hist_set_sort_key()
I like the name with "set" instead of "reset". The behaviour of the function should be described in the function comments - to stress that the old keys are overwritten.Steven suggested to name it 'reset' in the review of the first version. Both 'set' and 'reset' are OK for me.
Looking at this now, I think "set" is a better name.
I'll modify it.
-- Steve
PATCH v2 3/4 libtracefs: Add new 'hist' APIs
In reply to Yordan Karadzhov (VMware)The new APIs will be valuable in a number of different scenarios. For example if the user wants to implement a function that does the readout of a histogram, the only argument that will have to be passed to this function is the histogram descriptor. The same applies for the case when the user wants to print an adequate error message in a case of a failure.
--- include/tracefs.h | 3 +++ src/tracefs-hist.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)
include/tracefs.h +3 -0
@@ -329,6 +329,9 @@ struct tracefs_hist * tracefs_hist_alloc(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);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 +15 -0
@@ -39,6 +39,21 @@ struct tracefs_hist {unsigned int filter_state; }; +const char *tracefs_get_hist_name (struct tracefs_hist *hist) +{ +return hist ? hist->name :NULL ; +} + +const char *tracefs_get_hist_event (struct tracefs_hist *hist) +{ +return hist ? hist->event_name :NULL ; +} + +const char *tracefs_get_hist_system (struct tracefs_hist *hist) +{ +return hist ? hist->system :NULL ; +} +static void add_list (struct trace_seq *seq,const char *start,char **list) {
Signature · 1 line
2.30.2
PATCH v2 4/4 libtracefs: Update 'hist' documentation
In reply to Yordan Karadzhov (VMware)New 'hist' APIs have been added and some existing APIs have been modified. Here we update the documentation accordingly.
--- Documentation/libtracefs-hist-cont.txt | 30 ++++++++-- Documentation/libtracefs-hist.txt | 80 +++++++++++++++----------- 2 files changed, 69 insertions(+), 41 deletions(-)
Documentation/libtracefs-hist-cont.txt +24 -6
@@ -11,18 +11,36 @@ SYNOPSIS -- *#include <tracefs.h>* -int tracefs_hist_pause(struct tracefs_hist pass:[*]hist); -int tracefs_hist_continue(struct tracefs_hist pass:[*]hist); -int tracefs_hist_reset(struct tracefs_hist pass:[*]hist); +int tracefs_hist_start(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_destory(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_pause(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_continue(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_reset(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); + -- DESCRIPTION ----------- + +*tracefs_hist_start* is called to actually start the histogram _hist_. +The _instance_ is the instance to start the histogram in, NULL if it +should start at the top level. + *tracefs_hist_pause* is called to pause the histogram _hist_. +The _instance_ is the instance to pause the histogram in, NULL if it +is in the top level. *tracefs_hist_continue* is called to continue a paused histogram _hist_. +The _instance_ is the instance to continue the histogram, NULL if it +is in the top level. *tracefs_hist_reset* is called to clear / reset the histogram _hist_. +The _instance_ is the instance to clear the histogram, NULL if it +is in the top level. + +*tracefs_hist_destory* is called to delete the histogram where it will no longer +exist. The _instance_ is the instance to delete the histogram from, NULL if it +is in the top level. RETURN VALUE ------------
@@ -83,14 +101,14 @@ int main (int argc, char **argv, char **env) } hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + "call_site", TRACEFS_HIST_KEY_SYM, + "bytes_req", 0); if (!hist) { fprintf(stderr, "Failed hist create\n"); exit(-1); } - ret = tracefs_hist_add_key(hist, "bytes_req", 0); - ret |= tracefs_hist_add_value(hist, "bytes_alloc"); + ret = tracefs_hist_add_value(hist, "bytes_alloc"); ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL); ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc",
Documentation/libtracefs-hist.txt +45 -35
139 lines not on this page · raw message
Signature · 1 line
2.30.2
Hi Steven et al.
I would like to suggest some further modifications of the current APIs of libtracefs. The problem that I am trying to solve with this modifications is the unnecessary and potentially confusing variety of patterns used when implementing the APIs for dealing with 'instances', 'kprobes', 'histigrams' and 'synthetic events'. I believe that unifying/templating the structure of those APIs will be beneficial and will make the usage fare more intuitive. I am posting below a pseudo code for one possible implementation of such template APIs that can be used as a starting point for a discussion.
/**
* tracefs_XXX_alloc - allocate a new tracefs_XXX descriptor. This only
* initializes the descriptor, it does not introduce any changes on the
* system.
*
* @arguments: Some arguments specific for the type of the object ... *
* Returns a newly allocated tracefs_XXX descriptor objext, or NULL in case
* of an error. The returned instance must be freed by tracefs_XXX_free(). */
struct tracefs_XXX *tracefs_XXX_alloc(arguments);
/**
* tracefs_XXX_create - creates new tracefs_XXX object on the system.
* This method calls tracefs_XXX_alloc() internally.
*
* @arguments: Some arguments specific for the type of the object ...
* This function should not take an instance as argument. Otherwise the
* same instance will have to be passed to tracefs_XXX_destroy(), which
* can be a problem in some more sophisticated use-cases.
*
* Returns 0 on succes and -1 on error. On error, errno is set to:
* EBUSY - the object already exists on the system.
* ENOMEM - memory allocation failure.
* ENIVAL - a parameter is passed as NULL or value that should not be or
* a problem writing into the system.
*/
struct tracefs_XXX *tracefs_XXX_create(arguments);
/**
* tracefs_XXX_find - find a tracefs_XXX object that already exists on the
* system. This method calls tracefs_XXX_alloc() internally.
*
* @arguments: Some arguments specific for the type of the object ...
* This function should not take an instance as argument. Otherwise the same
* instance will have to be passed to tracefs_XXX_destroy(), which can be a
* problem in some more sophisticated use-cases.
*
* Returns tracefs_XXX descriptor on succes and NULL if the object do not
* exist on the system or in the case of an error. On error, errno is set to:
* ENOMEM - memory allocation failure.
* ENIVAL - a parameter is passed as NULL or value that should not be or
* a problem writing into the system.
*/
struct tracefs_XXX *tracefs_XXX_find(arguments);
/**
* tracefs_instance_destroy - Remove/clears a tracefs_XXX objext from the
* system. tracefs_XXX_free() must be called in order to free the memory used
* by the descriptor itself.
*
* @obj: Pointer to the tracefs_XXX descriptor of the objext to be destroyed.
* @force: If false the object is not guaranteed to be destroyed. If @force
* is true, all tangled objects that prevent the destruction of the object
* will be destroyed as well.
*
* This function should not take any other arguments.
*
* Returns -1 in case of an error or if the object failed to destroy.
* 0 otherwise.
*/
int tracefs_XXX_destroy(struct tracefs_XXX *obj, bool force);
/**
* tracefs_XXX_free - Free a tracefs_XXX descriptor, previously allocated
* by tracefs_XXX_alloc, tracefs_XXX_create() or tracefs_XXX_find(). *
* @obj: Pointer to the tracefs_XXX descriptor objext to be freed. *
* This function should not take any other arguments.
*/
void tracefs_XXX_free(struct tracefs_XXX *obj);
/**
* tracefs_XXX_YYY - Method implementing the user action 'YYY' (can be
* enable/disable, start/stop/clear, ... etc.)
*
* @obj: Pointer to the tracefs_XXX objext for witch the user action will
* apply.
* @instance: Ftrace instance, can be NULL for top tracing instance.
* @more_arguments: Some additional arguments specific for the type XXX and
* the action YYY.
*/
void/int tracefs_XXX_YYY(struct tracefs_XXX *obj,
struct tracefs_instance *inst, more_arguments);
Thanks a lot!
Yordan
Quoted 8 lines · On Mon, 11 Oct 2021 16:55:29 +0300 Yordan Karadzhov <[email protected]> wrote:
Hi Steven et al.
I would like to suggest some further modifications of the current APIs of libtracefs. The problem that I am trying to solve with this modifications is the unnecessary and potentially confusing variety of patterns used when implementing the APIs for dealing with 'instances', 'kprobes', 'histigrams' and 'synthetic events'. I believe that unifying/templating the structure of those APIs will be beneficial and will make the usage fare more intuitive. I am posting below a pseudo code for one possible implementation of such template APIs that can be used as a starting point for a discussion.
As we discussed. I think instances are a different beast than kprobes, histograms and sythetic events, as instances is a platform for events, where as the others are just events or part of events. So it's fine if instances had a different interface.
Quoted 5 lines
/**
*tracefs_XXX_alloc- allocate a newtracefs_XXXdescriptor. This only
* initializes the descriptor, it does not introduce any changes on the
* system.
This is fine, for all (including instances).
Quoted 11 lines
*
* @arguments: Some arguments specific for the type of the object ... *
* Returns a newly allocatedtracefs_XXXdescriptor objext, or NULL in case
* of an error. The returned instance must be freed bytracefs_XXX_free(). */
structtracefs_XXX*tracefs_XXX_alloc(arguments);/**
*tracefs_XXX_create- creates newtracefs_XXXobject on the system.
* This method callstracefs_XXX_alloc()internally.
This is fine too.
Quoted 8 lines
*
* @arguments: Some arguments specific for the type of the object ...
* This function should not take an instance as argument. Otherwise the
* same instance will have to be passed totracefs_XXX_destroy(), which
* can be a problem in some more sophisticated use-cases.
*
* Returns 0 on succes and -1 on error. On error, errno is set to:
* EBUSY - the object already exists on the system.
As we discussed, this is is fine for kprobes, histograms and synthetic events, but for instances, it can still succeed, but the user can check if it was created or not.
We could add: tracefs_instance_create_unique() that will fail if the instance already exists.
Quoted 9 lines
* ENOMEM - memory allocation failure.
* ENIVAL - a parameter is passed as NULL or value that should not be or
* a problem writing into the system.
*/
structtracefs_XXX*tracefs_XXX_create(arguments);/**
*tracefs_XXX_find- find atracefs_XXXobject that already exists on the
* system. This method callstracefs_XXX_alloc()internally.
I'm not sure we need this, as it only really makes sense for instances, and above we already talked about that.
If we were to have this interface for the other types, I would suggest calling it "open" and not "find". But creating kprobes / histograms and synthetic events may not be as trivial, as building it would require knowing the details of how they are used. Kprobes and histograms may be possible, but the synthetic events will prove to be more difficult.
Quoted 14 lines
*
* @arguments: Some arguments specific for the type of the object ...
* This function should not take an instance as argument. Otherwise the same
* instance will have to be passed totracefs_XXX_destroy(), which can be a
* problem in some more sophisticated use-cases.
*
* Returnstracefs_XXXdescriptor on succes and NULL if the object do not
* exist on the system or in the case of an error. On error, errno is set to:
* ENOMEM - memory allocation failure.
* ENIVAL - a parameter is passed as NULL or value that should not be or
* a problem writing into the system.
*/
structtracefs_XXX*tracefs_XXX_find(arguments);
Quoted 9 lines
/**
*tracefs_instance_destroy- Remove/clears atracefs_XXXobjext from the
* system.tracefs_XXX_free()must be called in order to free the memory used
* by the descriptor itself.
*
* @obj: Pointer to thetracefs_XXXdescriptor of the objext to be destroyed.
* @force: If false the object is not guaranteed to be destroyed. If @force
* is true, all tangled objects that prevent the destruction of the object
* will be destroyed as well.
As stated before, the force may still be a best effort attempt.
Quoted 18 lines
*
* This function should not take any other arguments.
*
* Returns -1 in case of an error or if the object failed to destroy.
* 0 otherwise.
*/
inttracefs_XXX_destroy(struct tracefs_XXX *obj, bool force);/**
*tracefs_XXX_free- Free atracefs_XXXdescriptor, previously allocated
* bytracefs_XXX_alloc,tracefs_XXX_create()ortracefs_XXX_find(). *
* @obj: Pointer to thetracefs_XXXdescriptor objext to be freed. *
* This function should not take any other arguments.
*/
voidtracefs_XXX_free(struct tracefs_XXX *obj);
Quoted 9 lines
/**
*tracefs_XXX_YYY- Method implementing the user action 'YYY' (can be
* enable/disable, start/stop/clear, ... etc.)
*
* @obj: Pointer to thetracefs_XXXobjext for witch the user action will
* apply.
* @instance: Ftrace instance, can be NULL for top tracing instance.
* @more_arguments: Some additional arguments specific for the type XXX and
* the action YYY.
Sounds fine to me.
Thanks for explicitly specifying the details of the interface.
-- Steve
Quoted 9 lines
*/
void/int tracefs_XXX_YYY(structtracefs_XXX*obj,struct tracefs_instance *inst, more_arguments);Thanks a lot!
Yordan