|
3 | 3 | #include <linux/compiler.h> |
4 | 4 | #include <linux/string.h> |
5 | 5 | #include <linux/zalloc.h> |
| 6 | +#include <linux/ctype.h> |
6 | 7 | #include <subcmd/pager.h> |
7 | 8 | #include <sys/types.h> |
8 | 9 | #include <errno.h> |
|
17 | 18 | #include <locale.h> |
18 | 19 | #include <regex.h> |
19 | 20 | #include <perf/cpumap.h> |
| 21 | +#include <fnmatch.h> |
20 | 22 | #include "debug.h" |
21 | 23 | #include "evsel.h" |
22 | 24 | #include "pmu.h" |
@@ -740,6 +742,27 @@ struct pmu_events_map *__weak pmu_events_map__find(void) |
740 | 742 | return perf_pmu__find_map(NULL); |
741 | 743 | } |
742 | 744 |
|
| 745 | +static bool perf_pmu__valid_suffix(char *pmu_name, char *tok) |
| 746 | +{ |
| 747 | + char *p; |
| 748 | + |
| 749 | + if (strncmp(pmu_name, tok, strlen(tok))) |
| 750 | + return false; |
| 751 | + |
| 752 | + p = pmu_name + strlen(tok); |
| 753 | + if (*p == 0) |
| 754 | + return true; |
| 755 | + |
| 756 | + if (*p != '_') |
| 757 | + return false; |
| 758 | + |
| 759 | + ++p; |
| 760 | + if (*p == 0 || !isdigit(*p)) |
| 761 | + return false; |
| 762 | + |
| 763 | + return true; |
| 764 | +} |
| 765 | + |
743 | 766 | bool pmu_uncore_alias_match(const char *pmu_name, const char *name) |
744 | 767 | { |
745 | 768 | char *tmp = NULL, *tok, *str; |
@@ -768,7 +791,7 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) |
768 | 791 | */ |
769 | 792 | for (; tok; name += strlen(tok), tok = strtok_r(NULL, ",", &tmp)) { |
770 | 793 | name = strstr(name, tok); |
771 | | - if (!name) { |
| 794 | + if (!name || !perf_pmu__valid_suffix((char *)name, tok)) { |
772 | 795 | res = false; |
773 | 796 | goto out; |
774 | 797 | } |
@@ -1872,3 +1895,14 @@ bool perf_pmu__has_hybrid(void) |
1872 | 1895 |
|
1873 | 1896 | return !list_empty(&perf_pmu__hybrid_pmus); |
1874 | 1897 | } |
| 1898 | + |
| 1899 | +int perf_pmu__match(char *pattern, char *name, char *tok) |
| 1900 | +{ |
| 1901 | + if (fnmatch(pattern, name, 0)) |
| 1902 | + return -1; |
| 1903 | + |
| 1904 | + if (tok && !perf_pmu__valid_suffix(name, tok)) |
| 1905 | + return -1; |
| 1906 | + |
| 1907 | + return 0; |
| 1908 | +} |
0 commit comments