]> git.baikalelectronics.ru Git - kernel.git/commitdiff
perf tools: Do not pass NULL to parse_events()
authorAdrian Hunter <adrian.hunter@intel.com>
Tue, 9 Aug 2022 08:07:02 +0000 (11:07 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Aug 2022 17:30:09 +0000 (14:30 -0300)
Many cases do not use the extra error information provided by
parse_events and instead pass NULL as the struct parse_events_error
pointer. Add a wrapper for those cases so that the pointer is never
NULL.

Signed-off-by: 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/r/20220809080702.6921-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
22 files changed:
tools/perf/arch/arm/util/cs-etm.c
tools/perf/arch/arm64/util/arm-spe.c
tools/perf/arch/x86/tests/intel-cqm.c
tools/perf/arch/x86/util/intel-bts.c
tools/perf/arch/x86/util/intel-pt.c
tools/perf/arch/x86/util/iostat.c
tools/perf/arch/x86/util/topdown.c
tools/perf/tests/code-reading.c
tools/perf/tests/event-times.c
tools/perf/tests/evsel-roundtrip-name.c
tools/perf/tests/hists_cumulate.c
tools/perf/tests/hists_filter.c
tools/perf/tests/hists_link.c
tools/perf/tests/hists_output.c
tools/perf/tests/keep-tracking.c
tools/perf/tests/perf-time-to-tsc.c
tools/perf/tests/switch-tracking.c
tools/perf/util/bpf-loader.c
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/perf_api_probe.c
tools/perf/util/record.c

index 1b54638d53b06bff61c7d63fda5d59f56a5c049c..a346d5f3dafabb4f63ac3b257b208112e1dd1470 100644 (file)
@@ -438,7 +438,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
        if (opts->full_auxtrace) {
                struct evsel *tracking_evsel;
 
-               err = parse_events(evlist, "dummy:u", NULL);
+               err = parse_event(evlist, "dummy:u");
                if (err)
                        goto out;
 
index 6f4db2ac5420574696a19bf9e80ffe654a436490..d4c234076541a53fb1abc0b10959e7b5f02bfb17 100644 (file)
@@ -257,7 +257,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
                evsel__set_sample_bit(arm_spe_evsel, PHYS_ADDR);
 
        /* Add dummy event to keep tracking */
-       err = parse_events(evlist, "dummy:u", NULL);
+       err = parse_event(evlist, "dummy:u");
        if (err)
                return err;
 
index cb5b2c6c3b3b755a7cbaff235730218a3f954923..360a082fc9280f87d3f3fa9069d2a7e50a42e79d 100644 (file)
@@ -56,7 +56,7 @@ int test__intel_cqm_count_nmi_context(struct test_suite *test __maybe_unused, in
                return TEST_FAIL;
        }
 
-       ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL);
+       ret = parse_event(evlist, "intel_cqm/llc_occupancy/");
        if (ret) {
                pr_debug("parse_events failed, is \"intel_cqm/llc_occupancy/\" available?\n");
                err = TEST_SKIP;
index bcccfbade5c672d7e78208aa46aff7c734807fcf..439c2956f3e786a02dd9cbf938a4f216b880a7cb 100644 (file)
@@ -233,7 +233,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
                struct evsel *tracking_evsel;
                int err;
 
-               err = parse_events(evlist, "dummy:u", NULL);
+               err = parse_event(evlist, "dummy:u");
                if (err)
                        return err;
 
index 06c2cdfd8f2fa7d5053021cf89a6ed9a56adb611..13933020a79eb182d26916108d1ca4505582348e 100644 (file)
@@ -426,7 +426,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
        if (!evlist__can_select_event(evlist, sched_switch))
                return -EPERM;
 
-       err = parse_events(evlist, sched_switch, NULL);
+       err = parse_event(evlist, sched_switch);
        if (err) {
                pr_debug2("%s: failed to parse %s, error %d\n",
                          __func__, sched_switch, err);
index 792cd75ade33d8707dd9dcab36962d5244c0977b..404de795ec0bf57f058c96214f89b6edd214344e 100644 (file)
@@ -316,7 +316,7 @@ static int iostat_event_group(struct evlist *evl,
                sprintf(iostat_cmd, iostat_cmd_template,
                        list->rps[idx]->pmu_idx, list->rps[idx]->pmu_idx,
                        list->rps[idx]->pmu_idx, list->rps[idx]->pmu_idx);
-               ret = parse_events(evl, iostat_cmd, NULL);
+               ret = parse_event(evl, iostat_cmd);
                if (ret)
                        goto err;
        }
index 67c5243241256385328ead8479671aaef722ac02..54810f9acd6f8469c0adbb642cb5e109325a2da5 100644 (file)
@@ -122,5 +122,5 @@ int topdown_parse_events(struct evlist *evlist)
                        topdown_events = TOPDOWN_L1_EVENTS;
        }
 
-       return parse_events(evlist, topdown_events, NULL);
+       return parse_event(evlist, topdown_events);
 }
index 5610767b407f013545705ba151cf353fd2038ca5..95feb6ef34a0aaa5325af0939fe2ce99bf10a598 100644 (file)
@@ -638,7 +638,7 @@ static int do_test_code_reading(bool try_kcore)
 
                str = do_determine_event(excl_kernel);
                pr_debug("Parsing event '%s'\n", str);
-               ret = parse_events(evlist, str, NULL);
+               ret = parse_event(evlist, str);
                if (ret < 0) {
                        pr_debug("parse_events failed\n");
                        goto out_put;
index 7606eb3df92f06f51e4b254dc9a35e28f19c51bd..e155f0e0e04d55532b91b653c7922e8f0b3b7b79 100644 (file)
@@ -174,7 +174,7 @@ static int test_times(int (attach)(struct evlist *),
                goto out_err;
        }
 
-       err = parse_events(evlist, "cpu-clock:u", NULL);
+       err = parse_event(evlist, "cpu-clock:u");
        if (err) {
                pr_debug("failed to parse event cpu-clock:u\n");
                goto out_err;
index 9d3c64974f7783d0f37573bc3a841f570965dfdd..e94fed901992b285000242985ce9f08c3d2e937d 100644 (file)
@@ -27,7 +27,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
 
                        for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
                                __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
-                               err = parse_events(evlist, name, NULL);
+                               err = parse_event(evlist, name);
                                if (err)
                                        ret = err;
                        }
@@ -75,7 +75,7 @@ static int __perf_evsel__name_array_test(const char *const names[], int nr_names
                 return -ENOMEM;
 
        for (i = 0; i < nr_names; ++i) {
-               err = parse_events(evlist, names[i], NULL);
+               err = parse_event(evlist, names[i]);
                if (err) {
                        pr_debug("failed to parse event '%s', err %d\n",
                                 names[i], err);
index 17f4fcd6bdcebce824bf30626a9d39f6660d1ecd..b42d37ff23993229ac91d74750801a24ea6e4c6d 100644 (file)
@@ -706,7 +706,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
 
        TEST_ASSERT_VAL("No memory", evlist);
 
-       err = parse_events(evlist, "cpu-clock", NULL);
+       err = parse_event(evlist, "cpu-clock");
        if (err)
                goto out;
        err = TEST_FAIL;
index 08cbeb9e39ae1b37846bd7099301d2ad75f9c32a..8e1ceeb9b7b6da7edb5fdc0b12c8f0279acb218c 100644 (file)
@@ -111,10 +111,10 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
 
        TEST_ASSERT_VAL("No memory", evlist);
 
-       err = parse_events(evlist, "cpu-clock", NULL);
+       err = parse_event(evlist, "cpu-clock");
        if (err)
                goto out;
-       err = parse_events(evlist, "task-clock", NULL);
+       err = parse_event(evlist, "task-clock");
        if (err)
                goto out;
        err = TEST_FAIL;
index c575e13a850dc65b8e1faf1cde56d99a1277a4f7..14b2ff808b5e68965bf7acacf872383fc9fff26d 100644 (file)
@@ -276,10 +276,10 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
        if (evlist == NULL)
                 return -ENOMEM;
 
-       err = parse_events(evlist, "cpu-clock", NULL);
+       err = parse_event(evlist, "cpu-clock");
        if (err)
                goto out;
-       err = parse_events(evlist, "task-clock", NULL);
+       err = parse_event(evlist, "task-clock");
        if (err)
                goto out;
 
index 0bde4a768c159920e1aa9d09a7ffbb8f4f38d9b0..62b0093253e3fd87bf79a77c8ad4d88836825c75 100644 (file)
@@ -593,7 +593,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
 
        TEST_ASSERT_VAL("No memory", evlist);
 
-       err = parse_events(evlist, "cpu-clock", NULL);
+       err = parse_event(evlist, "cpu-clock");
        if (err)
                goto out;
        err = TEST_FAIL;
index dd2067312452cc7afe20b316fc71a665a7d804b9..8f4f9b632e1e586a85911d61e4e180294041fff3 100644 (file)
@@ -89,8 +89,8 @@ static int test__keep_tracking(struct test_suite *test __maybe_unused, int subte
 
        perf_evlist__set_maps(&evlist->core, cpus, threads);
 
-       CHECK__(parse_events(evlist, "dummy:u", NULL));
-       CHECK__(parse_events(evlist, "cycles:u", NULL));
+       CHECK__(parse_event(evlist, "dummy:u"));
+       CHECK__(parse_event(evlist, "cycles:u"));
 
        evlist__config(evlist, &opts, NULL);
 
index 7c7d20fc503adbc98ff42c7ab6124f0a030c72cd..26ce30a35191ebfbf4eebef97715aa76cdd0a882 100644 (file)
@@ -100,7 +100,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 
        perf_evlist__set_maps(&evlist->core, cpus, threads);
 
-       CHECK__(parse_events(evlist, "cycles:u", NULL));
+       CHECK__(parse_event(evlist, "cycles:u"));
 
        evlist__config(evlist, &opts, NULL);
 
index 6f53bee33f7cb55234b6a3530b2b211dfdbf2d83..2d46af9ef93573495fefb200292ef0b7bf22f6eb 100644 (file)
@@ -364,7 +364,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
        perf_evlist__set_maps(&evlist->core, cpus, threads);
 
        /* First event */
-       err = parse_events(evlist, "cpu-clock:u", NULL);
+       err = parse_event(evlist, "cpu-clock:u");
        if (err) {
                pr_debug("Failed to parse event dummy:u\n");
                goto out_err;
@@ -375,14 +375,14 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
        /* Second event */
        if (perf_pmu__has_hybrid()) {
                cycles = "cpu_core/cycles/u";
-               err = parse_events(evlist, cycles, NULL);
+               err = parse_event(evlist, cycles);
                if (err) {
                        cycles = "cpu_atom/cycles/u";
                        pr_debug("Trying %s\n", cycles);
-                       err = parse_events(evlist, cycles, NULL);
+                       err = parse_event(evlist, cycles);
                }
        } else {
-               err = parse_events(evlist, cycles, NULL);
+               err = parse_event(evlist, cycles);
        }
        if (err) {
                pr_debug("Failed to parse event %s\n", cycles);
@@ -398,7 +398,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
                goto out;
        }
 
-       err = parse_events(evlist, sched_switch, NULL);
+       err = parse_event(evlist, sched_switch);
        if (err) {
                pr_debug("Failed to parse event %s\n", sched_switch);
                goto out_err;
@@ -428,7 +428,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
        evsel__set_sample_bit(cycles_evsel, TIME);
 
        /* Fourth event */
-       err = parse_events(evlist, "dummy:u", NULL);
+       err = parse_event(evlist, "dummy:u");
        if (err) {
                pr_debug("Failed to parse event dummy:u\n");
                goto out_err;
index d2c9b09ddb48b751233a09e0cb63945b898f2dc0..e2052f4fed33babd9602fc92edcc99cd7a1cfc31 100644 (file)
@@ -1879,7 +1879,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
                if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0)
                        return ERR_PTR(-ENOMEM);
 
-               err = parse_events(evlist, event_definition, NULL);
+               err = parse_event(evlist, event_definition);
                free(event_definition);
 
                if (err) {
index dfc7d7a0ec4e40b275afd0056cecdd1e97eb3c0c..f05e15acd33fe84532749dad8075ce07d1dfcdcd 100644 (file)
@@ -2240,6 +2240,17 @@ int __parse_events(struct evlist *evlist, const char *str,
        return ret;
 }
 
+int parse_event(struct evlist *evlist, const char *str)
+{
+       struct parse_events_error err;
+       int ret;
+
+       parse_events_error__init(&err);
+       ret = parse_events(evlist, str, &err);
+       parse_events_error__exit(&err);
+       return ret;
+}
+
 void parse_events_error__init(struct parse_events_error *err)
 {
        bzero(err, sizeof(*err));
@@ -2256,13 +2267,8 @@ void parse_events_error__exit(struct parse_events_error *err)
 void parse_events_error__handle(struct parse_events_error *err, int idx,
                                char *str, char *help)
 {
-       if (WARN(!str, "WARNING: failed to provide error string\n"))
-               goto out_free;
-       if (!err) {
-               /* Assume caller does not want message printed */
-               pr_debug("event syntax error: %s\n", str);
+       if (WARN(!str || !err, "WARNING: failed to provide error string or struct\n"))
                goto out_free;
-       }
        switch (err->num_errors) {
        case 0:
                err->idx = idx;
index ba9fa3ddaf6e4bb8efc691ab9fb3340657ab3c0b..7e6a601d9cd01bc45de9a93a8e1ef53fbd7cf187 100644 (file)
@@ -24,15 +24,19 @@ const char *event_type(int type);
 
 int parse_events_option(const struct option *opt, const char *str, int unset);
 int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset);
+__attribute__((nonnull(1, 2, 3)))
 int __parse_events(struct evlist *evlist, const char *str, struct parse_events_error *error,
                   struct perf_pmu *fake_pmu);
 
+__attribute__((nonnull))
 static inline int parse_events(struct evlist *evlist, const char *str,
                               struct parse_events_error *err)
 {
        return __parse_events(evlist, str, err, NULL);
 }
 
+int parse_event(struct evlist *evlist, const char *str);
+
 int parse_events_terms(struct list_head *terms, const char *str);
 int parse_filter(const struct option *opt, const char *str, int unset);
 int exclude_perf(const struct option *opt, const char *arg, int unset);
index c28dd50bd571b8b3190d21f7fed3dcfad4f746be..e1e2d701599c4294f05e1c73ca5aef4cd1ef8544 100644 (file)
@@ -23,7 +23,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha
        if (!evlist)
                return -ENOMEM;
 
-       if (parse_events(evlist, str, NULL))
+       if (parse_event(evlist, str))
                goto out_delete;
 
        evsel = evlist__first(evlist);
index b529636ab3ea147914e7f1ec167e27c56346f566..7b58f6c7c69dea0b92b984876375356b17d80ad6 100644 (file)
@@ -238,7 +238,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str)
        if (!temp_evlist)
                return false;
 
-       err = parse_events(temp_evlist, str, NULL);
+       err = parse_event(temp_evlist, str);
        if (err)
                goto out_delete;