Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1232650ybg; Tue, 2 Jun 2020 04:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyztc2dPA4ZzoEPRo853dmEtEjuo7xYhRGl0kD/yqEXR7okxBZiyR5sx5cZg43j3Y/fj6FL X-Received: by 2002:a50:d7d1:: with SMTP id m17mr27121789edj.126.1591098906667; Tue, 02 Jun 2020 04:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591098906; cv=none; d=google.com; s=arc-20160816; b=cLqEqtVE3NveZ0rfPBFKZPtzSQ0ijKNuz3BYlFxXLC2GVJVwr1mgiJuqmIpkZZMTx5 ixJwNmUYnn4DiM0UTQ5ligvGVuFDa5Y+udLOgTKZD41zE7MQicPKRiJwplgxDIz5R5DM GDgdBgBQmOw8DNy+4NEuKXkB/QMWcMZp4gKqGYZlkGYi/ejkHBdtDmFNdOpV6BkkABvH PCqMdk5rclZ564YN+tRRfyhmy6oCB3YNLkYXGlGnBhTF2F4ZUPkL2qhoCC73OU847VW6 DNWFkyOOPNYwaI5KcDFgv2NVRpYOJ/Q5zqQDzueEMw+IUS2gEwVPVlpX/OdvCQF5dJxb NYdw== 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=FcJ4zjgvfL0hoIeC7x4ARb06NJ7U23cviPIuZudldew=; b=OMGluUbEn5beg05JifVo41eN6B++wYyteqRDaOOpdjcCJei2owQYGrrLo8LqHMY8re afY0/RUGEe/Q9x4HFoPWHsEoLDZqU2+j0e0Nnd/3L6ySiVXf5/4fTuHx4vSUIrUj4A9B ahRst8/U1n0KcbISss2bnmSLzgQ2sOW1Z0k6QiiAyw/9uVYaOzOzSVeOnw3MkTZsij88 7efy2UL6Dqd1XzqFRR0wRdgrT/gDVctrFPkHchAi2P5ygK+4v5d+wRy2RCJK0kWI0ijA r2qvckfT7dKTBJ48fAAKuug/jpiDbnGwbF8FuZNlnhc7aerc63uHnNpyesI9IvLS61rb i2Ng== 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 u21si1409975edq.299.2020.06.02.04.54.43; Tue, 02 Jun 2020 04:55:06 -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 S1728346AbgFBLvx convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Jun 2020 07:51:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36531 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728070AbgFBLv3 (ORCPT ); Tue, 2 Jun 2020 07:51:29 -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-495-gYlz33UBM_2JG7ucv7nfDg-1; Tue, 02 Jun 2020 07:51:25 -0400 X-MC-Unique: gYlz33UBM_2JG7ucv7nfDg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AA5C80B724; Tue, 2 Jun 2020 11:51:23 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.195.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAD96100164D; Tue, 2 Jun 2020 11:51:20 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Stephane Eranian , Andi Kleen Subject: [PATCH 09/13] perf tools: Factor out prepare_metric function Date: Tue, 2 Jun 2020 13:50:51 +0200 Message-Id: <20200602115055.1168446-10-jolsa@kernel.org> In-Reply-To: <20200602115055.1168446-1-jolsa@kernel.org> References: <20200602115055.1168446-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 functio so it can be used in test interface coming in following changes. 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