Skip to content

Commit 63e2871

Browse files
captain5050namhyung
authored andcommitted
perf pmu: Rename name matching for no suffix or wildcard variants
Wildcard PMU naming will match a name like pmu_1 to a PMU name like pmu_10 but not to a PMU name like pmu_2 as the suffix forms part of the match. No suffix matching will match pmu_10 to either pmu_1 or pmu_2. Add or rename matching functions on PMU to make it clearer what kind of matching is being performed. Signed-off-by: Ian Rogers <[email protected]> Reviewed-by: Kan Liang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 57e1326 commit 63e2871

File tree

6 files changed

+235
-129
lines changed

6 files changed

+235
-129
lines changed

tools/perf/pmu-events/empty-pmu-events.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ int pmu_events_table__for_each_event(const struct pmu_events_table *table,
422422
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
423423
int ret;
424424

425-
if (pmu && !pmu__name_match(pmu, pmu_name))
425+
if (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
426426
continue;
427427

428428
ret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
@@ -443,7 +443,7 @@ int pmu_events_table__find_event(const struct pmu_events_table *table,
443443
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
444444
int ret;
445445

446-
if (!pmu__name_match(pmu, pmu_name))
446+
if (!perf_pmu__name_wildcard_match(pmu, pmu_name))
447447
continue;
448448

449449
ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
@@ -462,7 +462,7 @@ size_t pmu_events_table__num_events(const struct pmu_events_table *table,
462462
const struct pmu_table_entry *table_pmu = &table->pmus[i];
463463
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
464464

465-
if (pmu__name_match(pmu, pmu_name))
465+
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
466466
count += table_pmu->num_entries;
467467
}
468468
return count;
@@ -581,7 +581,7 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu)
581581
const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
582582
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
583583

584-
if (pmu__name_match(pmu, pmu_name))
584+
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
585585
return &map->event_table;
586586
}
587587
return NULL;

tools/perf/pmu-events/jevents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def print_system_mapping_table() -> None:
945945
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
946946
int ret;
947947
948-
if (pmu && !pmu__name_match(pmu, pmu_name))
948+
if (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
949949
continue;
950950
951951
ret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
@@ -966,7 +966,7 @@ def print_system_mapping_table() -> None:
966966
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
967967
int ret;
968968
969-
if (!pmu__name_match(pmu, pmu_name))
969+
if (!perf_pmu__name_wildcard_match(pmu, pmu_name))
970970
continue;
971971
972972
ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
@@ -985,7 +985,7 @@ def print_system_mapping_table() -> None:
985985
const struct pmu_table_entry *table_pmu = &table->pmus[i];
986986
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
987987
988-
if (pmu__name_match(pmu, pmu_name))
988+
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
989989
count += table_pmu->num_entries;
990990
}
991991
return count;
@@ -1104,7 +1104,7 @@ def print_system_mapping_table() -> None:
11041104
const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
11051105
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
11061106
1107-
if (pmu__name_match(pmu, pmu_name))
1107+
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
11081108
return &map->event_table;
11091109
}
11101110
return NULL;

tools/perf/tests/pmu.c

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __
452452
}
453453

454454
/**
455-
* Test perf_pmu__match() that's used to search for a PMU given a name passed
455+
* Test perf_pmu__wildcard_match() that's used to search for a PMU given a name passed
456456
* on the command line. The name that's passed may also be a filename type glob
457-
* match. If the name does not match, perf_pmu__match() attempts to match the
457+
* match. If the name does not match, perf_pmu__wildcard_match() attempts to match the
458458
* alias of the PMU, if provided.
459459
*/
460460
static int test__pmu_match(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
@@ -463,69 +463,72 @@ static int test__pmu_match(struct test_suite *test __maybe_unused, int subtest _
463463
.name = "pmuname",
464464
};
465465

466-
TEST_ASSERT_EQUAL("Exact match", perf_pmu__match(&test_pmu, "pmuname"), true);
467-
TEST_ASSERT_EQUAL("Longer token", perf_pmu__match(&test_pmu, "longertoken"), false);
468-
TEST_ASSERT_EQUAL("Shorter token", perf_pmu__match(&test_pmu, "pmu"), false);
466+
#define TEST_PMU_MATCH(msg, to_match, expect) \
467+
TEST_ASSERT_EQUAL(msg, perf_pmu__wildcard_match(&test_pmu, to_match), expect)
468+
469+
TEST_PMU_MATCH("Exact match", "pmuname", true);
470+
TEST_PMU_MATCH("Longer token", "longertoken", false);
471+
TEST_PMU_MATCH("Shorter token", "pmu", false);
469472

470473
test_pmu.name = "pmuname_10";
471-
TEST_ASSERT_EQUAL("Diff suffix_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
472-
TEST_ASSERT_EQUAL("Sub suffix_", perf_pmu__match(&test_pmu, "pmuname_1"), true);
473-
TEST_ASSERT_EQUAL("Same suffix_", perf_pmu__match(&test_pmu, "pmuname_10"), true);
474-
TEST_ASSERT_EQUAL("No suffix_", perf_pmu__match(&test_pmu, "pmuname"), true);
475-
TEST_ASSERT_EQUAL("Underscore_", perf_pmu__match(&test_pmu, "pmuname_"), true);
476-
TEST_ASSERT_EQUAL("Substring_", perf_pmu__match(&test_pmu, "pmuna"), false);
474+
TEST_PMU_MATCH("Diff suffix_", "pmuname_2", false);
475+
TEST_PMU_MATCH("Sub suffix_", "pmuname_1", true);
476+
TEST_PMU_MATCH("Same suffix_", "pmuname_10", true);
477+
TEST_PMU_MATCH("No suffix_", "pmuname", true);
478+
TEST_PMU_MATCH("Underscore_", "pmuname_", true);
479+
TEST_PMU_MATCH("Substring_", "pmuna", false);
477480

478481
test_pmu.name = "pmuname_ab23";
479-
TEST_ASSERT_EQUAL("Diff suffix hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
480-
TEST_ASSERT_EQUAL("Sub suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab"), true);
481-
TEST_ASSERT_EQUAL("Same suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab23"), true);
482-
TEST_ASSERT_EQUAL("No suffix hex_", perf_pmu__match(&test_pmu, "pmuname"), true);
483-
TEST_ASSERT_EQUAL("Underscore hex_", perf_pmu__match(&test_pmu, "pmuname_"), true);
484-
TEST_ASSERT_EQUAL("Substring hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
482+
TEST_PMU_MATCH("Diff suffix hex_", "pmuname_2", false);
483+
TEST_PMU_MATCH("Sub suffix hex_", "pmuname_ab", true);
484+
TEST_PMU_MATCH("Same suffix hex_", "pmuname_ab23", true);
485+
TEST_PMU_MATCH("No suffix hex_", "pmuname", true);
486+
TEST_PMU_MATCH("Underscore hex_", "pmuname_", true);
487+
TEST_PMU_MATCH("Substring hex_", "pmuna", false);
485488

486489
test_pmu.name = "pmuname10";
487-
TEST_ASSERT_EQUAL("Diff suffix", perf_pmu__match(&test_pmu, "pmuname2"), false);
488-
TEST_ASSERT_EQUAL("Sub suffix", perf_pmu__match(&test_pmu, "pmuname1"), true);
489-
TEST_ASSERT_EQUAL("Same suffix", perf_pmu__match(&test_pmu, "pmuname10"), true);
490-
TEST_ASSERT_EQUAL("No suffix", perf_pmu__match(&test_pmu, "pmuname"), true);
491-
TEST_ASSERT_EQUAL("Underscore", perf_pmu__match(&test_pmu, "pmuname_"), false);
492-
TEST_ASSERT_EQUAL("Substring", perf_pmu__match(&test_pmu, "pmuna"), false);
490+
TEST_PMU_MATCH("Diff suffix", "pmuname2", false);
491+
TEST_PMU_MATCH("Sub suffix", "pmuname1", true);
492+
TEST_PMU_MATCH("Same suffix", "pmuname10", true);
493+
TEST_PMU_MATCH("No suffix", "pmuname", true);
494+
TEST_PMU_MATCH("Underscore", "pmuname_", false);
495+
TEST_PMU_MATCH("Substring", "pmuna", false);
493496

494497
test_pmu.name = "pmunameab23";
495-
TEST_ASSERT_EQUAL("Diff suffix hex", perf_pmu__match(&test_pmu, "pmuname2"), false);
496-
TEST_ASSERT_EQUAL("Sub suffix hex", perf_pmu__match(&test_pmu, "pmunameab"), true);
497-
TEST_ASSERT_EQUAL("Same suffix hex", perf_pmu__match(&test_pmu, "pmunameab23"), true);
498-
TEST_ASSERT_EQUAL("No suffix hex", perf_pmu__match(&test_pmu, "pmuname"), true);
499-
TEST_ASSERT_EQUAL("Underscore hex", perf_pmu__match(&test_pmu, "pmuname_"), false);
500-
TEST_ASSERT_EQUAL("Substring hex", perf_pmu__match(&test_pmu, "pmuna"), false);
498+
TEST_PMU_MATCH("Diff suffix hex", "pmuname2", false);
499+
TEST_PMU_MATCH("Sub suffix hex", "pmunameab", true);
500+
TEST_PMU_MATCH("Same suffix hex", "pmunameab23", true);
501+
TEST_PMU_MATCH("No suffix hex", "pmuname", true);
502+
TEST_PMU_MATCH("Underscore hex", "pmuname_", false);
503+
TEST_PMU_MATCH("Substring hex", "pmuna", false);
501504

502505
/*
503506
* 2 hex chars or less are not considered suffixes so it shouldn't be
504507
* possible to wildcard by skipping the suffix. Therefore there are more
505508
* false results here than above.
506509
*/
507510
test_pmu.name = "pmuname_a3";
508-
TEST_ASSERT_EQUAL("Diff suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
511+
TEST_PMU_MATCH("Diff suffix 2 hex_", "pmuname_2", false);
509512
/*
510513
* This one should be false, but because pmuname_a3 ends in 3 which is
511514
* decimal, it's not possible to determine if it's a short hex suffix or
512515
* a normal decimal suffix following text. And we want to match on any
513516
* length of decimal suffix. Run the test anyway and expect the wrong
514517
* result. And slightly fuzzy matching shouldn't do too much harm.
515518
*/
516-
TEST_ASSERT_EQUAL("Sub suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a"), true);
517-
TEST_ASSERT_EQUAL("Same suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a3"), true);
518-
TEST_ASSERT_EQUAL("No suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname"), false);
519-
TEST_ASSERT_EQUAL("Underscore 2 hex_", perf_pmu__match(&test_pmu, "pmuname_"), false);
520-
TEST_ASSERT_EQUAL("Substring 2 hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
519+
TEST_PMU_MATCH("Sub suffix 2 hex_", "pmuname_a", true);
520+
TEST_PMU_MATCH("Same suffix 2 hex_", "pmuname_a3", true);
521+
TEST_PMU_MATCH("No suffix 2 hex_", "pmuname", false);
522+
TEST_PMU_MATCH("Underscore 2 hex_", "pmuname_", false);
523+
TEST_PMU_MATCH("Substring 2 hex_", "pmuna", false);
521524

522525
test_pmu.name = "pmuname_5";
523-
TEST_ASSERT_EQUAL("Glob 1", perf_pmu__match(&test_pmu, "pmu*"), true);
524-
TEST_ASSERT_EQUAL("Glob 2", perf_pmu__match(&test_pmu, "nomatch*"), false);
525-
TEST_ASSERT_EQUAL("Seq 1", perf_pmu__match(&test_pmu, "pmuname_[12345]"), true);
526-
TEST_ASSERT_EQUAL("Seq 2", perf_pmu__match(&test_pmu, "pmuname_[67890]"), false);
527-
TEST_ASSERT_EQUAL("? 1", perf_pmu__match(&test_pmu, "pmuname_?"), true);
528-
TEST_ASSERT_EQUAL("? 2", perf_pmu__match(&test_pmu, "pmuname_1?"), false);
526+
TEST_PMU_MATCH("Glob 1", "pmu*", true);
527+
TEST_PMU_MATCH("Glob 2", "nomatch*", false);
528+
TEST_PMU_MATCH("Seq 1", "pmuname_[12345]", true);
529+
TEST_PMU_MATCH("Seq 2", "pmuname_[67890]", false);
530+
TEST_PMU_MATCH("? 1", "pmuname_?", true);
531+
TEST_PMU_MATCH("? 2", "pmuname_1?", false);
529532

530533
return TEST_OK;
531534
}

tools/perf/util/parse-events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
16601660
/* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */
16611661
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
16621662
if (!parse_events__filter_pmu(parse_state, pmu) &&
1663-
perf_pmu__match(pmu, event_or_pmu)) {
1663+
perf_pmu__wildcard_match(pmu, event_or_pmu)) {
16641664
bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu);
16651665

16661666
if (!parse_events_add_pmu(parse_state, *listp, pmu,

0 commit comments

Comments
 (0)