From: tip-bot for Arnaldo Carvalho de Melo <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: adrian.hunter@intel.com, wangnan0@huawei.com, hpa@zytor.com,
linux-kernel@vger.kernel.org, jolsa@kernel.org,
namhyung@kernel.org, mingo@kernel.org, acme@redhat.com,
dsahern@gmail.com, tglx@linutronix.de
Subject: [tip:perf/core] perf augmented_syscalls: Use pid_filter
Date: Wed, 21 Nov 2018 23:04:19 -0800 [thread overview]
Message-ID: <tip-1i9s27wqqdhafk3fappow84x@git.kernel.org> (raw)
Commit-ID: ed9a77ba7703f7da8f106d241cd0c734f8664b4d
Gitweb: https://git.kernel.org/tip/ed9a77ba7703f7da8f106d241cd0c734f8664b4d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Tue, 6 Nov 2018 16:09:06 -0300
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Nov 2018 12:00:31 -0300
perf augmented_syscalls: Use pid_filter
Just to test filtering a bunch of pids, now its time to go and get that
hooked up in 'perf trace', right after we load the bpf program, if we
find a "pids_filtered" map defined, we'll populate it with the filtered
pids.
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: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-1i9s27wqqdhafk3fappow84x@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/examples/bpf/augmented_raw_syscalls.c | 34 ++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index 7d729319618c..5fed1eff889d 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <unistd.h>
+#include <pid_filter.h>
/* bpf-output associated map */
struct bpf_map SEC("maps") __augmented_syscalls__ = {
@@ -48,6 +49,29 @@ struct augmented_filename {
#define SYS_POLL 7
#define SYS_OPENAT 257
+pid_filter(pids_filtered);
+
+static void pid_filter__init(void)
+{
+ /*
+ * Filter a bunch of pids: gnome-shell, kvm, firefox threads,
+ * avahi-daemon, etc, just for testing as we go along.
+ *
+ * These will come from 'perf trace --filter-pids' in a explicit way
+ * and also it will filter out itself, to avoid the feedback loop:
+ * syscalls 'perf trace' does gets caught, reported, causing new
+ * syscalls to get emitted, rinse repeat forever.
+ */
+ if (pid_filter__add(&pids_filtered, 2971))
+ return; /* pid_filter__init() was already called, bail out */
+ pid_filter__add(&pids_filtered, 20016);
+ pid_filter__add(&pids_filtered, 12018);
+ pid_filter__add(&pids_filtered, 2310);
+ pid_filter__add(&pids_filtered, 3759);
+ pid_filter__add(&pids_filtered, 25978);
+ pid_filter__add(&pids_filtered, 883);
+}
+
SEC("raw_syscalls:sys_enter")
int sys_enter(struct syscall_enter_args *args)
{
@@ -57,8 +81,14 @@ int sys_enter(struct syscall_enter_args *args)
} augmented_args;
unsigned int len = sizeof(augmented_args);
const void *filename_arg = NULL;
+ /*
+ * We still don't have a "main()" called first and only once
+ * call it always, it will exit as soon as it realizes the
+ * first hard coded filtered pid was already added.
+ */
+ pid_filter__init();
- if (getpid() == 2971)
+ if (pid_filter__has(&pids_filtered, getpid()))
return 0;
probe_read(&augmented_args.args, sizeof(augmented_args.args), args);
@@ -132,7 +162,7 @@ int sys_enter(struct syscall_enter_args *args)
SEC("raw_syscalls:sys_exit")
int sys_exit(struct syscall_exit_args *args)
{
- return getpid() != 2971;
+ return !pid_filter__has(&pids_filtered, getpid());
}
license(GPL);
reply other threads:[~2018-11-22 7:04 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=tip-1i9s27wqqdhafk3fappow84x@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=wangnan0@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.