diff mbox series

[v2,10/11] libtraceeval: Make traceeval_stat() check size of keys array

Message ID 20230927123314.989589-11-rostedt@goodmis.org (mailing list archive)
State Accepted
Headers show
Series libtraceeval: Even more updates! | expand

Commit Message

Steven Rostedt Sept. 27, 2023, 12:33 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Make traceeval_stat() into a macro to pass in the size of the keys
array, and rename the function to traceeval_stat_size() that now takes
the size of the keys array.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/traceeval-hist.h | 10 +++++++---
 src/histograms.c         | 10 +++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

Comments

Ross Zwisler Oct. 2, 2023, 8:07 p.m. UTC | #1
On Wed, Sep 27, 2023 at 08:33:13AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Make traceeval_stat() into a macro to pass in the size of the keys
> array, and rename the function to traceeval_stat_size() that now takes
> the size of the keys array.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Reviewed-by: Ross Zwisler <zwisler@google.com>
diff mbox series

Patch

diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
index 804a0aaa631d..a1b498108fb4 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -211,9 +211,13 @@  int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *k
 void traceeval_results_release(struct traceeval *teval,
 			       const struct traceeval_data *results);
 
-struct traceeval_stat *traceeval_stat(struct traceeval *teval,
-				      const struct traceeval_data *keys,
-				      struct traceeval_type *type);
+#define traceeval_stat(teval, keys, type)				\
+	traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), type)
+
+struct traceeval_stat *traceeval_stat_size(struct traceeval *teval,
+					   const struct traceeval_data *keys,
+					   size_t nr_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);
diff --git a/src/histograms.c b/src/histograms.c
index 28cf0d4ed225..4d534d127cff 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -844,13 +844,17 @@  static bool is_stat_type(struct traceeval_type *type)
 	}
 }
 
-struct traceeval_stat *traceeval_stat(struct traceeval *teval,
-				      const struct traceeval_data *keys,
-				      struct traceeval_type *type)
+struct traceeval_stat *traceeval_stat_size(struct traceeval *teval,
+					   const struct traceeval_data *keys,
+					   size_t nr_keys,
+					   struct traceeval_type *type)
 {
 	struct entry *entry;
 	int ret;
 
+	if (teval->nr_key_types != nr_keys)
+		return NULL;
+
 	if (!is_stat_type(type))
 		return NULL;