Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp218686ybg; Sun, 26 Jul 2020 02:19:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziOPBjRB1y/Sp1PCWkx8oWJyuOX5idDMnD7pJF7/GhwIpycIdd7krRgk44R/g05eVUm4ur X-Received: by 2002:a05:6402:318d:: with SMTP id di13mr17225685edb.172.1595755177064; Sun, 26 Jul 2020 02:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595755177; cv=none; d=google.com; s=arc-20160816; b=PkbHecgn72COF4Zs77id5tOA8OLAA3nrp7mtl7zKbPxoznPDA9q/Lr6vE7HgvzC9LC QMUP4FPbEmGOEKf5hUphNeKN3BdyKx6p13vM0GwTepl2qSkbDs8oQQIwy6MPFyiiv32g Cyxj1S27uZxUIqjS0x0pikkpswJQS970LCu3/aPaL2aFaaRAb1bcS19+h0ujCupT74dS c9FYlPIx58HSQh1yypX2ACjgKTLumm9rvV7/dPdP8g511lGRcqKyZVFxPPxtyPQWa62F 9T6OQfDY65LNXrYdns1MXqHCMuSQ7eWgrCUxGMyviXVtLfrZDAmVGHElld/9RBBcWcO1 cO8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Z2pc2d+v1UV6Gju4O0/KJl/JVi5Zz0YPmbY4uAasj5c=; b=d1//xzvC3lQGQiq449itTAlBZVef3q4u8FqEMLia2/EJJ/ZCH2ZgC3kmB/w3IeCtJa q24xaPBsMIMTzwYZaDV2cM7oVCY13a5nadQlqlRnsky/ezJYnISEvQKOgoE3qhNvnu2A fn9DZHai1ixZdNWEB9Fy82p9QvCJxQAxM+7eP0BJwY73qW4X8vufaypDzIOVLdf3+qEe 5HF+AlHtzm5QQMe0ej5xsNC2Gdbt7ojl55apdc18DTAl6o0rM2EJHOErrmUPidVS5EPy znn3O0oVo4PIBTqNxcO2+ttXdR4qCcHWi3wBrhVgr1uaSMO+mCVavHXB3qr30MdQYSml UwRQ== 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si1970367ejb.407.2020.07.26.02.19.15; Sun, 26 Jul 2020 02:19:37 -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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbgGZJSw (ORCPT + 99 others); Sun, 26 Jul 2020 05:18:52 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41938 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727801AbgGZJSw (ORCPT ); Sun, 26 Jul 2020 05:18:52 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06Q92ZgE039735; Sun, 26 Jul 2020 05:17:44 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32h2bfmrnk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 26 Jul 2020 05:17:44 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06Q93JCe040850; Sun, 26 Jul 2020 05:17:43 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 32h2bfmrn8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 26 Jul 2020 05:17:43 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06Q9FbYn015012; Sun, 26 Jul 2020 09:17:43 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma04wdc.us.ibm.com with ESMTP id 32gcpqrwem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 26 Jul 2020 09:17:43 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06Q9HgAV50201024 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 26 Jul 2020 09:17:42 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6DD628058; Sun, 26 Jul 2020 09:17:42 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5AB6F2805A; Sun, 26 Jul 2020 09:17:38 +0000 (GMT) Received: from localhost.localdomain (unknown [9.199.34.120]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 26 Jul 2020 09:17:38 +0000 (GMT) Subject: Re: [PATCH 05/19] perf metric: Add macros for iterating map events To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Andi Kleen , John Garry , "Paul A. Clarke" , Stephane Eranian , Ian Rogers References: <20200719181320.785305-1-jolsa@kernel.org> <20200719181320.785305-6-jolsa@kernel.org> From: kajoljain Message-ID: <68188ed3-80a7-cf03-bfdd-6bee7ded09ca@linux.ibm.com> Date: Sun, 26 Jul 2020 14:47:37 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200719181320.785305-6-jolsa@kernel.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-26_02:2020-07-24,2020-07-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 spamscore=0 impostorscore=0 mlxscore=0 phishscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007260064 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/19/20 11:43 PM, Jiri Olsa wrote: > Adding following macros to iterate events and metric: > map_for_each_event(__pe, __idx, __map) > - iterates over all pmu_events_map events > map_for_each_metric(__pe, __idx, __map, __metric) > - iterates over all metrics that match __metric argument > > and use it in metricgroup__add_metric function. Macros > will be be used from other places in following changes. > > Signed-off-by: Jiri Olsa Reviewed-By : Kajol Jain Thanks, Kajol Jain > --- > tools/perf/util/metricgroup.c | 77 ++++++++++++++++++----------------- > 1 file changed, 40 insertions(+), 37 deletions(-) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > index df0356ec120d..b37008fc253c 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -614,6 +614,17 @@ static int __metricgroup__add_metric(struct list_head *group_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 int metricgroup__add_metric(const char *metric, bool metric_no_group, > struct strbuf *events, > struct list_head *group_list, > @@ -624,49 +635,41 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, > int i, ret; > bool has_match = false; > > - for (i = 0; ; i++) { > - pe = &map->table[i]; > - > - if (!pe->name && !pe->metric_group && !pe->metric_name) { > - /* End of pmu events. */ > - if (!has_match) > - return -EINVAL; > - break; > - } > - if (!pe->metric_expr) > - continue; > - if (match_metric(pe->metric_group, metric) || > - match_metric(pe->metric_name, metric)) { > - has_match = true; > - pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); > - > - if (!strstr(pe->metric_expr, "?")) { > - ret = __metricgroup__add_metric(group_list, > - pe, > - metric_no_group, > - 1); > - if (ret) > - return ret; > - } else { > - int j, count; > + map_for_each_metric(pe, i, map, metric) { > + pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); > + has_match = true; > + > + if (!strstr(pe->metric_expr, "?")) { > + ret = __metricgroup__add_metric(group_list, > + pe, > + metric_no_group, > + 1); > + if (ret) > + return ret; > + } else { > + int j, count; > > - count = arch_get_runtimeparam(); > + count = arch_get_runtimeparam(); > > - /* This loop is added to create multiple > - * events depend on count value and add > - * those events to group_list. > - */ > + /* This loop is added to create multiple > + * events depend on count value and add > + * those events to group_list. > + */ > > - for (j = 0; j < count; j++) { > - ret = __metricgroup__add_metric( > - group_list, pe, > - metric_no_group, j); > - if (ret) > - return ret; > - } > + for (j = 0; j < count; j++) { > + ret = __metricgroup__add_metric( > + group_list, pe, > + metric_no_group, j); > + if (ret) > + return ret; > } > } > } > + > + /* End of pmu events. */ > + if (!has_match) > + return -EINVAL; > + > list_for_each_entry(eg, group_list, nd) { > if (events->len > 0) > strbuf_addf(events, ","); >