[PATCH 06/19] perf metric: Add add_metric function
Decouple metric adding logging into add_metric function, so it can be used from other places in following changes. Signed-off-by: Jiri Olsa Reviewed-by: Kajol Jain Acked-by: Ian Rogers Cc: Alexander Shishkin Cc: Andi Kleen Cc: John Garry Cc: Michael Petlan Cc: Namhyung Kim Cc: Paul Clarke Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20200719181320.785305-7-jo...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/metricgroup.c | 62 --- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index b37008fc253c..4096be7a7a9e 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -625,6 +625,39 @@ static int __metricgroup__add_metric(struct list_head *group_list, (match_metric(__pe->metric_group, __metric) || \ match_metric(__pe->metric_name, __metric))) +static int add_metric(struct list_head *group_list, + struct pmu_event *pe, + bool metric_no_group) +{ + int ret = 0; + + pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); + + if (!strstr(pe->metric_expr, "?")) { + ret = __metricgroup__add_metric(group_list, + pe, + metric_no_group, + 1); + } else { + int j, count; + + count = arch_get_runtimeparam(); + + /* This loop is added to create multiple +* events depend on count value and add +* those events to group_list. +*/ + + for (j = 0; j < count && !ret; j++) { + ret = __metricgroup__add_metric( + group_list, pe, + metric_no_group, j); + } + } + + return ret; +} + static int metricgroup__add_metric(const char *metric, bool metric_no_group, struct strbuf *events, struct list_head *group_list, @@ -636,34 +669,11 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, bool has_match = false; map_for_each_metric(pe, i, map, metric) { - pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); has_match = true; - if (!strstr(pe->metric_expr, "?")) { - ret = __metricgroup__add_metric(group_list, - pe, - metric_no_group, - 1); - if (ret) - return ret; - } else { - int j, count; - - count = arch_get_runtimeparam(); - - /* This loop is added to create multiple -* events depend on count value and add -* those events to group_list. -*/ - - for (j = 0; j < count; j++) { - ret = __metricgroup__add_metric( - group_list, pe, - metric_no_group, j); - if (ret) - return ret; - } - } + ret = add_metric(group_list, pe, metric_no_group); + if (ret) + return ret; } /* End of pmu events. */ -- 2.25.4
Re: [PATCH 06/19] perf metric: Add add_metric function
Em Sun, Jul 26, 2020 at 02:47:53PM +0530, kajoljain escreveu: > > > On 7/19/20 11:43 PM, Jiri Olsa wrote: > > Decouple metric adding logging into add_metric function, > > so it can be used from other places in following changes. > > > > Acked-by: Ian Rogers > > Signed-off-by: Jiri Olsa > > --- > > Reviewed-By : Kajol Jain Thanks, applied. - Arnaldo > Thanks, > Kajol Jain > > tools/perf/util/metricgroup.c | 62 --- > > 1 file changed, 36 insertions(+), 26 deletions(-) > > > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > > index b37008fc253c..4096be7a7a9e 100644 > > --- a/tools/perf/util/metricgroup.c > > +++ b/tools/perf/util/metricgroup.c > > @@ -625,6 +625,39 @@ static int __metricgroup__add_metric(struct list_head > > *group_list, > > (match_metric(__pe->metric_group, __metric) || \ > > match_metric(__pe->metric_name, __metric))) > > > > +static int add_metric(struct list_head *group_list, > > + struct pmu_event *pe, > > + bool metric_no_group) > > +{ > > + int ret = 0; > > + > > + pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); > > + > > + if (!strstr(pe->metric_expr, "?")) { > > + ret = __metricgroup__add_metric(group_list, > > + pe, > > + metric_no_group, > > + 1); > > + } else { > > + int j, count; > > + > > + count = arch_get_runtimeparam(); > > + > > + /* This loop is added to create multiple > > +* events depend on count value and add > > +* those events to group_list. > > +*/ > > + > > + for (j = 0; j < count && !ret; j++) { > > + ret = __metricgroup__add_metric( > > + group_list, pe, > > + metric_no_group, j); > > + } > > + } > > + > > + return ret; > > +} > > + > > static int metricgroup__add_metric(const char *metric, bool > > metric_no_group, > >struct strbuf *events, > >struct list_head *group_list, > > @@ -636,34 +669,11 @@ static int metricgroup__add_metric(const char > > *metric, bool metric_no_group, > > bool has_match = false; > > > > map_for_each_metric(pe, i, map, metric) { > > - pr_debug("metric expr %s for %s\n", pe->metric_expr, > > pe->metric_name); > > has_match = true; > > > > - if (!strstr(pe->metric_expr, "?")) { > > - ret = __metricgroup__add_metric(group_list, > > - pe, > > - metric_no_group, > > - 1); > > - if (ret) > > - return ret; > > - } else { > > - int j, count; > > - > > - count = arch_get_runtimeparam(); > > - > > - /* This loop is added to create multiple > > -* events depend on count value and add > > -* those events to group_list. > > -*/ > > - > > - for (j = 0; j < count; j++) { > > - ret = __metricgroup__add_metric( > > - group_list, pe, > > - metric_no_group, j); > > - if (ret) > > - return ret; > > - } > > - } > > + ret = add_metric(group_list, pe, metric_no_group); > > + if (ret) > > + return ret; > > } > > > > /* End of pmu events. */ > > -- - Arnaldo
Re: [PATCH 06/19] perf metric: Add add_metric function
On 7/19/20 11:43 PM, Jiri Olsa wrote: > Decouple metric adding logging into add_metric function, > so it can be used from other places in following changes. > > Acked-by: Ian Rogers > Signed-off-by: Jiri Olsa > --- Reviewed-By : Kajol Jain Thanks, Kajol Jain > tools/perf/util/metricgroup.c | 62 --- > 1 file changed, 36 insertions(+), 26 deletions(-) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > index b37008fc253c..4096be7a7a9e 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -625,6 +625,39 @@ static int __metricgroup__add_metric(struct list_head > *group_list, > (match_metric(__pe->metric_group, __metric) || \ >match_metric(__pe->metric_name, __metric))) > > +static int add_metric(struct list_head *group_list, > + struct pmu_event *pe, > + bool metric_no_group) > +{ > + int ret = 0; > + > + pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); > + > + if (!strstr(pe->metric_expr, "?")) { > + ret = __metricgroup__add_metric(group_list, > + pe, > + metric_no_group, > + 1); > + } else { > + int j, count; > + > + count = arch_get_runtimeparam(); > + > + /* This loop is added to create multiple > + * events depend on count value and add > + * those events to group_list. > + */ > + > + for (j = 0; j < count && !ret; j++) { > + ret = __metricgroup__add_metric( > + group_list, pe, > + metric_no_group, j); > + } > + } > + > + return ret; > +} > + > static int metricgroup__add_metric(const char *metric, bool metric_no_group, > struct strbuf *events, > struct list_head *group_list, > @@ -636,34 +669,11 @@ static int metricgroup__add_metric(const char *metric, > bool metric_no_group, > bool has_match = false; > > map_for_each_metric(pe, i, map, metric) { > - pr_debug("metric expr %s for %s\n", pe->metric_expr, > pe->metric_name); > has_match = true; > > - if (!strstr(pe->metric_expr, "?")) { > - ret = __metricgroup__add_metric(group_list, > - pe, > - metric_no_group, > - 1); > - if (ret) > - return ret; > - } else { > - int j, count; > - > - count = arch_get_runtimeparam(); > - > - /* This loop is added to create multiple > - * events depend on count value and add > - * those events to group_list. > - */ > - > - for (j = 0; j < count; j++) { > - ret = __metricgroup__add_metric( > - group_list, pe, > - metric_no_group, j); > - if (ret) > - return ret; > - } > - } > + ret = add_metric(group_list, pe, metric_no_group); > + if (ret) > + return ret; > } > > /* End of pmu events. */ >
[PATCH 06/19] perf metric: Add add_metric function
Decouple metric adding logging into add_metric function, so it can be used from other places in following changes. Acked-by: Ian Rogers Signed-off-by: Jiri Olsa --- tools/perf/util/metricgroup.c | 62 --- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index b37008fc253c..4096be7a7a9e 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -625,6 +625,39 @@ static int __metricgroup__add_metric(struct list_head *group_list, (match_metric(__pe->metric_group, __metric) || \ match_metric(__pe->metric_name, __metric))) +static int add_metric(struct list_head *group_list, + struct pmu_event *pe, + bool metric_no_group) +{ + int ret = 0; + + pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); + + if (!strstr(pe->metric_expr, "?")) { + ret = __metricgroup__add_metric(group_list, + pe, + metric_no_group, + 1); + } else { + int j, count; + + count = arch_get_runtimeparam(); + + /* This loop is added to create multiple +* events depend on count value and add +* those events to group_list. +*/ + + for (j = 0; j < count && !ret; j++) { + ret = __metricgroup__add_metric( + group_list, pe, + metric_no_group, j); + } + } + + return ret; +} + static int metricgroup__add_metric(const char *metric, bool metric_no_group, struct strbuf *events, struct list_head *group_list, @@ -636,34 +669,11 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, bool has_match = false; map_for_each_metric(pe, i, map, metric) { - pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); has_match = true; - if (!strstr(pe->metric_expr, "?")) { - ret = __metricgroup__add_metric(group_list, - pe, - metric_no_group, - 1); - if (ret) - return ret; - } else { - int j, count; - - count = arch_get_runtimeparam(); - - /* This loop is added to create multiple -* events depend on count value and add -* those events to group_list. -*/ - - for (j = 0; j < count; j++) { - ret = __metricgroup__add_metric( - group_list, pe, - metric_no_group, j); - if (ret) - return ret; - } - } + ret = add_metric(group_list, pe, metric_no_group); + if (ret) + return ret; } /* End of pmu events. */ -- 2.25.4