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

perf parse-events: Improve error location of terms cloned from an event

A PMU event/alias will have a set of format terms that replace it when
an event is parsed. The location of the terms is their position when
parsed for the event/alias either from sysfs or json. This location is
of little use when an event fails to parse as the error will be given
in terms of the location in the string of events parsed not the json
or sysfs string. Fix this by making the cloned terms location that of
the event/alias.

If a cloned term from an event/alias is invalid the bad format is hard
to determine from the error string. Add the name of the bad format
into the error string.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@arm.com>
Cc: tchen168@asu.edu
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240131134940.593788-2-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
f5144eca 2882358b

+5 -4
+5 -4
tools/perf/util/pmu.c
··· 657 657 return 0; 658 658 } 659 659 660 - static int pmu_alias_terms(struct perf_pmu_alias *alias, struct list_head *terms) 660 + static int pmu_alias_terms(struct perf_pmu_alias *alias, int err_loc, struct list_head *terms) 661 661 { 662 662 struct parse_events_term *term, *cloned; 663 663 struct parse_events_terms clone_terms; ··· 675 675 * which we don't want for implicit terms in aliases. 676 676 */ 677 677 cloned->weak = true; 678 + cloned->err_term = cloned->err_val = err_loc; 678 679 list_add_tail(&cloned->list, &clone_terms.terms); 679 680 } 680 681 list_splice_init(&clone_terms.terms, terms); ··· 1364 1363 1365 1364 parse_events_error__handle(err, term->err_val, 1366 1365 asprintf(&err_str, 1367 - "value too big for format, maximum is %llu", 1368 - (unsigned long long)max_val) < 0 1366 + "value too big for format (%s), maximum is %llu", 1367 + format->name, (unsigned long long)max_val) < 0 1369 1368 ? strdup("value too big for format") 1370 1369 : err_str, 1371 1370 NULL); ··· 1519 1518 alias = pmu_find_alias(pmu, term); 1520 1519 if (!alias) 1521 1520 continue; 1522 - ret = pmu_alias_terms(alias, &term->list); 1521 + ret = pmu_alias_terms(alias, term->err_term, &term->list); 1523 1522 if (ret) { 1524 1523 parse_events_error__handle(err, term->err_term, 1525 1524 strdup("Failure to duplicate terms"),