Skip to content

Commit 8a0f8d7

Browse files
committed
perf parse-events: Add parse_uid_filter helper
JIRA: https://issues.redhat.com/browse/RHEL-78200 upstream ======== commit 466db42 Author: Ian Rogers <irogers@google.com> Date: Wed Jun 4 10:45:37 2025 -0700 description =========== Add parse_uid_filter filter as a helper to parse_filter, that constructs a uid filter string. As uid filters don't work with tracepoint filters, add a is_possible_tp_filter function so the tracepoint filter isn't attempted for tracepoint evsels. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250604174545.2853620-4-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
1 parent 59bb5ba commit 8a0f8d7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tools/perf/util/parse-events.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "pmu.h"
2626
#include "pmus.h"
2727
#include "asm/bug.h"
28+
#include "ui/ui.h"
2829
#include "util/parse-branch-options.h"
2930
#include "util/evsel_config.h"
3031
#include "util/event.h"
@@ -2556,6 +2557,12 @@ foreach_evsel_in_last_glob(struct evlist *evlist,
25562557
return 0;
25572558
}
25582559

2560+
/* Will a tracepoint filter work for str or should a BPF filter be used? */
2561+
static bool is_possible_tp_filter(const char *str)
2562+
{
2563+
return strstr(str, "uid") == NULL;
2564+
}
2565+
25592566
static int set_filter(struct evsel *evsel, const void *arg)
25602567
{
25612568
const char *str = arg;
@@ -2568,7 +2575,7 @@ static int set_filter(struct evsel *evsel, const void *arg)
25682575
return -1;
25692576
}
25702577

2571-
if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
2578+
if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && is_possible_tp_filter(str)) {
25722579
if (evsel__append_tp_filter(evsel, str) < 0) {
25732580
fprintf(stderr,
25742581
"not enough memory to hold filter string\n");
@@ -2604,6 +2611,30 @@ int parse_filter(const struct option *opt, const char *str,
26042611
(const void *)str);
26052612
}
26062613

2614+
int parse_uid_filter(struct evlist *evlist, uid_t uid)
2615+
{
2616+
struct option opt = {
2617+
.value = &evlist,
2618+
};
2619+
char buf[128];
2620+
int ret;
2621+
2622+
snprintf(buf, sizeof(buf), "uid == %d", uid);
2623+
ret = parse_filter(&opt, buf, /*unset=*/0);
2624+
if (ret) {
2625+
if (use_browser >= 1) {
2626+
/*
2627+
* Use ui__warning so a pop up appears above the
2628+
* underlying BPF error message.
2629+
*/
2630+
ui__warning("Failed to add UID filtering that uses BPF filtering.\n");
2631+
} else {
2632+
fprintf(stderr, "Failed to add UID filtering that uses BPF filtering.\n");
2633+
}
2634+
}
2635+
return ret;
2636+
}
2637+
26072638
static int add_exclude_perf_filter(struct evsel *evsel,
26082639
const void *arg __maybe_unused)
26092640
{

tools/perf/util/parse-events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/perf_event.h>
1212
#include <stdio.h>
1313
#include <string.h>
14+
#include <sys/types.h>
1415

1516
struct evsel;
1617
struct evlist;
@@ -45,6 +46,7 @@ static inline int parse_events(struct evlist *evlist, const char *str,
4546
int parse_event(struct evlist *evlist, const char *str);
4647

4748
int parse_filter(const struct option *opt, const char *str, int unset);
49+
int parse_uid_filter(struct evlist *evlist, uid_t uid);
4850
int exclude_perf(const struct option *opt, const char *arg, int unset);
4951

5052
enum parse_events__term_val_type {

0 commit comments

Comments
 (0)