From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
James Clark <james.clark@arm.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Atish Patra <atishp@rivosinc.com>,
linux-riscv@lists.infradead.org,
Beeman Strong <beeman@rivosinc.com>
Subject: [PATCH v2 04/16] perf pmu: Refactor perf_pmu__match
Date: Mon, 15 Apr 2024 23:15:20 -0700 [thread overview]
Message-ID: <20240416061533.921723-5-irogers@google.com> (raw)
In-Reply-To: <20240416061533.921723-1-irogers@google.com>
Move all implementation to pmu code. Don't allocate a fnmatch wildcard
pattern, matching ignoring the suffix already handles this, and only
use fnmatch if the given PMU name has a '*' in it.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.c | 19 ++-----------------
tools/perf/util/pmu.c | 27 +++++++++++++++++++--------
tools/perf/util/pmu.h | 2 +-
3 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 3b1f767039fa..39548ec645ec 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1611,7 +1611,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
struct list_head **listp,
void *loc_)
{
- char *pattern = NULL;
YYLTYPE *loc = loc_;
struct perf_pmu *pmu;
int ok = 0;
@@ -1631,22 +1630,9 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
pmu = NULL;
/* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */
- if (asprintf(&pattern, "%s*", event_or_pmu) < 0) {
- zfree(listp);
- return -ENOMEM;
- }
-
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
- const char *name = pmu->name;
-
- if (parse_events__filter_pmu(parse_state, pmu))
- continue;
-
- if (!strncmp(name, "uncore_", 7) &&
- strncmp(event_or_pmu, "uncore_", 7))
- name += 7;
- if (!perf_pmu__match(pattern, name, event_or_pmu) ||
- !perf_pmu__match(pattern, pmu->alias_name, event_or_pmu)) {
+ if (!parse_events__filter_pmu(parse_state, pmu) &&
+ perf_pmu__match(pmu, event_or_pmu)) {
bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu);
if (!parse_events_add_pmu(parse_state, *listp, pmu,
@@ -1657,7 +1643,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
}
}
}
- zfree(&pattern);
if (ok)
return 0;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index ce72c99e4f61..d7521d84fe4a 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -2073,18 +2073,29 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
name ?: "N/A", buf, config_name, config);
}
-int perf_pmu__match(const char *pattern, const char *name, const char *tok)
+bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok)
{
- if (!name)
- return -1;
+ const char *name = pmu->name;
+ bool need_fnmatch = strchr(tok, '*') != NULL;
- if (fnmatch(pattern, name, 0))
- return -1;
+ if (!strncmp(tok, "uncore_", 7))
+ tok += 7;
+ if (!strncmp(name, "uncore_", 7))
+ name += 7;
- if (tok && !perf_pmu__match_ignoring_suffix(name, tok))
- return -1;
+ if (perf_pmu__match_ignoring_suffix(name, tok) ||
+ (need_fnmatch && !fnmatch(tok, name, 0)))
+ return true;
- return 0;
+ name = pmu->alias_name;
+ if (!name)
+ return false;
+
+ if (!strncmp(name, "uncore_", 7))
+ name += 7;
+
+ return perf_pmu__match_ignoring_suffix(name, tok) ||
+ (need_fnmatch && !fnmatch(tok, name, 0));
}
double __weak perf_pmu__cpu_slots_per_cycle(void)
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 152700f78455..93d03bd3ecbe 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -263,7 +263,7 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
const char *config_name);
void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
-int perf_pmu__match(const char *pattern, const char *name, const char *tok);
+bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok);
double perf_pmu__cpu_slots_per_cycle(void);
int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
--
2.44.0.683.g7961c838ac-goog
next prev parent reply other threads:[~2024-04-16 6:15 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 6:15 [PATCH v2 00/16] Consistently prefer sysfs/json events Ian Rogers
2024-04-16 6:15 ` [PATCH v2 01/16] perf parse-events: Factor out '<event_or_pmu>/.../' parsing Ian Rogers
2024-04-16 6:15 ` [PATCH v2 02/16] perf parse-events: Directly pass PMU to parse_events_add_pmu Ian Rogers
2024-04-16 6:15 ` [PATCH v2 03/16] perf parse-events: Avoid copying an empty list Ian Rogers
2024-04-16 6:15 ` Ian Rogers [this message]
2024-04-16 6:15 ` [PATCH v2 05/16] perf tests parse-events: Use branches rather than cache-references Ian Rogers
2024-04-16 6:15 ` [PATCH v2 06/16] perf parse-events: Legacy cache names on all PMUs and lower priority Ian Rogers
2024-04-16 6:15 ` [PATCH v2 07/16] perf parse-events: Handle PE_TERM_HW in name_or_raw Ian Rogers
2024-04-16 6:15 ` [PATCH v2 08/16] perf parse-events: Constify parse_events_add_numeric Ian Rogers
2024-04-16 6:15 ` [PATCH v2 09/16] perf parse-events: Prefer sysfs/json hardware events over legacy Ian Rogers
2024-04-16 6:15 ` [PATCH v2 10/16] perf parse-events: Inline parse_events_update_lists Ian Rogers
2024-04-16 6:15 ` [PATCH v2 11/16] perf parse-events: Improve error message for bad numbers Ian Rogers
2024-04-18 20:27 ` Liang, Kan
2024-04-18 21:07 ` Ian Rogers
2024-04-19 13:29 ` Liang, Kan
2024-04-27 1:35 ` Arnaldo Carvalho de Melo
2024-04-27 1:36 ` Arnaldo Carvalho de Melo
2024-04-27 22:05 ` Ian Rogers
2024-04-16 6:15 ` [PATCH v2 12/16] perf parse-events: Inline parse_events_evlist_error Ian Rogers
2024-04-16 6:15 ` [PATCH v2 13/16] perf parse-events: Improvements to modifier parsing Ian Rogers
2024-04-18 20:32 ` Liang, Kan
2024-04-19 6:22 ` Ian Rogers
2024-04-19 13:20 ` Liang, Kan
2024-04-24 15:18 ` Ian Rogers
2024-04-24 15:30 ` Liang, Kan
2024-04-16 6:15 ` [PATCH v2 14/16] perf parse-event: Constify event_symbol arrays Ian Rogers
2024-04-16 6:15 ` [PATCH v2 15/16] perf parse-events: Minor grouping tidy up Ian Rogers
2024-04-16 6:15 ` [PATCH v2 16/16] perf parse-events: Tidy the setting of the default event name Ian Rogers
2024-04-24 0:28 ` [PATCH v2 00/16] Consistently prefer sysfs/json events Atish Kumar Patra
2024-04-24 15:14 ` Ian Rogers
2024-04-24 15:34 ` Liang, Kan
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=20240416061533.921723-5-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atishp@rivosinc.com \
--cc=beeman@rivosinc.com \
--cc=bpf@vger.kernel.org \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.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).