From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbdJLPNj (ORCPT ); Thu, 12 Oct 2017 11:13:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751370AbdJLPNi (ORCPT ); Thu, 12 Oct 2017 11:13:38 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E01CD46279 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jolsa@redhat.com Date: Thu, 12 Oct 2017 17:13:35 +0200 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Andi Kleen , Jiri Olsa , Wang Nan , linux-kernel@vger.kernel.org, Andi Kleen , He Kuang , Alexei Starovoitov Subject: Re: [PATCH 2/2] perf, tools: Don't force MetricExprs to lower case Message-ID: <20171012151335.GA20291@krava> References: <20170912195643.2611-1-andi@firstfloor.org> <20170912195643.2611-2-andi@firstfloor.org> <20171003160605.GC25388@kernel.org> <20171004103052.GC23759@krava> <20171004162711.GF2482@two.firstfloor.org> <20171009134151.GA15127@krava> <20171009140944.GD28623@kernel.org> <20171009144155.GB1561@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171009144155.GB1561@krava> User-Agent: Mutt/1.9.1 (2017-09-22) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 12 Oct 2017 15:13:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 09, 2017 at 04:41:55PM +0200, Jiri Olsa wrote: > On Mon, Oct 09, 2017 at 11:09:44AM -0300, Arnaldo Carvalho de Melo wrote: > > SNIP > > > [root@jouet bpf]# cat sys_read.c > > #define SEC(NAME) __attribute__((section(NAME), used)) > > SEC("func=sys_read") > > int bpf_func__sys_read(void *ctx) > > { > > return 1; > > } > > char _license[] SEC("license") = "GPL"; > > int _version SEC("version") = LINUX_VERSION_CODE; > > [root@jouet bpf]# perf trace --no-syscalls -e sys_read.c/max-stack=5/ sleep 1 > > bpf: builtin compilation failed: -95, try external compiler > > 0.000 perf_bpf_probe:func:(ffffffffb7263190)) > > sys_read ([kernel.kallsyms]) > > entry_SYSCALL_64_fastpath ([kernel.kallsyms]) > > __read (/usr/lib64/ld-2.25.so) > > _dl_map_object (/usr/lib64/ld-2.25.so) > > [root@jouet bpf]# perf trace --no-syscalls -e sys_read.c sleep 1 > > bpf: builtin compilation failed: -95, try external compiler > > 0.000 perf_bpf_probe:func:(ffffffffb7263190)) > > [root@jouet bpf]# > > is this ok? > > > > > [root@jouet bpf]# perf stat -e UOPS_EXECUTED.CORE sleep 1 > > > > Performance counter stats for 'sleep 1': > > > > 1,205,347 UOPS_EXECUTED.CORE > > > > 1.001694225 seconds time elapsed > > > > But I noticed this problem: > > > > [root@jouet bpf]# perf stat -e cpu/uops_executed.core/,uops_executed.core,cpu/UOPS_EXECUTED.CORE sleep 1 > > event syntax error: '..d=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:IY�' > > \___ parser error > > Run 'perf list' for a list of valid events > > > > mama mia, this looks like unhandled case of error printing.. I'll check I think I found the issue, could you please check following patch? and wrt Andi's concern about wrong error message, now if you make typo in your bpf file it says: [jolsa@krava perf]$ ./perf stat -e krava.c// sleep 1 event syntax error: 'krava.c//' \___ Cannot find PMU `krava.c'. Missing kernel support? Run 'perf list' for a list of valid events ... looks sane enough.. ;-) thanks, jirka --- diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index ea2426daf7e8..241396cd059d 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -8,6 +8,9 @@ %{ #include +#include +#include +#include #include "../perf.h" #include "parse-events.h" #include "parse-events-bison.h" @@ -53,9 +56,8 @@ static int str(yyscan_t scanner, int token) return token; } -static bool isbpf(yyscan_t scanner) +static bool isbpf_suffix(char *text) { - char *text = parse_events_get_text(scanner); int len = strlen(text); if (len < 2) @@ -68,6 +70,17 @@ static bool isbpf(yyscan_t scanner) return false; } +static bool isbpf(yyscan_t scanner) +{ + char *text = parse_events_get_text(scanner); + struct stat st; + + if (!isbpf_suffix(text)) + return false; + + return stat(text, &st) == 0; +} + /* * This function is called when the parser gets two kind of input: * @@ -141,6 +154,10 @@ do { \ yycolumn += yyleng; \ } while (0); +#define USER_REJECT \ + yycolumn -= yyleng; \ + REJECT + %} %x mem @@ -323,8 +340,8 @@ r{num_raw_hex} { return raw(yyscanner); } {num_hex} { return value(yyscanner, 16); } {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } -{bpf_object} { if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_OBJECT); } -{bpf_source} { if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_SOURCE); } +{bpf_object} { if (!isbpf(yyscanner)) USER_REJECT; return str(yyscanner, PE_BPF_OBJECT); } +{bpf_source} { if (!isbpf(yyscanner)) USER_REJECT; return str(yyscanner, PE_BPF_SOURCE); } {name} { return pmu_str_check(yyscanner); } "/" { BEGIN(config); return '/'; } - { return '-'; }