All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Vaish <nilayvaish@gmail.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: acme@kernel.org, jolsa@kernel.org,
	Linux Kernel list <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 1/4] perf stat: Basic support for TopDown in perf stat
Date: Wed, 1 Jun 2016 09:24:33 -0500	[thread overview]
Message-ID: <CACbG309Waj8Pwh5P-ANexaTqAF4p=Y1uV9Gq504DOQwXSnLh1w@mail.gmail.com> (raw)
In-Reply-To: <1464119559-17203-1-git-send-email-andi@firstfloor.org>

On 24 May 2016 at 14:52, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 715a1128daeb..dab184d86816 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -59,10 +59,13 @@
>  #include "util/thread.h"
>  #include "util/thread_map.h"
>  #include "util/counts.h"
> +#include "util/group.h"
>  #include "util/session.h"
>  #include "util/tool.h"
> +#include "util/group.h"
>  #include "asm/bug.h"

You have included util/group.h twice.  Is this intentional?

> +static int topdown_filter_events(const char **attr, char **str, bool use_group)
> +{
> +       int off = 0;
> +       int i;
> +       int len = 0;
> +       char *s;
> +
> +       for (i = 0; attr[i]; i++) {
> +               if (pmu_have_event("cpu", attr[i])) {
> +                       len += strlen(attr[i]) + 1;
> +                       attr[i - off] = attr[i];
> +               } else
> +                       off++;
> +       }
> +       attr[i - off] = NULL;
> +
> +       *str = malloc(len + 1 + 2);
> +       if (!*str)
> +               return -1;
> +       s = *str;
> +       if (i - off == 0) {
> +               *s = 0;
> +               return 0;
> +       }

I think we are leaking some memory here.  If i == off, then we set
attr[0] = NULL and do not free the memory allocated to str.


> @@ -1909,6 +1982,46 @@ static int add_default_attributes(void)
>                 return 0;
>         }
>
> +       if (topdown_run) {
> +               char *str = NULL;
> +               bool warn = false;
> +
> +               if (stat_config.aggr_mode != AGGR_GLOBAL &&
> +                   stat_config.aggr_mode != AGGR_CORE) {
> +                       pr_err("top down event configuration requires --per-core mode\n");
> +                       return -1;
> +               }
> +               stat_config.aggr_mode = AGGR_CORE;
> +               if (nr_cgroups || !target__has_cpu(&target)) {
> +                       pr_err("top down event configuration requires system-wide mode (-a)\n");
> +                       return -1;
> +               }
> +
> +               if (!force_metric_only)
> +                       metric_only = true;
> +               if (topdown_filter_events(topdown_attrs, &str,
> +                               arch_topdown_check_group(&warn)) < 0) {
> +                       pr_err("Out of memory\n");
> +                       return -1;
> +               }
> +               if (topdown_attrs[0] && str) {
> +                       if (warn)
> +                               arch_topdown_group_warn();
> +                       err = parse_events(evsel_list, str, NULL);
> +                       if (err) {
> +                               fprintf(stderr,
> +                                       "Cannot set up top down events %s: %d\n",
> +                                       str, err);
> +                               free(str);
> +                               return -1;
> +                       }
> +               } else {
> +                       fprintf(stderr, "System does not support topdown\n");
> +                       return -1;
> +               }
> +               free(str);
> +       }
> +

Continuing with my comment from above memory leak, if i == off,
topdown_attrs[0] will be NULL.  So we would enter the else portion
here and return -1.  But we never free the string we allocated in the
function topdown_filter_events().   I think we are leaking some memory
though seems only about 3 bytes.

--
Nilay

  parent reply	other threads:[~2016-06-01 14:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 19:52 [PATCH 1/4] perf stat: Basic support for TopDown in perf stat Andi Kleen
2016-05-24 19:52 ` [PATCH 2/4] perf stat: Add computation of TopDown formulas Andi Kleen
2016-06-01 14:50   ` Nilay Vaish
2016-06-01 14:56     ` Andi Kleen
2016-06-02 11:56       ` Nilay Vaish
2016-06-02 14:26         ` Andi Kleen
2016-06-08  8:39   ` [tip:perf/core] " tip-bot for Andi Kleen
2016-05-24 19:52 ` [PATCH 3/4] perf stat: Print topology/time headers with --metric-only Andi Kleen
2016-06-08  8:39   ` [tip:perf/core] " tip-bot for Andi Kleen
2016-05-24 19:52 ` [PATCH 4/4] perf stat: Add missing aggregation headers for --metric-only CSV Andi Kleen
2016-06-08  8:40   ` [tip:perf/core] " tip-bot for Andi Kleen
2016-05-30 16:01 ` [PATCH 1/4] perf stat: Basic support for TopDown in perf stat Arnaldo Carvalho de Melo
2016-05-30 16:04   ` Andi Kleen
2016-05-30 16:19     ` Arnaldo Carvalho de Melo
2016-06-06 14:00       ` Arnaldo Carvalho de Melo
2016-06-06 14:11         ` Arnaldo Carvalho de Melo
2016-06-06 14:36           ` Andi Kleen
2016-06-01 14:24 ` Nilay Vaish [this message]
2016-06-01 14:31   ` Andi Kleen
2016-06-01 15:24   ` Andi Kleen
2016-06-02 11:52     ` Nilay Vaish
2016-06-08  8:38 ` [tip:perf/core] " tip-bot for Andi Kleen

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='CACbG309Waj8Pwh5P-ANexaTqAF4p=Y1uV9Gq504DOQwXSnLh1w@mail.gmail.com' \
    --to=nilayvaish@gmail.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.