perf evsel: Use evsel__name_is() helper
authorYang Jihong <yangjihong@bytedance.com>
Mon, 1 Apr 2024 06:27:24 +0000 (14:27 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Apr 2024 14:48:56 +0000 (11:48 -0300)
Code cleanup, replace strcmp(evsel__name(evsel, {NAME})) with
evsel__name_is() helper.

No functional change.

Committer notes:

Fix this build error:

          trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
  -       assert(evsel__name_is(trace.syscalls.events.bpf_output), "__augmented_syscalls__");
  +       assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__"));

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240401062724.1006010-3-yangjihong@bytedance.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kmem.c
tools/perf/builtin-sched.c
tools/perf/builtin-script.c
tools/perf/builtin-trace.c
tools/perf/tests/evsel-roundtrip-name.c
tools/perf/tests/parse-events.c

index 9714327fd0eadd1b8dd58d83443668d0d2acd052..6fd95be5032b0e98a6cd7707974ae1bf7e4d4f34 100644 (file)
@@ -1408,7 +1408,7 @@ static int __cmd_kmem(struct perf_session *session)
        }
 
        evlist__for_each_entry(session->evlist, evsel) {
-               if (!strcmp(evsel__name(evsel), "kmem:mm_page_alloc") &&
+               if (evsel__name_is(evsel, "kmem:mm_page_alloc") &&
                    evsel__field(evsel, "pfn")) {
                        use_pfn = true;
                        break;
index 1bfb2234737150797f7434e8f22298ae02bc34c1..0fce7d8986c0741cb676d16c17bc1ad34a59aeb5 100644 (file)
@@ -2148,7 +2148,7 @@ static bool is_idle_sample(struct perf_sample *sample,
                           struct evsel *evsel)
 {
        /* pid 0 == swapper == idle task */
-       if (strcmp(evsel__name(evsel), "sched:sched_switch") == 0)
+       if (evsel__name_is(evsel, "sched:sched_switch"))
                return evsel__intval(evsel, sample, "prev_pid") == 0;
 
        return sample->pid == 0;
@@ -2375,7 +2375,7 @@ static bool timehist_skip_sample(struct perf_sched *sched,
        }
 
        if (sched->idle_hist) {
-               if (strcmp(evsel__name(evsel), "sched:sched_switch"))
+               if (!evsel__name_is(evsel, "sched:sched_switch"))
                        rc = true;
                else if (evsel__intval(evsel, sample, "prev_pid") != 0 &&
                         evsel__intval(evsel, sample, "next_pid") != 0)
index 2e7148d667bd21e4696883e6692c9c53bd6d7cfc..6a274e27b1087dbf734befdd3a3875049f63f60c 100644 (file)
@@ -3471,7 +3471,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
 
                        match = 0;
                        evlist__for_each_entry(session->evlist, pos) {
-                               if (!strcmp(evsel__name(pos), evname)) {
+                               if (evsel__name_is(pos, evname)) {
                                        match = 1;
                                        break;
                                }
index d3ec244e692a415e9ee9804aa4b364bbad7342aa..e5fef39c34bf40ff4cb66ba02db6a360dc1e8aae 100644 (file)
@@ -4916,7 +4916,7 @@ int cmd_trace(int argc, const char **argv)
                goto out;
        }
        trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
-       assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
+       assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__"));
 skip_augmentation:
 #endif
        err = -1;
@@ -4973,7 +4973,7 @@ skip_augmentation:
         */
        if (trace.syscalls.events.bpf_output) {
                evlist__for_each_entry(trace.evlist, evsel) {
-                       bool raw_syscalls_sys_exit = strcmp(evsel__name(evsel), "raw_syscalls:sys_exit") == 0;
+                       bool raw_syscalls_sys_exit = evsel__name_is(evsel, "raw_syscalls:sys_exit");
 
                        if (raw_syscalls_sys_exit) {
                                trace.raw_augmented_syscalls = true;
index 15ff86f9da0b1d94080c233a5b5a0e84e113aa13..1922cac13a24530c1d6a3e483e87122d50f83f54 100644 (file)
@@ -37,7 +37,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
                                        continue;
                                }
                                evlist__for_each_entry(evlist, evsel) {
-                                       if (strcmp(evsel__name(evsel), name)) {
+                                       if (!evsel__name_is(evsel, name)) {
                                                pr_debug("%s != %s\n", evsel__name(evsel), name);
                                                ret = TEST_FAIL;
                                        }
@@ -71,7 +71,7 @@ static int perf_evsel__name_array_test(const char *const names[], int nr_names)
                        continue;
                }
                evlist__for_each_entry(evlist, evsel) {
-                       if (strcmp(evsel__name(evsel), names[i])) {
+                       if (!evsel__name_is(evsel, names[i])) {
                                pr_debug("%s != %s\n", evsel__name(evsel), names[i]);
                                ret = TEST_FAIL;
                        }
index feb5727584d141632b76a4b82be3976dc305a2bc..0b70451451b3793892c2ff6a680276c6358a3270 100644 (file)
@@ -470,8 +470,7 @@ static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "mem:0:u"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:u"));
 
        return test__checkevent_breakpoint(evlist);
 }
@@ -484,8 +483,7 @@ static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "mem:0:x:k"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:x:k"));
 
        return test__checkevent_breakpoint_x(evlist);
 }
@@ -498,8 +496,7 @@ static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "mem:0:r:hp"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:r:hp"));
 
        return test__checkevent_breakpoint_r(evlist);
 }
@@ -512,8 +509,7 @@ static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "mem:0:w:up"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:w:up"));
 
        return test__checkevent_breakpoint_w(evlist);
 }
@@ -526,8 +522,7 @@ static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:rw:kp"));
 
        return test__checkevent_breakpoint_rw(evlist);
 }
@@ -540,8 +535,7 @@ static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "breakpoint"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));
 
        return test__checkevent_breakpoint(evlist);
 }
@@ -554,8 +548,7 @@ static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "breakpoint"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));
 
        return test__checkevent_breakpoint_x(evlist);
 }
@@ -568,8 +561,7 @@ static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "breakpoint"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));
 
        return test__checkevent_breakpoint_r(evlist);
 }
@@ -582,8 +574,7 @@ static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "breakpoint"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));
 
        return test__checkevent_breakpoint_w(evlist);
 }
@@ -596,8 +587,7 @@ static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
        TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "breakpoint"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));
 
        return test__checkevent_breakpoint_rw(evlist);
 }
@@ -609,12 +599,12 @@ static int test__checkevent_breakpoint_2_events(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
 
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
-       TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint1"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint1"));
 
        evsel = evsel__next(evsel);
 
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
-       TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint2"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint2"));
 
        return TEST_OK;
 }
@@ -691,15 +681,14 @@ static int test__checkevent_pmu_name(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
        TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
-       TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "krava"));
 
        /* cpu/config=2/u" */
        evsel = evsel__next(evsel);
        TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
        TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
-       TEST_ASSERT_VAL("wrong name",
-                       !strcmp(evsel__name(evsel), "cpu/config=2/u"));
+       TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "cpu/config=2/u"));
 
        return TEST_OK;
 }