Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2175278ybk; Mon, 11 May 2020 13:58:38 -0700 (PDT) X-Google-Smtp-Source: APiQypJZY2W9qWzsefO3Yn24jrs7jQ2Tc9EvlUjLqGHGKD852tFtI1IOv7bEsAipRwtek5L0QJd2 X-Received: by 2002:a17:906:da0c:: with SMTP id fi12mr11323833ejb.254.1589230718002; Mon, 11 May 2020 13:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589230717; cv=none; d=google.com; s=arc-20160816; b=w1Om1x+h7n591BSiYKN2ura650XDmbP2zX1/1BjBTYyXouGXCSUPfJbIAQhqKMOxta zQmj0MaJ6jrTgZ2NLlvthgb7pcnPRzgT2c8zz/GwPTUOD1b7yw+5BgBYzrI05VKcacst gmI8em8Q4/fJgjqysDf65yMeTskr0XhjqCni7uq8/R9OcJlhoVTXAG3qqo+elqudMYJ2 G2Fjs66zcntx9dgVwrBc8l4sJ0XxDGdZ40Jh9AyS28HpmykM+1h8iaf6x657rBM7os2a ZFmP+zK/wkzl8doZVwAPn7SlCraQ94lrPLXOFhKhBtFGhhQLko1L3x7VhUTLDsfe4HYR gMGw== 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=ci9zFu3Khld2fiZUDikqHyWvb84jHkz1nTmlyNDdH7o=; b=VyAKzVM+VXzPUPHzBGHTdAdqSErxGqAGkUvp78zsVs0EVqoQThDaHQJDW5tW2JkyDQ FTrpX4yf2+PU1G8G7QJAOMKTEguu89DtL8cUKDVHW76XZW65VrrwillaQbID64Pjmvu7 lSPdsGqtPjV2DSSKMj8rgDRlTPg6pe0ncjXa5m9pYXyKxr3hlG28HjfcMWf9qZ7R7Fr5 xJnnbxkrT6bU09QUZZolOcCxE1vBw4PkQ8cJSkOux2XIBWEhPyK88gpiNYOr4+FEh5dg JgcDhwuhCSMDXhiJ7g842wyCAFJsHwrtqmWEeA6U+poAtpRlMIKguR/hTgzWInheq5iC Tq+Q== 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 a26si4348709ejx.524.2020.05.11.13.58.14; Mon, 11 May 2020 13:58:37 -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 S1731823AbgEKUxe convert rfc822-to-8bit (ORCPT + 99 others); Mon, 11 May 2020 16:53:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26560 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731712AbgEKUxc (ORCPT ); Mon, 11 May 2020 16:53:32 -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-170-nFGSSzEuOJGXV8jNBTS-7Q-1; Mon, 11 May 2020 16:53:26 -0400 X-MC-Unique: nFGSSzEuOJGXV8jNBTS-7Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B76DC835B46; Mon, 11 May 2020 20:53:24 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5B256444B; Mon, 11 May 2020 20:53:21 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Joe Mario , Andi Kleen , Kajol Jain , John Garry Subject: [PATCH 4/4] perf expr: Report line number with error Date: Mon, 11 May 2020 22:53:07 +0200 Message-Id: <20200511205307.3107775-5-jolsa@kernel.org> In-Reply-To: <20200511205307.3107775-1-jolsa@kernel.org> References: <20200511205307.3107775-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 Display line number on when parsing custom metrics file, like: $ cat metrics // IPC mine1 = inst_retired.any / cpu_clk_unhalted.thread; krava $ sudo perf stat --metrics-file ./metrics -M mine1 -a -I 1000 --metric-only failed to parse metrics file: ./metrics:4 Please note that because the grammar is flexible on new lines, the syntax could be broken on the next 'not fitting' item and not the first wrong word, like: $ cat metrics // IPC krava mine1 = inst_retired.any / cpu_clk_unhalted.thread; $ sudo perf stat --metrics-file ./metrics -M mine1 -a -I 1000 --metric-only failed to parse metrics file: ./metrics:3 Signed-off-by: Jiri Olsa --- tools/perf/tests/expr.c | 5 +++++ tools/perf/util/expr.h | 2 ++ tools/perf/util/expr.l | 10 ++++++++++ tools/perf/util/expr.y | 8 +++++--- tools/perf/util/metricgroup.c | 3 ++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index c62e122fe719..3bffcd9f8397 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -84,5 +84,10 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) zfree(&ctx.custom[i].name); zfree(&ctx.custom[i].expr); } + + expr__ctx_init(&ctx); + ret = expr__parse_custom(&ctx, "IPC=INSTRUCTIONS / CYCLES;\n error"); + TEST_ASSERT_VAL("parse custom failed", ret != 0); + TEST_ASSERT_VAL("parse custom count", ctx.lineno == 2); return 0; } diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index ef116b58a5d4..ce95dfd2ad5a 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -27,6 +27,8 @@ struct expr_parse_ctx { struct expr_parse_custom custom[EXPR_MAX]; }; }; + /* Set on error for custom metrics. */ + int lineno; }; struct expr_scanner_ctx { diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l index e9b294ba09fc..718aac4316d7 100644 --- a/tools/perf/util/expr.l +++ b/tools/perf/util/expr.l @@ -1,6 +1,8 @@ %option prefix="expr_" %option reentrant %option bison-bridge +%option bison-locations +%option yylineno %{ #include @@ -79,6 +81,13 @@ static int str(yyscan_t scanner, int token, int runtime) yylval->str = normalize(yylval->str, runtime); return token; } + +#define YY_USER_ACTION \ +do { \ + yylloc->last_line = yylloc->first_line; \ + yylloc->first_line = yylineno; \ +} while (0); + %} %x custom @@ -101,6 +110,7 @@ all [^;]+ if (sctx->start_token) { sctx->start_token = 0; + yylineno = 1; return start_token; } } diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index 0521e48fa5e3..812d893bcd31 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -18,6 +18,7 @@ %parse-param { struct expr_parse_ctx *ctx } %parse-param {void *scanner} %lex-param {void* scanner} +%locations %union { double num; @@ -39,12 +40,13 @@ %type expr if_expr %{ -static void expr_error(double *final_val __maybe_unused, - struct expr_parse_ctx *ctx __maybe_unused, +static void expr_error(YYLTYPE *loc, double *final_val __maybe_unused, + struct expr_parse_ctx *ctx, void *scanner, const char *s) { - pr_debug("%s\n", s); + pr_debug("%s, line %d\n", s, loc->last_line); + ctx->lineno = loc->last_line; } static int lookup_id(struct expr_parse_ctx *ctx, char *id, double *val) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 3b4d5bdb5ac6..36df43546e84 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -615,7 +615,8 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events, ret = expr__parse_custom(&ctx, buf); free(buf); if (ret) { - pr_err("failed to parse metrics file: %s\n", metrics_file); + pr_err("failed to parse metrics file: %s:%d\n", + metrics_file, ctx.lineno); return -1; } } -- 2.25.4