4 #include <subcmd/parse-options.h> 8 #include <linux/stringify.h> 21 char *token, *saved_ptr = NULL;
23 fp = fopen(
"/proc/mounts",
"r");
35 while (fscanf(fp,
"%*s %"__stringify(
PATH_MAX)
"s %"__stringify(
PATH_MAX)
"s %" 37 mountpoint, type, tokens) == 3) {
39 if (!path_v1[0] && !strcmp(type,
"cgroup")) {
41 token = strtok_r(tokens,
",", &saved_ptr);
43 while (token != NULL) {
44 if (!strcmp(token,
"perf_event")) {
45 strcpy(path_v1, mountpoint);
48 token = strtok_r(NULL,
",", &saved_ptr);
52 if (!path_v2[0] && !strcmp(type,
"cgroup2"))
53 strcpy(path_v2, mountpoint);
55 if (path_v1[0] && path_v2[0])
67 if (strlen(path) < maxlen) {
84 scnprintf(path,
PATH_MAX,
"%s/%s", mnt, name);
86 fd = open(path, O_RDONLY);
88 fprintf(stderr,
"no access to cgroup %s\n", path);
102 if (!strcmp(counter->
cgrp->
name, str))
113 if (cgroup != NULL) {
114 refcount_set(&cgroup->
refcnt, 1);
116 cgroup->
name = strdup(name);
120 if (cgroup->
fd == -1)
162 counter->
cgrp = cgrp;
175 if (cgrp && refcount_dec_and_test(&cgrp->
refcnt)) {
183 refcount_inc(&cgroup->
refcnt);
189 if (evsel->
cgrp == NULL)
202 int unset __maybe_unused)
206 struct cgroup *cgrp = NULL;
207 const char *p, *e, *eos = str + strlen(str);
211 if (list_empty(&evlist->
entries)) {
212 fprintf(stderr,
"must define events before cgroups\n");
217 p = strchr(str,
',');
223 s = strndup(str, e - str);
242 cgrp = counter->cgrp;
244 counter->cgrp = cgrp;
245 refcount_inc(&cgrp->refcnt);
struct cgroup * cgroup__get(struct cgroup *cgroup)
int parse_cgroups(const struct option *opt, const char *str, int unset __maybe_unused)
static void cgroup__delete(struct cgroup *cgroup)
#define evlist__for_each_entry(evlist, evsel)
static int cgroupfs_find_mountpoint(char *buf, size_t maxlen)
static struct cgroup * cgroup__new(const char *name)
static struct cgroup * evlist__find_cgroup(struct perf_evlist *evlist, const char *str)
static void evsel__set_default_cgroup(struct perf_evsel *evsel, struct cgroup *cgroup)
static int str(yyscan_t scanner, int token)
struct cgroup * evlist__findnew_cgroup(struct perf_evlist *evlist, const char *name)
static int open_cgroup(const char *name)
static int add_cgroup(struct perf_evlist *evlist, const char *str)
void cgroup__put(struct cgroup *cgrp)
void evlist__set_default_cgroup(struct perf_evlist *evlist, struct cgroup *cgroup)
void static void * zalloc(size_t size)