Commit 806731a9 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf tools: Do not pass NULL to parse_events()

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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 1da1d607
...@@ -438,7 +438,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, ...@@ -438,7 +438,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
if (opts->full_auxtrace) { if (opts->full_auxtrace) {
struct evsel *tracking_evsel; struct evsel *tracking_evsel;
err = parse_events(evlist, "dummy:u", NULL); err = parse_event(evlist, "dummy:u");
if (err) if (err)
goto out; goto out;
......
...@@ -257,7 +257,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, ...@@ -257,7 +257,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
evsel__set_sample_bit(arm_spe_evsel, PHYS_ADDR); evsel__set_sample_bit(arm_spe_evsel, PHYS_ADDR);
/* Add dummy event to keep tracking */ /* Add dummy event to keep tracking */
err = parse_events(evlist, "dummy:u", NULL); err = parse_event(evlist, "dummy:u");
if (err) if (err)
return err; return err;
......
...@@ -56,7 +56,7 @@ int test__intel_cqm_count_nmi_context(struct test_suite *test __maybe_unused, in ...@@ -56,7 +56,7 @@ int test__intel_cqm_count_nmi_context(struct test_suite *test __maybe_unused, in
return TEST_FAIL; return TEST_FAIL;
} }
ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL); ret = parse_event(evlist, "intel_cqm/llc_occupancy/");
if (ret) { if (ret) {
pr_debug("parse_events failed, is \"intel_cqm/llc_occupancy/\" available?\n"); pr_debug("parse_events failed, is \"intel_cqm/llc_occupancy/\" available?\n");
err = TEST_SKIP; err = TEST_SKIP;
......
...@@ -233,7 +233,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, ...@@ -233,7 +233,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
struct evsel *tracking_evsel; struct evsel *tracking_evsel;
int err; int err;
err = parse_events(evlist, "dummy:u", NULL); err = parse_event(evlist, "dummy:u");
if (err) if (err)
return err; return err;
......
...@@ -426,7 +426,7 @@ static int intel_pt_track_switches(struct evlist *evlist) ...@@ -426,7 +426,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
if (!evlist__can_select_event(evlist, sched_switch)) if (!evlist__can_select_event(evlist, sched_switch))
return -EPERM; return -EPERM;
err = parse_events(evlist, sched_switch, NULL); err = parse_event(evlist, sched_switch);
if (err) { if (err) {
pr_debug2("%s: failed to parse %s, error %d\n", pr_debug2("%s: failed to parse %s, error %d\n",
__func__, sched_switch, err); __func__, sched_switch, err);
......
...@@ -316,7 +316,7 @@ static int iostat_event_group(struct evlist *evl, ...@@ -316,7 +316,7 @@ static int iostat_event_group(struct evlist *evl,
sprintf(iostat_cmd, iostat_cmd_template, 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,
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) if (ret)
goto err; goto err;
} }
......
...@@ -122,5 +122,5 @@ int topdown_parse_events(struct evlist *evlist) ...@@ -122,5 +122,5 @@ int topdown_parse_events(struct evlist *evlist)
topdown_events = TOPDOWN_L1_EVENTS; topdown_events = TOPDOWN_L1_EVENTS;
} }
return parse_events(evlist, topdown_events, NULL); return parse_event(evlist, topdown_events);
} }
...@@ -638,7 +638,7 @@ static int do_test_code_reading(bool try_kcore) ...@@ -638,7 +638,7 @@ static int do_test_code_reading(bool try_kcore)
str = do_determine_event(excl_kernel); str = do_determine_event(excl_kernel);
pr_debug("Parsing event '%s'\n", str); pr_debug("Parsing event '%s'\n", str);
ret = parse_events(evlist, str, NULL); ret = parse_event(evlist, str);
if (ret < 0) { if (ret < 0) {
pr_debug("parse_events failed\n"); pr_debug("parse_events failed\n");
goto out_put; goto out_put;
......
...@@ -174,7 +174,7 @@ static int test_times(int (attach)(struct evlist *), ...@@ -174,7 +174,7 @@ static int test_times(int (attach)(struct evlist *),
goto out_err; goto out_err;
} }
err = parse_events(evlist, "cpu-clock:u", NULL); err = parse_event(evlist, "cpu-clock:u");
if (err) { if (err) {
pr_debug("failed to parse event cpu-clock:u\n"); pr_debug("failed to parse event cpu-clock:u\n");
goto out_err; goto out_err;
......
...@@ -27,7 +27,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) ...@@ -27,7 +27,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
__evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name)); __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) if (err)
ret = err; ret = err;
} }
...@@ -75,7 +75,7 @@ static int __perf_evsel__name_array_test(const char *const names[], int nr_names ...@@ -75,7 +75,7 @@ static int __perf_evsel__name_array_test(const char *const names[], int nr_names
return -ENOMEM; return -ENOMEM;
for (i = 0; i < nr_names; ++i) { for (i = 0; i < nr_names; ++i) {
err = parse_events(evlist, names[i], NULL); err = parse_event(evlist, names[i]);
if (err) { if (err) {
pr_debug("failed to parse event '%s', err %d\n", pr_debug("failed to parse event '%s', err %d\n",
names[i], err); names[i], err);
......
...@@ -706,7 +706,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt ...@@ -706,7 +706,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt
TEST_ASSERT_VAL("No memory", evlist); TEST_ASSERT_VAL("No memory", evlist);
err = parse_events(evlist, "cpu-clock", NULL); err = parse_event(evlist, "cpu-clock");
if (err) if (err)
goto out; goto out;
err = TEST_FAIL; err = TEST_FAIL;
......
...@@ -111,10 +111,10 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes ...@@ -111,10 +111,10 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
TEST_ASSERT_VAL("No memory", evlist); TEST_ASSERT_VAL("No memory", evlist);
err = parse_events(evlist, "cpu-clock", NULL); err = parse_event(evlist, "cpu-clock");
if (err) if (err)
goto out; goto out;
err = parse_events(evlist, "task-clock", NULL); err = parse_event(evlist, "task-clock");
if (err) if (err)
goto out; goto out;
err = TEST_FAIL; err = TEST_FAIL;
......
...@@ -276,10 +276,10 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest ...@@ -276,10 +276,10 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest
if (evlist == NULL) if (evlist == NULL)
return -ENOMEM; return -ENOMEM;
err = parse_events(evlist, "cpu-clock", NULL); err = parse_event(evlist, "cpu-clock");
if (err) if (err)
goto out; goto out;
err = parse_events(evlist, "task-clock", NULL); err = parse_event(evlist, "task-clock");
if (err) if (err)
goto out; goto out;
......
...@@ -593,7 +593,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes ...@@ -593,7 +593,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes
TEST_ASSERT_VAL("No memory", evlist); TEST_ASSERT_VAL("No memory", evlist);
err = parse_events(evlist, "cpu-clock", NULL); err = parse_event(evlist, "cpu-clock");
if (err) if (err)
goto out; goto out;
err = TEST_FAIL; err = TEST_FAIL;
......
...@@ -89,8 +89,8 @@ static int test__keep_tracking(struct test_suite *test __maybe_unused, int subte ...@@ -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); perf_evlist__set_maps(&evlist->core, cpus, threads);
CHECK__(parse_events(evlist, "dummy:u", NULL)); CHECK__(parse_event(evlist, "dummy:u"));
CHECK__(parse_events(evlist, "cycles:u", NULL)); CHECK__(parse_event(evlist, "cycles:u"));
evlist__config(evlist, &opts, NULL); evlist__config(evlist, &opts, NULL);
......
...@@ -100,7 +100,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su ...@@ -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); 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); evlist__config(evlist, &opts, NULL);
......
...@@ -364,7 +364,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub ...@@ -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); perf_evlist__set_maps(&evlist->core, cpus, threads);
/* First event */ /* First event */
err = parse_events(evlist, "cpu-clock:u", NULL); err = parse_event(evlist, "cpu-clock:u");
if (err) { if (err) {
pr_debug("Failed to parse event dummy:u\n"); pr_debug("Failed to parse event dummy:u\n");
goto out_err; goto out_err;
...@@ -375,14 +375,14 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub ...@@ -375,14 +375,14 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
/* Second event */ /* Second event */
if (perf_pmu__has_hybrid()) { if (perf_pmu__has_hybrid()) {
cycles = "cpu_core/cycles/u"; cycles = "cpu_core/cycles/u";
err = parse_events(evlist, cycles, NULL); err = parse_event(evlist, cycles);
if (err) { if (err) {
cycles = "cpu_atom/cycles/u"; cycles = "cpu_atom/cycles/u";
pr_debug("Trying %s\n", cycles); pr_debug("Trying %s\n", cycles);
err = parse_events(evlist, cycles, NULL); err = parse_event(evlist, cycles);
} }
} else { } else {
err = parse_events(evlist, cycles, NULL); err = parse_event(evlist, cycles);
} }
if (err) { if (err) {
pr_debug("Failed to parse event %s\n", cycles); 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 ...@@ -398,7 +398,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
goto out; goto out;
} }
err = parse_events(evlist, sched_switch, NULL); err = parse_event(evlist, sched_switch);
if (err) { if (err) {
pr_debug("Failed to parse event %s\n", sched_switch); pr_debug("Failed to parse event %s\n", sched_switch);
goto out_err; goto out_err;
...@@ -428,7 +428,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub ...@@ -428,7 +428,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
evsel__set_sample_bit(cycles_evsel, TIME); evsel__set_sample_bit(cycles_evsel, TIME);
/* Fourth event */ /* Fourth event */
err = parse_events(evlist, "dummy:u", NULL); err = parse_event(evlist, "dummy:u");
if (err) { if (err) {
pr_debug("Failed to parse event dummy:u\n"); pr_debug("Failed to parse event dummy:u\n");
goto out_err; goto out_err;
......
...@@ -1879,7 +1879,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name) ...@@ -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) if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
err = parse_events(evlist, event_definition, NULL); err = parse_event(evlist, event_definition);
free(event_definition); free(event_definition);
if (err) { if (err) {
......
...@@ -2240,6 +2240,17 @@ int __parse_events(struct evlist *evlist, const char *str, ...@@ -2240,6 +2240,17 @@ int __parse_events(struct evlist *evlist, const char *str,
return ret; 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) void parse_events_error__init(struct parse_events_error *err)
{ {
bzero(err, sizeof(*err)); bzero(err, sizeof(*err));
...@@ -2256,13 +2267,8 @@ void parse_events_error__exit(struct parse_events_error *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, void parse_events_error__handle(struct parse_events_error *err, int idx,
char *str, char *help) char *str, char *help)
{ {
if (WARN(!str, "WARNING: failed to provide error string\n")) if (WARN(!str || !err, "WARNING: failed to provide error string or struct\n"))
goto out_free;
if (!err) {
/* Assume caller does not want message printed */
pr_debug("event syntax error: %s\n", str);
goto out_free; goto out_free;
}
switch (err->num_errors) { switch (err->num_errors) {
case 0: case 0:
err->idx = idx; err->idx = idx;
......
...@@ -24,15 +24,19 @@ const char *event_type(int type); ...@@ -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(const struct option *opt, const char *str, int unset);
int parse_events_option_new_evlist(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, int __parse_events(struct evlist *evlist, const char *str, struct parse_events_error *error,
struct perf_pmu *fake_pmu); struct perf_pmu *fake_pmu);
__attribute__((nonnull))
static inline int parse_events(struct evlist *evlist, const char *str, static inline int parse_events(struct evlist *evlist, const char *str,
struct parse_events_error *err) struct parse_events_error *err)
{ {
return __parse_events(evlist, str, err, NULL); 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_events_terms(struct list_head *terms, const char *str);
int parse_filter(const struct option *opt, const char *str, int unset); int parse_filter(const struct option *opt, const char *str, int unset);
int exclude_perf(const struct option *opt, const char *arg, int unset); int exclude_perf(const struct option *opt, const char *arg, int unset);
......
...@@ -23,7 +23,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha ...@@ -23,7 +23,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha
if (!evlist) if (!evlist)
return -ENOMEM; return -ENOMEM;
if (parse_events(evlist, str, NULL)) if (parse_event(evlist, str))
goto out_delete; goto out_delete;
evsel = evlist__first(evlist); evsel = evlist__first(evlist);
......
...@@ -238,7 +238,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) ...@@ -238,7 +238,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str)
if (!temp_evlist) if (!temp_evlist)
return false; return false;
err = parse_events(temp_evlist, str, NULL); err = parse_event(temp_evlist, str);
if (err) if (err)
goto out_delete; goto out_delete;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment