Re: [PATCH 2/2] perf test: Improve pmu event metric testing
From: Jiri Olsa
Date: Wed May 13 2020 - 13:48:37 EST
On Tue, May 12, 2020 at 11:22:36PM -0700, Ian Rogers wrote:
SNIP
> +
> +static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe)
> +{
> + struct parse_events_error error;
> + struct evlist *evlist;
> + int ret;
> +
> + /* Numbers are always valid. */
> + if (is_number(id))
> + return 0;
> +
> + evlist = evlist__new();
> + memset(&error, 0, sizeof(error));
> + ret = parse_events(evlist, id, &error);
> + if (ret && same_cpu) {
> + fprintf(stderr,
> + "\nWARNING: Parse event failed metric '%s' id '%s' expr '%s'\n",
> + pe->metric_name, id, pe->metric_expr);
> + fprintf(stderr, "Error string '%s' help '%s'\n",
> + error.str, error.help);
> + } else if (ret) {
> + pr_debug3("Parse event failed, but for an event that may not be supported by this CPU.\nid '%s' metric '%s' expr '%s'\n",
> + id, pe->metric_name, pe->metric_expr);
> + }
I wonder if we could add 'fake pmu' that would be used for tests
and use it parse_events_add_pmu to add 'fake' evsel but the name
would be correct.. we could add parse_events_state::fake_pmu bool
for that
rest of the event types (other than pmu syntax) might be ok
> + evlist__delete(evlist);
> + free(error.str);
> + free(error.help);
> + free(error.first_str);
> + free(error.first_help);
> + /* TODO: too many metrics are broken to fail on this test currently. */
> + return 0;
> +}
> +
> +static int test_parsing(void)
> +{
> + struct pmu_events_map *cpus_map = perf_pmu__find_map(NULL);
> + struct pmu_events_map *map;
> + struct pmu_event *pe;
> + int i, j, k;
> + const char **ids;
> + int idnum;
> + int ret = 0;
> + struct expr_parse_ctx ctx;
> + double result;
> +
> + i = 0;
> + for (;;) {
> + map = &pmu_events_map[i++];
> + if (!map->table) {
> + map = NULL;
hum, what's the map = NULL for in here?
thanks,
jirka
> + break;
> + }
> + j = 0;
> + for (;;) {
> + pe = &map->table[j++];
> + if (!pe->name && !pe->metric_group && !pe->metric_name)
> + break;
> + if (!pe->metric_expr)
> + continue;
> + if (expr__find_other(pe->metric_expr, NULL,
> + &ids, &idnum, 0) < 0) {
> + pr_debug("Parse other failed for map %s %s %s\n",
> + map->cpuid, map->version, map->type);
> + pr_debug("On metric %s\n", pe->metric_name);
> + pr_debug("On expression %s\n", pe->metric_expr);
> + ret++;
> + continue;
> + }
> + expr__ctx_init(&ctx);
> +
> + /*
> + * Add all ids with a made up value. The value may
> + * trigger divide by zero when subtracted and so try to
> + * make them unique.
> + */
> + for (k = 0; k < idnum; k++)
> + expr__add_id(&ctx, ids[k], k + 1);
> +
> + for (k = 0; k < idnum; k++) {
> + if (check_parse_id(ids[k], map == cpus_map, pe))
> + ret++;
> + }
> +
> + if (expr__parse(&result, &ctx, pe->metric_expr, 0)) {
> + pr_debug("Parse failed for map %s %s %s\n",
> + map->cpuid, map->version, map->type);
> + pr_debug("On metric %s\n", pe->metric_name);
> + pr_debug("On expression %s\n", pe->metric_expr);
> + ret++;
> + }
> + for (k = 0; k < idnum; k++)
> + zfree(&ids[k]);
> + free(ids);
> + }
> + }
> + return ret;
SNIP