diff options
| author | Emmanuel Vadot <manu@FreeBSD.org> | 2019-11-08 16:56:48 +0000 |
|---|---|---|
| committer | Emmanuel Vadot <manu@FreeBSD.org> | 2019-11-08 16:56:48 +0000 |
| commit | a0ac5706af0ef24fb490f1f3c78b81ff977f9d63 (patch) | |
| tree | ce8d5f3148216cc845d25e30e56c2c8057ea2971 /lib/libpmc | |
| parent | 854e90da4e4d304f2b676d0de416ebbcb85c8bba (diff) | |
Notes
Diffstat (limited to 'lib/libpmc')
| -rw-r--r-- | lib/libpmc/libpmc_pmu_util.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c index 591be94520a46..37f6ac0b0bbea 100644 --- a/lib/libpmc/libpmc_pmu_util.c +++ b/lib/libpmc/libpmc_pmu_util.c @@ -165,8 +165,11 @@ struct pmu_event_desc { static const struct pmu_events_map * pmu_events_map_get(const char *cpuid) { - size_t s; + regex_t re; + regmatch_t pmatch[1]; + size_t s, len; char buf[64]; + int match; const struct pmu_events_map *pme; if (cpuid != NULL) { @@ -179,9 +182,20 @@ pmu_events_map_get(const char *cpuid) (void *)NULL, 0) == -1) return (NULL); } - for (pme = pmu_events_map; pme->cpuid != NULL; pme++) - if (strcmp(buf, pme->cpuid) == 0) - return (pme); + for (pme = pmu_events_map; pme->cpuid != NULL; pme++) { + if (regcomp(&re, pme->cpuid, REG_EXTENDED) != 0) { + printf("regex '%s' failed to compile, ignoring\n", + pme->cpuid); + continue; + } + match = regexec(&re, buf, 1, pmatch, 0); + regfree(&re); + if (match == 0) { + len = pmatch[0].rm_eo - pmatch[0].rm_so; + if(len == strlen(buf)) + return (pme); + } + } return (NULL); } |
