diff mbox series

[v2,03/11] libtraceeval: Add traceeval_iterator_results_release()

Message ID 20230927123314.989589-4-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>

Add the function that can release the results from the
traceeval_iterator_qeury() function.

Currently, the user must use traceeval_results_release() for the results
returned by traceeval_iterator_query(), but that requires the caller to
also have access to the traceeval where the iterator came from. There
could be many iterators and many traceevals, the user should not need to
worry about which one goes with which.

This new traceeval_iterator_results_release() will take care of that for
them.

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

Comments

Ross Zwisler Oct. 2, 2023, 7:23 p.m. UTC | #1
On Wed, Sep 27, 2023 at 08:33:06AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Add the function that can release the results from the
> traceeval_iterator_qeury() function.
> 
> Currently, the user must use traceeval_results_release() for the results
> returned by traceeval_iterator_query(), but that requires the caller to
> also have access to the traceeval where the iterator came from. There
> could be many iterators and many traceevals, the user should not need to
> worry about which one goes with which.
> 
> This new traceeval_iterator_results_release() will take care of that for
> them.
> 
> 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 837a74f61a66..80450d7ae7f9 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -188,5 +188,7 @@  int traceeval_iterator_next(struct traceeval_iterator *iter,
 			    const union traceeval_data **keys);
 int traceeval_iterator_query(struct traceeval_iterator *iter,
 			     const union traceeval_data **results);
+void traceeval_iterator_results_release(struct traceeval_iterator *iter,
+					const union traceeval_data *results);
 
 #endif /* __LIBTRACEEVAL_HIST_H__ */
diff --git a/src/histograms.c b/src/histograms.c
index 06613a8933ec..50dc8b689637 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -1336,3 +1336,26 @@  int traceeval_iterator_query(struct traceeval_iterator *iter,
 
 	return 1;
 }
+
+/*
+ * traceeval_iterator_results_release - release the results return by traceeval_iterator_query()
+ * @iter: The iterator descriptor used in traceeval_iterator_query()
+ * @results: The results returned by traceeval_iterator_query()
+ *
+ * The @results returned by traceeval_iterator_query() is owned by @teval,
+ * that is attached to the iterator and how it manages it is implementation
+ * specific. The caller should not worry about it. When the caller of
+ * traceeval_iterator_query() is done with the @results, it must call
+ * traceeval_iterator_results_release() (or traceeval_results_release() if it
+ * has the handle of the teval used to get the iterator) on it to allow traceeval
+ * to clean up its references.
+ */
+void traceeval_iterator_results_release(struct traceeval_iterator *iter,
+					const union traceeval_data *results)
+{
+	if (!iter || !results) {
+		if (!iter)
+			print_err("Results to be freed without accompanied iterator!");
+		return;
+	}
+}