Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3629606ybz; Mon, 20 Apr 2020 06:36:47 -0700 (PDT) X-Google-Smtp-Source: APiQypLxV4bynk7YelnpyHEG+1YnuWOxuxk3uZyUg0tHXyf7+TkvhD01T+zH1qRxCYXxhJFt/1AI X-Received: by 2002:a17:906:3e44:: with SMTP id t4mr16289277eji.337.1587389807116; Mon, 20 Apr 2020 06:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587389807; cv=none; d=google.com; s=arc-20160816; b=lO0VwqKrEut6xb9cquw2F8+WAOVAnDn1Aj4O31CXRYquIV9fB6op3byebTn9RLmp7S 37bPijFdAqTNZwRd72PhtJXprhgt5v6DErsIBrAPFtnszGluZNz+mu7DOfIMtmb7NkAc iI0SD4nJmW2VSwpGpnf6Hohsr159lqwS4vTUquYXm72dK2Ot/ygw66u3bTUKV7UtzPEp vq2kOtVhECFOKNNDYy4GLIXn5a076OouGq7z+TA1RABogRLvhxj1NhyJo9aVg/tQ9wyH EVxFub7VszWHa+grDonVh5GYLMHGH/XmrKCd4hqSkyjCgRZzrwzgMpb4e4wGTIy+YFiX 1bHA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=39p69AsuSJuDvTRPtweklQnIW4aBLHk/Z1UwxEO+X6I=; b=Td1w6yQWIqVk4Ylu5HmBRrHo1pV+9qaA6+fZRWhN+ReXDQbnVcTZET/NYd6E9OiFKf 0DjRLlPl2wVEZKCPcsHOeh4JMOC3qMWl/Ix7+AYOnsMcFH66bAbnp11pvrU00hCNRfiY /5JsKeDltccxkzipxyX8JrAUxdKKdaM+fqEAS414XPsoMpU/aWS6q9QNka+KJx8FTTFf CvCHMZPQJU7B1VNmPQFR7UzuY8ZREqcfJNgdVw6TZaTE/lvgczB0o0wifvJa7fu4fJ+t 5RsmRHQVNQk/glRnrsmIyHcmco3yTPBRjCheIo39in4K2A/ZUkj1kuO0M3RPRSxBnSCI scWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wn5bJhgu; 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 oq20si541936ejb.419.2020.04.20.06.36.21; Mon, 20 Apr 2020 06:36:47 -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=@kernel.org header.s=default header.b=Wn5bJhgu; 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 S1726924AbgDTLzc (ORCPT + 99 others); Mon, 20 Apr 2020 07:55:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:39506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgDTLz1 (ORCPT ); Mon, 20 Apr 2020 07:55:27 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 691832071C; Mon, 20 Apr 2020 11:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383726; bh=/I6+4RM7D8Zv5L5YljhiXKJySF7xpqGi0M0uxOlZrLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wn5bJhguhfj8jX5psOITNL5gkggTGaOM8+Duhxi9gBwJlzBpKPTPM6sCytIiykBW2 2pZyM6PDOW94zWh7keTUOvDaihpl9OqCW5f7/thsMtOE1QBm1P2H3z+5NSIr2LqJIM masvu7YM9Ce1uyPi1lcoJiEwarWm3o5j5XV2amgk= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Kajol Jain , Jiri Olsa , Alexander Shishkin , Andi Kleen , Anju T Sudhakar , Benjamin Herrenschmidt , Greg Kroah-Hartman , Jin Yao , Joe Mario , Kan Liang , Madhavan Srinivasan , Mamatha Inamdar , Mark Rutland , Michael Ellerman , Michael Petlan , Paul Mackerras , Peter Zijlstra , Ravi Bangoria , Sukadev Bhattiprolu , linuxppc-dev@lists.ozlabs.org, Arnaldo Carvalho de Melo Subject: [PATCH 23/60] perf metrictroup: Split the metricgroup__add_metric function Date: Mon, 20 Apr 2020 08:52:39 -0300 Message-Id: <20200420115316.18781-24-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kajol Jain This patch refactors metricgroup__add_metric function where some part of it move to function metricgroup__add_metric_param. No logic change. Signed-off-by: Kajol Jain Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Anju T Sudhakar Cc: Benjamin Herrenschmidt Cc: Greg Kroah-Hartman Cc: Jin Yao Cc: Joe Mario Cc: Kan Liang Cc: Madhavan Srinivasan Cc: Mamatha Inamdar Cc: Mark Rutland Cc: Michael Ellerman Cc: Michael Petlan Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sukadev Bhattiprolu Cc: Thomas Gleixner Cc: linuxppc-dev@lists.ozlabs.org Link: http://lore.kernel.org/lkml/20200401203340.31402-4-kjain@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/metricgroup.c | 60 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 926449a7cdbf..7ad81c8177ea 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -485,6 +485,39 @@ static bool metricgroup__has_constraint(struct pmu_event *pe) return false; } +static int __metricgroup__add_metric(struct strbuf *events, + struct list_head *group_list, struct pmu_event *pe) +{ + + const char **ids; + int idnum; + struct egroup *eg; + + if (expr__find_other(pe->metric_expr, NULL, &ids, &idnum) < 0) + return -EINVAL; + + if (events->len > 0) + strbuf_addf(events, ","); + + if (metricgroup__has_constraint(pe)) + metricgroup__add_metric_non_group(events, ids, idnum); + else + metricgroup__add_metric_weak_group(events, ids, idnum); + + eg = malloc(sizeof(*eg)); + if (!eg) + return -ENOMEM; + + eg->ids = ids; + eg->idnum = idnum; + eg->metric_name = pe->metric_name; + eg->metric_expr = pe->metric_expr; + eg->metric_unit = pe->unit; + list_add_tail(&eg->nd, group_list); + + return 0; +} + static int metricgroup__add_metric(const char *metric, struct strbuf *events, struct list_head *group_list) { @@ -504,35 +537,12 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, continue; if (match_metric(pe->metric_group, metric) || match_metric(pe->metric_name, metric)) { - const char **ids; - int idnum; - struct egroup *eg; pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); - if (expr__find_other(pe->metric_expr, - NULL, &ids, &idnum) < 0) - continue; - if (events->len > 0) - strbuf_addf(events, ","); - - if (metricgroup__has_constraint(pe)) - metricgroup__add_metric_non_group(events, ids, idnum); - else - metricgroup__add_metric_weak_group(events, ids, idnum); - - eg = malloc(sizeof(struct egroup)); - if (!eg) { - ret = -ENOMEM; + ret = __metricgroup__add_metric(events, group_list, pe); + if (ret == -ENOMEM) break; - } - eg->ids = ids; - eg->idnum = idnum; - eg->metric_name = pe->metric_name; - eg->metric_expr = pe->metric_expr; - eg->metric_unit = pe->unit; - list_add_tail(&eg->nd, group_list); - ret = 0; } } return ret; -- 2.21.1