histograms: Fix memory leak, logic bugs, legibility
v4 cover histograms: Fix memory leak, logic bugs, legibility
From: Stevie Alvarez (Google) <[email protected]>
Changes in v4:
* Reorder enum traceeval_data_type numeric types for algorithmic access.
* Reorder union traceeval_data numeric fields for legibility.
* Remove parenthesis from function name in kerneldocs.
* Optimize logic in type_alloc().
* Distinguish internal vs public interfaces within include statements.
* Rework copy_traceeval_data() logic for legibility.
* Rework comparator return types to fix query and insert bugs.
* update_entry() frees the entries old values to avoid a memory leak.
Steven, I didn't get around to adding in the cstring field to traceeval_data, as I wasn't able to completely grasp what you were looking for. My apologies.
---
v3 discussion: https://lore.kernel.org/linux-trace-devel/20230808180156.GA1300@3xKetch/T/#t
Stevie Alvarez (Google) (5):
histograms: Initial histograms interface
histograms: Add traceeval initialize and release
histograms: Add traceeval compare
histograms: Add traceeval query
histograms: Add traceeval insert
Makefile | 2 +- include/traceeval-hist.h | 147 +++++++ include/traceeval-test.h | 16 + src/Makefile | 1 + src/histograms.c | 804 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 969 insertions(+), 1 deletion(-) create mode 100644 include/traceeval-hist.h create mode 100644 include/traceeval-test.h create mode 100644 src/histograms.c
Signature · 1 line
2.41.0
PATCH v4 1/5 histograms: Initial histograms interface
From: Stevie Alvarez (Google) <[email protected]>
Initial header file for libtraceeval's histogram API. The interface provides a simple way of aggregating trace data and reading through said data.
--- include/traceeval-hist.h | 130 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 include/traceeval-hist.h
include/traceeval-hist.h new file +130 -0
@@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: MIT */ +/* +* libtraceeval histogram interface. +* +* Copyright (C) 2023 Google Inc, Steven Rostedt <[email protected]> +* Copyright (C) 2023 Google Inc, Stevie Alvarez <[email protected]> +*/ +#ifndef __LIBTRACEEVAL_HIST_H__ +#define __LIBTRACEEVAL_HIST_H__ + +#include <stdlib.h> +#include <stddef.h> +#include <stdbool.h> + +/* Data definition interfaces */ + +/* Field name/descriptor for number of hits */ +#define TRACEEVAL_VAL_HITS ((const char *)(-1UL)) + +/* Data type distinguishers */ +enum traceeval_data_type { +TRACEEVAL_TYPE_NONE , +TRACEEVAL_TYPE_NUMBER_8 , +TRACEEVAL_TYPE_NUMBER_16 , +TRACEEVAL_TYPE_NUMBER_32 , +TRACEEVAL_TYPE_NUMBER_64 , +TRACEEVAL_TYPE_NUMBER , +TRACEEVAL_TYPE_STRING , +TRACEEVAL_TYPE_DYNAMIC +}; + +/* Statistics specification flags */ +enum traceeval_flags { +TRACEEVAL_FL_SIGNED = (1 <<0 ), +TRACEEVAL_FL_TIMESTAMP = (1 <<1 ), +}; + +/* +* struct traceeval_dynamic - Storage for dynamic traceeval_types +* @size: The size of the dynamic type +* @data: The pointer to the data of the dynamic type +*/ +struct traceeval_dynamic { +void *data; +size_t size; +}; + +/* +* Trace data entry for a traceeval histogram +* Constitutes keys and values. +*/ +union traceeval_data { +struct traceeval_dynamic dyn_data; +char *string; +unsigned long number; +unsigned long long number_64; +unsigned int number_32; +unsigned short number_16; +unsigned char number_8; +}; + +struct traceeval_type ; + +/* struct traceeval_dynamic release function signature */ +typedef void (*traceeval_dyn_release_fn )(struct traceeval_type *, +struct traceeval_dynamic ); + +/* struct traceeval_dynamic compare function signature */ +typedef int (*traceeval_dyn_cmp_fn )(struct traceeval_dynamic , +struct traceeval_dynamic , +struct traceeval_type *); + +/* +* struct traceeval_type - Describes the type of a traceevent_data instance +* @type: The enum type that describes the traceeval_data +* @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) +* +* The traceeval_type structure defines expectations for a corresponding +* traceeval_data instance for a traceeval histogram instance. Used to +* describe both keys and values. +* +* The @id field is an optional value in case the user has multiple struct +* traceeval_type instances with @type fields set to TRACEEVAL_TYPE_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. +* +* @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. +* +* 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. +*/ +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; +}; + +/* 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; +}; + +/* Iterator over aggregated data */ +struct traceeval_iterator ; + +struct traceeval ; + +#endif /* __LIBTRACEEVAL_HIST_H__ */
Signature · 1 line
2.41.0
Re: [PATCH v4 1/5] histograms: Initial histograms interface
Quoted 60 lines · On Wed, 9 Aug 2023 13:53:34 -0400 Stevie Alvarez <[email protected]>…
include/traceeval-hist.h new file +60
-0+/* SPDX-License-Identifier: MIT */ +/* +* libtraceeval histogram interface. +* +* Copyright (C) 2023 Google Inc, Steven Rostedt <[email protected]> +* Copyright (C) 2023 Google Inc, Stevie Alvarez <[email protected]> +*/ +#ifndef __LIBTRACEEVAL_HIST_H__ +#define __LIBTRACEEVAL_HIST_H__ + +#include <stdlib.h> +#include <stddef.h> +#include <stdbool.h> + +/* Data definition interfaces */ + +/* Field name/descriptor for number of hits */ +#define TRACEEVAL_VAL_HITS ((const char *)(-1UL)) + +/* Data type distinguishers */ +enum traceeval_data_type { +TRACEEVAL_TYPE_NONE , +TRACEEVAL_TYPE_NUMBER_8 , +TRACEEVAL_TYPE_NUMBER_16 , +TRACEEVAL_TYPE_NUMBER_32 , +TRACEEVAL_TYPE_NUMBER_64 , +TRACEEVAL_TYPE_NUMBER , +TRACEEVAL_TYPE_STRING , +TRACEEVAL_TYPE_DYNAMIC +}; + +/* Statistics specification flags */ +enum traceeval_flags { +TRACEEVAL_FL_SIGNED = (1 <<0 ), +TRACEEVAL_FL_TIMESTAMP = (1 <<1 ), +}; + +/* +* struct traceeval_dynamic - Storage for dynamic traceeval_types +* @size: The size of the dynamic type +* @data: The pointer to the data of the dynamic type +*/ +struct traceeval_dynamic { +void *data; +size_t size; +}; + +/* +* Trace data entry for a traceeval histogram +* Constitutes keys and values. +*/ +union traceeval_data { +struct traceeval_dynamic dyn_data; +char *string; +unsigned long number; +unsigned long long number_64; +unsigned int number_32; +unsigned short number_16; +unsigned char number_8; +};
include/traceeval-hist.h line 70
Quoted 10 lines
include/traceeval-hist.h new file +10
-0+ +struct traceeval_type ; + +/* struct traceeval_dynamic release function signature */ +typedef void (*traceeval_dyn_release_fn )(struct traceeval_type *, +struct traceeval_dynamic ); + +/* struct traceeval_dynamic compare function signature */ +typedef int (*traceeval_dyn_cmp_fn)(struct traceeval_dynamic, + struct traceeval_dynamic,
Even though we converted the union to struct traceveal_dynamic and it's no longer a pointer, we still need to pass a pointer to the compare functions. Passing structures by value is slow, as it needs to make a local copy of it, and compare functions are to be quick.
-- Steve
Quoted 60 lines
include/traceeval-hist.h new file +60
-0+ struct traceeval_type *); + +/* +* struct traceeval_type - Describes the type of a traceevent_data instance +* @type: The enum type that describes the traceeval_data +* @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) +* +* The traceeval_type structure defines expectations for a corresponding +* traceeval_data instance for a traceeval histogram instance. Used to +* describe both keys and values. +* +* The @id field is an optional value in case the user has multiple struct +* traceeval_type instances with @type fields set to TRACEEVAL_TYPE_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. +* +* @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. +* +* 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. +*/ +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; +}; + +/* 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; +}; + +/* Iterator over aggregated data */ +struct traceeval_iterator ; + +struct traceeval ; + +#endif /* __LIBTRACEEVAL_HIST_H__ */
PATCH v4 2/5 histograms: Add traceeval initialize and release
In reply to Stevie AlvarezFrom: Stevie Alvarez (Google) <[email protected]>
traceeval_init() creates a new struct traceeval instance with regards to the struct traceeval_type array arguments keys and vals. These arrays define the structure of the histogram, with each describing the expected structure of inserted arrays of union traceeval_data. The keys and vals arguments are copied on the heap to ensure that the struct traceeval instance has access to the definition regardless of how the user initialized keys and vals.
traceeval_init() uses traceeval_release() and it's helper functions to clean up on error.
traceeval_release() deconstructs a given struct traceeval instance. It frees any data allocated to the heap within the entries to the histogram, and the names allocated for the struct traceeval_type key-value definitions.
--- Makefile | 2 +- include/traceeval-hist.h | 7 + src/Makefile | 1 + src/histograms.c | 315 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 src/histograms.c
Makefile +1 -1
@@ -172,7 +172,7 @@ libs: $(LIBRARY_A) $(LIBRARY_SO) VALGRIND = $(shell which valgrind) UTEST_DIR = utest -UTEST_BINARY = trace-utest +UTEST_BINARY = eval-utest test: force $(LIBRARY_STATIC) ifneq ($(CUNIT_INSTALLED),1)
include/traceeval-hist.h +7 -0
@@ -127,4 +127,11 @@ struct traceeval_iterator;struct traceeval ; +/* Histogram interfaces */ + +struct traceeval *traceeval_init (const struct traceeval_type *keys, +const struct traceeval_type *vals); + +void traceeval_release (struct traceeval *teval); +#endif /* __LIBTRACEEVAL_HIST_H__ */
src/Makefile +1 -0
@@ -4,6 +4,7 @@ include $(src)/scripts/utils.mk OBJS = OBJS += trace-analysis.o +OBJS += histograms.o OBJS := $(OBJS:%.o=$(bdir)/%.o)
src/histograms.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v4 2/5] histograms: Add traceeval initialize and release
Quoted 32 lines · On Wed, 9 Aug 2023 13:53:35 -0400 Stevie Alvarez <[email protected]>…
From: Stevie Alvarez (Google) <[email protected]>
traceeval_init()creates a new struct traceeval instance with regards to the structtraceeval_typearray arguments keys and vals. These arrays define the structure of the histogram, with each describing the expected structure of inserted arrays of uniontraceeval_data. The keys and vals arguments are copied on the heap to ensure that the struct traceeval instance has access to the definition regardless of how the user initialized keys and vals.
traceeval_init()usestraceeval_release()and it's helper functions to clean up on error.
traceeval_release()deconstructs a given struct traceeval instance. It frees any data allocated to the heap within the entries to the histogram, and the names allocated for the structtraceeval_typekey-value definitions.Signed-off-by Stevie Alvarez (Google) <[email protected]>--- Makefile | 2 +- include/traceeval-hist.h | 7 + src/Makefile | 1 + src/histograms.c | 315 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 src/histograms.cMakefile +0
-0
Makefile libs: $(LIBRARY_A) $(LIBRARY_SO) · line 176
Quoted 6 lines
Makefile +1
-1@@ -172,7 +172,7 @@ libs: $(LIBRARY_A) $(LIBRARY_SO) VALGRIND = $(shell which valgrind) UTEST_DIR = utest -UTEST_BINARY = trace-utest +UTEST_BINARY = eval-utest
I forgot to mention this in previous reviews. I'm assuming this was a leftover from previous versions?
Rest of this patch looks good.
-- Steve
Quoted 8 lines
Makefile +0
-0test: force $(LIBRARY_STATIC) ifneq ($(CUNIT_INSTALLED),1)include/traceeval-hist.h +0
-0@@ -127,4 +127,11 @@ struct traceeval_iterator;
PATCH v4 3/5 histograms: Add traceeval compare
In reply to Stevie AlvarezFrom: Stevie Alvarez (Google) <[email protected]>
traceeval_compare() compares two struct traceeval instances for equality. This suite of comparitors was made for testing purposes.
--- include/traceeval-test.h | 16 +++ src/histograms.c | 214 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 include/traceeval-test.h
include/traceeval-test.h new file +16 -0
@@ -0,0 +1,16 @@ +/* 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 +214 -0
226 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v4 4/5 histograms: Add traceeval query
In reply to Stevie AlvarezFrom: Stevie Alvarez (Google) <[email protected]>
traceeval_query() fetches the values (aka results) of an entry with keys that match the array of keys provided. The results of a query can be useful for aggregating data between entries/trace events.
traceeval_results_release() frees the results fetched by the query. The user must free the results of a successful query.
--- include/traceeval-hist.h | 6 ++ src/histograms.c | 161 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+)
include/traceeval-hist.h +6 -0
@@ -134,4 +134,10 @@ struct traceeval *traceeval_init(const struct traceeval_type *keys,void traceeval_release (struct traceeval *teval); +int traceeval_query (struct traceeval *teval,const union traceeval_data *keys, +union traceeval_data **results); + +void traceeval_results_release (struct traceeval *teval, +union traceeval_data *results); +#endif /* __LIBTRACEEVAL_HIST_H__ */
src/histograms.c +161 -0
164 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v4 4/5] histograms: Add traceeval query
Quoted 15 lines · On Wed, 9 Aug 2023 13:53:37 -0400 Stevie Alvarez <[email protected]>…
src/histograms.c +15
-0+static int copy_traceeval_data_set (size_t size,struct traceeval_type *type, +const union traceeval_data *orig, +union traceeval_data **copy) +{ +size_t i; + + *copy =NULL ; +if (!size) +return 1 ; + + *copy =calloc (size,sizeof (**copy)); +if (!*copy) +return -1 ; + +for (i =0 ; i < size; i++) {
src/histograms.c void traceeval_release(struct traceeval *teval) · line 633
Quoted 10 lines
src/histograms.c +10
-0+if (copy_traceeval_data (type + i, orig + i, (*copy) + i)) + goto fail; + } + +return 1 ; + +fail: +data_release (i, copy, type); +return -1 ; +}
I think Ross mentioned this too, but we should have a copy() callback to allow things like the dyn events to be copied.
-- Steve
Re: [PATCH v4 4/5] histograms: Add traceeval query
In reply to Stevie AlvarezQuoted 6 lines · On Wed, 9 Aug 2023 13:53:37 -0400 Stevie Alvarez <[email protected]>…
src/histograms.c +6
-0+/* +* traceeval_results_release - release the results return by traceeval_query() +* @teval: The descriptor used in traceeval_query() +* @results: The results returned by traceeval_query() +* +* The @results returned by traceeval_query() is owned by @teval, and
src/histograms.c void traceeval_release(struct traceeval *teval) · line 684
Quoted 10 lines
src/histograms.c +10
-0+* how it manages it is implementation specific. The caller should not +* worry about it. When the caller of traceeval_query() is done with +* the @results, it must call traceeval_results_release() on it to +* allow traceeval to clean up its references. +*/ +void traceeval_results_release (struct traceeval *teval, +union traceeval_data *results) +{ +if (!teval || !results) { +if (!results)
I just triggered this. The above should be:
if (!teval)
Just FYI ;-)
-- Steve
Quoted 6 lines
src/histograms.c +6
-0+print_err ("Results to be freed without accompanied traceeval instance!" ); +return ; + } + +data_release (teval->nr_val_types, &results, teval->val_types); +}
PATCH v4 5/5 histograms: Add traceeval insert
In reply to Stevie AlvarezFrom: Stevie Alvarez (Google) <[email protected]>
traceeval_insert() updates the provided struct traceeval's histogram. If an entry that exists with a keys field that match the keys argument, the entries vals field are updated with a copy of the vals argument. If such an entry does not exist, a new entry is added to the histogram, with respect to the keys and vals arguments.
--- include/traceeval-hist.h | 4 ++ src/histograms.c | 114 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+)
include/traceeval-hist.h +4 -0
@@ -134,6 +134,10 @@ struct traceeval *traceeval_init(const struct traceeval_type *keys,void traceeval_release (struct traceeval *teval); +int traceeval_insert (struct traceeval *teval, +const union traceeval_data *keys, +const union traceeval_data *vals); +int traceeval_query (struct traceeval *teval,const union traceeval_data *keys,union traceeval_data **results);
src/histograms.c +114 -0
117 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v4 5/5] histograms: Add traceeval insert
Quoted 22 lines · On Wed, 9 Aug 2023 13:53:38 -0400 Stevie Alvarez <[email protected]>…
+++
b/src/histograms.csrc/histograms.c +17
-0@@ -688,3 +688,117 @@ void traceeval_results_release(struct traceeval *teval,data_release (teval->nr_val_types, &results, teval->val_types); } + +/* +* Create a new entry in @teval with respect to @keys and @vals. +* +* Returns 0 on success, -1 on error. +*/ +static int create_entry (struct traceeval *teval, +const union traceeval_data *keys, +const union traceeval_data *vals) +{ +union traceeval_data *new_keys; +union traceeval_data *new_vals; +struct entry *tmp_map; +struct hist_table *hist = teval->hist; + +/* copy keys */ + if (copy_traceeval_data_set(teval->nr_key_types, teval->key_types,
src/histograms.c void traceeval_results_release(struct traceeval *teval, · line 717
Quoted 10 lines
src/histograms.c +10
-0+ keys, &new_keys) == -1) +return -1 ; + +/* copy vals */ +if (copy_traceeval_data_set (teval->nr_val_types, teval->val_types, + vals, &new_vals) ==-1 ) + goto fail_vals; + +/* create new entry */ + tmp_map =realloc (hist->map, ++hist->nr_entries *sizeof (*tmp_map));
The "++hist->nr_entries" is called a side effect. Where the allocation is adding more functionality than expected. I try to avoid this even though it may seem to be clever. One reason is they tend to introduce bugs. For example, if the allocation fails, the nr_entries now has more entries then what exists.
I only would update nr_entries on a allocation success.
-- Steve
Quoted 16 lines
src/histograms.c +16
-0+if (!tmp_map) + goto fail; + tmp_map->keys = new_keys; + tmp_map->vals = new_vals; + hist->map = tmp_map; + +return 0 ; + +fail: +data_release (teval->nr_val_types, &new_vals, teval->val_types); + +fail_vals: +data_release (teval->nr_key_types, &new_keys, teval->key_types); +return -1 ; +} +
Quoted 12 lines · On Wed, 9 Aug 2023 13:53:33 -0400 Stevie Alvarez <[email protected]>…
From: Stevie Alvarez (Google) <[email protected]>
Changes in v4:
* Reorder enumtraceeval_data_typenumeric types for algorithmic access.
* Reorder uniontraceeval_datanumeric fields for legibility.
* Remove parenthesis from function name in kerneldocs.
* Optimize logic intype_alloc().
* Distinguish internal vs public interfaces within include statements.
* Reworkcopy_traceeval_data()logic for legibility.
* Rework comparator return types to fix query and insert bugs.
*update_entry()frees the entries old values to avoid a memory leak.
Quoted 3 lines
Steven, I didn't get around to adding in the cstring field to
traceeval_data, as I wasn't able to completely grasp what you were looking for. My apologies.
Thanks Stevie!
I'm going to pull these in as-is and build on top of them for the rest so that you can work on other things. I'll still do a review of these patches for your own understanding, but you don't need to send another series.
As for the cstring. Without it, I get these warnings in the task-eval.c program:
libtraceeval.git/samples/task-eval.c: In function ‘update_process’:libtraceeval.git/samples/task-eval.c:197:35: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
197 | .string = comm,
| ^~~~libtraceeval.git/samples/task-eval.c: In function ‘get_process_data’:libtraceeval.git/samples/task-eval.c:255:35: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
255 | .string = comm,
| ^~~~libtraceeval.git/samples/task-eval.c: In function ‘set_process_data’:libtraceeval.git/samples/task-eval.c:278:35: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
278 | .string = comm,
as in update_process() (and other functions) we have:
static void update_process(struct task_data *tdata, const char *comm,
enum sched_state state, enum command cmd, unsigned long long ts)
{
const union traceeval_data keys[] = {
{
.string = comm,
},
{
.number = state,
},
};Because these queries are performed on const char *strings. That is, in order to do a traceeval_query() I need to populate the keys array. And if I'm using a const char *string to do the search, I need to use a const pointer to assign with.
So, if we supply a "const char * cstring" to the union, and I use:
const union traceeval_data keys[] = {
{
.cstring = comm,
},It makes the compiler happy!
-- Steve
Quoted 21 lines
---
v3 discussion: https://lore.kernel.org/linux-trace-devel/20230808180156.GA1300@3xKetch/T/#tStevie Alvarez (Google) (5):
histograms: Initial histograms interface
histograms: Add traceeval initialize and release
histograms: Add traceeval compare
histograms: Add traceeval query
histograms: Add traceeval insertMakefile | 2 +- include/traceeval-hist.h | 147 +++++++ include/traceeval-test.h | 16 + src/Makefile | 1 + src/histograms.c | 804 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 969 insertions(+), 1 deletion(-) create mode 100644 include/traceeval-hist.h create mode 100644 include/traceeval-test.h create mode 100644 src/histograms.c
Ross Zwisler
Reviewed-byQuoted 19 lines · Steven Rostedt
Quoted 12 lines · On Wed, 9 Aug 2023 13:53:33 -0400 Stevie Alvarez <[email protected]>…
From: Stevie Alvarez (Google) <[email protected]>
Changes in v4:
* Reorder enumtraceeval_data_typenumeric types for algorithmic access.
* Reorder uniontraceeval_datanumeric fields for legibility.
* Remove parenthesis from function name in kerneldocs.
* Optimize logic intype_alloc().
* Distinguish internal vs public interfaces within include statements.
* Reworkcopy_traceeval_data()logic for legibility.
* Rework comparator return types to fix query and insert bugs.
*update_entry()frees the entries old values to avoid a memory leak.Quoted 3 lines
Steven, I didn't get around to adding in the cstring field to
traceeval_data, as I wasn't able to completely grasp what you were looking for. My apologies.
Quoted 5 lines
Thanks Stevie!
I'm going to pull these in as-is and build on top of them for the rest so that you can work on other things. I'll still do a review of these patches for your own understanding, but you don't need to send another series.
Thanks for these, Stevie. You've addressed all of my review comments, so Steven, feel free to add:
when you apply the series.
Quoted 12 lines · On Wed, 9 Aug 2023 13:53:33 -0400 Stevie Alvarez <[email protected]>…
From: Stevie Alvarez (Google) <[email protected]>
Changes in v4:
* Reorder enumtraceeval_data_typenumeric types for algorithmic access.
* Reorder uniontraceeval_datanumeric fields for legibility.
* Remove parenthesis from function name in kerneldocs.
* Optimize logic intype_alloc().
* Distinguish internal vs public interfaces within include statements.
* Reworkcopy_traceeval_data()logic for legibility.
* Rework comparator return types to fix query and insert bugs.
*update_entry()frees the entries old values to avoid a memory leak.
Quoted 4 lines
Steven, I didn't get around to adding in the cstring field to
traceeval_data, as I wasn't able to completely grasp what you were looking for. My apologies.
Congratulations Stevie,
Your patches are now committed:
https://github.com/rostedt/libtraceeval/commits?author=Shiztev
-- Steve