Commit 8586d274 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf metrics: Don't add all tool events for sharing

Tool events are added to the set of events for parsing so that having a
tool event in a metric doesn't inhibit event sharing of events between
metrics.

All tool events were added but this meant unused tool events would be
counted. Reduce this set of tool events to just those present in the
overall metric list.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20220507053410.3798748-6-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9aa09230
...@@ -1283,6 +1283,30 @@ static void metricgroup__free_metrics(struct list_head *metric_list) ...@@ -1283,6 +1283,30 @@ static void metricgroup__free_metrics(struct list_head *metric_list)
} }
} }
/**
* find_tool_events - Search for the pressence of tool events in metric_list.
* @metric_list: List to take metrics from.
* @tool_events: Array of false values, indices corresponding to tool events set
* to true if tool event is found.
*/
static void find_tool_events(const struct list_head *metric_list,
bool tool_events[PERF_TOOL_MAX])
{
struct metric *m;
list_for_each_entry(m, metric_list, nd) {
int i;
perf_tool_event__for_each_event(i) {
struct expr_id_data *data;
if (!tool_events[i] &&
!expr__get_id(m->pctx, perf_tool_event__to_str(i), &data))
tool_events[i] = true;
}
}
}
/** /**
* build_combined_expr_ctx - Make an expr_parse_ctx with all has_constraint * build_combined_expr_ctx - Make an expr_parse_ctx with all has_constraint
* metric IDs, as the IDs are held in a set, * metric IDs, as the IDs are held in a set,
...@@ -1332,11 +1356,14 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, ...@@ -1332,11 +1356,14 @@ static int build_combined_expr_ctx(const struct list_head *metric_list,
* @ids: the event identifiers parsed from a metric. * @ids: the event identifiers parsed from a metric.
* @modifier: any modifiers added to the events. * @modifier: any modifiers added to the events.
* @has_constraint: false if events should be placed in a weak group. * @has_constraint: false if events should be placed in a weak group.
* @tool_events: entries set true if the tool event of index could be present in
* the overall list of metrics.
* @out_evlist: the created list of events. * @out_evlist: the created list of events.
*/ */
static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
struct expr_parse_ctx *ids, const char *modifier, struct expr_parse_ctx *ids, const char *modifier,
bool has_constraint, struct evlist **out_evlist) bool has_constraint, const bool tool_events[PERF_TOOL_MAX],
struct evlist **out_evlist)
{ {
struct parse_events_error parse_error; struct parse_events_error parse_error;
struct evlist *parsed_evlist; struct evlist *parsed_evlist;
...@@ -1360,6 +1387,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, ...@@ -1360,6 +1387,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
* Add a tool event to avoid a parse error on an empty string. * Add a tool event to avoid a parse error on an empty string.
*/ */
perf_tool_event__for_each_event(i) { perf_tool_event__for_each_event(i) {
if (tool_events[i]) {
char *tmp = strdup(perf_tool_event__to_str(i)); char *tmp = strdup(perf_tool_event__to_str(i));
if (!tmp) if (!tmp)
...@@ -1367,6 +1395,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, ...@@ -1367,6 +1395,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
ids__insert(ids->ids, tmp); ids__insert(ids->ids, tmp);
} }
} }
}
ret = metricgroup__build_event_string(&events, ids, modifier, ret = metricgroup__build_event_string(&events, ids, modifier,
has_constraint); has_constraint);
if (ret) if (ret)
...@@ -1407,6 +1436,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1407,6 +1436,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
struct evlist *combined_evlist = NULL; struct evlist *combined_evlist = NULL;
LIST_HEAD(metric_list); LIST_HEAD(metric_list);
struct metric *m; struct metric *m;
bool tool_events[PERF_TOOL_MAX] = {false};
int ret; int ret;
if (metric_events_list->nr_entries == 0) if (metric_events_list->nr_entries == 0)
...@@ -1422,12 +1452,15 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1422,12 +1452,15 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
if (!metric_no_merge) { if (!metric_no_merge) {
struct expr_parse_ctx *combined = NULL; struct expr_parse_ctx *combined = NULL;
find_tool_events(&metric_list, tool_events);
ret = build_combined_expr_ctx(&metric_list, &combined); ret = build_combined_expr_ctx(&metric_list, &combined);
if (!ret && combined && hashmap__size(combined->ids)) { if (!ret && combined && hashmap__size(combined->ids)) {
ret = parse_ids(metric_no_merge, fake_pmu, combined, ret = parse_ids(metric_no_merge, fake_pmu, combined,
/*modifier=*/NULL, /*modifier=*/NULL,
/*has_constraint=*/true, /*has_constraint=*/true,
tool_events,
&combined_evlist); &combined_evlist);
} }
if (combined) if (combined)
...@@ -1475,7 +1508,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1475,7 +1508,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
} }
if (!metric_evlist) { if (!metric_evlist) {
ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier,
m->has_constraint, &m->evlist); m->has_constraint, tool_events, &m->evlist);
if (ret) if (ret)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment