Currently event aliases in the form foo-bar-baz are not supported.
The HiSilicon D06 platform has uncore event aliases in that form, and
using those aliases fail:
$ ./perf list sdir-home-migrate
List of pre-defined events (to be used in -e):
uncore hha:
sdir-home-migrate
[Unit: hisi_sccl,hha]
$ sudo ./perf stat -e sdir-home-migrate
event syntax error: 'sdir-home-migrate'
\___ parser error
Run 'perf list' for a list of valid events
Usage: perf stat [<options>] [<command>]
-e, --event <event>event selector. use 'perf list' to list available events
This series added support for such an event alias form.
I am no expert on l+y, so any and all review here would be appreciated,
especially the last patch which is marked as RFC (for that same reason).
The series is based on acme perf/core @ 9bce13ea88f8.
John Garry (3):
perf parse-events: Support event alias in form foo-bar-baz
perf test: Add pmu-events test for aliases with hyphens
perf test: Add parse-events test for aliases with hyphens
.../arch/test/test_soc/cpu/uncore.json | 16 +++++
tools/perf/tests/parse-events.c | 49 ++++++++++++++
tools/perf/tests/pmu-events.c | 32 +++++++++
tools/perf/util/parse-events.c | 67 ++++++++++++++++---
tools/perf/util/parse-events.h | 1 +
tools/perf/util/parse-events.l | 2 +
tools/perf/util/parse-events.y | 17 ++++-
7 files changed, 171 insertions(+), 13 deletions(-)
--
2.26.2
Add a test which allows us to test parsing an event alias with hyphens.
Since these events typically do not exist on most host systems, add the
alias to the fake pmu.
Function perf_pmu__test_parse_init() has terms added to match known test
aliases.
Signed-off-by: John Garry <[email protected]>
---
tools/perf/tests/parse-events.c | 49 +++++++++++++++++++++++++++++++++
tools/perf/util/parse-events.c | 42 ++++++++++++++++++++++------
2 files changed, 82 insertions(+), 9 deletions(-)
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index a508f1dbcb2a..e71efadb24f5 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -2069,6 +2069,31 @@ static int test_event(struct evlist_test *e)
return ret;
}
+static int test_event_fake_pmu(const char *str)
+{
+ struct parse_events_error err;
+ struct evlist *evlist;
+ int ret;
+
+ evlist = evlist__new();
+ if (!evlist)
+ return -ENOMEM;
+
+ parse_events_error__init(&err);
+ perf_pmu__test_parse_init();
+ ret = __parse_events(evlist, str, &err, &perf_pmu__fake);
+ if (ret) {
+ pr_debug("failed to parse event '%s', err %d, str '%s'\n",
+ str, ret, err.str);
+ parse_events_error__print(&err, str);
+ }
+
+ parse_events_error__exit(&err);
+ evlist__delete(evlist);
+
+ return ret;
+}
+
static int test_events(struct evlist_test *events, unsigned cnt)
{
int ret1, ret2 = 0;
@@ -2276,6 +2301,26 @@ static int test_pmu_events_alias(char *event, char *alias)
return test_event(&e);
}
+static int test_pmu_events_alias2(void)
+{
+ static const char events[][30] = {
+ "event-hyphen",
+ "event-two-hyph",
+ };
+ unsigned long i;
+ int ret = 0;
+
+ for (i = 0; i < ARRAY_SIZE(events); i++) {
+ ret = test_event_fake_pmu(&events[i][0]);
+ if (ret) {
+ pr_err("check_parse_fake %s failed\n", &events[i][0]);
+ break;
+ }
+ }
+
+ return ret;
+}
+
static int test__parse_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
int ret1, ret2 = 0;
@@ -2313,6 +2358,10 @@ do { \
return ret;
}
+ ret1 = test_pmu_events_alias2();
+ if (!ret2)
+ ret2 = ret1;
+
ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
if (!ret2)
ret2 = ret1;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 879f606e07e6..9739b05b999e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1697,6 +1697,15 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
}
}
}
+
+ if (parse_state->fake_pmu) {
+ if (!parse_events_add_pmu(parse_state, list, str, head,
+ true, true)) {
+ pr_debug("%s -> %s/%s/\n", str, "fake_pmu", str);
+ ok++;
+ }
+ }
+
out_err:
if (ok)
*listp = list;
@@ -2168,23 +2177,38 @@ static void perf_pmu__parse_init(void)
*/
int perf_pmu__test_parse_init(void)
{
- struct perf_pmu_event_symbol *list;
+ struct perf_pmu_event_symbol *list, *tmp, symbols[] = {
+ {(char *)"read", PMU_EVENT_SYMBOL},
+ {(char *)"event", PMU_EVENT_SYMBOL_PREFIX},
+ {(char *)"two", PMU_EVENT_SYMBOL_SUFFIX},
+ {(char *)"hyphen", PMU_EVENT_SYMBOL_SUFFIX},
+ {(char *)"hyph", PMU_EVENT_SYMBOL_SUFFIX2},
+ };
+ unsigned long i, j;
- list = malloc(sizeof(*list) * 1);
+ tmp = list = malloc(sizeof(*list) * ARRAY_SIZE(symbols));
if (!list)
return -ENOMEM;
- list->type = PMU_EVENT_SYMBOL;
- list->symbol = strdup("read");
-
- if (!list->symbol) {
- free(list);
- return -ENOMEM;
+ for (i = 0; i < ARRAY_SIZE(symbols); i++, tmp++) {
+ tmp->type = symbols[i].type;
+ tmp->symbol = strdup(symbols[i].symbol);
+ if (!list->symbol)
+ goto err_free;
}
perf_pmu_events_list = list;
- perf_pmu_events_list_num = 1;
+ perf_pmu_events_list_num = ARRAY_SIZE(symbols);
+
+ qsort(perf_pmu_events_list, ARRAY_SIZE(symbols),
+ sizeof(struct perf_pmu_event_symbol), comp_pmu);
return 0;
+
+err_free:
+ for (j = 0, tmp = list; j < i; j++, tmp++)
+ free(tmp->symbol);
+ free(list);
+ return -ENOMEM;
}
enum perf_pmu_event_symbol_type
--
2.26.2
On Mon, Jan 17, 2022 at 7:15 AM John Garry <[email protected]> wrote:
>
> Currently event aliases in the form foo-bar-baz are not supported.
>
> The HiSilicon D06 platform has uncore event aliases in that form, and
> using those aliases fail:
>
> $ ./perf list sdir-home-migrate
>
> List of pre-defined events (to be used in -e):
>
> uncore hha:
> sdir-home-migrate
> [Unit: hisi_sccl,hha]
>
> $ sudo ./perf stat -e sdir-home-migrate
> event syntax error: 'sdir-home-migrate'
> \___ parser error
> Run 'perf list' for a list of valid events
>
> Usage: perf stat [<options>] [<command>]
>
> -e, --event <event>event selector. use 'perf list' to list available events
>
> This series added support for such an event alias form.
>
> I am no expert on l+y, so any and all review here would be appreciated,
> especially the last patch which is marked as RFC (for that same reason).
>
> The series is based on acme perf/core @ 9bce13ea88f8.
>
> John Garry (3):
> perf parse-events: Support event alias in form foo-bar-baz
> perf test: Add pmu-events test for aliases with hyphens
> perf test: Add parse-events test for aliases with hyphens
The whole set:
Acked-by: Ian Rogers <[email protected]>
The additional code is no worse than the existing code. The testing is
a great addition!
Thanks,
Ian
> .../arch/test/test_soc/cpu/uncore.json | 16 +++++
> tools/perf/tests/parse-events.c | 49 ++++++++++++++
> tools/perf/tests/pmu-events.c | 32 +++++++++
> tools/perf/util/parse-events.c | 67 ++++++++++++++++---
> tools/perf/util/parse-events.h | 1 +
> tools/perf/util/parse-events.l | 2 +
> tools/perf/util/parse-events.y | 17 ++++-
> 7 files changed, 171 insertions(+), 13 deletions(-)
>
> --
> 2.26.2
>
Em Mon, Jan 17, 2022 at 08:21:42AM -0800, Ian Rogers escreveu:
> On Mon, Jan 17, 2022 at 7:15 AM John Garry <[email protected]> wrote:
> >
> > Currently event aliases in the form foo-bar-baz are not supported.
> >
> > The HiSilicon D06 platform has uncore event aliases in that form, and
> > using those aliases fail:
> >
> > $ ./perf list sdir-home-migrate
> >
> > List of pre-defined events (to be used in -e):
> >
> > uncore hha:
> > sdir-home-migrate
> > [Unit: hisi_sccl,hha]
> >
> > $ sudo ./perf stat -e sdir-home-migrate
> > event syntax error: 'sdir-home-migrate'
> > \___ parser error
> > Run 'perf list' for a list of valid events
> >
> > Usage: perf stat [<options>] [<command>]
> >
> > -e, --event <event>event selector. use 'perf list' to list available events
> >
> > This series added support for such an event alias form.
> >
> > I am no expert on l+y, so any and all review here would be appreciated,
> > especially the last patch which is marked as RFC (for that same reason).
> >
> > The series is based on acme perf/core @ 9bce13ea88f8.
> >
> > John Garry (3):
> > perf parse-events: Support event alias in form foo-bar-baz
> > perf test: Add pmu-events test for aliases with hyphens
> > perf test: Add parse-events test for aliases with hyphens
>
> The whole set:
>
> Acked-by: Ian Rogers <[email protected]>
>
> The additional code is no worse than the existing code. The testing is
> a great addition!
Indeed, thanks a lot!
Thanks, applied.
- Arnaldo
> Thanks,
> Ian
>
> > .../arch/test/test_soc/cpu/uncore.json | 16 +++++
> > tools/perf/tests/parse-events.c | 49 ++++++++++++++
> > tools/perf/tests/pmu-events.c | 32 +++++++++
> > tools/perf/util/parse-events.c | 67 ++++++++++++++++---
> > tools/perf/util/parse-events.h | 1 +
> > tools/perf/util/parse-events.l | 2 +
> > tools/perf/util/parse-events.y | 17 ++++-
> > 7 files changed, 171 insertions(+), 13 deletions(-)
> >
> > --
> > 2.26.2
> >
--
- Arnaldo