Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp94481pxk; Wed, 16 Sep 2020 20:06:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbOGMb2Dc/A+zODkQ8b1VyRg+iRAangf8iq2E3fRa1WU+ZDzLAI6xcxITjk0Yw98krif6D X-Received: by 2002:a17:906:a3d0:: with SMTP id ca16mr28355153ejb.455.1600311975650; Wed, 16 Sep 2020 20:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600311975; cv=none; d=google.com; s=arc-20160816; b=HAQ1RHQuemADHEUkAo35/NmGHLfFMHr2Y0yk7SkM2zWFaKGZYJpSzuKbYils/FxFpH nmhNmNM5xOusXMXmDvT9AwzgoC+GxtjLrFj8QOR+6EZNnICdb6kR7SB2KHdQ6p9M8tmc eWcBAZGypZXymXsnnlyoSbOBj6BTLzGM7Nj8SUuhCsFTT77ny3DaJfRwCRIt19N7QM7J pIkW+zqAtsXf/oxRgQA90eRDzQCIMRs/Zn6Pl94kKLYrduulZzw22QhmkhHkgdRsPy3/ VY63i/NozrIh6qCigHYQ46oYDEoVbtYTvM+paxjeufVNhA1VnSUok7ek1mo7yWE950MX TO7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=lwDmA3E51j7aq3BvP3qQj+SJzM4CJnnqPInws6xuRZM=; b=Qkc/XRzq56QY6vWfL+pP2H7f0go7amAN1Ohzlyo/dceCPp1CeL55ZfG2Mwn6iVNeBh JlgBVcObIx7MONKwCRlCoGKbJXQuRl/mEwKwMQlrKPKQdTF7JLV0+qayr+BQKQqBbyAU v842MaMXlH+x8ES7Ud76xhTf+rGERkSMe/IsijtpBfupfw+IMnSSGcs8uaJEV7BipeBw s04GU8+RSajiKOQ8MV7QYcT17Z/iaO3HdljoPG8hfSsXrsPfTt5Fjlv+kv20J0obChXS QX/eUdgh4QoijxTSo99CmTTWCo1lmeIndFjTzB7pll/e3MvQL7Wh1l7fbtEeYIGHrWo/ i0fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si13494640edv.381.2020.09.16.20.05.52; Wed, 16 Sep 2020 20:06:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726152AbgIQDBe (ORCPT + 99 others); Wed, 16 Sep 2020 23:01:34 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:12767 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726135AbgIQDB2 (ORCPT ); Wed, 16 Sep 2020 23:01:28 -0400 X-Greylist: delayed 971 seconds by postgrey-1.27 at vger.kernel.org; Wed, 16 Sep 2020 23:01:27 EDT Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 82F1A66FE07F77A47874; Thu, 17 Sep 2020 10:45:08 +0800 (CST) Received: from euler.huawei.com (10.175.124.27) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 17 Sep 2020 10:44:57 +0800 From: Wei Li To: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" , Ian Rogers , Kajol Jain , Kan Liang CC: , , Subject: [PATCH] perf metric: Code cleanup with map_for_each_event() Date: Thu, 17 Sep 2020 10:44:21 +0800 Message-ID: <20200917024421.46973-1-liwei391@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since we have introduced map_for_each_event() to walk the 'pmu_events_map', clean up metricgroup__print() and metricgroup__has_metric() with it. Signed-off-by: Wei Li --- tools/perf/util/metricgroup.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8831b964288f..3734cbb2c456 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -26,6 +26,17 @@ #include "util.h" #include +#define map_for_each_event(__pe, __idx, __map) \ + for (__idx = 0, __pe = &__map->table[__idx]; \ + __pe->name || __pe->metric_group || __pe->metric_name; \ + __pe = &__map->table[++__idx]) + +#define map_for_each_metric(__pe, __idx, __map, __metric) \ + map_for_each_event(__pe, __idx, __map) \ + if (__pe->metric_expr && \ + (match_metric(__pe->metric_group, __metric) || \ + match_metric(__pe->metric_name, __metric))) + struct metric_event *metricgroup__lookup(struct rblist *metric_events, struct evsel *evsel, bool create) @@ -475,12 +486,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; - for (i = 0; ; i++) { + map_for_each_event(pe, i, map) { const char *g; - pe = &map->table[i]; - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; if (!pe->metric_expr) continue; g = pe->metric_group; @@ -745,17 +753,6 @@ static int __add_metric(struct list_head *metric_list, return 0; } -#define map_for_each_event(__pe, __idx, __map) \ - for (__idx = 0, __pe = &__map->table[__idx]; \ - __pe->name || __pe->metric_group || __pe->metric_name; \ - __pe = &__map->table[++__idx]) - -#define map_for_each_metric(__pe, __idx, __map, __metric) \ - map_for_each_event(__pe, __idx, __map) \ - if (__pe->metric_expr && \ - (match_metric(__pe->metric_group, __metric) || \ - match_metric(__pe->metric_name, __metric))) - static struct pmu_event *find_metric(const char *metric, struct pmu_events_map *map) { struct pmu_event *pe; @@ -1092,11 +1089,7 @@ bool metricgroup__has_metric(const char *metric) if (!map) return false; - for (i = 0; ; i++) { - pe = &map->table[i]; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; + map_for_each_event(pe, i, map) { if (!pe->metric_expr) continue; if (match_metric(pe->metric_name, metric)) -- 2.17.1