Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp155785pxk; Wed, 16 Sep 2020 22:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWZXY/9uVX57XHkA9D6dgiTNzb7CIU8ck/sb5ZlHeAOWAGYxhC8nZVWhtN89u/lzLeYM0F X-Received: by 2002:a17:906:1787:: with SMTP id t7mr30148489eje.173.1600320099024; Wed, 16 Sep 2020 22:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600320099; cv=none; d=google.com; s=arc-20160816; b=hxEbwTTXxmfUyLYqZ3GEqeb6EfuxFhrBXp3tURKBOrKcnd419oXXYst91ksPQzif1/ PWaqswXrb4LbeCKpnhMPpooPAZrjVLr9SRm0iFI0TB+nMvFBMUqVg0v8FRPYnKzwWs5m tLcLeEPyg7A8gkl8VXuPgxoPcbbFN/KIyG0XQk+7C+UwjQMT5spZYeIW8oqEWTFFTvqs f7l6p9SC3dib+NqnQKZ7KPU2pal0JHOa8abuD3FObYNEsbfBrr0tvV5R7qpUP+v1g96P nKKCre68IgpQW7taVStETJ5Z3CrO3L3gNJzIgEZtMu5C+4DDkMiJASBGyqhuQZKs3GWZ O1nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=BHpuAUTaCPXW51YTfA4N1UnGTafHFhHpoxgaMPqjs9s=; b=uY+dKjc2025Q8p7hm5SytA84K1HJ/8UWd7RI3wttq+cwpzSd4fMGqX8zUvkeizhmMi mEOkJ48ol2UtOEZDkYVyujhhhpLfUla1Dd6acu6/r2IhGoGZIxurh/hMwsgX02dy1PpI 4ObGwpSeeUJYSMbhYWE9LgrwTNizQMS3OKUmIajeqAL+hl72GvyXSVTkH73ua3UN2QA0 OpZZHtMoS2jNcr8tuGmhifLNeeWj8oorRkxl+qr2ucKkODFfCZ6mfc/9SM0Hit4gh1YD TuqNdRWbUwUM3J8ywuULJFcBjBU3hGECgRd9/Ppc7w4FaPeky/YJhFI1+o6X0C7OWMLF gGkQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn20si15263069ejc.196.2020.09.16.22.21.15; Wed, 16 Sep 2020 22:21:39 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726180AbgIQFTv (ORCPT + 99 others); Thu, 17 Sep 2020 01:19:51 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38362 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbgIQFTu (ORCPT ); Thu, 17 Sep 2020 01:19:50 -0400 Received: by mail-wr1-f66.google.com with SMTP id g4so572328wrs.5 for ; Wed, 16 Sep 2020 22:19:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BHpuAUTaCPXW51YTfA4N1UnGTafHFhHpoxgaMPqjs9s=; b=Gpg6BsK889xdMQGVHQfOPjZuH8zFGPgixZK1fBYs6+epjmp/29B31SsiSUtaK0QXBj PWnGHprinHIcRo9UrMKkwYp+a1jpgmqfbWvAjL5jLCwJ13MHkNFTVbH/UJ2DZJPoCmaY A2HoODwZXqcIvtA5+as46UQLGHNXEob8Qj+rOcGw5Mf6SLhcirlMvEqkEGc4T3W5ZYBs HwnNdlD6JL8jHZN2lraYzkwahQ7I2jOjWibmsAczRATWTl0IIPSxVLSJTdgB+gYdxfOn /o6p2rVi9zVviLglEnXZprD002oDPxQGYyLhkamjeZVKRP4/qXg/iCfFsDcQl1v9C8HV 7PBw== X-Gm-Message-State: AOAM532UHY79JJM6GDL5hPNrtwOuILU0Rq3q9fZHuaodA4/YUhQSt7/4 asN2DZeBSLBQsrRaE8hWxPA6VXd4xM1yrRPuCEM= X-Received: by 2002:adf:a418:: with SMTP id d24mr22277038wra.80.1600319988591; Wed, 16 Sep 2020 22:19:48 -0700 (PDT) MIME-Version: 1.0 References: <20200917024421.46973-1-liwei391@huawei.com> In-Reply-To: <20200917024421.46973-1-liwei391@huawei.com> From: Namhyung Kim Date: Thu, 17 Sep 2020 14:19:37 +0900 Message-ID: Subject: Re: [PATCH] perf metric: Code cleanup with map_for_each_event() To: Wei Li Cc: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Kajol Jain , Kan Liang , linux-kernel , Li Bin , guohanjun@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Sep 17, 2020 at 11:45 AM Wei Li wrote: > > 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 A nit-pick below: > --- > 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))) > + You may consider adding a declaration of match_metric() here. Right now, all users are below the function so it's ok but having the macro here can enable future addition above IMHO. Thanks Namhyung > 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 >