Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1218371pxk; Fri, 18 Sep 2020 07:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ3X4MPAAbUj5r7eoD++8yS+grMuuyvWkwjAoQu9e1wuceT7INFVfs61rpA/xRMOxjKW/G X-Received: by 2002:a17:906:15c4:: with SMTP id l4mr35410208ejd.78.1600437671972; Fri, 18 Sep 2020 07:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600437671; cv=none; d=google.com; s=arc-20160816; b=qYcPa9rMUNCsaKgwiJRyqR6lsWQCaLZqQTe0YGrLlZ1fsWXw1FTw0aLI0ps/Fz5Ag0 CTpEXlOqlmPNgsRqx/x+rPkB8vqXjlCXyByw/fvu9xAKlzutJQPwmANhOgWRHh6RzU44 96hBzM4032l1A5Ww71QqMdMrV/XgwFL/XsXhXzmXmc8GG5IyCrqqPez26FOTVHO1jDmR ++T9X4pZTw78tcT3KV4jvV06J1aBpWx+1Bu69rfpD50Srp5YPDB6vyLzG8P4wADTgG7X SQ2pqcQr0aF8cT0L0OUQylxBDzzykz7iAToq+EzVWTSpJ5X2LNllI6Z6IYAuz/OuNX2e JeLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=s3feYbRX5RF30aYeydKYF7mV0YVysGFrSM26kIF+cdg=; b=Bk7S4GWpVHFOTUtQWZnEb5H9EMfxSWiO9vE60J9WunxIf2HYx73XPV6neHKYGhX6uU 4Yx/GghYBXZul6rBLCegwJ3H8aS62PoAMXlNpi+6fJg3fDbTSukR0ZPrllufY/AmCDz0 Conjg3M4CkpyPpfaLF6Qgfy/QsQDEoUpIkTqGCV9ZWyN39vbmKK1Fhy1ssQvceAW/OtG sVi2rAK/JLko4zai0md1dW179WpbLYvsOOSx7EiiAcFSFa8HQzbU7PBa+RV5TE3pjXiV 89yeGgzKEJk1V3cGa93U+4PphnKfc3SJMD7K+hH10Ip3XwA5kVzXFXqS+jn6NGUVaoj9 1X5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fRAnDMH4; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx18si2142059edb.372.2020.09.18.07.00.48; Fri, 18 Sep 2020 07:01:11 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fRAnDMH4; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbgIRN5o (ORCPT + 99 others); Fri, 18 Sep 2020 09:57:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38616 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbgIRN5e (ORCPT ); Fri, 18 Sep 2020 09:57:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600437453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=s3feYbRX5RF30aYeydKYF7mV0YVysGFrSM26kIF+cdg=; b=fRAnDMH4Ah6bRHVIVPGdavBFaK4KkvtBzu3A5QH7tC1fImca2e4SCMC4daItvvPXlV4W4h IJPiCLS+pY9/9/KYpzv8cDch2HyoXDO//kdYlFaUT8HZea5gjIrUZeloKh7xgBCbruVtdC kD5FlTnHAavmZ8E+OzjROvStpObtzIw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-iIapkWVhP4aTLzlHnAiGCw-1; Fri, 18 Sep 2020 09:57:29 -0400 X-MC-Unique: iIapkWVhP4aTLzlHnAiGCw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A9EC1007B2B; Fri, 18 Sep 2020 13:57:27 +0000 (UTC) Received: from krava (ovpn-114-24.ams2.redhat.com [10.36.114.24]) by smtp.corp.redhat.com (Postfix) with SMTP id 787F41C4; Fri, 18 Sep 2020 13:57:22 +0000 (UTC) Date: Fri, 18 Sep 2020 15:57:21 +0200 From: Jiri Olsa To: Wei Li Cc: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Ian Rogers , Kajol Jain , Kan Liang , linux-kernel@vger.kernel.org, huawei.libin@huawei.com, guohanjun@huawei.com Subject: Re: [PATCH v2] perf metric: Code cleanup with map_for_each_event() Message-ID: <20200918135721.GE2626435@krava> References: <20200918012948.2798-1-liwei391@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200918012948.2798-1-liwei391@huawei.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2020 at 09:29:48AM +0800, 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 Acked-by: Jiri Olsa thanks, jirka > --- > 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 >