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: 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>
This commit is contained in:
parent
1da1d60774
commit
806731a946
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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"))
|
||||
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;
|
||||
}
|
||||
switch (err->num_errors) {
|
||||
case 0:
|
||||
err->idx = idx;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user