linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf bpf-filter: Fix sample flag check with ||
@ 2023-08-11  2:58 Namhyung Kim
  2023-08-11  2:58 ` [PATCH 2/2] perf test: Add perf record sample filtering test Namhyung Kim
  2023-08-15  8:16 ` [PATCH 1/2] perf bpf-filter: Fix sample flag check with || Ian Rogers
  0 siblings, 2 replies; 8+ messages in thread
From: Namhyung Kim @ 2023-08-11  2:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

For logical OR operator, the actual sample_flags are in the 'groups'
list so it needs to check entries in the list instead.  Otherwise it
would show the following error message.

  $ sudo perf record -a -e cycles:p --filter 'period > 100 || weight > 0' sleep 1
  Error: cycles:p event does not have sample flags 0
  failed to set filter "BPF" on event cycles:p with 2 (No such file or directory)

Actually it should warn on 'weight' is used without WEIGHT flag.

  Error: cycles:p event does not have PERF_SAMPLE_WEIGHT
   Hint: please add -W option to perf record
  failed to set filter "BPF" on event cycles:p with 2 (No such file or directory)

Fixes: 4310551b76e0 ("perf bpf filter: Show warning for missing sample flags")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/bpf-filter.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
index 47f01df658d9..b51544996046 100644
--- a/tools/perf/util/bpf-filter.c
+++ b/tools/perf/util/bpf-filter.c
@@ -62,6 +62,16 @@ static int check_sample_flags(struct evsel *evsel, struct perf_bpf_filter_expr *
 	if (evsel->core.attr.sample_type & expr->sample_flags)
 		return 0;
 
+	if (expr->op == PBF_OP_GROUP_BEGIN) {
+		struct perf_bpf_filter_expr *group;
+
+		list_for_each_entry(group, &expr->groups, list) {
+			if (check_sample_flags(evsel, group) < 0)
+				return -1;
+		}
+		return 0;
+	}
+
 	info = get_sample_info(expr->sample_flags);
 	if (info == NULL) {
 		pr_err("Error: %s event does not have sample flags %lx\n",
-- 
2.41.0.640.ga95def55d0-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-23 11:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-11  2:58 [PATCH 1/2] perf bpf-filter: Fix sample flag check with || Namhyung Kim
2023-08-11  2:58 ` [PATCH 2/2] perf test: Add perf record sample filtering test Namhyung Kim
2023-08-15  8:17   ` Ian Rogers
2023-08-15 17:30   ` Arnaldo Carvalho de Melo
2023-08-15 17:42     ` Arnaldo Carvalho de Melo
2023-08-23  0:50       ` Namhyung Kim
2023-08-23 11:34         ` Arnaldo Carvalho de Melo
2023-08-15  8:16 ` [PATCH 1/2] perf bpf-filter: Fix sample flag check with || Ian Rogers

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).