Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69239ec8 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf cgroup: Add evlist__findnew_cgroup()

Similar to machine__findnew_thread(), etc, i.e. try to find, get a
refcount if found and return it, otherwise return a new cgroup object.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-im1omevlihhyneiic4nl3g24@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4b5ea3bd
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -128,18 +128,21 @@ static struct cgroup *cgroup__new(char *name)
	return NULL;
	return NULL;
}
}


struct cgroup *evlist__findnew_cgroup(struct perf_evlist *evlist, char *name)
{
	struct cgroup *cgroup = evlist__find_cgroup(evlist, name);

	return cgroup ?: cgroup__new(name);
}

static int add_cgroup(struct perf_evlist *evlist, char *str)
static int add_cgroup(struct perf_evlist *evlist, char *str)
{
{
	struct perf_evsel *counter;
	struct perf_evsel *counter;
	struct cgroup *cgrp = evlist__find_cgroup(evlist, str);
	struct cgroup *cgrp = evlist__findnew_cgroup(evlist, str);
	int n;
	int n;


	if (!cgrp) {
		cgrp = cgroup__new(str);
	if (!cgrp)
	if (!cgrp)
		return -1;
		return -1;
	}

	/*
	/*
	 * find corresponding event
	 * find corresponding event
	 * if add cgroup N, then need to find event N
	 * if add cgroup N, then need to find event N
+4 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,10 @@ extern int nr_cgroups; /* number of explicit cgroups defined */
struct cgroup *cgroup__get(struct cgroup *cgroup);
struct cgroup *cgroup__get(struct cgroup *cgroup);
void cgroup__put(struct cgroup *cgroup);
void cgroup__put(struct cgroup *cgroup);


struct perf_evlist;

struct cgroup *evlist__findnew_cgroup(struct perf_evlist *evlist, char *name);

int parse_cgroups(const struct option *opt, const char *str, int unset);
int parse_cgroups(const struct option *opt, const char *str, int unset);


#endif /* __CGROUP_H__ */
#endif /* __CGROUP_H__ */