Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp838091pxk; Thu, 17 Sep 2020 18:32:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwUzzMsFYzWuaBECc1bwoqSiFzz74h7iaTg+XohSvviepO6jZkqyTX0I8O+Rdlg+AxMLYt X-Received: by 2002:a17:906:cb98:: with SMTP id mf24mr34910845ejb.90.1600392724630; Thu, 17 Sep 2020 18:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600392724; cv=none; d=google.com; s=arc-20160816; b=oOiuRlnkaEDAtGqwfErj/Yje6kqKyz70a+jrZmFJqKyfzL3XFYUOkq9SeaSEbYHWzY xBF8Fu+YYp47T5BiEwRi9IyxiUxfptc8SArYBBZDlzQU0VXKSP1zDZI8OQgcHrN9dJY3 jx0p5YWdozxWh+IVT/ua7Mk2QbTRgEJN6wsIW7NE4/xMp4e//pIveWaqSioT46QhZVj6 Exfy1ewAbUBas9OpxsJ2EBoq3ZCeOyg6xpdpmsgF6kpJsxyC7ou5jSYhUvHz8B+qIdS5 7dBVv8LZbu4Xrqmr+cXG4lk2GeX1jy/Kgc3MAH6NSojL4wWBgy7Td8/A1nRj8nDN6NGx TzjQ== 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=Gy6qdXnQG606hQrNKuq1m58djHdb44pr4lMAKeYscN8=; b=qidDSsrlza/+ktO2TzKcKkOtLcyCBqxKthMgtmecYJRB1qjiWs8gE8t02lz4v9pHJU YXRfW+sHmPJzhDCcVdjyX+T+geaV9Vtlcm28YrZkWHKPjw5tuxjvq47BxNZ2v8gLCjxa EiN418mACVjglAvyqghTOlSNM2D/9Uc4v8gSjjWY1D2dv5rxLLF8h1zV3bf7gSy1GL7Z MvR5kQ+p0J15f8IKWxpo0fHcheDbWlawAxT8JkUlpPgW34shW1cEzESRSR/I5s+ewaCL 8+N7gMrFy0aVufVibGOgpCjxXjEL7DvsGfb9xGbZ3PLSEXtzuWH/P03WvAvtXiW9A1J0 vkGQ== 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 h2si1195234ejo.1.2020.09.17.18.31.41; Thu, 17 Sep 2020 18:32:04 -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 S1726196AbgIRBai (ORCPT + 99 others); Thu, 17 Sep 2020 21:30:38 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:55568 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726185AbgIRBai (ORCPT ); Thu, 17 Sep 2020 21:30:38 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B80F0FF0C86E8A2A2705; Fri, 18 Sep 2020 09:30:35 +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; Fri, 18 Sep 2020 09:30:26 +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 v2] perf metric: Code cleanup with map_for_each_event() Date: Fri, 18 Sep 2020 09:29:48 +0800 Message-ID: <20200918012948.2798-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 Acked-by: Namhyung Kim --- v1 -> v2: - Move map_for_each_metric() after match_metric() to avoid potential use-before-declare. --- 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..50ee36437b99 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -374,6 +374,17 @@ static bool match_metric(const char *n, const char *list) return false; } +#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 mep { struct rb_node nd; const char *name; @@ -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