perf tools: Add read_cgroup_id() function
[linux-2.6-microblaze.git] / tools / perf / util / cgroup.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __CGROUP_H__
3 #define __CGROUP_H__
4
5 #include <linux/compiler.h>
6 #include <linux/refcount.h>
7 #include <linux/rbtree.h>
8 #include "util/env.h"
9
10 struct option;
11
12 struct cgroup {
13         struct rb_node          node;
14         u64                     id;
15         char                    *name;
16         int                     fd;
17         refcount_t              refcnt;
18 };
19
20 extern int nr_cgroups; /* number of explicit cgroups defined */
21
22 struct cgroup *cgroup__get(struct cgroup *cgroup);
23 void cgroup__put(struct cgroup *cgroup);
24
25 struct evlist;
26 struct rblist;
27
28 struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name);
29 int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups,
30                           struct rblist *metric_events, bool open_cgroup);
31
32 void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup);
33
34 int parse_cgroups(const struct option *opt, const char *str, int unset);
35
36 struct cgroup *cgroup__findnew(struct perf_env *env, uint64_t id,
37                                const char *path);
38 struct cgroup *cgroup__find(struct perf_env *env, uint64_t id);
39
40 void perf_env__purge_cgroups(struct perf_env *env);
41
42 #ifdef HAVE_FILE_HANDLE
43 int read_cgroup_id(struct cgroup *cgrp);
44 #else
45 static inline int read_cgroup_id(struct cgroup *cgrp __maybe_unused)
46 {
47         return -1;
48 }
49 #endif  /* HAVE_FILE_HANDLE */
50
51 #endif /* __CGROUP_H__ */