Recent code factoring screwed up runtime metrics for powerpc,
because we did not treat separate runtime metrics as single
metrics, but added them as referenced ones.

Fixing this by zero-ing parent metric object for __add_metric
call. Also there's no need to pass metric object to resolve_metric
function, we just need to iterate the metric_list.

Tested/Reviewed-By : Kajol Jain<[email protected]>
Fixes: e975d61c466b ("perf metric: Collect referenced metrics in struct 
metric_ref_node")
Signed-off-by: Jiri Olsa <[email protected]>
---
 tools/perf/util/metricgroup.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index e91a625fa1be..50bd485094ba 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -820,11 +820,11 @@ static int add_metric(struct list_head *metric_list,
                      struct expr_id *parent,
                      struct expr_ids *ids);
 
-static int resolve_metric(struct metric *m,
-                         bool metric_no_group,
-                         struct list_head *metric_list,
-                         struct pmu_events_map *map,
-                         struct expr_ids *ids)
+static int __resolve_metric(struct metric *m,
+                           bool metric_no_group,
+                           struct list_head *metric_list,
+                           struct pmu_events_map *map,
+                           struct expr_ids *ids)
 {
        struct hashmap_entry *cur;
        size_t bkt;
@@ -869,6 +869,23 @@ static int resolve_metric(struct metric *m,
        return 0;
 }
 
+static int resolve_metric(bool metric_no_group,
+                         struct list_head *metric_list,
+                         struct pmu_events_map *map,
+                         struct expr_ids *ids)
+{
+       struct metric *m;
+       int err;
+
+       list_for_each_entry(m, metric_list, nd) {
+               err = __resolve_metric(m, metric_no_group, metric_list, map, 
ids);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
 static int add_metric(struct list_head *metric_list,
                      struct pmu_event *pe,
                      bool metric_no_group,
@@ -876,6 +893,7 @@ static int add_metric(struct list_head *metric_list,
                      struct expr_id *parent,
                      struct expr_ids *ids)
 {
+       struct metric *orig = *m;
        int ret = 0;
 
        pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
@@ -892,9 +910,8 @@ static int add_metric(struct list_head *metric_list,
                 * those events to metric_list.
                 */
 
-               for (j = 0; j < count && !ret; j++) {
+               for (j = 0; j < count && !ret; j++, *m = orig)
                        ret = __add_metric(metric_list, pe, metric_no_group, j, 
m, parent, ids);
-               }
        }
 
        return ret;
@@ -907,8 +924,8 @@ static int metricgroup__add_metric(const char *metric, bool 
metric_no_group,
 
 {
        struct expr_ids ids = { 0 };
+       struct metric *m = NULL;
        struct pmu_event *pe;
-       struct metric *m;
        LIST_HEAD(list);
        int i, ret;
        bool has_match = false;
@@ -925,7 +942,7 @@ static int metricgroup__add_metric(const char *metric, bool 
metric_no_group,
                 * Process any possible referenced metrics
                 * included in the expression.
                 */
-               ret = resolve_metric(m, metric_no_group,
+               ret = resolve_metric(metric_no_group,
                                     &list, map, &ids);
                if (ret)
                        return ret;
-- 
2.25.4

Reply via email to