linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Stephane Eranian <eranian@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>
Subject: Re: [PATCH 2/4] perf stat: Add --for-each-cgroup option
Date: Mon, 21 Sep 2020 14:45:28 +0900	[thread overview]
Message-ID: <CAM9d7chyg_h7aZ9ONwu7qH4mD9p=nLSrHpdubUptMk=8S7i79g@mail.gmail.com> (raw)
In-Reply-To: <20200918133439.GB2626435@krava>

On Fri, Sep 18, 2020 at 10:34 PM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Wed, Sep 16, 2020 at 03:31:27PM +0900, Namhyung Kim wrote:
>
> SNIP
>
> > +int evlist__expand_cgroup(struct evlist *evlist, const char *str)
> > +{
> > +     struct evlist *orig_list, *tmp_list;
> > +     struct evsel *pos, *evsel, *leader;
> > +     struct cgroup *cgrp = NULL;
> > +     const char *p, *e, *eos = str + strlen(str);
> > +     int ret = -1;
> > +
> > +     if (evlist->core.nr_entries == 0) {
> > +             fprintf(stderr, "must define events before cgroups\n");
> > +             return -EINVAL;
> > +     }
> > +
> > +     orig_list = evlist__new();
> > +     tmp_list = evlist__new();
> > +     if (orig_list == NULL || tmp_list == NULL) {
> > +             fprintf(stderr, "memory allocation failed\n");
> > +             return -ENOMEM;
> > +     }
> > +
> > +     /* save original events and init evlist */
> > +     perf_evlist__splice_list_tail(orig_list, &evlist->core.entries);
> > +     evlist->core.nr_entries = 0;
> > +
> > +     for (;;) {
> > +             p = strchr(str, ',');
> > +             e = p ? p : eos;
> > +
> > +             /* allow empty cgroups, i.e., skip */
> > +             if (e - str) {
> > +                     /* termination added */
> > +                     char *name = strndup(str, e - str);
> > +                     if (!name)
> > +                             break;
> > +
> > +                     cgrp = cgroup__new(name);
> > +                     free(name);
> > +                     if (cgrp == NULL)
> > +                             break;
> > +             } else {
> > +                     cgrp = NULL;
> > +             }
> > +
> > +             leader = NULL;
> > +             evlist__for_each_entry(orig_list, pos) {
> > +                     evsel = evsel__clone(pos);
>
> missing check on evsel == NULL

Will check.

Thanks
Namhyung


> > +                     cgroup__put(evsel->cgrp);
> > +                     evsel->cgrp = cgroup__get(cgrp);
> > +
> > +                     if (evsel__is_group_leader(pos))
> > +                             leader = evsel;
> > +                     evsel->leader = leader;
> > +
> > +                     evlist__add(tmp_list, evsel);
> > +             }
> > +             /* cgroup__new() has a refcount, release it here */
> > +             cgroup__put(cgrp);
> > +             nr_cgroups++;
> > +
> > +             perf_evlist__splice_list_tail(evlist, &tmp_list->core.entries);
> > +             tmp_list->core.nr_entries = 0;
> > +
> > +             if (!p) {
> > +                     ret = 0;
> > +                     break;
> > +             }
> > +             str = p+1;
> > +     }
> > +     evlist__delete(orig_list);
> > +     evlist__delete(tmp_list);
> > +
> > +     return ret;
> > +}
>
> SNIP
>

  reply	other threads:[~2020-09-21  5:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16  6:31 [PATCHSET v2 0/4] perf stat: Expand events for each cgroup Namhyung Kim
2020-09-16  6:31 ` [PATCH 1/4] perf evsel: Add evsel__clone() function Namhyung Kim
2020-09-18 13:31   ` Jiri Olsa
2020-09-21  5:44     ` Namhyung Kim
2020-09-16  6:31 ` [PATCH 2/4] perf stat: Add --for-each-cgroup option Namhyung Kim
2020-09-16 13:51   ` Arnaldo Carvalho de Melo
2020-09-17  1:33     ` Namhyung Kim
2020-09-18 13:34   ` Jiri Olsa
2020-09-21  5:45     ` Namhyung Kim [this message]
2020-09-16  6:31 ` [PATCH 3/4] perf tools: Copy metric events properly when expand cgroups Namhyung Kim
2020-09-18 13:45   ` Jiri Olsa
2020-09-21  5:48     ` Namhyung Kim
2020-09-16  6:31 ` [PATCH 4/4] perf test: Add expand cgroup event test Namhyung Kim
2020-09-18 13:51   ` Jiri Olsa
2020-09-21  5:49     ` Namhyung Kim

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='CAM9d7chyg_h7aZ9ONwu7qH4mD9p=nLSrHpdubUptMk=8S7i79g@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@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 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).