aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Budankov <alexey.budankov@linux.intel.com>2018-06-04 02:50:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-06-06 11:52:04 -0400
commitf92da71280fb8da3a7c489e08a096f0b8715f939 (patch)
tree6aa3d3c659472d88ee121f11325671ffb6847ad4
parentaef4feace285f27c8ed35830a5d575bec7f3e90a (diff)
perf record: Enable arbitrary event names thru name= modifier
Enable complex event names containing [.:=,] symbols to be encoded into Perf trace using name= modifier e.g. like this: perf record -e cpu/name=\'OFFCORE_RESPONSE:request=DEMAND_RFO:response=L3_HIT.SNOOP_HITM\',\ period=0x3567e0,event=0x3c,cmask=0x1/Duk ./futex Below is how it looks like in the report output. Please note explicit escaped quoting at cmdline string in the header so that thestring can be directly reused for another collection in shell: perf report --header # ======== ... # cmdline : /root/abudanko/kernel/tip/tools/perf/perf record -v -e cpu/name=\'OFFCORE_RESPONSE:request=DEMAND_RFO:response=L3_HIT.SNOOP_HITM\',period=0x3567e0,event=0x3c,cmask=0x1/Duk ./futex # event : name = OFFCORE_RESPONSE:request=DEMAND_RFO:response=L3_HIT.SNOOP_HITM, , type = 4, size = 112, config = 0x100003c, { sample_period, sample_freq } = 3500000, sample_type = IP|TID|TIME, disabled = 1, inh ... # ======== # # # Total Lost Samples: 0 # # Samples: 24K of event 'OFFCORE_RESPONSE:request=DEMAND_RFO:response=L3_HIT.SNOOP_HITM' # Event count (approx.): 86492000000 # # Overhead Command Shared Object Symbol # ........ ....... ................ .............................................. # 14.75% futex [kernel.vmlinux] [k] __entry_trampoline_start ... perf stat -e cpu/name=\'CPU_CLK_UNHALTED.THREAD:cmask=0x1\',period=0x3567e0,event=0x3c,cmask=0x1/Duk ./futex 10000000 process context switches in 16678890291ns (1667.9ns/ctxsw) Performance counter stats for './futex': 88,095,770,571 CPU_CLK_UNHALTED.THREAD:cmask=0x1 16.679542407 seconds time elapsed Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/c194b060-761d-0d50-3b21-bb4ed680002d@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-list.txt6
-rw-r--r--tools/perf/Documentation/perf-record.txt3
-rw-r--r--tools/perf/util/header.c20
-rw-r--r--tools/perf/util/parse-events.l18
4 files changed, 43 insertions, 4 deletions
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 2549c34a7895..11300dbe35c5 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -124,7 +124,11 @@ The available PMUs and their raw parameters can be listed with
124For example the raw event "LSD.UOPS" core pmu event above could 124For example the raw event "LSD.UOPS" core pmu event above could
125be specified as 125be specified as
126 126
127 perf stat -e cpu/event=0xa8,umask=0x1,name=LSD.UOPS_CYCLES,cmask=1/ ... 127 perf stat -e cpu/event=0xa8,umask=0x1,name=LSD.UOPS_CYCLES,cmask=0x1/ ...
128
129 or using extended name syntax
130
131 perf stat -e cpu/event=0xa8,umask=0x1,cmask=0x1,name=\'LSD.UOPS_CYCLES:cmask=0x1\'/ ...
128 132
129PER SOCKET PMUS 133PER SOCKET PMUS
130--------------- 134---------------
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index cc37b3a4be76..04168da4268e 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -57,6 +57,9 @@ OPTIONS
57 FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and 57 FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and
58 "no" for disable callgraph. 58 "no" for disable callgraph.
59 - 'stack-size': user stack size for dwarf mode 59 - 'stack-size': user stack size for dwarf mode
60 - 'name' : User defined event name. Single quotes (') may be used to
61 escape symbols in the name from parsing by shell and tool
62 like this: name=\'CPU_CLK_UNHALTED.THREAD:cmask=0x1\'.
60 63
61 See the linkperf:perf-list[1] man page for more parameters. 64 See the linkperf:perf-list[1] man page for more parameters.
62 65
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 2625cc38a0d6..540cd2dcd3e7 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1459,8 +1459,24 @@ static void print_cmdline(struct feat_fd *ff, FILE *fp)
1459 1459
1460 fprintf(fp, "# cmdline : "); 1460 fprintf(fp, "# cmdline : ");
1461 1461
1462 for (i = 0; i < nr; i++) 1462 for (i = 0; i < nr; i++) {
1463 fprintf(fp, "%s ", ff->ph->env.cmdline_argv[i]); 1463 char *argv_i = strdup(ff->ph->env.cmdline_argv[i]);
1464 if (!argv_i) {
1465 fprintf(fp, "%s ", ff->ph->env.cmdline_argv[i]);
1466 } else {
1467 char *mem = argv_i;
1468 do {
1469 char *quote = strchr(argv_i, '\'');
1470 if (!quote)
1471 break;
1472 *quote++ = '\0';
1473 fprintf(fp, "%s\\\'", argv_i);
1474 argv_i = quote;
1475 } while (1);
1476 fprintf(fp, "%s ", argv_i);
1477 free(mem);
1478 }
1479 }
1464 fputc('\n', fp); 1480 fputc('\n', fp);
1465} 1481}
1466 1482
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index a1a01b1ac8b8..5f761f3ed0f3 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -53,7 +53,21 @@ static int str(yyscan_t scanner, int token)
53 YYSTYPE *yylval = parse_events_get_lval(scanner); 53 YYSTYPE *yylval = parse_events_get_lval(scanner);
54 char *text = parse_events_get_text(scanner); 54 char *text = parse_events_get_text(scanner);
55 55
56 yylval->str = strdup(text); 56 if (text[0] != '\'') {
57 yylval->str = strdup(text);
58 } else {
59 /*
60 * If a text tag specified on the command line
61 * contains opening single quite ' then it is
62 * expected that the tag ends with single quote
63 * as well, like this:
64 * name=\'CPU_CLK_UNHALTED.THREAD:cmask=1\'
65 * quotes need to be escaped to bypass shell
66 * processing.
67 */
68 yylval->str = strndup(&text[1], strlen(text) - 2);
69 }
70
57 return token; 71 return token;
58} 72}
59 73
@@ -176,6 +190,7 @@ num_dec [0-9]+
176num_hex 0x[a-fA-F0-9]+ 190num_hex 0x[a-fA-F0-9]+
177num_raw_hex [a-fA-F0-9]+ 191num_raw_hex [a-fA-F0-9]+
178name [a-zA-Z_*?\[\]][a-zA-Z0-9_*?.\[\]]* 192name [a-zA-Z_*?\[\]][a-zA-Z0-9_*?.\[\]]*
193name_tag [\'][a-zA-Z_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=]*[\']
179name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* 194name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
180drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? 195drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
181/* If you add a modifier you need to update check_modifier() */ 196/* If you add a modifier you need to update check_modifier() */
@@ -344,6 +359,7 @@ r{num_raw_hex} { return raw(yyscanner); }
344{bpf_object} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_OBJECT); } 359{bpf_object} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_OBJECT); }
345{bpf_source} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_SOURCE); } 360{bpf_source} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_SOURCE); }
346{name} { return pmu_str_check(yyscanner); } 361{name} { return pmu_str_check(yyscanner); }
362{name_tag} { return str(yyscanner, PE_NAME); }
347"/" { BEGIN(config); return '/'; } 363"/" { BEGIN(config); return '/'; }
348- { return '-'; } 364- { return '-'; }
349, { BEGIN(event); return ','; } 365, { BEGIN(event); return ','; }