linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] traceeval: Add way to extract the number of elements
@ 2023-09-28 14:24 Steven Rostedt
  2023-10-02 20:40 ` Ross Zwisler
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2023-09-28 14:24 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Ross Zwisler

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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) <rostedt@goodmis.org>
---
 include/traceeval-hist.h |  2 ++
 src/histograms.c         | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
index eefa48d..44d071f 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -204,6 +204,8 @@ int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *k
 void 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)
 
diff --git a/src/histograms.c b/src/histograms.c
index 2456342..ac3f7f7 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -1006,6 +1006,17 @@ int traceeval_remove_size(struct traceeval *teval,
 	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->update_counter;
+}
+
 /**
  * traceeval_iterator_put - release a given iterator
  * @iter: The iterartor to release
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] traceeval: Add way to extract the number of elements
  2023-09-28 14:24 [PATCH] traceeval: Add way to extract the number of elements Steven Rostedt
@ 2023-10-02 20:40 ` Ross Zwisler
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Zwisler @ 2023-10-02 20:40 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Linux Trace Devel, Ross Zwisler

On Thu, Sep 28, 2023 at 10:24:34AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> 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) <rostedt@goodmis.org>
> ---
>  include/traceeval-hist.h |  2 ++
>  src/histograms.c         | 11 +++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
> index eefa48d..44d071f 100644
> --- a/include/traceeval-hist.h
> +++ b/include/traceeval-hist.h
> @@ -204,6 +204,8 @@ int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *k
>  void 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)
>  
> diff --git a/src/histograms.c b/src/histograms.c
> index 2456342..ac3f7f7 100644
> --- a/src/histograms.c
> +++ b/src/histograms.c
> @@ -1006,6 +1006,17 @@ int traceeval_remove_size(struct traceeval *teval,
>  	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->update_counter;

I don't think this is going to do what you want.  'teval->update_counter'
is a generation number, is monotonically increasing, and is incremented any
time an element is added or removed from the hash.

I think we either need to actually keep an element count (increment in
create_entry(), decrement in traceeval_remove_size() and
traceeval_iterator_remove()), or else we're going to have to count the
elements by walking the 'struct hash_table' buckets.  Probably easier to just
keep an explicit element count.

> +}
> +
>  /**
>   * traceeval_iterator_put - release a given iterator
>   * @iter: The iterartor to release
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-02 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-28 14:24 [PATCH] traceeval: Add way to extract the number of elements Steven Rostedt
2023-10-02 20:40 ` Ross Zwisler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).