From: Jinshan Xiong <jinshan.xiong@gmail.com>
To: jolsa@redhat.com
Cc: Jinshan Xiong <jinshan.xiong@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] tools/lib/perf: add a flag to specify cgroup fd
Date: Sat, 25 Sep 2021 19:15:25 -0700 [thread overview]
Message-ID: <20210926021611.2312331-1-jinshan.xiong@gmail.com> (raw)
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 <jinshan.xiong@gmail.com>
---
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(-)
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index 8441e3e1aaac..67f86513a816 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -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;
diff --git a/tools/lib/perf/include/internal/threadmap.h b/tools/lib/perf/include/internal/threadmap.h
index df748baf9eda..5d7bd6968563 100644
--- a/tools/lib/perf/include/internal/threadmap.h
+++ b/tools/lib/perf/include/internal/threadmap.h
@@ -8,6 +8,7 @@
struct thread_map_data {
pid_t pid;
+ int flags;
char *comm;
};
diff --git a/tools/lib/perf/include/perf/threadmap.h b/tools/lib/perf/include/perf/threadmap.h
index a7c50de8d010..5fea1a403e28 100644
--- a/tools/lib/perf/include/perf/threadmap.h
+++ b/tools/lib/perf/include/perf/threadmap.h
@@ -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);
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index e92c368b0a6c..3b8ec4f944b9 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -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;
--
2.30.2
reply other threads:[~2021-09-26 2:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210926021611.2312331-1-jinshan.xiong@gmail.com \
--to=jinshan.xiong@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).