From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-6.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,
	SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id B9C48C54FCC
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:13:59 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id A344F206E9
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:13:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1587492839;
	bh=1r2YT2MwVBclZi0yBJtvnmVPr+pwRzYsdkT5t1PhyWo=;
	h=From:To:Cc:Subject:Date:List-ID:From;
	b=SIpMiDui4TUMcEaHFZJuaxowPyRaklQiVyI8T58XQGFmQWIaGQM39rv51k0h+200e
	 ou8F6y88GRl8W+lRaEweJObegg3AUuNbJPtaQV2va1WTqzOGFCtzuI9pid6X5oOOeC
	 f0pC9uAZkP0u5U2MFN9voVVTlJ7gDr+qWDQGHokY=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729310AbgDUSN6 convert rfc822-to-8bit (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:13:58 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53048 "EHLO
        us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1729083AbgDUSN4 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:13:56 -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-203-8jo4PPKNN6GUc1SdNnEATA-1; Tue, 21 Apr 2020 14:13:47 -0400
X-MC-Unique: 8jo4PPKNN6GUc1SdNnEATA-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 C7ED8107ACC4;
        Tue, 21 Apr 2020 18:13:43 +0000 (UTC)
Received: from krava.redhat.com (unknown [10.40.196.43])
        by smtp.corp.redhat.com (Postfix) with ESMTP id 8EC6FB3A76;
        Tue, 21 Apr 2020 18:13:38 +0000 (UTC)
From:   Jiri Olsa <jolsa@kernel.org>
To:     Arnaldo Carvalho de Melo <acme@kernel.org>
Cc:     lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: [PATCHv2 0/3] perf tools: Add support for user defined metric
Date:   Tue, 21 Apr 2020 20:13:33 +0200
Message-Id: <20200421181337.988681-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: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

hi,
Joe asked for possibility to add user defined metrics. Given that
we already have metrics support, I added --metrics-file option that
allows to specify custom metrics.

  $ cat metrics
  # IPC
  mine1 = instructions / cycles;
  /* DECODED_ICACHE_UOPS% */
  mine2 = 100 * (idq.dsb_uops / \ (idq.ms_uops + idq.mite_uops + idq.dsb_uops + lsd.uops));

  $ sudo perf stat --metrics-file ./metrics -M mine1,mine2 --metric-only -a -I 1000
  #           time       insn per cycle                mine1                mine2
       1.000536263                0.71                   0.7                 41.4
       2.002069025                0.31                   0.3                 14.1
       3.003427684                0.27                   0.3                 14.8
       4.004807132                0.25                   0.2                 12.1
  ...

v2 changes:
  - add new --metrics-file option
  - rebased on current perf/core expression bison/flex enhancements

Also available in:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/metric

thanks,
jirka


---
Jiri Olsa (3):
      perf expr: Add parsing support for multiple expressions
      perf expr: Allow comments in custom metric file
      perf stat: Add --metrics-file option

 tools/perf/Documentation/perf-stat.txt |  3 +++
 tools/perf/builtin-stat.c              |  7 +++++--
 tools/perf/tests/expr.c                | 13 +++++++++++++
 tools/perf/util/expr.c                 |  6 ++++++
 tools/perf/util/expr.h                 | 19 +++++++++++++++++--
 tools/perf/util/expr.l                 | 24 ++++++++++++++++++++++++
 tools/perf/util/expr.y                 | 13 ++++++++++++-
 tools/perf/util/metricgroup.c          | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 tools/perf/util/metricgroup.h          |  3 ++-
 tools/perf/util/stat.h                 |  1 +
 10 files changed, 142 insertions(+), 13 deletions(-)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 1EB35C54FCC
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:05 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id E92112071C
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1587492845;
	bh=x5hh6u6AOJRwguyddOnQbdsEreg3pUkbLzlrcZS/sZw=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From;
	b=0UX524jRNVqjiam0ntpkG75Wc+3Aj89iHaiLENOSYMwp/30RqK2ZLJfjJOr7/d3kC
	 CO8y9tt9vVVQtycJC7G4zIuGfZ1LA95K3OQKzL/yyCR9/k6brVtvUhxFsiqGFw/nUH
	 OoDSrdFzsQkJlBk3XfmsGzOMC3pOSm4Ulwl/yoIg=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729390AbgDUSOE convert rfc822-to-8bit (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:14:04 -0400
Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24757 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1729297AbgDUSOB (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:14:01 -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-509-OWGE0evsOZ2eE0ulp0BewQ-1; Tue, 21 Apr 2020 14:13:54 -0400
X-MC-Unique: OWGE0evsOZ2eE0ulp0BewQ-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 761A1DB60;
        Tue, 21 Apr 2020 18:13:52 +0000 (UTC)
Received: from krava.redhat.com (unknown [10.40.196.43])
        by smtp.corp.redhat.com (Postfix) with ESMTP id 2FE3AB3A64;
        Tue, 21 Apr 2020 18:13:44 +0000 (UTC)
From:   Jiri Olsa <jolsa@kernel.org>
To:     Arnaldo Carvalho de Melo <acme@kernel.org>
Cc:     lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: [PATCH 1/3] perf expr: Add parsing support for multiple expressions
Date:   Tue, 21 Apr 2020 20:13:34 +0200
Message-Id: <20200421181337.988681-2-jolsa@kernel.org>
In-Reply-To: <20200421181337.988681-1-jolsa@kernel.org>
References: <20200421181337.988681-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: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Adding support to parse metric difinitions in following form:

  NAME = EXPRESSION ;
  NAME = EXPRESSION ;
  ...

The parsed NAME and EXPRESSION will be used in following
changes to feed the metric code with definitions from
custom file.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/expr.c | 13 +++++++++++++
 tools/perf/util/expr.c  |  6 ++++++
 tools/perf/util/expr.h  | 19 +++++++++++++++++--
 tools/perf/util/expr.l  | 12 ++++++++++++
 tools/perf/util/expr.y  | 13 ++++++++++++-
 5 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
index ea10fc4412c4..b220e316048a 100644
--- a/tools/perf/tests/expr.c
+++ b/tools/perf/tests/expr.c
@@ -63,5 +63,18 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
 		zfree(&other[i]);
 	free((void *)other);
 
+	expr__ctx_init(&ctx);
+	ret = expr__parse_custom(&ctx, "IPC=INSTRUCTIONS / CYCLES; CPI=CYCLES / INSTRUCTIONS;");
+	TEST_ASSERT_VAL("parse custom failed", ret == 0);
+	TEST_ASSERT_VAL("parse custom count", ctx.num_custom == 2);
+	TEST_ASSERT_VAL("parse custom name", !strcmp(ctx.custom[0].name, "IPC"));
+	TEST_ASSERT_VAL("parse custom name", !strcmp(ctx.custom[1].name, "CPI"));
+	TEST_ASSERT_VAL("parse custom expr", !strcmp(ctx.custom[0].expr, "INSTRUCTIONS / CYCLES"));
+	TEST_ASSERT_VAL("parse custom expr", !strcmp(ctx.custom[1].expr, "CYCLES / INSTRUCTIONS"));
+
+	for (i = 0; i < ctx.num_custom; i++) {
+		zfree(&ctx.custom[i].name);
+		zfree(&ctx.custom[i].expr);
+	}
 	return 0;
 }
diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index c3382d58cf40..805fbf6bffc8 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -23,6 +23,7 @@ void expr__add_id(struct expr_parse_ctx *ctx, const char *name, double val)
 void expr__ctx_init(struct expr_parse_ctx *ctx)
 {
 	ctx->num_ids = 0;
+	ctx->num_custom = 0;
 }
 
 static int
@@ -59,6 +60,11 @@ int expr__parse(double *final_val, struct expr_parse_ctx *ctx, const char *expr)
 	return __expr__parse(final_val, ctx, expr, EXPR_PARSE) ? -1 : 0;
 }
 
+int expr__parse_custom(struct expr_parse_ctx *ctx, const char *expr)
+{
+	return __expr__parse(NULL, ctx, expr, EXPR_CUSTOM);
+}
+
 static bool
 already_seen(const char *val, const char *one, const char **other,
 	     int num_other)
diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h
index 0938ad166ece..4bbd24f9aaaa 100644
--- a/tools/perf/util/expr.h
+++ b/tools/perf/util/expr.h
@@ -4,15 +4,29 @@
 
 #define EXPR_MAX_OTHER 20
 #define MAX_PARSE_ID EXPR_MAX_OTHER
+#define EXPR_MAX 20
 
 struct expr_parse_id {
 	const char *name;
 	double val;
 };
 
+struct expr_parse_custom {
+	const char *name;
+	const char *expr;
+};
+
 struct expr_parse_ctx {
-	int num_ids;
-	struct expr_parse_id ids[MAX_PARSE_ID];
+	union {
+		struct {
+			int			 num_ids;
+			struct expr_parse_id	 ids[MAX_PARSE_ID];
+		};
+		struct {
+			int			 num_custom;
+			struct expr_parse_custom custom[EXPR_MAX];
+		};
+	};
 };
 
 struct expr_scanner_ctx {
@@ -22,6 +36,7 @@ struct expr_scanner_ctx {
 void expr__ctx_init(struct expr_parse_ctx *ctx);
 void expr__add_id(struct expr_parse_ctx *ctx, const char *id, double val);
 int expr__parse(double *final_val, struct expr_parse_ctx *ctx, const char *expr);
+int expr__parse_custom(struct expr_parse_ctx *ctx, const char *expr);
 int expr__find_other(const char *expr, const char *one, const char ***other,
 		int *num_other);
 
diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
index 2582c2464938..5561c360cd27 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -68,12 +68,15 @@ static int str(yyscan_t scanner, int token)
 }
 %}
 
+%x custom
+
 number		[0-9]+
 
 sch		[-,=]
 spec		\\{sch}
 sym		[0-9a-zA-Z_\.:@]+
 symbol		{spec}*{sym}*{spec}*{sym}*
+all		[^;]+
 
 %%
 	struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
@@ -87,6 +90,12 @@ symbol		{spec}*{sym}*{spec}*{sym}*
 		}
 	}
 
+<custom>{
+
+{all}		{ BEGIN(INITIAL); return str(yyscanner, ALL); }
+
+}
+
 max		{ return MAX; }
 min		{ return MIN; }
 if		{ return IF; }
@@ -105,6 +114,9 @@ else		{ return ELSE; }
 "("		{ return '('; }
 ")"		{ return ')'; }
 ","		{ return ','; }
+";"		{ return ';'; }
+"="		{ BEGIN(custom); return '='; }
+\n		{ }
 .		{ }
 %%
 
diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index cd17486c1c5d..a853974e7871 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -24,9 +24,10 @@
 	char	*str;
 }
 
-%token EXPR_PARSE EXPR_OTHER EXPR_ERROR
+%token EXPR_PARSE EXPR_OTHER EXPR_CUSTOM EXPR_ERROR
 %token <num> NUMBER
 %token <str> ID
+%token <str> ALL
 %token MIN MAX IF ELSE SMT_ON
 %left MIN MAX IF
 %left '|'
@@ -66,6 +67,16 @@ start:
 EXPR_PARSE all_expr
 |
 EXPR_OTHER all_other
+|
+EXPR_CUSTOM all_custom
+
+all_custom: all_custom ID '=' ALL ';'
+{
+	ctx->custom[ctx->num_custom].name = $2;
+	ctx->custom[ctx->num_custom].expr = $4;
+	ctx->num_custom++;
+}
+|
 
 all_other: all_other other
 |
-- 
2.25.3


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 6FFE1C55181
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:07 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 5A7A3206E9
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1587492847;
	bh=6huj4mmIlJBkPfGFW9vY9nUtSYLnzE7IR70Viouldjo=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From;
	b=PfHoc6wbVnNPxhAaHx5lD5sZfBYR8I+wgNRVWXKW9MOBqliHJuWIumruar8K9YSe6
	 hjURDT4jdHbeF21zW9hMdGvEDWFdSIpOPzciTWN+feCUk2ppQ+6glR25JuUzaynYGV
	 j4M036W3KMlRo3Y/OAfBsrrN3OMB7AkO3vA/77LI=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729360AbgDUSOC convert rfc822-to-8bit (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:14:02 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54991 "EHLO
        us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1725963AbgDUSN5 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:13:57 -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-72-36cRdr2xOFu80gjgFgFA5A-1; Tue, 21 Apr 2020 14:13:54 -0400
X-MC-Unique: 36cRdr2xOFu80gjgFgFA5A-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 CB5A21005509;
        Tue, 21 Apr 2020 18:13:52 +0000 (UTC)
Received: from krava.redhat.com (unknown [10.40.196.43])
        by smtp.corp.redhat.com (Postfix) with ESMTP id F23F9B3A7B;
        Tue, 21 Apr 2020 18:13:49 +0000 (UTC)
From:   Jiri Olsa <jolsa@kernel.org>
To:     Arnaldo Carvalho de Melo <acme@kernel.org>
Cc:     lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: [PATCH 2/3] perf expr: Allow comments in custom metric file
Date:   Tue, 21 Apr 2020 20:13:35 +0200
Message-Id: <20200421181337.988681-3-jolsa@kernel.org>
In-Reply-To: <20200421181337.988681-1-jolsa@kernel.org>
References: <20200421181337.988681-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: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Adding support to use comments within the custom metric file
with both the shell '# ... ' and C '/* ... */ styles.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/expr.l | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
index 5561c360cd27..99547182ef79 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -69,6 +69,8 @@ static int str(yyscan_t scanner, int token)
 %}
 
 %x custom
+%x comment_C
+%x comment_sh
 
 number		[0-9]+
 
@@ -103,6 +105,16 @@ else		{ return ELSE; }
 #smt_on		{ return SMT_ON; }
 {number}	{ return value(yyscanner, 10); }
 {symbol}	{ return str(yyscanner, ID); }
+
+"/*"		{ BEGIN(comment_C); }
+<comment_C>"*/"	{ BEGIN(INITIAL); }
+<comment_C>\n	{ }
+<comment_C>.	{ }
+
+"#"		{ BEGIN(comment_sh); }
+<comment_sh>\n	{ BEGIN(INITIAL); }
+<comment_sh>.	{ }
+
 "|"		{ return '|'; }
 "^"		{ return '^'; }
 "&"		{ return '&'; }
-- 
2.25.3


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 0E6FCC54FCC
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:09 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id E6C0F20722
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:14:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1587492849;
	bh=WdIFy6vrsum21qUjwMbqoMHjlL25lWqWkTxfnoSgYpQ=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From;
	b=aWjPmoNBePpB2Hxhngphw4I+60EcjG70zQkMhOQ+Fu/55vnVVMFTSVpF1aMwwP2M3
	 E38QqxHCOaE+/OaMEJ91J0/P0c6i9NmqlIXN5omRFRczymXJ5gZ50eZrPuAmq9M2JX
	 Wws5sHi0MDLx819PUWAM2iJ+7TK1TmC/n2EnN8cQ=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729407AbgDUSOH convert rfc822-to-8bit (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:14:07 -0400
Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58487 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1729083AbgDUSOC (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:14:02 -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-144-wmhDccJUPpqzac3h8w80Gg-1; Tue, 21 Apr 2020 14:13:58 -0400
X-MC-Unique: wmhDccJUPpqzac3h8w80Gg-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 92C92802568;
        Tue, 21 Apr 2020 18:13:56 +0000 (UTC)
Received: from krava.redhat.com (unknown [10.40.196.43])
        by smtp.corp.redhat.com (Postfix) with ESMTP id 861FDB3A64;
        Tue, 21 Apr 2020 18:13:53 +0000 (UTC)
From:   Jiri Olsa <jolsa@kernel.org>
To:     Arnaldo Carvalho de Melo <acme@kernel.org>
Cc:     lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: [PATCH 3/3] perf stat: Add --metrics-file option
Date:   Tue, 21 Apr 2020 20:13:36 +0200
Message-Id: <20200421181337.988681-4-jolsa@kernel.org>
In-Reply-To: <20200421181337.988681-1-jolsa@kernel.org>
References: <20200421181337.988681-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: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Adding --metrics-file option that allows to specify metrics
in the file.

It's now possible to define metrics in file and use them like:

  $ cat metrics
  # IPC
  mine1 = instructions / cycles;
  /* DECODED_ICACHE_UOPS% */
  mine2 = 100 * (idq.dsb_uops / \ (idq.ms_uops + idq.mite_uops + idq.dsb_uops + lsd.uops));

  $ sudo perf stat --metrics-file ./metrics -M mine1,mine2 --metric-only -a -I 1000
  #           time       insn per cycle                mine1                mine2
       1.000536263                0.71                   0.7                 41.4
       2.002069025                0.31                   0.3                 14.1
       3.003427684                0.27                   0.3                 14.8
       4.004807132                0.25                   0.2                 12.1
  ...

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-stat.txt |  3 ++
 tools/perf/builtin-stat.c              |  7 ++-
 tools/perf/util/metricgroup.c          | 66 +++++++++++++++++++++++---
 tools/perf/util/metricgroup.h          |  3 +-
 tools/perf/util/stat.h                 |  1 +
 5 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 4d56586b2fb9..263b0d2bb835 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -264,6 +264,9 @@ For a group all metrics from the group are added.
 The events from the metrics are automatically measured.
 See perf list output for the possble metrics and metricgroups.
 
+--metrics-file file::
+Read metrics definitions from file in addition to compiled in metrics.
+
 -A::
 --no-aggr::
 Do not aggregate counts across all monitored CPUs.
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9207b6c45475..81c2b2f8ec53 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -841,7 +841,8 @@ static int parse_metric_groups(const struct option *opt,
 			       const char *str,
 			       int unset __maybe_unused)
 {
-	return metricgroup__parse_groups(opt, str, &stat_config.metric_events);
+	return metricgroup__parse_groups(opt, str, &stat_config.metric_events,
+					 stat_config.metrics_file);
 }
 
 static struct option stat_options[] = {
@@ -926,6 +927,8 @@ static struct option stat_options[] = {
 	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
 		     "monitor specified metrics or metric groups (separated by ,)",
 		     parse_metric_groups),
+	OPT_STRING(0, "metrics-file", &stat_config.metrics_file, "file path",
+		   "file with metrics definitions"),
 	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
 			 "Configure all used events to run in kernel space.",
 			 PARSE_OPT_EXCLUSIVE),
@@ -1443,7 +1446,7 @@ static int add_default_attributes(void)
 			struct option opt = { .value = &evsel_list };
 
 			return metricgroup__parse_groups(&opt, "transaction",
-							 &stat_config.metric_events);
+							 &stat_config.metric_events, NULL);
 		}
 
 		if (pmu_have_event("cpu", "cycles-ct") &&
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 7ad81c8177ea..99e0ef725a6f 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -519,17 +519,17 @@ static int __metricgroup__add_metric(struct strbuf *events,
 }
 
 static int metricgroup__add_metric(const char *metric, struct strbuf *events,
-				   struct list_head *group_list)
+				   struct list_head *group_list,
+				   struct expr_parse_ctx *ctx)
 {
 	struct pmu_events_map *map = perf_pmu__find_map(NULL);
-	struct pmu_event *pe;
 	int i, ret = -EINVAL;
 
 	if (!map)
 		return 0;
 
 	for (i = 0; ; i++) {
-		pe = &map->table[i];
+		struct pmu_event *pe = &map->table[i];
 
 		if (!pe->name && !pe->metric_group && !pe->metric_name)
 			break;
@@ -545,15 +545,56 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
 				break;
 		}
 	}
+
+	if (!ctx->num_custom || ret == -ENOMEM)
+		return ret;
+
+	for (i = 0; i < ctx->num_custom; i++) {
+		struct pmu_event pe = { 0 };
+
+		if (!match_metric(ctx->custom[i].name, metric))
+			continue;
+
+		pe.metric_name = strdup(ctx->custom[i].name);
+		pe.metric_expr = strdup(ctx->custom[i].expr);
+
+		if (!pe.metric_name && !pe.metric_expr)
+			return -ENOMEM;
+
+		ret = __metricgroup__add_metric(events, group_list, &pe);
+		if (ret) {
+			free((char *) pe.metric_name);
+			free((char *) pe.metric_expr);
+			break;
+		}
+	}
+
 	return ret;
 }
 
 static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
-				        struct list_head *group_list)
+					struct list_head *group_list,
+					const char *metrics_file)
 {
+	struct expr_parse_ctx ctx = { 0 };
 	char *llist, *nlist, *p;
 	int ret = -EINVAL;
 
+	if (metrics_file) {
+		size_t size;
+		char *buf;
+
+		if (filename__read_str(metrics_file, &buf, &size)) {
+			pr_err("failed to read metrics file: %s\n", metrics_file);
+			return -1;
+		}
+
+		expr__ctx_init(&ctx);
+		expr__parse_custom(&ctx, buf);
+
+		free(buf);
+	}
+
 	nlist = strdup(list);
 	if (!nlist)
 		return -ENOMEM;
@@ -563,7 +604,7 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
 	strbuf_addf(events, "%s", "");
 
 	while ((p = strsep(&llist, ",")) != NULL) {
-		ret = metricgroup__add_metric(p, events, group_list);
+		ret = metricgroup__add_metric(p, events, group_list, &ctx);
 		if (ret == -EINVAL) {
 			fprintf(stderr, "Cannot find metric or group `%s'\n",
 					p);
@@ -575,6 +616,15 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
 	if (!ret)
 		metricgroup___watchdog_constraint_hint(NULL, true);
 
+	if (metrics_file) {
+		int i;
+
+		for (i = 0; i < ctx.num_custom; i++) {
+			zfree(&ctx.custom[i].name);
+			zfree(&ctx.custom[i].expr);
+		}
+	}
+
 	return ret;
 }
 
@@ -594,7 +644,8 @@ static void metricgroup__free_egroups(struct list_head *group_list)
 
 int metricgroup__parse_groups(const struct option *opt,
 			   const char *str,
-			   struct rblist *metric_events)
+			   struct rblist *metric_events,
+			   const char *metrics_file)
 {
 	struct parse_events_error parse_error;
 	struct evlist *perf_evlist = *(struct evlist **)opt->value;
@@ -604,7 +655,8 @@ int metricgroup__parse_groups(const struct option *opt,
 
 	if (metric_events->nr_entries == 0)
 		metricgroup__rblist_init(metric_events);
-	ret = metricgroup__add_metric_list(str, &extra_events, &group_list);
+	ret = metricgroup__add_metric_list(str, &extra_events, &group_list,
+					   metrics_file);
 	if (ret)
 		return ret;
 	pr_debug("adding %s\n", extra_events.buf);
diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h
index 475c7f912864..bf6e4281915f 100644
--- a/tools/perf/util/metricgroup.h
+++ b/tools/perf/util/metricgroup.h
@@ -29,7 +29,8 @@ struct metric_event *metricgroup__lookup(struct rblist *metric_events,
 					 bool create);
 int metricgroup__parse_groups(const struct option *opt,
 			const char *str,
-			struct rblist *metric_events);
+			struct rblist *metric_events,
+			const char *metrics_file);
 
 void metricgroup__print(bool metrics, bool groups, char *filter,
 			bool raw, bool details);
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index b4fdfaa7f2c0..57c4c7695aaf 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -123,6 +123,7 @@ struct perf_stat_config {
 	struct runtime_stat	*stats;
 	int			 stats_num;
 	const char		*csv_sep;
+	const char		*metrics_file;
 	struct stats		*walltime_nsecs_stats;
 	struct rusage		 ru_data;
 	struct perf_cpu_map		*aggr_map;
-- 
2.25.3


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id DF78FC54FCC
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:36:17 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 9D4812068F
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:36:17 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729203AbgDUSgQ (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:36:16 -0400
Received: from mga11.intel.com ([192.55.52.93]:46292 "EHLO mga11.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725930AbgDUSgP (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:36:15 -0400
IronPort-SDR: scvtaxEkEngtdjnBdaN6kHmNvCqceikiJP4GD7vEYgf4AMdvtrdyz429rhtp46ep+h22R2fd3r
 I8H42nMWZJxQ==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga002.jf.intel.com ([10.7.209.21])
  by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 11:36:15 -0700
IronPort-SDR: htjAKHyunl6st7EPXfAJmsqzIZ/0M/Kh4zbkR26LdWAaQerXxhJ8Cef19+An/ZUDAks4TOdXPc
 7DtBkWX+G4lQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.72,411,1580803200"; 
   d="scan'208";a="273617738"
Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.21])
  by orsmga002.jf.intel.com with ESMTP; 21 Apr 2020 11:36:15 -0700
Received: by tassilo.localdomain (Postfix, from userid 1000)
        id 325D63019B6; Tue, 21 Apr 2020 11:36:15 -0700 (PDT)
Date:   Tue, 21 Apr 2020 11:36:15 -0700
From:   Andi Kleen <ak@linux.intel.com>
To:     Jiri Olsa <jolsa@kernel.org>
Cc:     Arnaldo Carvalho de Melo <acme@kernel.org>,
        lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: Re: [PATCH 3/3] perf stat: Add --metrics-file option
Message-ID: <20200421183615.GD608746@tassilo.jf.intel.com>
References: <20200421181337.988681-1-jolsa@kernel.org>
 <20200421181337.988681-4-jolsa@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200421181337.988681-4-jolsa@kernel.org>
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

> +--metrics-file file::
> +Read metrics definitions from file in addition to compiled in metrics.
> +

You would need to define the syntax and format. Perhaps in a separate
man page.

Also there are some asserts that can be triggered by expressions. I think
you should fix those too and convert them to errors.

-Andi

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 1105FC54FC9
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:53:08 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id D2E492068F
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 18:53:07 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hIsJrYHH"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726386AbgDUSxG (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 14:53:06 -0400
Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28845 "EHLO
        us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1725870AbgDUSxG (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 14:53:06 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1587495185;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         in-reply-to:in-reply-to:references:references;
        bh=2EGJfjTFggwaFFy3edNseI3v+h0M2XMOWbVl/ZbsKrg=;
        b=hIsJrYHHxti7kf9UktPgowQm//lJixXKWRZe70Umoi+y3AFUPOpsz7mDSlJSeKdQ8wUqYX
        3F4Camd8Uhx9xVC/dg0Nyh2RFILnpuEv/Nnz2PvBZnipV+/kPKn5eoHRK68D/UHjXQtIec
        sYn38zgHvGC56ASc4i2JGcRuFA7QdM4=
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-121-lqdHmYfsMniKTXzB82Q-Hw-1; Tue, 21 Apr 2020 14:53:01 -0400
X-MC-Unique: lqdHmYfsMniKTXzB82Q-Hw-1
Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])
        (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
        (No client certificate requested)
        by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A1F9107ACCC;
        Tue, 21 Apr 2020 18:52:59 +0000 (UTC)
Received: from krava (unknown [10.40.196.43])
        by smtp.corp.redhat.com (Postfix) with ESMTPS id E9EF25C1D4;
        Tue, 21 Apr 2020 18:52:55 +0000 (UTC)
Date:   Tue, 21 Apr 2020 20:52:52 +0200
From:   Jiri Olsa <jolsa@redhat.com>
To:     Andi Kleen <ak@linux.intel.com>
Cc:     Jiri Olsa <jolsa@kernel.org>,
        Arnaldo Carvalho de Melo <acme@kernel.org>,
        lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: Re: [PATCH 3/3] perf stat: Add --metrics-file option
Message-ID: <20200421185252.GA962614@krava>
References: <20200421181337.988681-1-jolsa@kernel.org>
 <20200421181337.988681-4-jolsa@kernel.org>
 <20200421183615.GD608746@tassilo.jf.intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200421183615.GD608746@tassilo.jf.intel.com>
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Tue, Apr 21, 2020 at 11:36:15AM -0700, Andi Kleen wrote:
> > +--metrics-file file::
> > +Read metrics definitions from file in addition to compiled in metrics.
> > +
> 
> You would need to define the syntax and format. Perhaps in a separate
> man page.

I'm not sure it's worthy of new man page, but perhaps section in
perf-stat

> 
> Also there are some asserts that can be triggered by expressions. I think
> you should fix those too and convert them to errors.

do you have some details on this? examples of those failures?

thanks,
jirka

> 
> -Andi
> 


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=8uoY=6F=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id B77FFC54FCC
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 20:06:33 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 9034E206B8
	for <linux-kernel@archiver.kernel.org>; Tue, 21 Apr 2020 20:06:33 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726200AbgDUUGc (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Tue, 21 Apr 2020 16:06:32 -0400
Received: from mga06.intel.com ([134.134.136.31]:1677 "EHLO mga06.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725987AbgDUUGc (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 21 Apr 2020 16:06:32 -0400
IronPort-SDR: L4nZDE7pqRowTFaaI2BK0srPc+H5edwjFPNz4189iHpuc/w50FvUpDANIGc/t5OASve1kRkOVF
 jGaW8a9Z4tQg==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga008.fm.intel.com ([10.253.24.58])
  by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 13:06:31 -0700
IronPort-SDR: RO23W0D2pXrfBWwzMV3NBUTnrL4YYUAL8T/lx+vgIyA22DauPPQtjCZGEMJ/0QjHOyTxzLsgnR
 OGJheq79i4KA==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.72,411,1580803200"; 
   d="scan'208";a="247267230"
Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.21])
  by fmsmga008.fm.intel.com with ESMTP; 21 Apr 2020 13:06:31 -0700
Received: by tassilo.localdomain (Postfix, from userid 1000)
        id 09B9E3019B6; Tue, 21 Apr 2020 13:06:31 -0700 (PDT)
Date:   Tue, 21 Apr 2020 13:06:30 -0700
From:   Andi Kleen <ak@linux.intel.com>
To:     Jiri Olsa <jolsa@redhat.com>
Cc:     Jiri Olsa <jolsa@kernel.org>,
        Arnaldo Carvalho de Melo <acme@kernel.org>,
        lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: Re: [PATCH 3/3] perf stat: Add --metrics-file option
Message-ID: <20200421200630.GG608746@tassilo.jf.intel.com>
References: <20200421181337.988681-1-jolsa@kernel.org>
 <20200421181337.988681-4-jolsa@kernel.org>
 <20200421183615.GD608746@tassilo.jf.intel.com>
 <20200421185252.GA962614@krava>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200421185252.GA962614@krava>
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

> > Also there are some asserts that can be triggered by expressions. I think
> > you should fix those too and convert them to errors.
> 
> do you have some details on this? examples of those failures?

At a minimum 

/* Caller must make sure id is allocated */
void expr__add_id(struct parse_ctx *ctx, const char *name, double val)
{
        int idx;
        assert(ctx->num_ids < MAX_PARSE_ID);


-Andi

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rw9U=6H=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 29B2FC54FCB
	for <linux-kernel@archiver.kernel.org>; Thu, 23 Apr 2020 13:25:00 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id E5A1120781
	for <linux-kernel@archiver.kernel.org>; Thu, 23 Apr 2020 13:24:59 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IKMTdZ84"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1728076AbgDWNY7 (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 23 Apr 2020 09:24:59 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28808 "EHLO
        us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1726224AbgDWNY6 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 23 Apr 2020 09:24:58 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1587648297;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         in-reply-to:in-reply-to:references:references;
        bh=RuDyAj20bmjbvYj7VsEeP7XEemVCDcYopHSDDueemOo=;
        b=IKMTdZ841e3eRC6MqAXGGG083JUfn7NQC/xNrOs017m6jk9jMYSbYTsVEk6j0/C6F1None
        m4dU9LJ0hZpPcV3zXLQ+Xmnw1DixrFh6B/GhaIJJK1uwo90HWPnoUJ+H4zg5M9D4rj7gvR
        goWPbIvPQF1Zlx0BWMJEC++gbbCntv0=
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-22--jOYvudAO7eUPhq-S7CEWA-1; Thu, 23 Apr 2020 09:24:53 -0400
X-MC-Unique: -jOYvudAO7eUPhq-S7CEWA-1
Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
        (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
        (No client certificate requested)
        by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC00380B70F;
        Thu, 23 Apr 2020 13:24:51 +0000 (UTC)
Received: from krava (ovpn-115-157.ams2.redhat.com [10.36.115.157])
        by smtp.corp.redhat.com (Postfix) with ESMTPS id 52D1C619C0;
        Thu, 23 Apr 2020 13:24:48 +0000 (UTC)
Date:   Thu, 23 Apr 2020 15:24:46 +0200
From:   Jiri Olsa <jolsa@redhat.com>
To:     Andi Kleen <ak@linux.intel.com>
Cc:     Jiri Olsa <jolsa@kernel.org>,
        Arnaldo Carvalho de Melo <acme@kernel.org>,
        lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>,
        Kajol Jain <kjain@linux.ibm.com>,
        John Garry <john.garry@huawei.com>
Subject: Re: [PATCH 3/3] perf stat: Add --metrics-file option
Message-ID: <20200423132446.GN1136647@krava>
References: <20200421181337.988681-1-jolsa@kernel.org>
 <20200421181337.988681-4-jolsa@kernel.org>
 <20200421183615.GD608746@tassilo.jf.intel.com>
 <20200421185252.GA962614@krava>
 <20200421200630.GG608746@tassilo.jf.intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20200421200630.GG608746@tassilo.jf.intel.com>
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Tue, Apr 21, 2020 at 01:06:30PM -0700, Andi Kleen wrote:
> > > Also there are some asserts that can be triggered by expressions. I think
> > > you should fix those too and convert them to errors.
> > 
> > do you have some details on this? examples of those failures?
> 
> At a minimum 
> 
> /* Caller must make sure id is allocated */
> void expr__add_id(struct parse_ctx *ctx, const char *name, double val)
> {
>         int idx;
>         assert(ctx->num_ids < MAX_PARSE_ID);
> 
> 
> -Andi
> 

I did it and then I realized this is already caught in the parsing
code (expr.y) with this check:

        if (ctx->num_ids + 1 >= EXPR_MAX_OTHER) {
                pr_err("failed: way too many variables\n");
                YYABORT;
        }

so that assert can stay there and shouldn't be ever hit

jirka


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=SogR=6O=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,
	USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 10365C8300A
	for <linux-kernel@archiver.kernel.org>; Thu, 30 Apr 2020 11:25:00 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id E8F2F20774
	for <linux-kernel@archiver.kernel.org>; Thu, 30 Apr 2020 11:24:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726829AbgD3LY7 (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 30 Apr 2020 07:24:59 -0400
Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44456 "EHLO
        mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726413AbgD3LY6 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 30 Apr 2020 07:24:58 -0400
Received: from pps.filterd (m0098421.ppops.net [127.0.0.1])
        by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03UB3S6Z178050;
        Thu, 30 Apr 2020 07:24:50 -0400
Received: from pps.reinject (localhost [127.0.0.1])
        by mx0a-001b2d01.pphosted.com with ESMTP id 30q80qsngs-1
        (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
        Thu, 30 Apr 2020 07:24:50 -0400
Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1])
        by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 03UB44Gc184266;
        Thu, 30 Apr 2020 07:24:49 -0400
Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11])
        by mx0a-001b2d01.pphosted.com with ESMTP id 30q80qsngg-1
        (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
        Thu, 30 Apr 2020 07:24:49 -0400
Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1])
        by ppma03dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 03UBO0bs029241;
        Thu, 30 Apr 2020 11:24:48 GMT
Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17])
        by ppma03dal.us.ibm.com with ESMTP id 30mcu805gr-1
        (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
        Thu, 30 Apr 2020 11:24:48 +0000
Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233])
        by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 03UBOlis20316518
        (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK);
        Thu, 30 Apr 2020 11:24:47 GMT
Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1])
        by IMSVA (Postfix) with ESMTP id 876FD13605D;
        Thu, 30 Apr 2020 11:24:47 +0000 (GMT)
Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1])
        by IMSVA (Postfix) with ESMTP id 824BB136053;
        Thu, 30 Apr 2020 11:24:43 +0000 (GMT)
Received: from localhost.localdomain (unknown [9.85.85.241])
        by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP;
        Thu, 30 Apr 2020 11:24:43 +0000 (GMT)
Subject: Re: [PATCHv2 0/3] perf tools: Add support for user defined metric
To:     Jiri Olsa <jolsa@kernel.org>,
        Arnaldo Carvalho de Melo <acme@kernel.org>
Cc:     lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        John Garry <john.garry@huawei.com>
References: <20200421181337.988681-1-jolsa@kernel.org>
From:   kajoljain <kjain@linux.ibm.com>
Message-ID: <8df4b32b-4abc-7ea9-feaf-a16be6edf64f@linux.ibm.com>
Date:   Thu, 30 Apr 2020 16:54:41 +0530
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.8.0
MIME-Version: 1.0
In-Reply-To: <20200421181337.988681-1-jolsa@kernel.org>
Content-Type: text/plain; charset=windows-1252
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-TM-AS-GCONF: 00
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676
 definitions=2020-04-30_05:2020-04-30,2020-04-30 signatures=0
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0
 priorityscore=1501 mlxscore=0 clxscore=1015 impostorscore=0 phishscore=0
 bulkscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999
 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1
 engine=8.12.0-2003020000 definitions=main-2004300087
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org



On 4/21/20 11:43 PM, Jiri Olsa wrote:
> hi,
> Joe asked for possibility to add user defined metrics. Given that
> we already have metrics support, I added --metrics-file option that
> allows to specify custom metrics.
> 
>   $ cat metrics
>   # IPC
>   mine1 = instructions / cycles;
>   /* DECODED_ICACHE_UOPS% */
>   mine2 = 100 * (idq.dsb_uops / \ (idq.ms_uops + idq.mite_uops + idq.dsb_uops + lsd.uops));
> 
>   $ sudo perf stat --metrics-file ./metrics -M mine1,mine2 --metric-only -a -I 1000
>   #           time       insn per cycle                mine1                mine2
>        1.000536263                0.71                   0.7                 41.4
>        2.002069025                0.31                   0.3                 14.1
>        3.003427684                0.27                   0.3                 14.8
>        4.004807132                0.25                   0.2                 12.1
>   ...
> 
> v2 changes:
>   - add new --metrics-file option
>   - rebased on current perf/core expression bison/flex enhancements
> 
> Also available in:
>   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
>   perf/metric
> 
> thanks,
> jirka
> 
> 
> ---
> Jiri Olsa (3):
>       perf expr: Add parsing support for multiple expressions
>       perf expr: Allow comments in custom metric file
>       perf stat: Add --metrics-file option

Hi Jiri,
     I try to look into these patches. As far as I understand we are using
syntax "Name: Expression" for user defined events. It will be great if we mention
this format somewhere for users.

Otherwise it works fine for me. Try by testing it for different metric expressions.
But still curious about reason for adding this support. Isn't json file is there for same purpose?

Thanks,
Kajol Jain
> 
>  tools/perf/Documentation/perf-stat.txt |  3 +++
>  tools/perf/builtin-stat.c              |  7 +++++--
>  tools/perf/tests/expr.c                | 13 +++++++++++++
>  tools/perf/util/expr.c                 |  6 ++++++
>  tools/perf/util/expr.h                 | 19 +++++++++++++++++--
>  tools/perf/util/expr.l                 | 24 ++++++++++++++++++++++++
>  tools/perf/util/expr.y                 | 13 ++++++++++++-
>  tools/perf/util/metricgroup.c          | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  tools/perf/util/metricgroup.h          |  3 ++-
>  tools/perf/util/stat.h                 |  1 +
>  10 files changed, 142 insertions(+), 13 deletions(-)
> 

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=SogR=6O=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-5.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 92656C8300A
	for <linux-kernel@archiver.kernel.org>; Thu, 30 Apr 2020 12:43:21 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 682C02072A
	for <linux-kernel@archiver.kernel.org>; Thu, 30 Apr 2020 12:43:21 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JGLye7rd"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726850AbgD3MnU (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 30 Apr 2020 08:43:20 -0400
Received: from us-smtp-2.mimecast.com ([207.211.31.81]:20107 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726520AbgD3MnU (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 30 Apr 2020 08:43:20 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1588250598;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         in-reply-to:in-reply-to:references:references;
        bh=BAg82KvpzRQfogFt02yjyfPQP7IP6UKcwesWkwykLkE=;
        b=JGLye7rdSmwMnNM7ST4YFIHAeIHi3vOMCN9k2Jj9R6lbKA+zqA0ggJA/+EqP2nHOPvLvpx
        GUuD/hmVsNUOvNP7gn5zqWJhFLScQl3aXpCCxMlEX2An05dACdrGHRThRizQDR/VMcTfUp
        wvrLooIZXly3oOtXhG+Dco+fwDC+RUg=
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-105-JzxphAwAO8irvk7l5Tymgg-1; Thu, 30 Apr 2020 08:43:14 -0400
X-MC-Unique: JzxphAwAO8irvk7l5Tymgg-1
Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23])
        (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
        (No client certificate requested)
        by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F19211800D4A;
        Thu, 30 Apr 2020 12:43:12 +0000 (UTC)
Received: from krava (unknown [10.40.192.9])
        by smtp.corp.redhat.com (Postfix) with ESMTPS id 04515196AE;
        Thu, 30 Apr 2020 12:43:09 +0000 (UTC)
Date:   Thu, 30 Apr 2020 14:43:06 +0200
From:   Jiri Olsa <jolsa@redhat.com>
To:     kajoljain <kjain@linux.ibm.com>
Cc:     Jiri Olsa <jolsa@kernel.org>,
        Arnaldo Carvalho de Melo <acme@kernel.org>,
        lkml <linux-kernel@vger.kernel.org>,
        Ingo Molnar <mingo@kernel.org>,
        Namhyung Kim <namhyung@kernel.org>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@chello.nl>,
        Michael Petlan <mpetlan@redhat.com>,
        Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
        John Garry <john.garry@huawei.com>
Subject: Re: [PATCHv2 0/3] perf tools: Add support for user defined metric
Message-ID: <20200430124306.GD1694693@krava>
References: <20200421181337.988681-1-jolsa@kernel.org>
 <8df4b32b-4abc-7ea9-feaf-a16be6edf64f@linux.ibm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <8df4b32b-4abc-7ea9-feaf-a16be6edf64f@linux.ibm.com>
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Thu, Apr 30, 2020 at 04:54:41PM +0530, kajoljain wrote:
> 
> 
> On 4/21/20 11:43 PM, Jiri Olsa wrote:
> > hi,
> > Joe asked for possibility to add user defined metrics. Given that
> > we already have metrics support, I added --metrics-file option that
> > allows to specify custom metrics.
> > 
> >   $ cat metrics
> >   # IPC
> >   mine1 = instructions / cycles;
> >   /* DECODED_ICACHE_UOPS% */
> >   mine2 = 100 * (idq.dsb_uops / \ (idq.ms_uops + idq.mite_uops + idq.dsb_uops + lsd.uops));
> > 
> >   $ sudo perf stat --metrics-file ./metrics -M mine1,mine2 --metric-only -a -I 1000
> >   #           time       insn per cycle                mine1                mine2
> >        1.000536263                0.71                   0.7                 41.4
> >        2.002069025                0.31                   0.3                 14.1
> >        3.003427684                0.27                   0.3                 14.8
> >        4.004807132                0.25                   0.2                 12.1
> >   ...
> > 
> > v2 changes:
> >   - add new --metrics-file option
> >   - rebased on current perf/core expression bison/flex enhancements
> > 
> > Also available in:
> >   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
> >   perf/metric
> > 
> > thanks,
> > jirka
> > 
> > 
> > ---
> > Jiri Olsa (3):
> >       perf expr: Add parsing support for multiple expressions
> >       perf expr: Allow comments in custom metric file
> >       perf stat: Add --metrics-file option
> 
> Hi Jiri,
>      I try to look into these patches. As far as I understand we are using
> syntax "Name: Expression" for user defined events. It will be great if we mention
> this format somewhere for users.

right, Andi also asked for that, I'll describe it in a man page

> 
> Otherwise it works fine for me. Try by testing it for different metric expressions.

thanks for testing

> But still curious about reason for adding this support. Isn't json file is there for same purpose?

we've been asked by Joe about the possibility to specify metric by user
through the command line..  with json you have all them compiled in and 
you can't change them or specify your own without recompiling perf

jirka

> 
> Thanks,
> Kajol Jain
> > 
> >  tools/perf/Documentation/perf-stat.txt |  3 +++
> >  tools/perf/builtin-stat.c              |  7 +++++--
> >  tools/perf/tests/expr.c                | 13 +++++++++++++
> >  tools/perf/util/expr.c                 |  6 ++++++
> >  tools/perf/util/expr.h                 | 19 +++++++++++++++++--
> >  tools/perf/util/expr.l                 | 24 ++++++++++++++++++++++++
> >  tools/perf/util/expr.y                 | 13 ++++++++++++-
> >  tools/perf/util/metricgroup.c          | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
> >  tools/perf/util/metricgroup.h          |  3 ++-
> >  tools/perf/util/stat.h                 |  1 +
> >  10 files changed, 142 insertions(+), 13 deletions(-)
> > 
> 


