libtraceeval histogram: Updates
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.
The last patch updates the task-eval to use the new API. It added stubs that are needed for the display portion. These can be implemented later.
Note, when running the new task-eval, it crashes immediately, so there's lots of bugs to still fix in the existing histogram code.
Happy programming!
Steven Rostedt (Google) (6):
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: Fix the return value of traceeval_query() libtraceeval samples: Update task-eval to use the histogram logic
Makefile | 3 + include/traceeval-hist.h | 38 +- samples/Makefile | 29 ++ samples/task-eval.c | 948 +++++++++++++++++++++++++++++++++++++++ src/histograms.c | 48 +- 5 files changed, 1026 insertions(+), 40 deletions(-) create mode 100644 samples/Makefile create mode 100644 samples/task-eval.c
Signature · 1 line
2.40.1
PATCH 1/6 libtraceeval: Add sample task-eval program
From: "Steven Rostedt (Google)" <[email protected]>
Add a sample task eval program to test the traceeval logic.
This relies on having libtracecmd installed.
--- 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 2/6 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_16 ,TRACEEVAL_TYPE_NUMBER_8 ,TRACEEVAL_TYPE_NUMBER , +TRACEEVAL_TYPE_POINTER ,TRACEEVAL_TYPE_STRING , TRACEEVAL_TYPE_DYNAMIC };
@@ -41,7 +42,9 @@ enum traceeval_flags {*/ union traceeval_data {char *string; +const char *cstring;struct traceeval_dynamic *dyn_data; +void *pointer;unsigned long long number_64;unsigned long number;unsigned int number_32;
Signature · 1 line
2.40.1
PATCH 3/6 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.
In the structure, rename dyn_cmp to just cmp, and dyn_release to just release.
--- include/traceeval-hist.h | 33 +++++++++++++++------------------ src/histograms.c | 26 ++++++++++++++------------ 2 files changed, 29 insertions(+), 30 deletions(-)
include/traceeval-hist.h +15 -18
@@ -65,13 +65,13 @@ struct traceeval_dynamic {struct traceeval_type ;/* struct traceeval_dynamic release function signature */ -typedef void (*traceeval_dyn_release_fn )(struct traceeval_type *, -struct traceeval_dynamic *); +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 *); +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) +* @data_release: An optional callback for when the data is being released +* @data_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,26 @@ 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 +* For flexibility, @data_cmp() and @data_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. +* @data_cmp() is used to override the default compare of a type. This is +* required to compare types of 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. +* data_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 -12
@@ -89,9 +89,9 @@ static int compare_traceeval_type(struct traceeval_type *orig,return 1 ;if (orig[i].id != copy[i].id)return 1 ; -if (orig[i].dyn_release != copy[i].dyn_release) +if (orig[i].release != copy[i].release)return 1 ; -if (orig[i].dyn_cmp != copy[i].dyn_cmp) +if (orig[i].cmp != copy[i].cmp)return 1 ;// make sure both names are same type
@@ -127,6 +127,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);
@@ -148,8 +151,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 :
@@ -235,8 +237,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 0 if @orig and @copy are the same, 1 if not, and -1 on error. */
@@ -450,14 +452,14 @@ static void clean_data(union traceeval_data *data, struct traceeval_type *defs, }for (i =0 ; i < size; i++) { +if (defs[i].release) { + defs[i].release (defs + i, data + i); +continue ; + }switch (defs[i].type) {case TRACEEVAL_TYPE_STRING :free (data[i].string);break ; -case TRACEEVAL_TYPE_DYNAMIC : -if (defs[i].dyn_release) - defs[i].dyn_release (defs + i, data[i].dyn_data); -break ;default :break ; }
@@ -506,7 +508,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 +590,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 release on type TRACEEVAL_TYPE_DYNAMIC. */ static void data_release (size_t size,union traceeval_data **data,struct traceeval_type *type)
Signature · 1 line
2.40.1
PATCH 4/6 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 last as they are the values of the function.
--- include/traceeval-hist.h | 13 +++++++------ src/histograms.c | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-)
include/traceeval-hist.h +7 -6
@@ -63,16 +63,17 @@ struct traceeval_dynamic { };struct traceeval_type ; +struct traceeval ;/* struct traceeval_dynamic release function signature */ -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);/* struct traceeval_dynamic compare function signature */ -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 +10 -8
@@ -112,7 +112,8 @@ 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, +static int compare_traceeval_data (struct traceeval *teval, +union traceeval_data *orig,const union traceeval_data *copy,struct traceeval_type *type) {
@@ -128,7 +129,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 :
@@ -166,7 +167,8 @@ static int compare_traceeval_data(union traceeval_data *orig,* * Return 0 if @orig and @copy are the same, 1 if not, and -1 on error. */ -static int compare_traceeval_data_set (union traceeval_data *orig, +static int compare_traceeval_data_set (struct traceeval *teval, +union traceeval_data *orig,const union traceeval_data *copy,struct traceeval_type *defs,size_t size) {
@@ -175,7 +177,7 @@ static int compare_traceeval_data_set(union traceeval_data *orig,/* 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, orig + i, copy + i, defs + i)))return check ==-2 ?-1 :1 ; }
@@ -191,13 +193,13 @@ static int compare_entries(struct entry *orig, struct entry *copy,int check;/* compare keys */ - check =compare_traceeval_data_set (orig->keys, copy->keys, + check =compare_traceeval_data_set (teval, orig->keys, copy->keys, teval->key_types, teval->nr_key_types);if (check)return check;/* compare values */ - check =compare_traceeval_data_set (orig->vals, copy->vals, + check =compare_traceeval_data_set (teval, orig->vals, copy->vals, teval->val_types, teval->nr_val_types);return check; }
@@ -543,8 +545,8 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys, i =0 ;for (struct entry *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, entry->keys, keys, + teval->key_types, teval->nr_key_types);/* return entry if keys match */ if (!check) {
Signature · 1 line
2.40.1
PATCH 5/6 libtraceeval histogram: Fix the return value of traceeval_query()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The comments state that traceeval_query() returns 1 if found, 0 if not, and -1 on error, but in reality it returns 0 if found and 1 if not found.
It makes more sense to have it return 1 if found and zero if not found as the comment states.
--- src/histograms.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/histograms.c +3 -3
@@ -551,7 +551,7 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys,/* return entry if keys match */ if (!check) { *result = entry; -return 0 ; +return 1 ; }else if (check ==1 ) {continue ; }else {
@@ -559,7 +559,7 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys, } } -return 1 ; +return 0 ; }/*
@@ -660,7 +660,7 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,return -1 ;/* find key and copy its corresponding value pair */ -if ((check =get_entry (teval, keys, &entry))) +if ((check =get_entry (teval, keys, &entry)) <0 )return check;return copy_traceeval_data_set (teval->nr_val_types, teval->val_types, entry->vals, results);
Signature · 1 line
2.40.1
Re: [PATCH 5/6] libtraceeval histogram: Fix the return value of traceeval_query()
Quoted 4 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
The comments state that
traceeval_query()returns 1 if found, 0 if not, and -1 on error, but in reality it returns 0 if found and 1 if not found.
The comment currently says:
Quoted 5 lines
/*
* Find the entry that @keys corresponds to within @teval. *
* Returns 0 on success, 1 if no match found, -1 on error. */
I think this needs to be updated to match the new logic (1=found, 0=not found, -1=error)
Quoted 31 lines
It makes more sense to have it return 1 if found and zero if not found as the comment states.
Signed-off-by Steven Rostedt (Google) <[email protected]>--- src/histograms.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/histograms.c +2
-2@@ -551,7 +551,7 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys,/* return entry if keys match */ if (!check) { *result = entry; -return 0 ; +return 1 ; }else if (check ==1 ) {continue ; }else {@@ -559,7 +559,7 @@ static int get_entry(struct traceeval *teval, const union traceeval_data *keys, } } -return 1 ; +return 0 ; }/*
src/histograms.c int traceeval_query(struct traceeval *teval, const union traceeval_data *keys, · line 663
Quoted 5 lines
src/histograms.c +1
-1@@ -660,7 +660,7 @@ int traceeval_query(struct traceeval *teval, const union traceeval_data *keys,return -1 ;/* find key and copy its corresponding value pair */ -if ((check =get_entry (teval, keys, &entry))) +if ((check =get_entry (teval, keys, &entry)) <0 )
should this be
if ((check = get_entry(teval, keys, &entry)) <= 0)
so we return 0 (not found) in that case, and avoid dropping into copy_traceeval_data_set() when we have nothing to copy?
Quoted 6 lines
src/histograms.c +0
-0return check;return copy_traceeval_data_set (teval->nr_val_types, teval->val_types, entry->vals, results);Signature · 1 line
2.40.1
I think you also need to update the logic in traceeval_insert(), which right now uses a return of 1 to mean "not found" and will do a create_entry() in response.
For clarity maybe in all these consumers 'check' should be renamed 'found'?
Then the logic would read:
found = get_entry(..);
if (found == -1)
error;
if (found)
update_entry();
else /* ! found */
create_entry();
Re: [PATCH 5/6] libtraceeval histogram: Fix the return value of traceeval_query()
Quoted 8 lines · On Thu, 10 Aug 2023 11:47:50 -0600 Ross Zwisler <[email protected]> wrote:
Quoted 4 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
The comments state that
traceeval_query()returns 1 if found, 0 if not, and -1 on error, but in reality it returns 0 if found and 1 if not found.The comment currently says:
Quoted 9 lines
Quoted 5 lines
/*
* Find the entry that @keys corresponds to within @teval. *
* Returns 0 on success, 1 if no match found, -1 on error. */I think this needs to be updated to match the new logic (1=found, 0=not found, -1=error)
Yeah, but I believe Stevie's latest version fixed all this.
-- Steve
PATCH 6/6 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.
Note, it still requires some functions for displaying the output, but those were added just as stubs to get an idea on how to use it.
--- include/traceeval-hist.h | 1 + samples/Makefile | 2 +- samples/task-eval.c | 683 ++++++++++++++++++++++----------------- 3 files changed, 388 insertions(+), 298 deletions(-)
include/traceeval-hist.h +1 -0
@@ -74,6 +74,7 @@ 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
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 +386 -297
949 lines not on this page · raw message
Signature · 1 line
2.40.1
Re: [PATCH 6/6] libtraceeval samples: Update task-eval to use the histogram logic
Quoted 6 lines · On Tue, 8 Aug 2023 23:13:13 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (Google)" <[email protected]>
Convert task-eval over to the new API.
Note, it still requires some functions for displaying the output, but those were added just as stubs to get an idea on how to use it.
I should add that this is still RFC, and not ready at all for inclusion.
There's lots of issues with this patch (like I see I use .number still for the data that's of POINTER type). These will all be fixed before they go upstream.
Anyway, I posted this so that you can have an idea of a use case for how this will work.
-- Steve
Quoted 8 lines
Signed-off-by Steven Rostedt (Google) <[email protected]>--- include/traceeval-hist.h | 1 + samples/Makefile | 2 +- samples/task-eval.c | 683 ++++++++++++++++++++++----------------- 3 files changed, 388 insertions(+), 298 deletions(-)
Re: [PATCH 6/6] libtraceeval samples: Update task-eval to use the histogram logic
In reply to Steven Rostedtinclude/traceeval-hist.h
Quoted 18 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
Convert task-eval over to the new API.
Note, it still requires some functions for displaying the output, but those were added just as stubs to get an idea on how to use it.
Signed-off-by Steven Rostedt (Google) <[email protected]>--- include/traceeval-hist.h | 1 + samples/Makefile | 2 +- samples/task-eval.c | 683 ++++++++++++++++++++++----------------- 3 files changed, 388 insertions(+), 298 deletions(-)include/traceeval-hist.h +0
-0
<>
include/traceeval-hist.h static void update_process(struct task_data *tdata, const char *comm, · line 193
Quoted 3 lines
include/traceeval-hist.h +0
-0@@ -111,28 +192,45 @@ static void update_process(struct task_data *tdata, const char *comm, enum sched_state state, enum command cmd, unsigned long long ts)
update_process(), update_cpu() and update_thread() are all pretty much the same, and I think you could combine them if you wanted. Just create a generic 'update' that takes keys & vals & a pair of 'struct traceval' pointers, one for start data and one for delta data. That also relies on the fact that the TS always comes first in 'vals'. Up to you if that's cleaner or not.
Quoted 40 lines
include/traceeval-hist.h +19
-7{ -struct traceeval_key keys[] = { +union traceeval_data keys[] = { { - .type =TRACEEVAL_TYPE_STRING , - .string = comm, + .cstring = comm, }, { - .type =TRACEEVAL_TYPE_NUMBER , - .number = state, + .number = state, + }, + }; +union traceeval_data vals[] = { + { + .number_64 = ts, + }, + { + .number = (long )NULL ,/* data */ } }; +union traceeval_data *results; +unsigned long long delta;int ret;switch (cmd) {case START : - ret =traceeval_n_start (tdata->teval_processes, keys, ts); + ret =traceeval_insert (tdata->teval_processes_start, keys, vals);if (ret <0 )pdie ("Could not start process" );return ;case STOP : - ret =traceeval_n_stop (tdata->teval_processes, keys, ts); + ret =traceeval_query (tdata->teval_processes_start, keys, &results); +if (ret <0 ) +return ; + + delta = ts - results[0 ].number_64;
include/traceeval-hist.h static void update_process(struct task_data *tdata, const char *comm, · line 236
Quoted 10 lines
include/traceeval-hist.h +5
-0+ results[0 ].number_64 = delta; + + ret =traceeval_insert (tdata->teval_processes, keys, results);if (ret <0 )pdie ("Could not stop process" ); + +traceeval_results_release (tdata->teval_processes_start, results);return ; } }
<>
Quoted 22 lines
include/traceeval-hist.h +0
-18@@ -283,32 +421,15 @@ static struct tep_format_field *get_field(struct tep_event *event, const char *nstatic void init_process_data (struct process_data *pdata) { -struct traceeval_key_info cpu_info[] = { - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="CPU" , - }, - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="Schedule state" , - } - }; -struct traceeval_key_info thread_info[] = { - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="TID" , - }, - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="Schedule state" ,
include/traceeval-hist.h static struct tep_format_field *get_field(struct tep_event *event, const char *n · line 430
Quoted 10 lines
include/traceeval-hist.h +4
-3- } - }; - pdata->teval_cpus =traceeval_2_alloc ("CPUs" , cpu_info); + pdata->teval_cpus =traceeval_init (cpu_keys, timestamp_vals); +if (!pdata->teval_cpus) +pdie ("Creating trace eval" ); + pdata->teval_cpus =traceeval_init (cpu_keys, timestamp_vals);if (!pdata->teval_cpus)pdie ("Creating trace eval" );
We're initializing pdata->teval_cpus twice - I'm guessing one of these wants to be pdata->teval_cpus_start?
include/traceeval-hist.h static struct tep_format_field *get_field(struct tep_event *event, const char *n · line 433
Quoted 5 lines
include/traceeval-hist.h +1
-1- pdata->teval_threads =traceeval_2_alloc ("Threads" , thread_info); + pdata->teval_threads =traceeval_init (thread_keys, timestamp_vals);if (!pdata->teval_threads)pdie ("Creating trace eval" );
Missing init of pdata->teval_threads_start?
Quoted 1 line
include/traceeval-hist.h +0
-0}
Re: [PATCH 6/6] libtraceeval samples: Update task-eval to use the histogram logic
Quoted 20 lines · On Thu, 10 Aug 2023 14:28:38 -0600 Ross Zwisler <[email protected]> wrote:
include/traceeval-hist.h
Quoted 18 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
Convert task-eval over to the new API.
Note, it still requires some functions for displaying the output, but those were added just as stubs to get an idea on how to use it.
Signed-off-by Steven Rostedt (Google) <[email protected]>--- include/traceeval-hist.h | 1 + samples/Makefile | 2 +- samples/task-eval.c | 683 ++++++++++++++++++++++----------------- 3 files changed, 388 insertions(+), 298 deletions(-)include/traceeval-hist.h +0
-0<>
Quoted 9 lines
include/traceeval-hist.h static void update_process(struct task_data *tdata, const char *comm, · line 193
Quoted 3 lines
include/traceeval-hist.h +0
-0@@ -111,28 +192,45 @@ static void update_process(struct task_data *tdata, const char *comm, enum sched_state state, enum command cmd, unsigned long long ts)
update_process(),update_cpu()andupdate_thread()are all pretty much the same, and I think you could combine them if you wanted. Just create a generic 'update' that takes keys & vals & a pair of 'struct traceval' pointers, one for start data and one for delta data. That also relies on the fact that the TS always comes first in 'vals'. Up to you if that's cleaner or not.
I did actually create a struct teval_pair because I was getting confused ;-)
But I do agree, some of this can be consolidated a bit more. Right now, this is just a bare minimum switch from the old logic to the new so that I can make sure they produce the same output.
Quoted 77 lines
Quoted 41 lines
include/traceeval-hist.h +19
-7{ -struct traceeval_key keys[] = { +union traceeval_data keys[] = { { - .type =TRACEEVAL_TYPE_STRING , - .string = comm, + .cstring = comm, }, { - .type =TRACEEVAL_TYPE_NUMBER , - .number = state, + .number = state, + }, + }; +union traceeval_data vals[] = { + { + .number_64 = ts, + }, + { + .number = (long )NULL ,/* data */ } }; +union traceeval_data *results; +unsigned long long delta;int ret;switch (cmd) {case START : - ret =traceeval_n_start (tdata->teval_processes, keys, ts); + ret =traceeval_insert (tdata->teval_processes_start, keys, vals);if (ret <0 )pdie ("Could not start process" );return ;case STOP : - ret =traceeval_n_stop (tdata->teval_processes, keys, ts); + ret =traceeval_query (tdata->teval_processes_start, keys, &results); +if (ret <0 ) +return ; + + delta = ts - results[0 ].number_64;include/traceeval-hist.h static void update_process(struct task_data *tdata, const char *comm, · line 236
Quoted 10 lines
include/traceeval-hist.h +5
-0+ results[0 ].number_64 = delta; + + ret =traceeval_insert (tdata->teval_processes, keys, results);if (ret <0 )pdie ("Could not stop process" ); + +traceeval_results_release (tdata->teval_processes_start, results);return ; } }<>
Quoted 25 lines
include/traceeval-hist.h +0
-20@@ -283,32 +421,15 @@ static struct tep_format_field *get_field(struct tep_event *event, const char *nstatic void init_process_data (struct process_data *pdata) { -struct traceeval_key_info cpu_info[] = { - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="CPU" , - }, - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="Schedule state" , - } - }; -struct traceeval_key_info thread_info[] = { - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="TID" , - }, - { - .type =TRACEEVAL_TYPE_NUMBER , - .name ="Schedule state" , - } - };
Quoted 10 lines
include/traceeval-hist.h static struct tep_format_field *get_field(struct tep_event *event, const char *n · line 430
Quoted 7 lines
include/traceeval-hist.h +4
-1- pdata->teval_cpus =traceeval_2_alloc ("CPUs" , cpu_info); + pdata->teval_cpus =traceeval_init (cpu_keys, timestamp_vals); +if (!pdata->teval_cpus) +pdie ("Creating trace eval" ); + pdata->teval_cpus =traceeval_init (cpu_keys, timestamp_vals);if (!pdata->teval_cpus)pdie ("Creating trace eval" );We're initializing
pdata->teval_cpustwice - I'm guessing one of these wants to bepdata->teval_cpus_start?
Good catch. I also caught it when I started working back on it.
Quoted 8 lines
include/traceeval-hist.h static struct tep_format_field *get_field(struct tep_event *event, const char *n · line 433
Quoted 6 lines
include/traceeval-hist.h +1
-1- pdata->teval_threads =traceeval_2_alloc ("Threads" , thread_info); + pdata->teval_threads =traceeval_init (thread_keys, timestamp_vals);if (!pdata->teval_threads)pdie ("Creating trace eval" );Missing init of
pdata->teval_threads_start?
Yep.
new patches in a bit. (now I can go to bed!)
-- Steve