traceeval: Add way to extract the number of elements
PATCH v2 1/1 traceeval: Add way to extract the number of elements
From: "Steven Rostedt (Google)" <[email protected]>
Add traceeval_count() that will return the number of elements in the traceeval. This can be useful for allocating an array to store the elements. By getting the count, the allocation can be done first and then iterated to load the elements into the array.
---
Changes since v1: https://lore.kernel.org/linux-trace-devel/[email protected]
- Do not use "update_counter" for count, but create a new nr_elements to keep track of the number of elements in the traceeval (Ross Zwisler)
include/traceeval-hist.h | 2 ++ src/eval-local.h | 1 + src/histograms.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+)
include/traceeval-hist.h +2 -0
@@ -204,6 +204,8 @@ int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *kvoid traceeval_results_release (struct traceeval *teval,const struct traceeval_data *results); +size_t traceeval_count (struct traceeval *teval); +#define traceeval_stat (teval, keys, type) \ traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), type)
src/eval-local.h +1 -0
@@ -69,6 +69,7 @@ struct traceeval {size_t nr_key_types;size_t nr_val_types;size_t update_counter; +size_t nr_elements;size_t sizeof_type;size_t sizeof_data; };
src/histograms.c +17 -0
@@ -786,6 +786,7 @@ static int create_entry(struct traceeval *teval, entry->vals = new_vals; teval->update_counter++; + teval->nr_elements++;return 0 ;
@@ -1002,11 +1003,26 @@ int traceeval_remove_size(struct traceeval *teval,hash_remove (hist, &entry->hash);free_entry (teval, entry); +/* update_counter is used to know if there was an update. */ teval->update_counter++; +/* nr_elements keeps track of the number of stored elemnets */ + teval->nr_elements--; +return 1 ; } +/** +* traceeval_count - Return the number of elements in the traceeval +* @teval: The traceeval handle to get the count from +* +* Returns the number of elements stored by unique keys in the @teval. +*/ +size_t traceeval_count (struct traceeval *teval) +{ +return teval->nr_elements; +} +/** * traceeval_iterator_put - release a given iterator * @iter: The iterartor to release
@@ -1457,6 +1473,7 @@ int traceeval_iterator_remove(struct traceeval_iterator *iter)/* The entry no longer exists */ iter->entries[iter->next -1 ] =NULL ; teval->update_counter++; + teval->nr_elements--;return 1 ; }
Signature · 1 line
2.40.1
Quoted 8 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
Add
traceeval_count()that will return the number of elements in the traceeval. This can be useful for allocating an array to store the elements. By getting the count, the allocation can be done first and then iterated to load the elements into the array.Signed-off-by Steven Rostedt (Google) <[email protected]>