libtraceeval histogram: Updates
v4 cover libtraceeval histogram: Updates
From: "Steven Rostedt (Google)" <[email protected]>
This patch set is based on top of:
https://lore.kernel.org/all/[email protected]/
I added a sample program task-eval which is one of the tools that will be using this library. The first patch adds task-eval but that is still using the old API (defined in trace-analysis.c).
The next patches modify the new API to fit with the use case of task-eval. One is to use "pointer" as I'm not sure exactly the usecase of the dynamic structure.
The cmp and release callbacks are changed to be more generic, and they get called if they simply exist for a given type. I can imagine wanting a release function for event the most mundane types (like number_32).
The cmp was also updated to pass in the traceeval descriptor, as I found that I needed access to it while doing a compare (although, I rewrote the code a bit where that use case isn't in the tool anymore).
Some fixes were made to the query.
I also did a bit of code restructuring and add the hash and iterator logic.
The last patch updates the sample code task-eval.c and has it give pretty much the same logic as the original.
That sample could be updated to implement the code consolidation that Ross suggested. I may do that later.
Happy programming!
Changes since v3: https://lore.kernel.org/all/[email protected]/
- Added patch to reordered the parameters of copy_traceeval_data() and renamed copy to dst and orig to src to match that of memcpy() and strcpy().
- Added patch to rename copy_traceeval_data_set() to dup_traceeval_data_set() to not have the parameter order to be confusing with the typical copy order.
- Fixed comment of traceeval_remove() (Ross Zwisler)
Changes since v2: https://lore.kernel.org/all/[email protected]/
- Fixed comments on traceeval_dyn_release_fn and traceeval_dyn_cmp_fn (Ross Zwisler)
- Change parameter ordering of compare_traceeval_data (Ross Zwisler)
- Added (size_t) to offset_of() macro (Ross Zwisler)
- Fixed iter->current_bucket off by one bug (Ross Zwisler)
- Removed HASH_MASK() from make_hash()
- Fixed goto fail_release in traceeval_init() (Ross Zwisler)
- Free sort and direction in traceeval_iterator_put() (Ross Zwisler)
- Use num_levels variable instead of (level + 1) (Ross Zwisler)
- Return 0 on success of update_entry (Ross Zwisler)
- Fixed the cleanup of old values in update_entry() (Ross Zwisler)
- Fixed resetting iter->next = 0 in traceeval_iterator_sort_custom() (Ross Zwisler)
- Added failure checks to task-eval.c sample for all traceeval_query() calls.
- Added traceeval_remove() to remove an item from traceveal (opposite of traceeval_insert())
Changes since v1: https://lore.kernel.org/all/[email protected]/
- Lots!
- Converted to using a hash table
- Removed the unused compare code. With the other updates, it was taking too much time to keep updating them.
- Added checks and labels to the types to have them know what type they are, and index they are at.
- Added stat logic
- Added iterator logic
- Have a working sample with the new code!
Steven Rostedt (Google) (20):
libtraceeval histograms: Fix traceeval_results_release() error message
libtraceeval: Reverse params of copy_traceeval_data()
libtraceeval: Rename copy_traceeval_data_set() to dup_traceeval_data()
libtraceeval: Add sample task-eval program
libtraceeval hist: Add pointer and const string types libtraceeval histogram: Have cmp and release functions be generic libtraceeval histograms: Add traceeval struct to compare function libtraceeval histogram: Remove comparing of traceeval and types
libtraceeval: Convert hist array into a hash table libtraceeval histograms: Move hash functions into their own file libtraceeval histogram: Label and check keys and values libtraceeval histogram: Add updating of stats
libtraceeval histogram: Add iterator APIs
libtraceeval histogram: Add data copy callback libtraceeval histogram: Do the release on updates libtraceeval histogram: Use stack for old copy in update libtraceeval histogram: Add traceeval_iterator_sort_custom() libtraceeval histogram: Have traceeval_query() just give the pointer
to results
libtraceeval samples: Update task-eval to use the histogram logic
libtraceeval: Add traceeval_remove()
Makefile | 4 +- include/traceeval-hist.h | 117 +++-- include/traceeval-test.h | 16 - samples/Makefile | 29 ++ samples/task-eval.c | 966 +++++++++++++++++++++++++++++++++++++++ src/Makefile | 1 + src/eval-local.h | 123 +++++ src/hash.c | 123 +++++ src/histograms.c | 945 ++++++++++++++++++++++++++++---------- 9 files changed, 2023 insertions(+), 301 deletions(-) delete mode 100644 include/traceeval-test.h create mode 100644 samples/Makefile create mode 100644 samples/task-eval.c create mode 100644 src/eval-local.h create mode 100644 src/hash.c
Signature · 1 line
2.40.1
PATCH v4 1/20 libtraceeval histograms: Fix traceeval_results_release() error message
From: "Steven Rostedt (Google)" <[email protected]>
The function traceeval_results_release() must have a teval if passed in to free the accompanying results, but currently the error message is only displayed if the results is NULL and teval exists. It should be the other way around.
--- src/histograms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/histograms.c +1 -1
@@ -681,7 +681,7 @@ void traceeval_results_release(struct traceeval *teval, union traceeval_data *results) {if (!teval || !results) { -if (!results) +if (!teval)print_err ("Results to be freed without accompanied traceeval instance!" );return ; }
Signature · 1 line
2.40.1
PATCH v4 2/20 libtraceeval: Reverse params of copy_traceeval_data()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Most C library functions copy data from "dst", "src" order, but copy_traceeval_data() does it as "src", "dst", and I already made one bug because of this. Reverse the order of the copy_traceeval_data() parameters, and also rename them to match standard library names "dst" and "src".
--- src/histograms.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
src/histograms.c +9 -9
@@ -560,25 +560,25 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys, }/* -* Copy @orig to @copy with respect to @type. +* Copy @src to @dst with respect to @type. * * Return 0 on success, -1 on error. */ static int copy_traceeval_data (struct traceeval_type *type, -const union traceeval_data *orig, -union traceeval_data *copy) +union traceeval_data *dst, +const union traceeval_data *src) { - *copy = *orig; + *dst = *src;if (type->type ==TRACEEVAL_TYPE_STRING ) { - copy->string =NULL ; + dst->string =NULL ; -if (orig->string) - copy->string =strdup (orig->string); +if (src->string) + dst->string =strdup (src->string);else return 0 ; -if (!copy->string) +if (!dst->string)return -1 ; }
@@ -621,7 +621,7 @@ static int copy_traceeval_data_set(size_t size, struct traceeval_type *type,return -1 ;for (i =0 ; i < size; i++) { -if (copy_traceeval_data (type + i, orig + i, (*copy) + i)) +if (copy_traceeval_data (type + i, (*copy) + i, orig + i)) goto fail; }
Signature · 1 line
2.40.1
PATCH v4 3/20 libtraceeval: Rename copy_traceeval_data_set() to dup_traceeval_data()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The name "copy_traceveal_data_set()" is misleading. It's actually duplicating the data. The difference is that it allocates a new data element and does not "copy" it. This is considered a "dup" and not a copy. This makes it more in line of "strdup()".
It also removes the association of the order of the parameters, as when something is being allocated, it usually comes at the end.
--- src/histograms.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
src/histograms.c +12 -12
@@ -602,13 +602,13 @@ static void data_release(size_t size, union traceeval_data **data, }/* -* Copy @orig to @copy with respect to @size and @type. +* Duplicate a traceeval_data @orig into an newly allocated @copy. * * Returns 1 on success, -1 on error. */ -static int copy_traceeval_data_set (size_t size,struct traceeval_type *type, -const union traceeval_data *orig, -union traceeval_data **copy) +static int dup_traceeval_data_set (size_t size,struct traceeval_type *type, +const union traceeval_data *orig, +union traceeval_data **copy) {size_t i;
@@ -662,8 +662,8 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,/* find key and copy its corresponding value pair */ if ((check =get_entry (teval, keys, &entry)) <1 )return check; -return copy_traceeval_data_set (teval->nr_val_types, teval->val_types, - entry->vals, results); +return dup_traceeval_data_set (teval->nr_val_types, teval->val_types, + entry->vals, results); }/*
@@ -704,13 +704,13 @@ static int create_entry(struct traceeval *teval,struct hist_table *hist = teval->hist;/* copy keys */ -if (copy_traceeval_data_set (teval->nr_key_types, teval->key_types, - keys, &new_keys) ==-1 ) +if (dup_traceeval_data_set (teval->nr_key_types, teval->key_types, + keys, &new_keys) ==-1 )return -1 ;/* copy vals */ -if (copy_traceeval_data_set (teval->nr_val_types, teval->val_types, - vals, &new_vals) ==-1 ) +if (dup_traceeval_data_set (teval->nr_val_types, teval->val_types, + vals, &new_vals) ==-1 ) goto fail_vals;/* create new entry */
@@ -743,8 +743,8 @@ static int update_entry(struct traceeval *teval, struct entry *entry, {union traceeval_data *new_vals; -if (copy_traceeval_data_set (teval->nr_val_types, teval->val_types, - vals, &new_vals) ==-1 ) +if (dup_traceeval_data_set (teval->nr_val_types, teval->val_types, + vals, &new_vals) ==-1 )return -1 ;clean_data_set (entry->vals, teval->val_types, teval->nr_val_types);
Signature · 1 line
2.40.1
PATCH v4 4/20 libtraceeval: Add sample task-eval program
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add a sample task eval program to test the traceeval logic.
This relies on having libtracecmd installed.
This version uses the old API, and will be used to compare when converted over to the new API.
--- Makefile | 3 + samples/Makefile | 29 ++ samples/task-eval.c | 859 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 891 insertions(+) create mode 100644 samples/Makefile create mode 100644 samples/task-eval.c
Makefile +3 -0
@@ -348,6 +348,9 @@ $(LIBRARY_STATIC): force $(LIBRARY_SHARED): force $(Q)$(call descend,$(src)/src,$(LIBRARY_SO)) +samples: $(LIBRARY_STATIC) force + $(Q)$(call descend,$(src)/samples,all) + # $(Q)$(call descend_clean,utest) clean: $(Q)$(call descend_clean,src)
samples/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +# SPDX-License-Identifier: LGPL-2.1 + +include $(src)/scripts/utils.mk + +TARGETS := +TARGETS += task-eval + +sdir := $(obj)/bin + +CFLAGS += `pkg-config --cflags libtracecmd` +LIBRARY_LIBS += `pkg-config --libs libtracecmd` + +TARGETS := $(patsubst %,$(sdir)/%,$(TARGETS)) + +all: $(TARGETS) + +$(sdir): + @mkdir -p $(sdir) + +$(TARGETS): $(sdir) $(LIBTRACEEVAL_STATIC) + +$(sdir)/%: $(bdir)/%.o + $(call do_sample_build,$@,$<) + +$(bdir)/%.o: $(bdir)/%.c + $(Q)$(CC) -o $@ -c $< $(CFLAGS) $(INCLUDES) + +clean: + $(Q)$(call do_clean,$(sdir)/*)
samples/task-eval.c new file +859 -0
859 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 5/20 libtraceeval hist: Add pointer and const string types
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add a pointer type to traceeval_data, as this can be used as a generic pointer type. This may even obsolete the dynamic type.
Also, add a const char * "cstring" type. There's times where the key and value data needs to be assigned to a const char *string, and without having an option of that type, the compiler complains about losing the const.
--- include/traceeval-hist.h | 3 +++ 1 file changed, 3 insertions(+)
include/traceeval-hist.h +3 -0
@@ -25,6 +25,7 @@ enum traceeval_data_type {TRACEEVAL_TYPE_NUMBER_32 ,TRACEEVAL_TYPE_NUMBER_64 ,TRACEEVAL_TYPE_NUMBER , +TRACEEVAL_TYPE_POINTER ,TRACEEVAL_TYPE_STRING , TRACEEVAL_TYPE_DYNAMIC };
@@ -52,6 +53,8 @@ struct traceeval_dynamic {union traceeval_data {struct traceeval_dynamic dyn_data;char *string; +const char *cstring; +void *pointer;unsigned long number;unsigned long long number_64;unsigned int number_32;
Signature · 1 line
2.40.1
PATCH v4 6/20 libtraceeval histogram: Have cmp and release functions be generic
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Having the ability to override the compare function for a given type can be very advantageous. There's also no reason that any type could ask for a release callback to be called when the type is being released. It could be used for information as well as for freeing.
Rename traceeval_dyn_cmp_fn to traceeval_data_cmp_fn and
traceeval_dyn_release_fn to traceeval_data_release_fn and have
them take the union traceeval_type instead of struct traceeval_dynamic.
Also this changes the compare to pass a pointer to union traceeval_data instead of passing in the structure of the dyn_data type.
In the structure, rename dyn_cmp to just cmp, and dyn_release to just release.
--- include/traceeval-hist.h | 50 +++++++++++++++++++++------------------- src/histograms.c | 28 +++++++++++----------- 2 files changed, 40 insertions(+), 38 deletions(-)
include/traceeval-hist.h +26 -24
@@ -64,14 +64,14 @@ union traceeval_data {struct traceeval_type ; -/* struct traceeval_dynamic release function signature */ -typedef void (*traceeval_dyn_release_fn )(struct traceeval_type *, -struct traceeval_dynamic ); +/* release function callback on traceeval_data */ +typedef void (*traceeval_data_release_fn )(struct traceeval_type *, +union traceeval_data *); -/* struct traceeval_dynamic compare function signature */ -typedef int (*traceeval_dyn_cmp_fn )(struct traceeval_dynamic , -struct traceeval_dynamic , -struct traceeval_type *); +/* compare function callback to compare traceeval_data */ +typedef int (*traceeval_data_cmp_fn )(const union traceeval_data *, +const union traceeval_data *, +struct traceeval_type *);/* * struct traceeval_type - Describes the type of a traceevent_data instance
@@ -79,8 +79,8 @@ typedef int (*traceeval_dyn_cmp_fn)(struct traceeval_dynamic,* @name: The string name of the traceeval_data * @flags: flags to describe the traceeval_data * @id: User specified identifier -* @dyn_release: For dynamic types called on release (ignored for other types) -* @dyn_cmp: A way to compare dynamic types (ignored for other types) +* @release: An optional callback for when the data is being released +* @cmp: An optional callback to specify a way to compare the type * * The traceeval_type structure defines expectations for a corresponding * traceeval_data instance for a traceeval histogram instance. Used to
@@ -91,29 +91,31 @@ typedef int (*traceeval_dyn_cmp_fn)(struct traceeval_dynamic,* which each relate to distinct user defined struct traceeval_dynamic * 'sub-types'. * -* For flexibility, @dyn_cmp() and @dyn_release() take a struct -* traceeval_type instance. This allows the user to distinguish between -* different sub-types of struct traceeval_dynamic within a single -* callback function by examining the @id field. This is not a required -* approach, merely one that is accommodated. +* For flexibility, @cmp() and @release() take a struct traceeval_type +* instance. This allows the user to handle dyn_data and pointer types. +* It may also be used for other types if the default cmp() or release() +* need to be overridden. Note for string types, even if the release() +* is called, the string freeing is still taken care of by the traceeval +* infrastructure. * -* @dyn_cmp() is used to compare two struct traceeval_dynamic instances when a -* corresponding struct traceeval_type is reached with its type field set to -* TRACEEVAL_TYPE_DYNAMIC. It should return 0 on equality, 1 if the first -* argument is greater than the second, -1 for the other way around, and -2 on -* error. +* The @id field is a user specified field that may allow the same callback +* to be used by multiple types and not needing to do a strcmp() against the +* name (could be used for switch statements). * -* dyn_release() is used during traceeval_release() to release a union -* traceeval_data's struct traceeval_dynamic field when the corresponding -* traceeval_type type is set to TRACEEVAL_TYPE_DYNAMIC. +* @cmp() is used to override the default compare of a type. This is +* required to compare dyn_data and pointer types. It should return 0 +* on equality, 1 if the first argument is greater than the second, +* -1 for the other way around, and -2 on error. +* +* @release() is called when a data element is being released (or freed). */ struct traceeval_type {char *name;enum traceeval_data_type type;size_t flags;size_t id; -traceeval_dyn_release_fn dyn_release; -traceeval_dyn_cmp_fn dyn_cmp; +traceeval_data_release_fn release; +traceeval_data_cmp_fn cmp; };/* Statistics about a given entry element */
src/histograms.c +14 -14
@@ -90,9 +90,9 @@ static int compare_traceeval_type(struct traceeval_type *orig,return 0 ;if (orig[i].id != copy[i].id)return 0 ; -if (orig[i].dyn_release != copy[i].dyn_release) +if (orig[i].release != copy[i].release)return 0 ; -if (orig[i].dyn_cmp != copy[i].dyn_cmp) +if (orig[i].cmp != copy[i].cmp)return 0 ;// make sure both names are same type
@@ -128,6 +128,9 @@ static int compare_traceeval_data(union traceeval_data *orig,if (!copy)return 1 ; +if (type->cmp) +return type->cmp (orig, copy, type); +switch (type->type) {case TRACEEVAL_TYPE_STRING : i =strcmp (orig->string, copy->string);
@@ -149,8 +152,7 @@ static int compare_traceeval_data(union traceeval_data *orig,compare_numbers_return (orig->number_8, copy->number_8);case TRACEEVAL_TYPE_DYNAMIC : -if (type->dyn_cmp) -return type->dyn_cmp (orig->dyn_data, copy->dyn_data, type); +/* If it didn't specify a cmp function, then punt */ return 0 ;default :
@@ -236,8 +238,8 @@ static int compare_hist(struct traceeval *orig, struct traceeval *copy)* * This compares the values of the key definitions, value definitions, and * inserted data between @orig and @copy in order. It does not compare -* by memory address, except for struct traceeval_type's dyn_release() and -* dyn_cmp() fields. +* by memory address, except for struct traceeval_type's release() and +* cmp() fields. * * Returns 1 if @orig and @copy are the same, 0 if not, and -1 on error. */
@@ -438,14 +440,13 @@ fail:*/ static void clean_data (union traceeval_data *data,struct traceeval_type *type) { +if (type->release) + type->release (type, data); +switch (type->type) {case TRACEEVAL_TYPE_STRING :free (data->string);break ; -case TRACEEVAL_TYPE_DYNAMIC : -if (type->dyn_release) - type->dyn_release (type, data->dyn_data); -break ;default :break ; }
@@ -465,9 +466,8 @@ static void clean_data_set(union traceeval_data *data, struct traceeval_type *dereturn ; } -for (i =0 ; i < size; i++) { +for (i =0 ; i < size; i++)clean_data (data + i, defs + i); - }free (data); }
@@ -512,7 +512,7 @@ static void hist_table_release(struct traceeval *teval)* it must call traceeval_release(). * * This frees all internally allocated data of @teval and will call the -* corresponding dyn_release() functions registered for keys and values of +* corresponding release() functions registered for keys and values of * type TRACEEVAL_TYPE_DYNAMIC. */ void traceeval_release (struct traceeval *teval)
@@ -588,7 +588,7 @@ static int copy_traceeval_data(struct traceeval_type *type,/* * Free @data with respect to @size and @type. * -* Does not call dyn_release on type TRACEEVAL_TYPE_DYNAMIC. +* Does not call the release callback on the data. */ static void data_release (size_t size,union traceeval_data **data,struct traceeval_type *type)
Signature · 1 line
2.40.1
PATCH v4 7/20 libtraceeval histograms: Add traceeval struct to compare function
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
When looking at how this code would be implemented, I found that I needed access to the traceeval structure within the compare callbacks. Pass that in too.
Also, rearrange the parameters a little. The traceeval and type should go first as they describe the "object", and the data should go last as they are the values of the function.
--- include/traceeval-hist.h | 13 +++++++------ src/histograms.c | 31 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-)
include/traceeval-hist.h +7 -6
@@ -63,16 +63,17 @@ union traceeval_data { };struct traceeval_type ; +struct traceeval ;/* release function callback on traceeval_data */ -typedef void (*traceeval_data_release_fn )(struct traceeval_type *, -union traceeval_data *); +typedef void (*traceeval_data_release_fn )(const struct traceeval_type *type, +union traceeval_data *data);/* compare function callback to compare traceeval_data */ -typedef int (*traceeval_data_cmp_fn )(const union traceeval_data *, -const union traceeval_data *, -struct traceeval_type *); - +typedef int (*traceeval_data_cmp_fn )(struct traceeval *teval, +const struct traceeval_type *type, +const union traceeval_data *A , +const union traceeval_data *B );/* * struct traceeval_type - Describes the type of a traceevent_data instance * @type: The enum type that describes the traceeval_data
src/histograms.c +16 -15
@@ -113,9 +113,10 @@ static int compare_traceeval_type(struct traceeval_type *orig,* Return 0 if @orig and @copy are the same, 1 if @orig is greater than @copy, * -1 for the other way around, and -2 on error. */ -static int compare_traceeval_data (union traceeval_data *orig, -const union traceeval_data *copy, -struct traceeval_type *type) +static int compare_traceeval_data (struct traceeval *teval, +struct traceeval_type *type, +union traceeval_data *orig, +const union traceeval_data *copy) {int i;
@@ -129,7 +130,7 @@ static int compare_traceeval_data(union traceeval_data *orig,return 1 ;if (type->cmp) -return type->cmp (orig, copy, type); +return type->cmp (teval, type, orig, copy);switch (type->type) {case TRACEEVAL_TYPE_STRING :
@@ -167,16 +168,17 @@ static int compare_traceeval_data(union traceeval_data *orig,* * Return 1 if @orig and @copy are the same, 0 if not, and -1 on error. */ -static int compare_traceeval_data_set (union traceeval_data *orig, -const union traceeval_data *copy, -struct traceeval_type *defs,size_t size) +static int compare_traceeval_data_set (struct traceeval *teval, +struct traceeval_type *defs, +union traceeval_data *orig, +const union traceeval_data *copy,size_t size) {int check;size_t i;/* compare data arrays */ for (i =0 ; i < size; i++) { -if ((check =compare_traceeval_data (orig + i, copy + i, defs + i))) +if ((check =compare_traceeval_data (teval, defs + i, orig + i, copy + i)))return check ==-2 ?-1 :0 ; }
@@ -192,14 +194,14 @@ static int compare_entries(struct entry *orig, struct entry *copy,int check;/* compare keys */ - check =compare_traceeval_data_set (orig->keys, copy->keys, - teval->key_types, teval->nr_key_types); + check =compare_traceeval_data_set (teval, teval->key_types, + orig->keys, copy->keys, teval->nr_key_types);if (check <1 )return check;/* compare values */ - check =compare_traceeval_data_set (orig->vals, copy->vals, - teval->val_types, teval->nr_val_types); + check =compare_traceeval_data_set (teval, teval->val_types, + orig->vals, copy->vals, teval->nr_val_types);return check; }
@@ -546,9 +548,8 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys, hist = teval->hist;for (i =0 , entry = hist->map; i < hist->nr_entries; entry = &hist->map[++i]) { - check =compare_traceeval_data_set (entry->keys, keys, - teval->key_types, teval->nr_key_types); - + check =compare_traceeval_data_set (teval, teval->key_types, + entry->keys, keys, teval->nr_key_types);if (!check)continue ;break ;
Signature · 1 line
2.40.1
PATCH v4 8/20 libtraceeval histogram: Remove comparing of traceeval and types
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The compare functions for traceeval and types were created for testing. But because the tests have not yet been pulled in, remove these functions as they are currently unused and cause an unnecessary burden of making sure they are updated when other code they use is updated.
--- Makefile | 1 - include/traceeval-test.h | 16 ----- src/histograms.c | 127 --------------------------------------- 3 files changed, 144 deletions(-) delete mode 100644 include/traceeval-test.h
Makefile +0 -1
@@ -172,7 +172,6 @@ libs: $(LIBRARY_A) $(LIBRARY_SO) VALGRIND = $(shell which valgrind) UTEST_DIR = utest -UTEST_BINARY = eval-utest test: force $(LIBRARY_STATIC) ifneq ($(CUNIT_INSTALLED),1)
include/traceeval-test.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* libtraceeval interface for unit testing. -* -* Copyright (C) 2023 Google Inc, Steven Rostedt <[email protected]> -* Copyright (C) 2023 Google Inc, Stevie Alvarez <[email protected]> -*/ - -#ifndef __LIBTRACEEVAL_TEST_H__ -#define __LIBTRACEEVAL_TEST_H__ - -#include <traceeval-hist.h> - -int traceeval_compare (struct traceeval *orig,struct traceeval *copy); - -#endif /* __LIBTRACEEVAL_TEST_H__ */
src/histograms.c +0 -127
145 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 9/20 libtraceeval: Convert hist array into a hash table
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The lookups need to be extremely fast. Instead of doing a linear search across all entries (which could be thousands), do a hash lookup instead.
--- include/traceeval-hist.h | 7 ++ src/histograms.c | 166 +++++++++++++++++++++++++++++++++------ 2 files changed, 147 insertions(+), 26 deletions(-)
include/traceeval-hist.h +7 -0
@@ -74,6 +74,12 @@ typedef int (*traceeval_data_cmp_fn)(struct traceeval *teval,const struct traceeval_type *type, const union traceeval_data *A, const union traceeval_data *B); + +/* make a unique value */ +typedef int (*traceeval_data_hash_fn )(struct traceeval *teval, +const struct traceeval_type *type, +const union traceeval_data *data); +/* * struct traceeval_type - Describes the type of a traceevent_data instance * @type: The enum type that describes the traceeval_data
@@ -117,6 +123,7 @@ struct traceeval_type {size_t id;traceeval_data_release_fn release;traceeval_data_cmp_fn cmp; +traceeval_data_hash_fn hash; };/* Statistics about a given entry element */
src/histograms.c +140 -26
270 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 10/20 libtraceeval histograms: Move hash functions into their own file
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Move the hash functions into their own file so that it does not clutter the histogram.c file. Functionality should be the same, but some code restructuring was done.
To keep the hash abstract, helper functions were introduced:
hash_iter_start() - to start iterating over all items in the hash hash_iter_next() - to get the next item in the hash
hash_iter_bucket() - to start iterating over a single bucket in the hash hash_iter_bucket_next() - to get the next item in the bucket
hash_nr_items() - to get the number of items in the hash
Also implemented hash_remove() to remove an item from the hash.
Also created a eval-local.h header file to store the prototypes of the local functions as well as moved the structures there too.
--- src/Makefile | 1 + src/eval-local.h | 103 +++++++++++++++++++++++++++++++++++++++ src/hash.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++ src/histograms.c | 121 +++++++--------------------------------------- 4 files changed, 244 insertions(+), 104 deletions(-) create mode 100644 src/eval-local.h create mode 100644 src/hash.c
src/Makefile +1 -0
@@ -5,6 +5,7 @@ include $(src)/scripts/utils.mk OBJS = OBJS += trace-analysis.o OBJS += histograms.o +OBJS += hash.o OBJS := $(OBJS:%.o=$(bdir)/%.o)
src/eval-local.h new file +103 -0
103 lines not on this page · raw message
src/hash.c new file +123 -0
123 lines not on this page · raw message
src/histograms.c +17 -104
195 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 11/20 libtraceeval histogram: Label and check keys and values
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
When initializing the traceeval descriptor, mark each key and value as their type via the flags (keys get TRACEEVAL_FL_KEY and values get TRACEEVAL_FL_VALUE) as well as adding the index of that key/value type of the key/value data it represents. This will be used by the iterators for sorting. The iterator will point to the key/value type and use that information to know which key/value data to sort with.
The keys and values passed in will also be updated to have their flags match the proper key/value type as well as the index. This will be useful for traceeval_stat() that will take the type as a parameter, and use it to figure out fast where the data is that is to be looked up.
All pointer and dynamic types in keys must have both a cmp and hash function defined, otherwise they cannot be indexed or hashed. Add a check to make sure all key types of pointer and dynamic have those functions.
--- include/traceeval-hist.h | 11 +++++--- src/histograms.c | 60 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 7 deletions(-)
include/traceeval-hist.h +7 -4
@@ -32,8 +32,10 @@ enum traceeval_data_type {/* Statistics specification flags */ enum traceeval_flags { -TRACEEVAL_FL_SIGNED = (1 <<0 ), -TRACEEVAL_FL_TIMESTAMP = (1 <<1 ), +TRACEEVAL_FL_KEY = (1 <<0 ), +TRACEEVAL_FL_VALUE = (1 <<1 ), +TRACEEVAL_FL_SIGNED = (1 <<2 ), +TRACEEVAL_FL_TIMESTAMP = (1 <<3 ), };/*
@@ -120,6 +122,7 @@ struct traceeval_type {char *name;enum traceeval_data_type type;size_t flags; +size_t index;size_t id;traceeval_data_release_fn release;traceeval_data_cmp_fn cmp;
@@ -142,8 +145,8 @@ struct traceeval;/* Histogram interfaces */ -struct traceeval *traceeval_init (const struct traceeval_type *keys, -const struct traceeval_type *vals); +struct traceeval *traceeval_init (struct traceeval_type *keys, +struct traceeval_type *vals);void traceeval_release (struct traceeval *teval);
src/histograms.c +57 -3
87 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 12/20 libtraceeval histogram: Add updating of stats
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Whenever an entry is added that already exists (overwriting the values) keep track of the stats for the number values (max, min, total, count).
Also move the stat structure out of the public view. We may want to modify this structure in the future, and so it should not become an API.
Add accessor functions to get to the stat values.
Add traceeval_stat() to acquire a stat handle from a specific key for a specific value.
--- include/traceeval-hist.h | 17 ++-- src/eval-local.h | 9 ++ src/histograms.c | 182 +++++++++++++++++++++++++++++++++++---- 3 files changed, 183 insertions(+), 25 deletions(-)
include/traceeval-hist.h +10 -7
@@ -130,13 +130,7 @@ struct traceeval_type { };/* Statistics about a given entry element */ -struct traceeval_stat { -unsigned long long max; -unsigned long long min; -unsigned long long total; -unsigned long long avg; -unsigned long long std; -}; +struct traceeval_stat ;/* Iterator over aggregated data */ struct traceeval_iterator ;
@@ -160,4 +154,13 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,void traceeval_results_release (struct traceeval *teval,union traceeval_data *results); +struct traceeval_stat *traceeval_stat (struct traceeval *teval, +const union traceeval_data *keys, +struct traceeval_type *type); + +unsigned long long traceeval_stat_max (struct traceeval_stat *stat); +unsigned long long traceeval_stat_min (struct traceeval_stat *stat); +unsigned long long traceeval_stat_total (struct traceeval_stat *stat); +unsigned long long traceeval_stat_count (struct traceeval_stat *stat); +#endif /* __LIBTRACEEVAL_HIST_H__ */
src/eval-local.h +9 -0
@@ -45,11 +45,20 @@ struct hash_table {struct hash_iter iter; }; +struct traceeval_stat { +unsigned long long max; +unsigned long long min; +unsigned long long total; +unsigned long long std; +size_t count; +}; +/* A key-value pair */ struct entry {struct hash_item hash;union traceeval_data *keys;union traceeval_data *vals; +struct traceeval_stat *val_stats; };/* Histogram */
src/histograms.c +164 -18
246 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 13/20 libtraceeval histogram: Add iterator APIs
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Provide an interface for the application to iterate over all the entries in the traceeval histogram.
traceeval_iterator_get() - acquire an iterator for the given traceeval traceveal_iterator_put() - release the iterator traceeval_iterator_sort() - sort the iterator for a given key/value traceeval_iterator_next() - return the keys of the next entry in the
traceeval
--- include/traceeval-hist.h | 7 ++ src/eval-local.h | 11 ++ src/histograms.c | 258 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 275 insertions(+), 1 deletion(-)
include/traceeval-hist.h +7 -0
@@ -163,4 +163,11 @@ unsigned long long traceeval_stat_min(struct traceeval_stat *stat);unsigned long long traceeval_stat_total (struct traceeval_stat *stat);unsigned long long traceeval_stat_count (struct traceeval_stat *stat); +struct traceeval_iterator *traceeval_iterator_get (struct traceeval *teval); +void traceeval_iterator_put (struct traceeval_iterator *iter); +int traceeval_iterator_sort (struct traceeval_iterator *iter,const char *sort_field, +int level,bool ascending); +int traceeval_iterator_next (struct traceeval_iterator *iter, +const union traceeval_data **keys); +#endif /* __LIBTRACEEVAL_HIST_H__ */
src/eval-local.h +11 -0
@@ -70,6 +70,17 @@ struct traceeval {size_t nr_val_types; }; +struct traceeval_iterator { +struct traceeval *teval; +struct entry **entries; +struct traceeval_type **sort; +bool *direction; +size_t nr_entries; +size_t nr_sort; +size_t next; +bool needs_sort; +}; +extern struct hash_table *hash_alloc (void );extern void hash_free (struct hash_table *hash);extern void hash_add (struct hash_table *hash,struct hash_item *item,unsigned key);
src/histograms.c +257 -1
267 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 14/20 libtraceeval histogram: Add data copy callback
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add a callback "copy" to the type that gets called when a copy is done. This is can be used to copy dynamic types. Otherwise the old one is just going to be released.
--- include/traceeval-hist.h | 5 +++++ src/histograms.c | 3 +++ 2 files changed, 8 insertions(+)
include/traceeval-hist.h +5 -0
@@ -82,6 +82,10 @@ typedef int (*traceeval_data_hash_fn)(struct traceeval *teval,const struct traceeval_type *type, const union traceeval_data *data); +typedef int (*traceeval_data_copy_fn )(const struct traceeval_type *type, +union traceeval_data *dst, +const union traceeval_data *src); +/* * struct traceeval_type - Describes the type of a traceevent_data instance * @type: The enum type that describes the traceeval_data
@@ -126,6 +130,7 @@ struct traceeval_type {size_t id;traceeval_data_release_fn release;traceeval_data_cmp_fn cmp; +traceeval_data_copy_fn copy;traceeval_data_hash_fn hash; };
src/histograms.c +3 -0
@@ -511,6 +511,9 @@ static int copy_traceeval_data(struct traceeval_type *type, {unsigned long long val; +if (type->copy) +return type->copy (type, dst, src); + *dst = *src;switch (type->type) {
Signature · 1 line
2.40.1
PATCH v4 15/20 libtraceeval histogram: Do the release on updates
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
If no copy() function exists for a type but a release() function does, then do the release on the old copy.
--- src/histograms.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
src/histograms.c +5 -1
@@ -595,12 +595,16 @@ static int copy_traceeval_data(struct traceeval_type *type,/* * Free @data with respect to @size and @type. * -* Does not call the release callback on the data. +* Does not call the release() callback if a copy() exists. */ static void data_release (size_t size,union traceeval_data **data,struct traceeval_type *type) {for (size_t i =0 ; i < size; i++) { +/* A copy should handle releases */ +if (type[i].release && !type[i].copy) + type[i].release (&type[i], &(*data)[i]); +if (type[i].type ==TRACEEVAL_TYPE_STRING )free ((*data)[i].string); }
Signature · 1 line
2.40.1
PATCH v4 16/20 libtraceeval histogram: Use stack for old copy in update
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
In the update, instead of using the heap, use the stack to save the old values. This should save time where it does not need to allocate and then free the value list to do an update.
--- src/histograms.c | 51 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 13 deletions(-)
src/histograms.c +38 -13
@@ -597,17 +597,23 @@ static int copy_traceeval_data(struct traceeval_type *type,* * Does not call the release() callback if a copy() exists. */ -static void data_release (size_t size,union traceeval_data **data, -struct traceeval_type *type) +static void data_release (size_t size,union traceeval_data *data, +struct traceeval_type *type) {for (size_t i =0 ; i < size; i++) {/* A copy should handle releases */ if (type[i].release && !type[i].copy) - type[i].release (&type[i], &(*data)[i]); + type[i].release (&type[i], &data[i]);if (type[i].type ==TRACEEVAL_TYPE_STRING ) -free ((*data)[i].string); +free (data[i].string); } +} + +static void data_release_and_free (size_t size,union traceeval_data **data, +struct traceeval_type *type) +{ +data_release (size, *data, type);free (*data); *data =NULL ; }
@@ -641,7 +647,7 @@ static int dup_traceeval_data_set(size_t size, struct traceeval_type *type,return 1 ; fail: -data_release (i, copy, type); +data_release_and_free (i, copy, type);return -1 ; }
@@ -700,7 +706,7 @@ void traceeval_results_release(struct traceeval *teval,return ; } -data_release (teval->nr_val_types, &results, teval->val_types); +data_release_and_free (teval->nr_val_types, &results, teval->val_types); } static struct entry *create_hist_entry(struct traceeval *teval,
@@ -756,7 +762,7 @@ static int create_entry(struct traceeval *teval,return 0 ; fail: -data_release (teval->nr_key_types, &new_keys, teval->key_types); +data_release_and_free (teval->nr_key_types, &new_keys, teval->key_types); fail_stats:free (entry->val_stats);
@@ -776,15 +782,34 @@ fail_entry:static int update_entry (struct traceeval *teval,struct entry *entry,const union traceeval_data *vals) { -union traceeval_data *new_vals; +struct traceeval_stat *stats = entry->val_stats; +struct traceeval_type *types = teval->val_types; +union traceeval_data *copy = entry->vals; +union traceeval_data old[teval->nr_val_types]; +size_t size = teval->nr_val_types; +size_t i; -if (dup_traceeval_data_set (teval->nr_val_types, teval->val_types, - entry->val_stats, vals, &new_vals) ==-1 ) -return -1 ; +if (!size) +return 0 ; -clean_data_set (entry->vals, teval->val_types, teval->nr_val_types); - entry->vals = new_vals; +for (i =0 ; i < size; i++) { + old[i] = copy[i]; + +if (copy_traceeval_data (types + i, stats + i, + copy + i, vals + i)) + goto fail; + } +data_release (size, old, types);return 0 ; + fail: +/* Free the new values that were added */ +data_release (i, copy, types); +/* Put back the old values */ +for (i--; i >=0 ; i--) { +copy_traceeval_data (types + i,NULL , + copy + i, old + i); + } +return -1 ; } struct traceeval_stat *traceeval_stat(struct traceeval *teval,
Signature · 1 line
2.40.1
PATCH v4 17/20 libtraceeval histogram: Add traceeval_iterator_sort_custom()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add an iterator where the application can supply the sort algorithm where it gets the teval descriptor along with the keys and values of both of the entries to compare against. Also, allow it to submit its own data to the compare function:
int traceeval_iterator_sort_custom(struct traceeval_iterator *iter,
traceeval_cmp_fn sort_fn, void *data);
with
typedef int (*traceeval_cmp_fn)(struct traceeval *teval,
const union traceeval_data *Akeys, const union traceeval_data *Avals, const union traceeval_data *Bkeys, const union traceeval_data *Bvals, void *data);
--- include/traceeval-hist.h | 9 +++++++++ src/histograms.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
include/traceeval-hist.h +9 -0
@@ -86,6 +86,13 @@ typedef int (*traceeval_data_copy_fn)(const struct traceeval_type *type,union traceeval_data *dst, const union traceeval_data *src); +typedef int (*traceeval_cmp_fn )(struct traceeval *teval, +const union traceeval_data *Akeys, +const union traceeval_data *Avals, +const union traceeval_data *Bkeys, +const union traceeval_data *Bvals, +void *data); +/* * struct traceeval_type - Describes the type of a traceevent_data instance * @type: The enum type that describes the traceeval_data
@@ -172,6 +179,8 @@ struct traceeval_iterator *traceeval_iterator_get(struct traceeval *teval);void traceeval_iterator_put (struct traceeval_iterator *iter);int traceeval_iterator_sort (struct traceeval_iterator *iter,const char *sort_field,int level,bool ascending); +int traceeval_iterator_sort_custom (struct traceeval_iterator *iter, +traceeval_cmp_fn sort_fn,void *data);int traceeval_iterator_next (struct traceeval_iterator *iter,const union traceeval_data **keys);
src/histograms.c +35 -0
@@ -1160,6 +1160,41 @@ static int sort_iter(struct traceeval_iterator *iter)return 0 ; } +struct iter_custom_data { +struct traceeval_iterator *iter; +traceeval_cmp_fn sort_fn; +void *data; +}; + +static int iter_custom_cmp (const void *A ,const void *B ,void *data) +{ +struct iter_custom_data *cust_data = data; +struct traceeval_iterator *iter = cust_data->iter; +struct traceeval *teval = iter->teval; +const struct entry *a = *((const struct entry **)A ); +const struct entry *b = *((const struct entry **)B ); + +return cust_data->sort_fn (teval, a->keys, a->vals, b->keys, b->vals, + cust_data->data); +} + +int traceeval_iterator_sort_custom (struct traceeval_iterator *iter, +traceeval_cmp_fn sort_fn,void *data) +{ +struct iter_custom_data cust_data = { + .iter = iter, + .sort_fn = sort_fn, + .data = data + }; + +qsort_r (iter->entries, iter->nr_entries,sizeof (*iter->entries), + iter_custom_cmp, &cust_data); + + iter->needs_sort = false; + iter->next =0 ; +return 0 ; +} +/** * traceeval_iterator_next - retrieve the next entry from an iterator * @iter: The iterator to retrieve the next entry from
Signature · 1 line
2.40.1
PATCH v4 18/20 libtraceeval histogram: Have traceeval_query() just give the pointer to results
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Instead of wasting allocation to return the results for queries, especially since the query is likely not to modify the results, just give a direct pointer to the entry->vals.
Mark it as const so (hopefully) nobody modifies it.
We still require the traceeval_results_release() to be called on it, as we may in the future add a ref count to it and perhaps do a copy-on-write if an update happens while something still has a hold on it.
--- include/traceeval-hist.h | 4 ++-- src/histograms.c | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-)
include/traceeval-hist.h +2 -2
@@ -161,10 +161,10 @@ int traceeval_insert(struct traceeval *teval, const union traceeval_data *vals);int traceeval_query (struct traceeval *teval,const union traceeval_data *keys, -union traceeval_data **results); +const union traceeval_data **results);void traceeval_results_release (struct traceeval *teval, -union traceeval_data *results); +const union traceeval_data *results); struct traceeval_stat *traceeval_stat(struct traceeval *teval, const union traceeval_data *keys,
src/histograms.c +4 -6
@@ -670,7 +670,7 @@ fail:* Returns 1 if found, 0 if not found, and -1 on error. */ int traceeval_query (struct traceeval *teval,const union traceeval_data *keys, -union traceeval_data **results) +const union traceeval_data **results) {struct entry *entry;int check;
@@ -682,8 +682,8 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,if ((check =get_entry (teval, keys, &entry)) <1 )return check; -return dup_traceeval_data_set (teval->nr_val_types, teval->val_types, -NULL , entry->vals, results); + *results = entry->vals; +return 1 ; }/*
@@ -698,15 +698,13 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,* allow traceeval to clean up its references. */ void traceeval_results_release (struct traceeval *teval, -union traceeval_data *results) +const union traceeval_data *results) {if (!teval || !results) {if (!teval)print_err ("Results to be freed without accompanied traceeval instance!" );return ; } - -data_release_and_free (teval->nr_val_types, &results, teval->val_types); } static struct entry *create_hist_entry(struct traceeval *teval,
Signature · 1 line
2.40.1
PATCH v4 19/20 libtraceeval samples: Update task-eval to use the histogram logic
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Convert task-eval over to the new API.
--- samples/Makefile | 2 +- samples/task-eval.c | 743 +++++++++++++++++++++++++------------------- 2 files changed, 426 insertions(+), 319 deletions(-)
samples/Makefile +1 -1
@@ -19,7 +19,7 @@ $(sdir): $(TARGETS): $(sdir) $(LIBTRACEEVAL_STATIC) -$(sdir)/%: $(bdir)/%.o +$(sdir)/%: $(LIBTRACEEVAL_STATIC) $(bdir)/%.o $(call do_sample_build,$@,$<) $(bdir)/%.o: $(bdir)/%.c
samples/task-eval.c +425 -318
999 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 20/20 libtraceeval: Add traceeval_remove()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add a way to remove an entry that's in the traceeval. Currently there's only ways to add entries, but there also needs to be a way to remove them too.
--- include/traceeval-hist.h | 3 +++ src/histograms.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
include/traceeval-hist.h +3 -0
@@ -160,6 +160,9 @@ int traceeval_insert(struct traceeval *teval,const union traceeval_data *keys, const union traceeval_data *vals); +int traceeval_remove (struct traceeval *teval, +const union traceeval_data *keys); +int traceeval_query (struct traceeval *teval,const union traceeval_data *keys,const union traceeval_data **results);
src/histograms.c +29 -0
@@ -934,6 +934,35 @@ int traceeval_insert(struct traceeval *teval,return update_entry (teval, entry, vals); } +/** +* traceeval_remove - remove an item from the traceeval descriptor +* @teval: The descriptor to removed from +* @keys: The list of keys that defines what is being removed +* +* This is the opposite of traceeval_insert(). Instead of inserting +* an item into the traceeval historgram, it removes it. +* +* Returns 1 if it found and removed an item, +* 0 if it did not find an time matching @keys +* -1 if there was an error. +*/ +int traceeval_remove (struct traceeval *teval, +const union traceeval_data *keys) +{ +struct hash_table *hist = teval->hist; +struct entry *entry; +int check; + + entry =NULL ; + check =get_entry (teval, keys, &entry); + +if (check <1 ) +return check; + +hash_remove (hist, &entry->hash); +return 1 ; +} +/** * traceeval_iterator_put - release a given iterator * @iter: The iterartor to release
Signature · 1 line
2.40.1
Quoted 1 line · On Thu, 17 Aug 2023 16:45:08 -0400 Steven Rostedt <[email protected]> wrote:
Changes since v3: https://lore.kernel.org/all/[email protected]/
The diff between this version and the last version:
include/traceeval-hist.h +2 -2
@@ -83,8 +83,8 @@ typedef int (*traceeval_data_hash_fn)(struct traceeval *teval, const union traceeval_data *data);typedef int (*traceeval_data_copy_fn )(const struct traceeval_type *type, -union traceeval_data *copy, -const union traceeval_data *origin); +union traceeval_data *dst, +const union traceeval_data *src); typedef int (*traceeval_cmp_fn)(struct traceeval *teval, const union traceeval_data *Akeys,
src/histograms.c +31 -31
144 lines not on this page · raw message
-- Steve
Quoted 26 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
This patch set is based on top of:
https://lore.kernel.org/all/[email protected]/
I added a sample program task-eval which is one of the tools that will be using this library. The first patch adds task-eval but that is still using the old API (defined in
trace-analysis.c).The next patches modify the new API to fit with the use case of task-eval. One is to use "pointer" as I'm not sure exactly the usecase of the dynamic structure.
The cmp and release callbacks are changed to be more generic, and they get called if they simply exist for a given type. I can imagine wanting a release function for event the most mundane types (like
number_32).The cmp was also updated to pass in the traceeval descriptor, as I found that I needed access to it while doing a compare (although, I rewrote the code a bit where that use case isn't in the tool anymore).
Some fixes were made to the query.
I also did a bit of code restructuring and add the hash and iterator logic.
Quoted 7 lines
The last patch updates the sample code
task-eval.cand has it give pretty much the same logic as the original.That sample could be updated to implement the code consolidation that Ross suggested. I may do that later.
Happy programming!
Looks good, you can add:
Quoted 99 lines
Changes since v3: https://lore.kernel.org/all/[email protected]/
- Added patch to reordered the parameters of
copy_traceeval_data()and renamed copy to dst and orig to src to match that ofmemcpy()andstrcpy().- Added patch to rename
copy_traceeval_data_set()todup_traceeval_data_set()to not have the parameter order to be confusing with the typical copy order.- Fixed comment of
traceeval_remove()(Ross Zwisler)Changes since v2: https://lore.kernel.org/all/[email protected]/
- Fixed comments on
traceeval_dyn_release_fnandtraceeval_dyn_cmp_fn(Ross Zwisler)- Change parameter ordering of
compare_traceeval_data(Ross Zwisler)- Added (
size_t) tooffset_of()macro (Ross Zwisler)- Fixed
iter->current_bucketoff by one bug (Ross Zwisler)- Removed
HASH_MASK()frommake_hash()- Fixed goto
fail_releaseintraceeval_init()(Ross Zwisler)- Free sort and direction in
traceeval_iterator_put()(Ross Zwisler)- Use
num_levelsvariable instead of (level + 1) (Ross Zwisler)- Return 0 on success of
update_entry(Ross Zwisler)- Fixed the cleanup of old values in
update_entry()(Ross Zwisler)- Fixed resetting
iter->next= 0 intraceeval_iterator_sort_custom()(Ross Zwisler)- Added failure checks to
task-eval.csample for alltraceeval_query()calls.- Added
traceeval_remove()to remove an item from traceveal (opposite oftraceeval_insert())Changes since v1: https://lore.kernel.org/all/[email protected]/
- Lots!
- Converted to using a hash table
- Removed the unused compare code. With the other updates, it was taking too much time to keep updating them.
- Added checks and labels to the types to have them know what type they are, and index they are at.
- Added stat logic
- Added iterator logic
- Have a working sample with the new code!
Steven Rostedt (Google) (20):
libtraceeval histograms: Fixtraceeval_results_release()error message
libtraceeval: Reverse params ofcopy_traceeval_data()
libtraceeval: Renamecopy_traceeval_data_set()todup_traceeval_data()
libtraceeval: Add sample task-eval program
libtraceeval hist: Add pointer and const string types libtraceeval histogram: Have cmp and release functions be generic libtraceeval histograms: Add traceeval struct to compare function libtraceeval histogram: Remove comparing of traceeval and types
libtraceeval: Convert hist array into a hash table libtraceeval histograms: Move hash functions into their own file libtraceeval histogram: Label and check keys and values libtraceeval histogram: Add updating of stats
libtraceeval histogram: Add iterator APIs
libtraceeval histogram: Add data copy callback libtraceeval histogram: Do the release on updates libtraceeval histogram: Use stack for old copy in update libtraceeval histogram: Addtraceeval_iterator_sort_custom()libtraceeval histogram: Havetraceeval_query()just give the pointer
to results
libtraceeval samples: Update task-eval to use the histogram logic
libtraceeval: Addtraceeval_remove()Makefile | 4 +- include/traceeval-hist.h | 117 +++-- include/traceeval-test.h | 16 - samples/Makefile | 29 ++ samples/task-eval.c | 966 +++++++++++++++++++++++++++++++++++++++ src/Makefile | 1 + src/eval-local.h | 123 +++++ src/hash.c | 123 +++++ src/histograms.c | 945 ++++++++++++++++++++++++++++---------- 9 files changed, 2023 insertions(+), 301 deletions(-) delete mode 100644 include/traceeval-test.h create mode 100644 samples/Makefile create mode 100644 samples/task-eval.c create mode 100644 src/eval-local.h create mode 100644 src/hash.cSignature · 1 line
2.40.1