Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp350419pxk; Thu, 17 Sep 2020 05:00:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz62gmgXDxNga1OHau2JofY3qsqwWq8tkbEfQQKbpmCAnZNAxD6yzuJZVGstuEk2RqI1cAQ X-Received: by 2002:a50:d2d1:: with SMTP id q17mr32616902edg.167.1600344003244; Thu, 17 Sep 2020 05:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600344003; cv=none; d=google.com; s=arc-20160816; b=r2pt6nSNCdtsIwN1vzuuKKKQgoR/i7S0u7axHwpErnojiCcZomspT/UxkOWPyUcTxh yGb7VsBFgiyVlRMPvlA2whgcXiyNuNsA1CI18DjT7AK3ddFiKPVBlhmwOKj3VNZGUA04 P9lIfutxzSVg4vxjnkvtjqM8uOntrw9qrWO3F14JUtystLbJ9pQxfVBcueqsLW91Nqxj tqb2Talp6vGCMRAib+T/0wcdJnEkLM42eFM8/idi4gl4a7F5ZVzZev/1Ym+VRoEjzqsZ ZHfXkeuDZIRMuUgvN5aa1VJwnF4+ciZY/tcFS1HCLuB990eB2DRBwnMQHE0y7qE+0TLs pg0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=6eZwAa86pGKuOG/N+t3IwHK3RrlhwQ8TZFanqggT1sw=; b=tuOgdkMJavlyR+TQ52PjZuR6VamyxibbSsZgpDB13Q3maO6ojByYvLZULZNyGZwRnC wlXrnLEUYN1w5W5LWnVq5HSan3KdD8zMs9M80jEEw8LFwYomaslbAhhu1V6bNfHnF0UH Ak2yg4GpErBhX3ukWjgw1ZS78UzKXYhRHZ60iRrOeRTvNnhCOUUextAqW++qFIEZUPVN I5kwFWkGghKPzAKEZfs7uoeADDE6Wusfcw/be6KYxGGP1lMnaJpeNXagD3OPhHkJ96bC 64z0ifF4YkyHapAzSijbd+igQwJMrkf4adsB0vY5ppxy/8qv83XcamHlN8ePv2QEq4Bx +WiA== 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 bh20si12971069ejb.294.2020.09.17.04.59.39; Thu, 17 Sep 2020 05:00:03 -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 S1726719AbgIQL41 (ORCPT + 99 others); Thu, 17 Sep 2020 07:56:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:41592 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726755AbgIQLxn (ORCPT ); Thu, 17 Sep 2020 07:53:43 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C4D0B93D595EB4C328D5; Thu, 17 Sep 2020 19:53:40 +0800 (CST) Received: from [10.174.178.63] (10.174.178.63) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 17 Sep 2020 19:53:30 +0800 Subject: Re: [PATCH] perf metric: Code cleanup with map_for_each_event() To: Namhyung Kim CC: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , "Ian Rogers" , Kajol Jain , Kan Liang , linux-kernel , "Li Bin" , References: <20200917024421.46973-1-liwei391@huawei.com> From: "liwei (GF)" Message-ID: <6fca1006-f7a6-160a-e6ef-17701dfe9d4c@huawei.com> Date: Thu, 17 Sep 2020 19:53:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.63] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Namhyung, On 2020/9/17 13:19, Namhyung Kim wrote: > 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 for spotting that. I'd like to move them just below match_metric() for now, when we really need to use them somewhere else, we may move them to header file then. Thanks, Wei