Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp11348ybg; Tue, 2 Jun 2020 14:52:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbv3eM4nNsFtLxPew0tIOxsGW/ihAbMuFFEeTie7q9jixzKKne6rQVMvphyTY7qXhM5wqQ X-Received: by 2002:aa7:d48f:: with SMTP id b15mr13063704edr.8.1591134720760; Tue, 02 Jun 2020 14:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591134720; cv=none; d=google.com; s=arc-20160816; b=biJEvW387r3/WXE9duGoqDmzeOxfBcfL5L2WbZIZ1Cyjj8lPUXswHH/PxyXIUVChyD gp3SDuCLXEXh3JqSjsjEIiZWkwR8giYAArD+oQlftxbLe+kN7bk3lIrq+QP8whe+Lry6 s7zOjmxovxTR6Wq7UEo0gTOkDacx1S/sJfsFPTmuMlqpBIpjxW1eQ51XUj0JAhjid4H0 73olOVrRUgXU9mXJh7/uN+qdEFF0PtbdeqczD6p8lFnZEOOSfkscB2NZYhogb8pS3P1h tOBQyIVATsj7eAHCdOCeBSeoVzW2OE7fVq2xJUEUesYm9J7TRWv4ZDFaQJ7tLKvMCPOC hNkA== 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=GIUQR6wcs12qWnFholx8Ow8v3zqAMnxpnOlkOLTlTwk=; b=hzCytyVkskp1W4sdHXQeXKu7rYtdjvib190NTTypxLIKULxGYRSUus4rYmfpCZ9X1J 5YR950LXwVgqcACLArr8iZjr87G0MQJuiH+hk576grTtrAtxZtXtc3DvYM4ia9r68AyL Sh5IftyHgMFYJs/2RVknmvmZ7ibk0Y2CrK//NjUHQF2Rj3ws0heg6AJ1PORJqElvq9IL KT7XTEUtiQboFTGIbcR7mU/fjaG5H2KXFMkxrTofASOWhftJ+lKHbLrXmIwZO787yrCd kCfZwjaMrhpxEQilYu8Y1RROkWyxAFe0IBdGjYIOGrXCA7tkgEeO3+y5Q5H+eBGFNaxx 3rpQ== 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 dk10si3410edb.73.2020.06.02.14.51.38; Tue, 02 Jun 2020 14:52:00 -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 S1728523AbgFBVsj convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Jun 2020 17:48:39 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34401 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728504AbgFBVsg (ORCPT ); Tue, 2 Jun 2020 17:48:36 -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-183--VZqDzCeMaW9Fx5mvp9ckQ-1; Tue, 02 Jun 2020 17:48:29 -0400 X-MC-Unique: -VZqDzCeMaW9Fx5mvp9ckQ-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 178DB1856955; Tue, 2 Jun 2020 21:48:28 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67BA21BCBE; Tue, 2 Jun 2020 21:48:25 +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 11/13] perf tools: Add test_generic_metric function Date: Tue, 2 Jun 2020 23:47:39 +0200 Message-Id: <20200602214741.1218986-12-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 Adding test_generic_metric that prepares and runs given metric over the data from struct runtime_stat object. Acked-by: Ian Rogers Signed-off-by: Jiri Olsa --- tools/perf/util/stat-shadow.c | 14 ++++++++++++++ tools/perf/util/stat.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 27be7ce2fff4..8fdef47005e6 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -842,6 +842,20 @@ static void generic_metric(struct perf_stat_config *config, expr__ctx_clear(&pctx); } +double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st) +{ + struct expr_parse_ctx pctx; + double ratio; + + if (prepare_metric(mexp->metric_events, &pctx, cpu, st) < 0) + return 0.; + + if (expr__parse(&ratio, &pctx, mexp->metric_expr, 1)) + return 0.; + + return ratio; +} + void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct evsel *evsel, double avg, int cpu, diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index f75ae679eb28..6911c7249199 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -230,4 +230,7 @@ perf_evlist__print_counters(struct evlist *evlist, struct target *_target, struct timespec *ts, int argc, const char **argv); + +struct metric_expr; +double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st); #endif -- 2.25.4