[RFC PATCH 21/25] perf stat: Add tool events support in hardware-grouping

weilin.wang
2023-09-25T06:21:15Z

Add tool events into default_core grouping strings if find tool events so
that metrics use tool events could be correctly calculated. Need this step
to support TopdownL4-L5.

Signed-off-by: Weilin Wang <weilin.wang@intel.com>
---
tools/perf/util/metricgroup.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 3c569d838..d10f6afb0 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1950,6 +1950,7 @@ static int assign_event_grouping(struct metricgroup__event_info *e,

static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs,
const char *modifier,
+ const bool tool_events[PERF_TOOL_MAX],
struct list_head *groups)
{
struct metricgroup__pmu_group_list *p;
@@ -2029,6 +2030,22 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs
}
ret = strbuf_addf(events, "}:W");
RETURN_IF_NON_ZERO(ret);
+ if (!strcmp(p->pmu_name, "default_core")) {
+ int i = 0;
+
+ perf_tool_event__for_each_event(i) {
+ if (tool_events[i]) {
+ const char *tmp = strdup(perf_tool_event__to_str(i));
+
+ if (!tmp)
+ return -ENOMEM;
+ ret = strbuf_addstr(events, ",");
+ RETURN_IF_NON_ZERO(ret);
+ ret = strbuf_addstr(events, tmp);
+ RETURN_IF_NON_ZERO(ret);
+ }
+ }
+ }
pr_debug("events-buf: %s\n", events->buf);
list_add_tail(&new_group_str->nd, group_strs);
}
@@ -2094,7 +2111,8 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx,
pr_debug("found event %s\n", id);
if (!strncmp(id, special_pattern, strlen(special_pattern))) {
struct metricgroup__event_info *event;
- event = event_info__new(id, "default_core", "0", false, true);
+ event = event_info__new(id, "default_core", "0", false,
+ /*free_counter=*/true);
if (!event) {
ret = -ENOMEM;
goto err_out;
@@ -2106,6 +2124,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx,
if (ret)
goto err_out;
}
+
ret = get_pmu_counter_layouts(&pmu_info_list, ltable);
if (ret)
goto err_out;
@@ -2151,6 +2170,7 @@ static void metricgroup__free_grouping_strs(struct list_head
*/
static int hw_aware_parse_ids(struct perf_pmu *fake_pmu,
struct expr_parse_ctx *ids, const char *modifier,
+ const bool tool_events[PERF_TOOL_MAX],
struct evlist **out_evlist)
{
struct parse_events_error parse_error;
@@ -2164,7 +2184,8 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu,
ret = hw_aware_build_grouping(ids, &grouping);
if (ret)
goto err_out;
- ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping);
+ ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier,
+ tool_events, &grouping);
if (ret)
goto err_out;

@@ -2298,6 +2319,7 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist,
struct evlist *combined_evlist = NULL;
LIST_HEAD(metric_list);
struct metric *m;
+ bool tool_events[PERF_TOOL_MAX] = {false};
int ret;
bool metric_no_group = false;
bool metric_no_merge = false;
@@ -2316,11 +2338,14 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist,
if (!metric_no_merge) {
struct expr_parse_ctx *combined = NULL;

+ find_tool_events(&metric_list, tool_events);
+
ret = hw_aware_build_combined_expr_ctx(&metric_list, &combined);

if (!ret && combined && hashmap__size(combined->ids)) {
ret = hw_aware_parse_ids(fake_pmu, combined,
/*modifier=*/NULL,
+ tool_events,
&combined_evlist);
}

--
2.39.3