From: Steven Rostedt <rostedt@goodmis.org>
To: Stevie Alvarez <stevie.6strings@gmail.com>
Cc: linux-trace-devel@vger.kernel.org, Ross Zwisler <zwisler@google.com>
Subject: Re: [PATCH 3/5] histograms: traceeval release
Date: Fri, 28 Jul 2023 18:07:33 -0400 [thread overview]
Message-ID: <20230728180733.2720ae8c@rorschach.local.home> (raw)
In-Reply-To: <20230728190515.23088-3-stevie.6strings@gmail.com>
On Fri, 28 Jul 2023 15:04:38 -0400
Stevie Alvarez <stevie.6strings@gmail.com> wrote:
> From: "Stevie Alvarez (Google)" <stevie.6strings@gmail.com>
>
> traceeval_release() deconstructs a given struct traceeval instance. It
> frees any data allocated to the heap within the union traceeval_data
> arrays of entries to the histogram, and the names allocated for the
> struct traceeval_type key-value definitions.
>
> Signed-off-by: Stevie Alvarez (Google) <stevie.6strings@gmail.com>
> ---
> src/histograms.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 85 insertions(+), 2 deletions(-)
>
> diff --git a/src/histograms.c b/src/histograms.c
> index 13830e4..f46a0e0 100644
> --- a/src/histograms.c
> +++ b/src/histograms.c
> @@ -209,10 +209,93 @@ fail_eval_init_unalloced:
> return NULL;
> }
>
> -// TODO
> -void traceeval_release(struct traceeval *teval)
> +/**
> + * Deallocate array of traceeval_type's, which must be terminated by
> + * TRACEEVAL_TYPE_NONE.
> + */
> +static void type_release(struct traceeval_type *defs)
So if we keep track of the number of defs, we should just pass in the
size. And ignore the NONE.
> {
> + size_t i = 0;
> +
> + if (!defs)
> + return;
> +
> + for_each_key(i, defs) {
> + if (defs[i].name)
> + free(defs[i].name);
> + }
> +
> + free(defs);
> +}
> +
> +/**
> + * Deallocate any specified dynamic data in @data.
> + */
> +static void clean_data(union traceeval_data *data, struct traceeval_type *def) +{
> + size_t i = 0;
> +
> + if (!data || !def)
> + return;
> +
> + for_each_key(i, def) {
> + switch (def[i].type) {
> + case TRACEEVAL_TYPE_STRING:
> + if (data[i].string)
> + free(data[i].string);
> + break;
> + case TRACEEVAL_TYPE_DYNAMIC:
> + def[i].dyn_release(data[i].dyn_data, &def[i]);
Note, it should be OK if the dynamic event does not have a release
function. This should be:
if (def[i].dyn_release)
def[i].dyn_release(data[i].dyn_data, &def[i]);
> + break;
> + default:
> + break;
> + }
> + }
> +}
>
> +/**
> + * Deallocate all possible data stored within the entry.
Use the word "Free" and not "Deallocate". This goes for all other
places.
-- Steve
> + */
> +static void clean_entry(struct entry *entry, struct traceeval *teval)
> +{
> + if (!entry)
> + return;
> +
> + // deallocate dynamic traceeval_data
> + clean_data(entry->keys, teval->def_keys);
> + clean_data(entry->vals, teval->def_vals);
> + free(entry->keys);
> + free(entry->vals);
> +}
> +
> +/**
> + * Deallocate the hist_table allocated to a traceeval instance.
> + */
> +static void hist_table_release(struct traceeval *teval)
> +{
> + struct hist_table *hist = teval->hist;
> +
> + if (!hist)
> + return;
> +
> + for (size_t i = 0; i < hist->nr_entries; i++) {
> + clean_entry(&hist->map[i], teval);
> + }
> + free(hist->map);
> + free(hist);
> +}
> +
> +/**
> + * Deallocate a traceeval instance.
> + */
> +void traceeval_release(struct traceeval *teval)
> +{
> + if (teval) {
> + hist_table_release(teval);
> + type_release(teval->def_keys);
> + type_release(teval->def_vals);
> + free(teval);
> + }
> }
>
> // TODO
next prev parent reply other threads:[~2023-07-28 22:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 19:04 [PATCH 1/5] histograms: initial histograms interface Stevie Alvarez
2023-07-28 19:04 ` [PATCH 2/5] histograms: traceeval initialize Stevie Alvarez
2023-07-28 22:03 ` Steven Rostedt
2023-08-02 21:07 ` Ross Zwisler
2023-08-02 21:39 ` Steven Rostedt
2023-07-28 19:04 ` [PATCH 3/5] histograms: traceeval release Stevie Alvarez
2023-07-28 22:07 ` Steven Rostedt [this message]
2023-08-02 21:54 ` Ross Zwisler
2023-08-02 22:20 ` Steven Rostedt
2023-08-02 22:21 ` Steven Rostedt
2023-07-28 19:04 ` [PATCH 4/5] histograms: traceeval compare Stevie Alvarez
2023-07-28 22:25 ` Steven Rostedt
2023-08-02 22:51 ` Ross Zwisler
2023-07-28 19:04 ` [PATCH 5/5] histograms: Add struct traceeval unit tests Stevie Alvarez
2023-07-28 22:30 ` Steven Rostedt
2023-08-03 16:27 ` Ross Zwisler
2023-07-28 20:25 ` [PATCH 1/5] histograms: initial histograms interface Steven Rostedt
2023-07-31 20:53 ` Stevie Alvarez
2023-07-31 21:04 ` Steven Rostedt
2023-08-01 19:08 ` Stevie Alvarez
2023-08-01 19:29 ` Steven Rostedt
2023-08-01 0:36 ` Ross Zwisler
2023-08-01 1:25 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230728180733.2720ae8c@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=stevie.6strings@gmail.com \
--cc=zwisler@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).