Modifications of some 'hist' APIs
cover Modifications of some 'hist' APIs
The patch-set contains various minor modifications inspired by my first experience using these APIs.
This patch-set applies on top of patch 'libtracefs-Fix-code-indentation'.
Yordan Karadzhov (VMware) (4):
libtracefs: Add new constructors for histograms
libtracefs: Transform tracefs_hist_add_sort_key()
libtracefs: Add new 'hist' APIs
libtracefs: Remove tracefs_hist_add_key()
Documentation/libtracefs-hist-cont.txt | 8 +- Documentation/libtracefs-hist.txt | 8 +- include/tracefs.h | 27 +++- src/tracefs-hist.c | 173 ++++++++++++++++++------- 4 files changed, 159 insertions(+), 57 deletions(-)
Signature · 1 line
2.30.2
RFC PATCH 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 | 17 +++++++++- src/tracefs-hist.c | 82 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 14 deletions(-)
include/tracefs.h +16 -1
@@ -280,10 +280,25 @@ enum tracefs_hist_sort_direction {struct tracefs_hist ;void tracefs_hist_free (struct tracefs_hist *hist); +struct tracefs_hist * +tracefs_hist1d_alloc (struct tracefs_instance * instance, +const char *system,const char *event, +const char *key,enum tracefs_hist_key_type type); +struct tracefs_hist * +tracefs_hist2d_alloc (struct tracefs_instance * instance, +const char *system,const char *event, +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 tracefs_instance * instance,const char *system,const char *event, -const char *key,enum tracefs_hist_key_type type); +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 +69 -13
114 lines not on this page · raw message
Signature · 1 line
2.30.2
RFC PATCH 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 have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting tracefs_hist_add_sort_key() into two methods - one that overwrite and one that does not.
--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-)
include/tracefs.h +3 -1
@@ -303,7 +303,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, ...); +char *sort_key); +int tracefs_hist_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 +19 -2
@@ -453,6 +453,23 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)return tracefs_list_add (list, sort_key); } +int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +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_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to
@@ -464,8 +481,8 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)* * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_sort_key (struct tracefs_hist *hist, +const char *sort_key, ...) {char **list =NULL ;char **tmp;
Signature · 1 line
2.30.2
Re: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 18 lines · On Fri, 10 Sep 2021 19:38:55 +0300 "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 have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-)include/tracefs.h +0
-0
include/tracefs.h int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, · line 306
Quoted 5 lines
include/tracefs.h +1
-1@@ -303,7 +303,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, ...); +char *sort_key);
Why did you remove the const? The add_sort_key() takes a const and makes a copy of it.
src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 455
Quoted 13 lines
include/tracefs.h +2
-0+int tracefs_hist_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 +0
-0@@ -453,6 +453,23 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)return tracefs_list_add (list, sort_key); }
Needs a kerneldoc documentation header.
Quoted 9 lines
src/tracefs-hist.c +9
-0+int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +char *sort_key) +{ +char **list = hist->sort; + +if (!hist || !sort_key) +return -1 ; + + list =add_sort_key (hist, sort_key, hist->sort);
src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 474
Quoted 10 lines
src/tracefs-hist.c +8
-0+if (!list) +return -1 ; + + hist->sort = list; + +return 0 ; +} +/** * tracefs_hist_add_sort_key - add a key for sorting the histogram
The above name needs to be updated.
src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 484
Quoted 8 lines
src/tracefs-hist.c +1
-2* @hist: The histogram to add the sort key to @@ -464,8 +481,8 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)* * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_sort_key(struct tracefs_hist *hist,
How about if we call this:
tracefs_hist_replace_sort_keys()
I think that would be a more intuitive name.
-- Steve
Quoted 4 lines
src/tracefs-hist.c +1
-0+ const char *sort_key, ...) { char **list = NULL;char **tmp;
Re: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 16 lines · Steven Rostedt
Quoted 13 lines · On Fri, 10 Sep 2021 19:38:55 +0300 "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 have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- include/tracefs.h | 4 +++- src/tracefs-hist.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-)
Quoted 13 lines
include/tracefs.h int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, · line 306
Quoted 10 lines
include/tracefs.h +1
-1@@ -303,7 +303,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, ...); +char *sort_key);Why did you remove the const? The
add_sort_key()takes a const and makes a copy of it.
This is a mistake. It must be 'const'.
Quoted 16 lines
Quoted 11 lines
include/tracefs.h +2
-0+int tracefs_hist_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 +0
-0src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 455
Quoted 3 lines
src/tracefs-hist.c +0
-0@@ -453,6 +453,23 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)return tracefs_list_add (list, sort_key); }Needs a kerneldoc documentation header.
OK
Quoted 34 lines
Quoted 10 lines
src/tracefs-hist.c +9
-0+int tracefs_hist_add_sort_key (struct tracefs_hist *hist, +char *sort_key) +{ +char **list = hist->sort; + +if (!hist || !sort_key) +return -1 ; + + list =add_sort_key (hist, sort_key, hist->sort);src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 474
Quoted 10 lines
src/tracefs-hist.c +8
-0+if (!list) +return -1 ; + + hist->sort = list; + +return 0 ; +} +/** * tracefs_hist_add_sort_key - add a key for sorting the histogram The above name needs to be updated.
src/tracefs-hist.c add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) · line 484
Quoted 8 lines
src/tracefs-hist.c +1
-2* @hist: The histogram to add the sort key to @@ -464,8 +481,8 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)* * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key (struct tracefs_hist *hist, -const char *sort_key, ...) +int tracefs_hist_sort_key(struct tracefs_hist *hist,How about if we call this:
Quoted 3 lines
tracefs_hist_replace_sort_keys()I think that would be a more intuitive name.
The user may call this function with a histogram that has no sort keys added. So there will be nothing to replace.
What about naming it 'tracefs_hist_set_sort_keys()'?
Thanks a lot!
Yordan
Quoted 8 lines
-- Steve
Quoted 4 lines
src/tracefs-hist.c +1
-0+ const char *sort_key, ...) { char **list = NULL;char **tmp;
Re: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 9 lines · On Mon, 13 Sep 2021 15:26:51 +0300 Yordan Karadzhov <[email protected]> wrote:
Quoted 5 lines
How about if we call this:
tracefs_hist_replace_sort_keys()I think that would be a more intuitive name.
The user may call this function with a histogram that has no sort keys added. So there will be nothing to replace.
What about naming it 'tracefs_hist_set_sort_keys()'?
Nothing is something to replace?
Or we remove this completely, and have a:
tracefs_hist_reset_sort_keys()
Which removes all sort keys, and let you to start with a clean plate. Thus, the above would really just be "reset" followed by "add".
-- Steve
Re: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
In reply to Yordan Karadzhov (VMware)Quoted 6 lines · On Fri, 10 Sep 2021 19:38:55 +0300 "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 have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not.
If I'm building a histogram via some interactive method, and have created a histogram instance. How do I add a new key before executing it?
-- Steve
Re: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key()
Quoted 10 lines · Steven Rostedt
Quoted 6 lines · On Fri, 10 Sep 2021 19:38:55 +0300 "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 have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting
tracefs_hist_add_sort_key()into two methods - one that overwrite and one that does not.
Quoted 2 lines
If I'm building a histogram via some interactive method, and have created a histogram instance. How do I add a new key before executing it?
Is this comment about adding 'key' or about adding 'sort key'?
Thanks!
Yordan
Quoted 3 lines
-- Steve
RFC PATCH 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 | 4 ++++ src/tracefs-hist.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/tracefs.h +4 -0
@@ -299,6 +299,10 @@ struct tracefs_hist * tracefs_hist_alloc(struct tracefs_instance * instance, const char *system, const char *event, 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); +struct tracefs_instance *tracefs_get_hist_instance (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 +20 -0
@@ -34,6 +34,26 @@ struct tracefs_hist {int size; }; +const char *tracefs_get_hist_name (struct tracefs_hist *hist) +{ +return hist ? hist->name :NULL ; +} + +struct tracefs_instance *tracefs_get_hist_instance (struct tracefs_hist *hist) +{ +return hist ? hist->instance :NULL ; +} + +const char *tracefs_get_hist_event (struct tracefs_hist *hist) +{ +return hist ? hist->event :NULL ; +} + +const char *tracefs_get_hist_system (struct tracefs_hist *hist) +{ +return hist ? hist->system :NULL ; +} +enum tracefs_hist_command {HIST_CMD_NONE =0 ,HIST_CMD_PAUSE ,
Signature · 1 line
2.30.2
RFC PATCH 4/4 libtracefs: Remove tracefs_hist_add_key()
In reply to Yordan Karadzhov (VMware)Since we have appropriate constructor for N-dimensional histograms, this method is no longer needed.
--- Documentation/libtracefs-hist-cont.txt | 8 +- Documentation/libtracefs-hist.txt | 8 +- include/tracefs.h | 2 - src/tracefs-hist.c | 110 +++++++++++-------------- 4 files changed, 58 insertions(+), 70 deletions(-)
Documentation/libtracefs-hist-cont.txt +4 -4
@@ -82,15 +82,15 @@ int main (int argc, char **argv, char **env) exit(-1); } - hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc", + "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 +4 -4
@@ -186,15 +186,15 @@ int main (int argc, char **argv, char **env) exit(-1); } - hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc", + "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",
include/tracefs.h +0 -2
@@ -303,8 +303,6 @@ 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);struct tracefs_instance *tracefs_get_hist_instance (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);int tracefs_hist_add_sort_key (struct tracefs_hist *hist,char *sort_key);
src/tracefs-hist.c +50 -60
128 lines not on this page · raw message
Signature · 1 line
2.30.2