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

Configure Feed

Select the types of activity you want to include in your feed.

perf parse-events: Improve error message for double setting

Double setting information for an event would produce an error message
associated with the PMU rather than the term that was double setting.
Improve the error message to be on the term.

Before:

$ perf stat -e 'cpu/inst_retired.any,inst_retired.any/' true
event syntax error: 'cpu/inst_retired.any,inst_retired.any/'
\___ Bad event or PMU

Unabled to find PMU or event on a PMU of 'cpu'
Run 'perf list' for a list of valid events
$

After:

$ perf stat -e 'cpu/inst_retired.any,inst_retired.any/' true
event syntax error: '..etired.any,inst_retired.any/'
\___ Bad event or PMU

Unabled to find PMU or event on a PMU of 'cpu'

Initial error:

event syntax error: '..etired.any,inst_retired.any/'
\___ Attempt to set event's scale twice
Run 'perf list' for a list of valid events

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
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>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
9d31cb93 2e255b4f

+29 -9
+1 -1
tools/perf/util/parse-events.c
··· 1348 1348 return evsel ? 0 : -ENOMEM; 1349 1349 } 1350 1350 1351 - if (!parse_state->fake_pmu && perf_pmu__check_alias(pmu, head_config, &info)) 1351 + if (!parse_state->fake_pmu && perf_pmu__check_alias(pmu, head_config, &info, err)) 1352 1352 return -EINVAL; 1353 1353 1354 1354 if (verbose > 1) {
+27 -7
tools/perf/util/pmu.c
··· 1443 1443 1444 1444 1445 1445 static int check_info_data(struct perf_pmu_alias *alias, 1446 - struct perf_pmu_info *info) 1446 + struct perf_pmu_info *info, 1447 + struct parse_events_error *err, 1448 + int column) 1447 1449 { 1448 1450 /* 1449 1451 * Only one term in event definition can 1450 1452 * define unit, scale and snapshot, fail 1451 1453 * if there's more than one. 1452 1454 */ 1453 - if ((info->unit && alias->unit[0]) || 1454 - (info->scale && alias->scale) || 1455 - (info->snapshot && alias->snapshot)) 1455 + if (info->unit && alias->unit[0]) { 1456 + parse_events_error__handle(err, column, 1457 + strdup("Attempt to set event's unit twice"), 1458 + NULL); 1456 1459 return -EINVAL; 1460 + } 1461 + if (info->scale && alias->scale) { 1462 + parse_events_error__handle(err, column, 1463 + strdup("Attempt to set event's scale twice"), 1464 + NULL); 1465 + return -EINVAL; 1466 + } 1467 + if (info->snapshot && alias->snapshot) { 1468 + parse_events_error__handle(err, column, 1469 + strdup("Attempt to set event snapshot twice"), 1470 + NULL); 1471 + return -EINVAL; 1472 + } 1457 1473 1458 1474 if (alias->unit[0]) 1459 1475 info->unit = alias->unit; ··· 1488 1472 * defined for the alias 1489 1473 */ 1490 1474 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, 1491 - struct perf_pmu_info *info) 1475 + struct perf_pmu_info *info, struct parse_events_error *err) 1492 1476 { 1493 1477 struct parse_events_term *term, *h; 1494 1478 struct perf_pmu_alias *alias; ··· 1509 1493 if (!alias) 1510 1494 continue; 1511 1495 ret = pmu_alias_terms(alias, &term->list); 1512 - if (ret) 1496 + if (ret) { 1497 + parse_events_error__handle(err, term->err_term, 1498 + strdup("Failure to duplicate terms"), 1499 + NULL); 1513 1500 return ret; 1501 + } 1514 1502 1515 - ret = check_info_data(alias, info); 1503 + ret = check_info_data(alias, info, err, term->err_term); 1516 1504 if (ret) 1517 1505 return ret; 1518 1506
+1 -1
tools/perf/util/pmu.h
··· 185 185 __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name); 186 186 int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); 187 187 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, 188 - struct perf_pmu_info *info); 188 + struct perf_pmu_info *info, struct parse_events_error *err); 189 189 int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb); 190 190 191 191 int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_load);