tools/lib/perf: add a flag to specify cgroup fd
PATCH 1/1 tools/lib/perf: add a flag to specify cgroup fd
This patch adds an API perf_thread_map__set_flags() so that we can use it to pass down a flag to specific cgroup fd in sys_perf_event_open().
This API can be used in the following way:
int cgroup_fd = open("/sys/fs/cgroup/perf_event", O_RDONLY);
struct thread_map *threadmap = perf_thread_map__new_dummy();
perf_thread_map__set_pid(threadmap, 0, cgroup_fd);
perf_thread_map__set_flags(threadmap, 0, PERF_FLAG_PID_CGROUP);Therefore, we can only collect perf events in a specific docker container.
Signed-off-by Jinshan Xiong <[email protected]>
--- tools/lib/perf/evsel.c | 3 ++- tools/lib/perf/include/internal/threadmap.h | 1 + tools/lib/perf/include/perf/threadmap.h | 1 + tools/lib/perf/threadmap.c | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-)
tools/lib/perf/evsel.c +2 -1
@@ -153,7 +153,8 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, fd =sys_perf_event_open (&evsel->attr, threads->map[thread].pid, - cpus->map[cpu], group_fd,0 ); + cpus->map[cpu], group_fd, + threads->map[thread].flags);if (fd <0 )return -errno;
tools/lib/perf/include/internal/threadmap.h +1 -0
@@ -8,6 +8,7 @@struct thread_map_data {pid_t pid; +int flags;char *comm; };
tools/lib/perf/include/perf/threadmap.h +1 -0
@@ -10,6 +10,7 @@ struct perf_thread_map; LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void); LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid); +LIBPERF_API void perf_thread_map__set_flags(struct perf_thread_map *map, int thread, int flags); LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread); LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads); LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
tools/lib/perf/threadmap.c +5 -0
@@ -37,6 +37,11 @@ void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid map->map[thread].pid = pid; } +void perf_thread_map__set_flags (struct perf_thread_map *map,int thread,int flags) +{ + map->map[thread].flags = flags; +} +char *perf_thread_map__comm (struct perf_thread_map *map,int thread) {return map->map[thread].comm;
Signature · 1 line
2.30.2