Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp646566ybz; Wed, 22 Apr 2020 05:25:21 -0700 (PDT) X-Google-Smtp-Source: APiQypJIBZRlZ+fohPzli+4YUh/e3XUUo6ltf+L29HngktW90CkIgFGAOc9I/xOOONsoztkftiQb X-Received: by 2002:aa7:d4c3:: with SMTP id t3mr4098471edr.191.1587558321677; Wed, 22 Apr 2020 05:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587558321; cv=none; d=google.com; s=arc-20160816; b=eWy3MpLDPUukc6D1YMJiC3Z26skidfYj4K8mGXAf2xbg+Jpn+oE1aIDj/U5uEkZ5h4 drLrioCHyMM+AsJQNmPjj9CMojHMlE+/EJKkF3H/NseAvzl5vqirVSkRR2oNiaYGt3qL BEp2hcr/bRj3+4vPuafFhH3L67yJ0C2/qLHmjpV94DWbcj7huZzk/5/h8Yy1Gt8xxW0b X6kLwatheFdcaDR4rWU5nop4fImXYBictsNAAWgq4wBUcYWkFvowXuy+5WGCkfDM//UD hYhmIiW3fqOVtP5YI8pEW9VWAfatTsw163Vgmp0hPZMIMi6q5PXSXUi0mwYAwUY72Cua 1OJw== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=aW01KP2EbSBILjqO72l4I+e50SCv+yMN/t3rTq913rw=; b=Co8L6tprvWATwVZijErhhLUDryRRRgmhH+Nwr/ZCt+0AEnkWwn+aPnzNVxev0M7KdR jTF3Op1QKKsTMLmonrWewIEVGKDxeDEXJPTId1QvUTXd2/Lx5TCRM8ZaicBwy7Xuv3Vx fKCSprE9JHcbO9s8s+2n0o7lZYMcy00Hf8fT3qliqbw/VPKbzrwBdC5io0DXO/0Topgg KtAR0utKR4aWzoePJwu1wjA1b6KxPxSj+l4XD+8gf45cEUbYxpgjTqJBAAhqAYFVBsE/ FKzqylYUyglIgGQe/CsJbc15XkTw+5hAxuwx55UwEjVgOnX7hruFjdswBjIqGChqNtZl R0lA== 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 gr21si998487ejb.482.2020.04.22.05.24.58; Wed, 22 Apr 2020 05:25:21 -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 S1728928AbgDVMSf (ORCPT + 99 others); Wed, 22 Apr 2020 08:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729055AbgDVMSL (ORCPT ); Wed, 22 Apr 2020 08:18:11 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC8CC03C1A8; Wed, 22 Apr 2020 05:18:11 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jREJu-0007tT-3B; Wed, 22 Apr 2020 14:17:38 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 637021C0451; Wed, 22 Apr 2020 14:17:28 +0200 (CEST) Date: Wed, 22 Apr 2020 12:17:27 -0000 From: "tip-bot2 for Kajol Jain" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf metrictroup: Split the metricgroup__add_metric function Cc: 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 , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Ravi Bangoria , Sukadev Bhattiprolu , Thomas Gleixner , linuxppc-dev@lists.ozlabs.org, Arnaldo Carvalho de Melo , x86 , LKML In-Reply-To: <20200401203340.31402-4-kjain@linux.ibm.com> References: <20200401203340.31402-4-kjain@linux.ibm.com> MIME-Version: 1.0 Message-ID: <158755784797.28353.3422186725377296528.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 47352aba40035ab3fdc50dd03a94456feabed7d8 Gitweb: https://git.kernel.org/tip/47352aba40035ab3fdc50dd03a94456feabed7d8 Author: Kajol Jain AuthorDate: Thu, 02 Apr 2020 02:03:36 +05:30 Committer: Arnaldo Carvalho de Melo CommitterDate: Thu, 16 Apr 2020 12:19:13 -03:00 perf metrictroup: Split the metricgroup__add_metric function 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 926449a..7ad81c8 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;