Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string

This makes the logic a bit clear by avoiding the !strcmp() pattern and
also a way to intercept the pointer if we need to do extra validation on
it or to do lazy setting of evsel->name via evsel__name(evsel).

Reviewed-by: "Liang, Kan" <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/ZEGLM8VehJbS0gP2@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+31 -25
+2 -2
tools/perf/arch/arm64/util/kvm-stat.c
··· 44 44 struct perf_sample *sample __maybe_unused, 45 45 struct event_key *key __maybe_unused) 46 46 { 47 - return !strcmp(evsel->name, kvm_entry_trace); 47 + return evsel__name_is(evsel, kvm_entry_trace); 48 48 } 49 49 50 50 static bool event_end(struct evsel *evsel, 51 51 struct perf_sample *sample, 52 52 struct event_key *key) 53 53 { 54 - if (!strcmp(evsel->name, kvm_exit_trace)) { 54 + if (evsel__name_is(evsel, kvm_exit_trace)) { 55 55 event_get_key(evsel, sample, key); 56 56 return true; 57 57 }
+2 -2
tools/perf/arch/powerpc/util/kvm-stat.c
··· 60 60 struct perf_sample *sample __maybe_unused, 61 61 struct event_key *key __maybe_unused) 62 62 { 63 - return (!strcmp(evsel->name, kvm_events_tp[3])); 63 + return (evsel__name_is(evsel, kvm_events_tp[3])); 64 64 } 65 65 66 66 static bool hcall_event_begin(struct evsel *evsel, 67 67 struct perf_sample *sample, struct event_key *key) 68 68 { 69 - if (!strcmp(evsel->name, kvm_events_tp[2])) { 69 + if (evsel__name_is(evsel, kvm_events_tp[2])) { 70 70 hcall_event_get_key(evsel, sample, key); 71 71 return true; 72 72 }
+4 -4
tools/perf/arch/x86/util/kvm-stat.c
··· 46 46 return true; 47 47 48 48 /* MMIO write begin event in kernel. */ 49 - if (!strcmp(evsel->name, "kvm:kvm_mmio") && 49 + if (evsel__name_is(evsel, "kvm:kvm_mmio") && 50 50 evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { 51 51 mmio_event_get_key(evsel, sample, key); 52 52 return true; ··· 63 63 return true; 64 64 65 65 /* MMIO read end event in kernel.*/ 66 - if (!strcmp(evsel->name, "kvm:kvm_mmio") && 66 + if (evsel__name_is(evsel, "kvm:kvm_mmio") && 67 67 evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { 68 68 mmio_event_get_key(evsel, sample, key); 69 69 return true; ··· 101 101 struct perf_sample *sample, 102 102 struct event_key *key) 103 103 { 104 - if (!strcmp(evsel->name, "kvm:kvm_pio")) { 104 + if (evsel__name_is(evsel, "kvm:kvm_pio")) { 105 105 ioport_event_get_key(evsel, sample, key); 106 106 return true; 107 107 } ··· 145 145 struct perf_sample *sample, 146 146 struct event_key *key) 147 147 { 148 - if (!strcmp(evsel->name, "kvm:kvm_msr")) { 148 + if (evsel__name_is(evsel, "kvm:kvm_msr")) { 149 149 msr_event_get_key(evsel, sample, key); 150 150 return true; 151 151 }
+3 -3
tools/perf/builtin-kvm.c
··· 625 625 626 626 bool kvm_exit_event(struct evsel *evsel) 627 627 { 628 - return !strcmp(evsel->name, kvm_exit_trace); 628 + return evsel__name_is(evsel, kvm_exit_trace); 629 629 } 630 630 631 631 bool exit_event_begin(struct evsel *evsel, ··· 641 641 642 642 bool kvm_entry_event(struct evsel *evsel) 643 643 { 644 - return !strcmp(evsel->name, kvm_entry_trace); 644 + return evsel__name_is(evsel, kvm_entry_trace); 645 645 } 646 646 647 647 bool exit_event_end(struct evsel *evsel, ··· 878 878 return false; 879 879 880 880 for (; child_ops->name; child_ops++) { 881 - if (!strcmp(evsel->name, child_ops->name)) { 881 + if (evsel__name_is(evsel, child_ops->name)) { 882 882 child_ops->get_key(evsel, sample, key); 883 883 return true; 884 884 }
+1 -1
tools/perf/builtin-stat.c
··· 2170 2170 2171 2171 evlist__for_each_entry(evsel_list, counter) { 2172 2172 if (!counter->core.requires_cpu && 2173 - strcmp(counter->name, "duration_time")) { 2173 + !evsel__name_is(counter, "duration_time")) { 2174 2174 return; 2175 2175 } 2176 2176 }
+1 -1
tools/perf/tests/expand-cgroup.c
··· 61 61 62 62 i = 0; 63 63 evlist__for_each_entry(evlist, evsel) { 64 - if (strcmp(evsel->name, ev_name[i % nr_events])) { 64 + if (!evsel__name_is(evsel, ev_name[i % nr_events])) { 65 65 pr_debug("event name doesn't match:\n"); 66 66 pr_debug(" evsel[%d]: %s\n expected: %s\n", 67 67 i, evsel->name, ev_name[i % nr_events]);
+6 -6
tools/perf/tests/parse-events.c
··· 1401 1401 { 1402 1402 struct evsel *evsel = evlist__first(evlist); 1403 1403 1404 - TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0); 1404 + TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn")); 1405 1405 return TEST_OK; 1406 1406 } 1407 1407 ··· 1409 1409 { 1410 1410 struct evsel *evsel = evlist__first(evlist); 1411 1411 1412 - TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0); 1412 + TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu")); 1413 1413 return TEST_OK; 1414 1414 } 1415 1415 ··· 1417 1417 { 1418 1418 struct evsel *evsel = evlist__first(evlist); 1419 1419 1420 - TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0); 1420 + TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu")); 1421 1421 return TEST_OK; 1422 1422 } 1423 1423 ··· 1425 1425 { 1426 1426 struct evsel *evsel = evlist__first(evlist); 1427 1427 1428 - TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0); 1428 + TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu")); 1429 1429 return TEST_OK; 1430 1430 } 1431 1431 ··· 1438 1438 { 1439 1439 struct evsel *evsel = evlist__first(evlist); 1440 1440 1441 - TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0); 1441 + TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u")); 1442 1442 return TEST_OK; 1443 1443 } 1444 1444 ··· 1446 1446 { 1447 1447 struct evsel *evsel = evlist__first(evlist); 1448 1448 1449 - TEST_ASSERT_VAL("wrong complex name parsing", strcmp(evsel->name, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks") == 0); 1449 + TEST_ASSERT_VAL("wrong complex name parsing", evsel__name_is(evsel, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks")); 1450 1450 return TEST_OK; 1451 1451 } 1452 1452
+1 -1
tools/perf/tests/parse-metric.c
··· 39 39 evlist__for_each_entry(evlist, evsel) { 40 40 count = find_value(evsel->name, vals); 41 41 evsel->stats->aggr->counts.val = count; 42 - if (!strcmp(evsel->name, "duration_time")) 42 + if (evsel__name_is(evsel, "duration_time")) 43 43 update_stats(&walltime_nsecs_stats, count); 44 44 } 45 45 }
+1 -1
tools/perf/tests/pmu-events.c
··· 866 866 evlist__alloc_aggr_stats(evlist, 1); 867 867 evlist__for_each_entry(evlist, evsel) { 868 868 evsel->stats->aggr->counts.val = k; 869 - if (!strcmp(evsel->name, "duration_time")) 869 + if (evsel__name_is(evsel, "duration_time")) 870 870 update_stats(&walltime_nsecs_stats, k); 871 871 k++; 872 872 }
+2 -2
tools/perf/util/evlist.c
··· 467 467 return 0; 468 468 if (evsel__is_dummy_event(pos)) 469 469 return 1; 470 - return strcmp(pos->name, evsel_name); 470 + return !evsel__name_is(pos, evsel_name); 471 471 } 472 472 473 473 static int evlist__is_enabled(struct evlist *evlist) ··· 1706 1706 evlist__for_each_entry(evlist, evsel) { 1707 1707 if (!evsel->name) 1708 1708 continue; 1709 - if (strcmp(str, evsel->name) == 0) 1709 + if (evsel__name_is(evsel, str)) 1710 1710 return evsel; 1711 1711 } 1712 1712
+6 -1
tools/perf/util/evsel.c
··· 821 821 return "unknown"; 822 822 } 823 823 824 + bool evsel__name_is(struct evsel *evsel, const char *name) 825 + { 826 + return !strcmp(evsel__name(evsel), name); 827 + } 828 + 824 829 const char *evsel__group_pmu_name(const struct evsel *evsel) 825 830 { 826 831 const struct evsel *leader; ··· 1151 1146 1152 1147 static bool evsel__is_offcpu_event(struct evsel *evsel) 1153 1148 { 1154 - return evsel__is_bpf_output(evsel) && !strcmp(evsel->name, OFFCPU_EVENT); 1149 + return evsel__is_bpf_output(evsel) && evsel__name_is(evsel, OFFCPU_EVENT); 1155 1150 } 1156 1151 1157 1152 /*
+1
tools/perf/util/evsel.h
··· 282 282 283 283 int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size); 284 284 const char *evsel__name(struct evsel *evsel); 285 + bool evsel__name_is(struct evsel *evsel, const char *name); 285 286 const char *evsel__group_pmu_name(const struct evsel *evsel); 286 287 const char *evsel__metric_id(const struct evsel *evsel); 287 288
+1 -1
tools/perf/util/sort.c
··· 2893 2893 full_name = !!strchr(event_name, ':'); 2894 2894 evlist__for_each_entry(evlist, pos) { 2895 2895 /* case 2 */ 2896 - if (full_name && !strcmp(pos->name, event_name)) 2896 + if (full_name && evsel__name_is(pos, event_name)) 2897 2897 return pos; 2898 2898 /* case 3 */ 2899 2899 if (!full_name && strstr(pos->name, event_name)) {