linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] perf pmu: Add pmu name wildcards matching function
@ 2021-06-30 12:09 Jin Yao
  2021-06-30 12:09 ` [PATCH v2 2/2] perf tools: Fix pattern matching for same substring in different pmu type Jin Yao
  0 siblings, 1 reply; 4+ messages in thread
From: Jin Yao @ 2021-06-30 12:09 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Wildcards is supported on pmu name for dynamic pmu events
(e.g. uncore events). Now move the pmu name wildcards matching
to a new function perf_pmu__pattern_match().

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/util/parse-events.y |  7 +------
 tools/perf/util/pmu.c          | 16 ++++++++++++++++
 tools/perf/util/pmu.h          |  1 +
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index aba12a4d488e..6d467ce745d8 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -311,12 +311,7 @@ event_pmu_name opt_pmu_config
 			CLEANUP_YYABORT;
 
 		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
-			char *name = pmu->name;
-
-			if (!strncmp(name, "uncore_", 7) &&
-			    strncmp($1, "uncore_", 7))
-				name += 7;
-			if (!fnmatch(pattern, name, 0)) {
+			if (!perf_pmu__pattern_match(pmu, pattern, $1)) {
 				if (parse_events_copy_term_list(orig_terms, &terms))
 					CLEANUP_YYABORT;
 				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 88c8ecdc60b0..96f5ff9b5440 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -17,6 +17,7 @@
 #include <locale.h>
 #include <regex.h>
 #include <perf/cpumap.h>
+#include <fnmatch.h>
 #include "debug.h"
 #include "evsel.h"
 #include "pmu.h"
@@ -1872,3 +1873,18 @@ bool perf_pmu__has_hybrid(void)
 
 	return !list_empty(&perf_pmu__hybrid_pmus);
 }
+
+int perf_pmu__pattern_match(struct perf_pmu *pmu, char *pattern, char *tok)
+{
+	char *name = pmu->name;
+
+	if (!strncmp(name, "uncore_", 7) &&
+	    strncmp(tok, "uncore_", 7)) {
+		name += 7;
+	}
+
+	if (fnmatch(pattern, name, 0))
+		return -1;
+
+	return 0;
+}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index a790ef758171..1b08e706d6e9 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -133,5 +133,6 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
 				   char *name);
 
 bool perf_pmu__has_hybrid(void);
+int perf_pmu__pattern_match(struct perf_pmu *pmu, char *pattern, char *tok);
 
 #endif /* __PMU_H */
-- 
2.17.1


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

end of thread, other threads:[~2021-07-01  1:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 12:09 [PATCH v2 1/2] perf pmu: Add pmu name wildcards matching function Jin Yao
2021-06-30 12:09 ` [PATCH v2 2/2] perf tools: Fix pattern matching for same substring in different pmu type Jin Yao
2021-06-30 19:18   ` Liang, Kan
2021-07-01  1:22     ` Jin, Yao

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