Messages in this thread | | | Date | Thu, 10 Sep 2020 10:59:26 +0200 | From | Jiri Olsa <> | Subject | Re: [PATCH 1/4] perf evsel: Add evsel__clone() function |
| |
On Tue, Sep 08, 2020 at 01:42:25PM +0900, Namhyung Kim wrote: > The evsel__clone() is to create an exactly same evsel from same > attributes. Note that metric events will be handled by later patch. > > It will be used by perf stat to generate separate events for each > cgroup. > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > --- > tools/perf/util/evsel.c | 57 +++++++++++++++++++++++++++++++++++++++++ > tools/perf/util/evsel.h | 1 + > 2 files changed, 58 insertions(+) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index fd865002cbbd..4f50f9499973 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -331,6 +331,63 @@ struct evsel *evsel__new_cycles(bool precise) > goto out; > } > > +/** > + * evsel__clone - create a new evsel copied from @orig > + * @orig: original evsel > + * > + * The assumption is that @orig is not configured nor opened yet. > + * So we only care about the attributes that can be set while it's parsed. > + */ > +struct evsel *evsel__clone(struct evsel *orig) > +{ > + struct evsel *evsel; > + struct evsel_config_term *pos, *tmp; > + > + BUG_ON(orig->core.fd); > + > + evsel = evsel__new(&orig->core.attr); > + if (evsel == NULL) > + return NULL; > + > + *evsel = *orig;
this seems wild ;-) I saw that assumption above, but I wonder we could add some check or zero/init the rest of the fields fields
jirka
| |