Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp883164ybv; Wed, 19 Feb 2020 11:12:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwn4P6rVo0n7bwziWmZe2pEkH5jHTCFQoTSIdkCnY/dtwH9FftaDjayPaz0CkOcAOhxsNd8 X-Received: by 2002:a9d:768b:: with SMTP id j11mr4508853otl.278.1582139570422; Wed, 19 Feb 2020 11:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582139570; cv=none; d=google.com; s=arc-20160816; b=LMK7W0nhegXgYCXUIOlQ63CGa4r/rqU309sMbgb4SrIQ307frsCMkhaVKu2C6JysSo kPf/jf4PCC4Fy6sQgWcgszvEYYZWc0CldM95CTT97NGe380kcahbwFYQRnYCIujGC8Rq yHdP45r2upHdNJ4pVcqXcLT7mGbMfxJ/rbPcot46woUKR1HgRiK4NpCe1xEBiqTsQ67Z c1rDJro8b84PMYNwF/Lt9kituyRVXPH9jBrh9QRzsEEmJZ6xKpBbA3MS8AX3ZhyxaYcp Yz1pAbrt5tpy3mXTmRseZVlNY8RPucmQELR4pMyIvXg52cKXSQlw6jejHTMNoZN/XFaa FokA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=5vKkIwFON+DKXgW4hborexlPG4WutpD+mPVbG9eDBsY=; b=aA8lYFZGhE9JoPK8SEkAT+NnixUB6A9ZXuBNA/2CQxsexQuLpqYv3sB8KL9gCPRLM4 GESgVfLCoWbd4t0o96QNK1rqFXG2uM/89OmlTkfmwTJ3suWGoQ+PFZ3ROzRQdb0IJn2F +HO1bm3YmC6UCIhkmJl0BztaD/47b5k31NvB7n98ppGCV9eUURxW0HSBr6i4hlZvIt+F m5j/aKwuy1/QIlW2/m67m000XYJa1H9Onv5K4ZsjVxB9Ec7L0JKxmFgrysXgUdoybOXS wVYpqfL5QEzQJ0prIfMyZ2rH1LMaMwvygll8Qyaob13IahB8BVmT2xWMKj6txQP/kJBR xhcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si9818494oii.163.2020.02.19.11.12.38; Wed, 19 Feb 2020 11:12:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbgBSTKs (ORCPT + 99 others); Wed, 19 Feb 2020 14:10:48 -0500 Received: from mga05.intel.com ([192.55.52.43]:7642 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726756AbgBSTKc (ORCPT ); Wed, 19 Feb 2020 14:10:32 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2020 11:10:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,461,1574150400"; d="scan'208";a="408536206" Received: from otc-lr-04.jf.intel.com ([10.54.39.48]) by orsmga005.jf.intel.com with ESMTP; 19 Feb 2020 11:10:31 -0800 From: kan.liang@linux.intel.com To: acme@kernel.org, jolsa@redhat.com, mingo@redhat.com, peterz@infradead.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, namhyung@kernel.org, ravi.bangoria@linux.ibm.com, yao.jin@linux.intel.com, ak@linux.intel.com, Kan Liang Subject: [PATCH 2/5] perf metricgroup: Factor out metricgroup__add_metric_weak_group() Date: Wed, 19 Feb 2020 11:08:37 -0800 Message-Id: <1582139320-75181-3-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582139320-75181-1-git-send-email-kan.liang@linux.intel.com> References: <1582139320-75181-1-git-send-email-kan.liang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang Factor out metricgroup__add_metric_weak_group() which add metrics into a weak group. The change can improve code readability. Because following patch will introduce a function which add standalone metrics. Signed-off-by: Kan Liang --- tools/perf/util/metricgroup.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 02aee94..1cd042c 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -399,13 +399,42 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, strlist__delete(metriclist); } +static void metricgroup__add_metric_weak_group(struct strbuf *events, + const char **ids, + int idnum) +{ + bool no_group = false; + int i; + + for (i = 0; i < idnum; i++) { + pr_debug("found event %s\n", ids[i]); + /* + * Duration time maps to a software event and can make + * groups not count. Always use it outside a + * group. + */ + if (!strcmp(ids[i], "duration_time")) { + if (i > 0) + strbuf_addf(events, "}:W,"); + strbuf_addf(events, "duration_time"); + no_group = true; + continue; + } + strbuf_addf(events, "%s%s", + i == 0 || no_group ? "{" : ",", + ids[i]); + no_group = false; + } + if (!no_group) + strbuf_addf(events, "}:W"); +} + static int metricgroup__add_metric(const char *metric, struct strbuf *events, struct list_head *group_list) { struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_event *pe; - int ret = -EINVAL; - int i, j; + int i, ret = -EINVAL; if (!map) return 0; @@ -422,7 +451,6 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, const char **ids; int idnum; struct egroup *eg; - bool no_group = false; pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); @@ -431,27 +459,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, continue; if (events->len > 0) strbuf_addf(events, ","); - for (j = 0; j < idnum; j++) { - pr_debug("found event %s\n", ids[j]); - /* - * Duration time maps to a software event and can make - * groups not count. Always use it outside a - * group. - */ - if (!strcmp(ids[j], "duration_time")) { - if (j > 0) - strbuf_addf(events, "}:W,"); - strbuf_addf(events, "duration_time"); - no_group = true; - continue; - } - strbuf_addf(events, "%s%s", - j == 0 || no_group ? "{" : ",", - ids[j]); - no_group = false; - } - if (!no_group) - strbuf_addf(events, "}:W"); + + metricgroup__add_metric_weak_group(events, ids, idnum); eg = malloc(sizeof(struct egroup)); if (!eg) { -- 2.7.4