Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp12161ybg; Tue, 2 Jun 2020 14:54:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjqH/+khQSxqAv/3KaVU/O/hJMjHlscSm6g32lf1WV96zOTOzXEPsWWCiaKtngve9CwhjY X-Received: by 2002:a17:906:ce30:: with SMTP id sd16mr19977064ejb.374.1591134841283; Tue, 02 Jun 2020 14:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591134841; cv=none; d=google.com; s=arc-20160816; b=x+XxksbGnT1OqJPziHiUToN2VG4xrUd5GESUeepY82K4CrGdTu5XS5cPgnzeh9w8qd Jl8tS5JzkXSQWD4ynk0yiLyOUXiBJFPwDglTmLBMAD8627hcWd/FSfjMAM+4/rPQHf2f 45joobHZYb4yv5MHylt6yCTApdIHKACTI1Tu/UeQSTL9DJyQEPM7qxzwXkWXWTJY9OkI LRS8Jf2R2Q7ImMGk7V3aKMhuLTWKNoBKR0AkcV60LPgW6Nn5PH40hjmm+KTEVWBrYagG WJQv6cdisXbr8HLVljlURNAAQPboqrYtDldUHQO9hisVFVl7yaysikCofsg3NeXDuQnF ybAw== 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; bh=nIS2yw8ylKIQ/9IcrV1OkjVbcoebh9Dwj/pkCjWYudg=; b=bYq1XapYKeD6V3X7/s2wRK5LVaDo2sqZD7Ls6I2YY2wO1S1RpGLZ5uV9KHTVvgPUsv cN1xlD9mZVXHJ1ufBf5/h+RNuDrKKAllcfrzwRhiDi8NSV1RpaCmN+a5OkeBXL4qnIbm f/iF1sN/mu//UHyYNb3GUgTgW7zBklfvelEzkats/B8yyfgv0XQWVEv8iRmprBIdaa0h MrnarVqrPcHbvJahdc7eJxTuwnnbJSS+JVDQK/2gn73S0Rva2gihup60r5eT/44uhmR6 lAPsV1ZAEeGzHLv9xnojUN+uPVjv5MqzvZRb79uAWcwx+5nj1ryrkIkCQqhNqOdZVqhR 6E8g== 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=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 g8si82911ejb.85.2020.06.02.14.53.38; Tue, 02 Jun 2020 14:54:01 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728480AbgFBVsc convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Jun 2020 17:48:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57577 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728451AbgFBVs2 (ORCPT ); Tue, 2 Jun 2020 17:48:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-HfKlUvPPPCKe_7CimpWc5g-1; Tue, 02 Jun 2020 17:48:23 -0400 X-MC-Unique: HfKlUvPPPCKe_7CimpWc5g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF70A835B40; Tue, 2 Jun 2020 21:48:21 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5C0478EF7; Tue, 2 Jun 2020 21:48:17 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Stephane Eranian , Andi Kleen Subject: [PATCH 09/13] perf tools: Factor out prepare_metric function Date: Tue, 2 Jun 2020 23:47:37 +0200 Message-Id: <20200602214741.1218986-10-jolsa@kernel.org> In-Reply-To: <20200602214741.1218986-1-jolsa@kernel.org> References: <20200602214741.1218986-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factoring out prepare_metric function so it can be used in test interface coming in following changes. Acked-by: Ian Rogers Signed-off-by: Jiri Olsa --- tools/perf/util/stat-shadow.c | 53 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index a7c13a88ecb9..27be7ce2fff4 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -730,25 +730,16 @@ static void print_smi_cost(struct perf_stat_config *config, out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num); } -static void generic_metric(struct perf_stat_config *config, - const char *metric_expr, - struct evsel **metric_events, - char *name, - const char *metric_name, - const char *metric_unit, - int runtime, - int cpu, - struct perf_stat_output_ctx *out, - struct runtime_stat *st) +static int prepare_metric(struct evsel **metric_events, + struct expr_parse_ctx *pctx, + int cpu, + struct runtime_stat *st) { - print_metric_t print_metric = out->print_metric; - struct expr_parse_ctx pctx; - double ratio, scale; - int i; - void *ctxp = out->ctx; + double scale; char *n, *pn; + int i; - expr__ctx_init(&pctx); + expr__ctx_init(pctx); for (i = 0; metric_events[i]; i++) { struct saved_value *v; struct stats *stats; @@ -771,7 +762,7 @@ static void generic_metric(struct perf_stat_config *config, n = strdup(metric_events[i]->name); if (!n) - return; + return -ENOMEM; /* * This display code with --no-merge adds [cpu] postfixes. * These are not supported by the parser. Remove everything @@ -782,11 +773,35 @@ static void generic_metric(struct perf_stat_config *config, *pn = 0; if (metric_total) - expr__add_id(&pctx, n, metric_total); + expr__add_id(pctx, n, metric_total); else - expr__add_id(&pctx, n, avg_stats(stats)*scale); + expr__add_id(pctx, n, avg_stats(stats)*scale); } + return i; +} + +static void generic_metric(struct perf_stat_config *config, + const char *metric_expr, + struct evsel **metric_events, + char *name, + const char *metric_name, + const char *metric_unit, + int runtime, + int cpu, + struct perf_stat_output_ctx *out, + struct runtime_stat *st) +{ + print_metric_t print_metric = out->print_metric; + struct expr_parse_ctx pctx; + double ratio, scale; + int i; + void *ctxp = out->ctx; + + i = prepare_metric(metric_events, &pctx, cpu, st); + if (i < 0) + return; + if (!metric_events[i]) { if (expr__parse(&ratio, &pctx, metric_expr, runtime) == 0) { char *unit; -- 2.25.4