[PATCH 2/3] perf tools: Factor metric setup code into metricgroup__setup function

From: Jiri Olsa
Date: Wed Dec 11 2019 - 17:48:20 EST


Factoring metric setup code into metricgroup__setup function,
so it can be used to add metric from different sources in
following patches.

Link: https://lkml.kernel.org/n/tip-7hjix4t30ls3qqd4l60dbr2n@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/metricgroup.c | 38 +++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 1d01958c148d..abcfa3c1b4d5 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -521,32 +521,44 @@ static void metricgroup__free_egroups(struct list_head *group_list)
}
}

+static int metricgroup__setup(struct evlist *evlist,
+ struct rblist *metric_events,
+ struct strbuf *extra_events,
+ struct list_head *group_list)
+{
+ struct parse_events_error parse_error;
+ int ret;
+
+ pr_debug("adding %s\n", extra_events->buf);
+ bzero(&parse_error, sizeof(parse_error));
+
+ ret = parse_events(evlist, extra_events->buf, &parse_error);
+ if (ret) {
+ parse_events_print_error(&parse_error, extra_events->buf);
+ return ret;
+ }
+
+ if (metric_events->nr_entries == 0)
+ metricgroup__rblist_init(metric_events);
+ return metricgroup__setup_events(group_list, evlist, metric_events);
+}
+
int metricgroup__parse_groups(const struct option *opt,
const char *str,
struct rblist *metric_events)
{
- struct parse_events_error parse_error;
struct evlist *perf_evlist = *(struct evlist **)opt->value;
struct strbuf extra_events;
LIST_HEAD(group_list);
int ret;

- if (metric_events->nr_entries == 0)
- metricgroup__rblist_init(metric_events);
ret = metricgroup__add_metric_list(str, &extra_events, &group_list);
if (ret)
return ret;
- pr_debug("adding %s\n", extra_events.buf);
- bzero(&parse_error, sizeof(parse_error));
- ret = parse_events(perf_evlist, extra_events.buf, &parse_error);
- if (ret) {
- parse_events_print_error(&parse_error, extra_events.buf);
- goto out;
- }
+
+ ret = metricgroup__setup(perf_evlist, metric_events, &extra_events,
+ &group_list);
strbuf_release(&extra_events);
- ret = metricgroup__setup_events(&group_list, perf_evlist,
- metric_events);
-out:
metricgroup__free_egroups(&group_list);
return ret;
}
--
2.21.1