forked from Minki/linux
374ce938aa
This patch allows perf record setting event's attr.inherit bit by config terms like: # perf record -e cycles/no-inherit/ ... # perf record -e cycles/inherit/ ... So user can control inherit bit for each event separately. In following example, a.out fork()s in main then do some complex CPU intensive computations in both of its children. Basic result with and without inherit: # perf record -e cycles -e instructions ./a.out [ perf record: Woken up 9 times to write data ] [ perf record: Captured and wrote 2.205 MB perf.data (47920 samples) ] # perf report --stdio # ... # Samples: 23K of event 'cycles' # Event count (approx.): 23641752891 ... # Samples: 24K of event 'instructions' # Event count (approx.): 30428312415 # perf record -i -e cycles -e instructions ./a.out [ perf record: Woken up 5 times to write data ] [ perf record: Captured and wrote 1.111 MB perf.data (24019 samples) ] ... # Samples: 12K of event 'cycles' # Event count (approx.): 11699501775 ... # Samples: 12K of event 'instructions' # Event count (approx.): 15058023559 Cancel inherit for one event when globally enable: # perf record -e cycles/no-inherit/ -e instructions ./a.out [ perf record: Woken up 7 times to write data ] [ perf record: Captured and wrote 1.660 MB perf.data (36004 samples) ] ... # Samples: 12K of event 'cycles/no-inherit/' # Event count (approx.): 11895759282 ... # Samples: 24K of event 'instructions' # Event count (approx.): 30668000441 Enable inherit for one event when globally disable: # perf record -i -e cycles/inherit/ -e instructions ./a.out [ perf record: Woken up 7 times to write data ] [ perf record: Captured and wrote 1.654 MB perf.data (35868 samples) ] ... # Samples: 23K of event 'cycles/inherit/' # Event count (approx.): 23285400229 ... # Samples: 11K of event 'instructions' # Event count (approx.): 14969050259 Committer note: One can check if the bit was set, in addition to seeing the result in the perf.data file size as above by doing one of: # perf record -e cycles -e instructions -a usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.911 MB perf.data (63 samples) ] # perf evlist -v cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 instructions: size: 112, config: 0x1, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, inherit: 1, freq: 1, sample_id_all: 1, exclude_guest: 1 # So, the inherit bit was set in both, now, if we disable it globally using --no-inherit: # perf record --no-inherit -e cycles -e instructions -a usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.910 MB perf.data (56 samples) ] # perf evlist -v cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 instructions: size: 112, config: 0x1, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, freq: 1, sample_id_all: 1, exclude_guest: 1 No inherit bit set, then disabling it and setting just on the cycles event: # perf record --no-inherit -e cycles/inherit/ -e instructions -a usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.909 MB perf.data (48 samples) ] # perf evlist -v cycles/inherit/: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 instructions: size: 112, config: 0x1, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, freq: 1, sample_id_all: 1, exclude_guest: 1 # We can see it as well in by using a more verbose level of debug messages in the tool that sets up the perf_event_attr, 'perf record' in this case: [root@zoo ~]# perf record -vv --no-inherit -e cycles/inherit/ -e instructions -a usleep 1 ------------------------------------------------------------ perf_event_attr: size 112 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 inherit 1 mmap 1 comm 1 freq 1 task 1 sample_id_all 1 exclude_guest 1 mmap2 1 comm_exec 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 sys_perf_event_open: pid -1 cpu 1 group_fd -1 flags 0x8 sys_perf_event_open: pid -1 cpu 2 group_fd -1 flags 0x8 sys_perf_event_open: pid -1 cpu 3 group_fd -1 flags 0x8 ------------------------------------------------------------ perf_event_attr: size 112 config 0x1 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 freq 1 sample_id_all 1 exclude_guest 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 <SNIP> Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexei Starovoitov <ast@plumgrid.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: David S. Miller <davem@davemloft.net> Cc: Li Zefan <lizefan@huawei.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446029705-199659-2-git-send-email-wangnan0@huawei.com [ s/u64/bool/ for the perf_evsel_config_term inherit field - jolsa] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
286 lines
8.4 KiB
Plaintext
286 lines
8.4 KiB
Plaintext
|
|
%option reentrant
|
|
%option bison-bridge
|
|
%option prefix="parse_events_"
|
|
%option stack
|
|
%option bison-locations
|
|
%option yylineno
|
|
|
|
%{
|
|
#include <errno.h>
|
|
#include "../perf.h"
|
|
#include "parse-events-bison.h"
|
|
#include "parse-events.h"
|
|
|
|
char *parse_events_get_text(yyscan_t yyscanner);
|
|
YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
|
|
|
|
static int __value(YYSTYPE *yylval, char *str, int base, int token)
|
|
{
|
|
u64 num;
|
|
|
|
errno = 0;
|
|
num = strtoull(str, NULL, base);
|
|
if (errno)
|
|
return PE_ERROR;
|
|
|
|
yylval->num = num;
|
|
return token;
|
|
}
|
|
|
|
static int value(yyscan_t scanner, int base)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
return __value(yylval, text, base, PE_VALUE);
|
|
}
|
|
|
|
static int raw(yyscan_t scanner)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
return __value(yylval, text + 1, 16, PE_RAW);
|
|
}
|
|
|
|
static int str(yyscan_t scanner, int token)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
yylval->str = strdup(text);
|
|
return token;
|
|
}
|
|
|
|
#define REWIND(__alloc) \
|
|
do { \
|
|
YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \
|
|
char *text = parse_events_get_text(yyscanner); \
|
|
\
|
|
if (__alloc) \
|
|
__yylval->str = strdup(text); \
|
|
\
|
|
yycolumn -= strlen(text); \
|
|
yyless(0); \
|
|
} while (0)
|
|
|
|
static int pmu_str_check(yyscan_t scanner)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
yylval->str = strdup(text);
|
|
switch (perf_pmu__parse_check(text)) {
|
|
case PMU_EVENT_SYMBOL_PREFIX:
|
|
return PE_PMU_EVENT_PRE;
|
|
case PMU_EVENT_SYMBOL_SUFFIX:
|
|
return PE_PMU_EVENT_SUF;
|
|
case PMU_EVENT_SYMBOL:
|
|
return PE_KERNEL_PMU_EVENT;
|
|
default:
|
|
return PE_NAME;
|
|
}
|
|
}
|
|
|
|
static int sym(yyscan_t scanner, int type, int config)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
yylval->num = (type << 16) + config;
|
|
return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
|
|
}
|
|
|
|
static int term(yyscan_t scanner, int type)
|
|
{
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
yylval->num = type;
|
|
return PE_TERM;
|
|
}
|
|
|
|
#define YY_USER_ACTION \
|
|
do { \
|
|
yylloc->last_column = yylloc->first_column; \
|
|
yylloc->first_column = yycolumn; \
|
|
yycolumn += yyleng; \
|
|
} while (0);
|
|
|
|
%}
|
|
|
|
%x mem
|
|
%s config
|
|
%x event
|
|
|
|
group [^,{}/]*[{][^}]*[}][^,{}/]*
|
|
event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
|
|
event [^,{}/]+
|
|
|
|
num_dec [0-9]+
|
|
num_hex 0x[a-fA-F0-9]+
|
|
num_raw_hex [a-fA-F0-9]+
|
|
name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
|
|
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
|
|
/* If you add a modifier you need to update check_modifier() */
|
|
modifier_event [ukhpPGHSDI]+
|
|
modifier_bp [rwx]{1,3}
|
|
|
|
%%
|
|
|
|
%{
|
|
{
|
|
int start_token;
|
|
|
|
start_token = parse_events_get_extra(yyscanner);
|
|
|
|
if (start_token == PE_START_TERMS)
|
|
BEGIN(config);
|
|
else if (start_token == PE_START_EVENTS)
|
|
BEGIN(event);
|
|
|
|
if (start_token) {
|
|
parse_events_set_extra(NULL, yyscanner);
|
|
/*
|
|
* The flex parser does not init locations variable
|
|
* via the scan_string interface, so we need do the
|
|
* init in here.
|
|
*/
|
|
yycolumn = 0;
|
|
return start_token;
|
|
}
|
|
}
|
|
%}
|
|
|
|
<event>{
|
|
|
|
{group} {
|
|
BEGIN(INITIAL);
|
|
REWIND(0);
|
|
}
|
|
|
|
{event_pmu} |
|
|
{event} {
|
|
BEGIN(INITIAL);
|
|
REWIND(1);
|
|
return PE_EVENT_NAME;
|
|
}
|
|
|
|
<<EOF>> {
|
|
BEGIN(INITIAL);
|
|
REWIND(0);
|
|
}
|
|
|
|
}
|
|
|
|
<config>{
|
|
/*
|
|
* Please update parse_events_formats_error_string any time
|
|
* new static term is added.
|
|
*/
|
|
config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
|
|
config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
|
|
config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
|
|
name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
|
|
period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
|
|
freq { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ); }
|
|
branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
|
|
time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
|
|
call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
|
|
stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
|
|
inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
|
|
no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
|
|
, { return ','; }
|
|
"/" { BEGIN(INITIAL); return '/'; }
|
|
{name_minus} { return str(yyscanner, PE_NAME); }
|
|
}
|
|
|
|
<mem>{
|
|
{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
|
|
: { return ':'; }
|
|
"/" { return '/'; }
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
{num_hex} { return value(yyscanner, 16); }
|
|
/*
|
|
* We need to separate 'mem:' scanner part, in order to get specific
|
|
* modifier bits parsed out. Otherwise we would need to handle PE_NAME
|
|
* and we'd need to parse it manually. During the escape from <mem>
|
|
* state we need to put the escaping char back, so we dont miss it.
|
|
*/
|
|
. { unput(*yytext); BEGIN(INITIAL); }
|
|
/*
|
|
* We destroy the scanner after reaching EOF,
|
|
* but anyway just to be sure get back to INIT state.
|
|
*/
|
|
<<EOF>> { BEGIN(INITIAL); }
|
|
}
|
|
|
|
cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
|
|
stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
|
|
stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
|
|
instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
|
|
cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
|
|
cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
|
|
branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
|
|
branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
|
|
bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
|
|
ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
|
|
cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
|
|
task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
|
|
page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
|
|
minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
|
|
major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
|
|
context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
|
|
cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
|
|
alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
|
|
emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
|
|
dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
|
|
|
|
/*
|
|
* We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately.
|
|
* Because the prefix cycles is mixed up with cpu-cycles.
|
|
* loads and stores are mixed up with cache event
|
|
*/
|
|
cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
|
|
L1-dcache|l1-d|l1d|L1-data |
|
|
L1-icache|l1-i|l1i|L1-instruction |
|
|
LLC|L2 |
|
|
dTLB|d-tlb|Data-TLB |
|
|
iTLB|i-tlb|Instruction-TLB |
|
|
branch|branches|bpu|btb|bpc |
|
|
node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
|
|
|
|
load|loads|read |
|
|
store|stores|write |
|
|
prefetch|prefetches |
|
|
speculative-read|speculative-load |
|
|
refs|Reference|ops|access |
|
|
misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
|
|
|
|
mem: { BEGIN(mem); return PE_PREFIX_MEM; }
|
|
r{num_raw_hex} { return raw(yyscanner); }
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
{num_hex} { return value(yyscanner, 16); }
|
|
|
|
{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
|
|
{name} { return pmu_str_check(yyscanner); }
|
|
"/" { BEGIN(config); return '/'; }
|
|
- { return '-'; }
|
|
, { BEGIN(event); return ','; }
|
|
: { return ':'; }
|
|
"{" { BEGIN(event); return '{'; }
|
|
"}" { return '}'; }
|
|
= { return '='; }
|
|
\n { }
|
|
. { }
|
|
|
|
%%
|
|
|
|
int parse_events_wrap(void *scanner __maybe_unused)
|
|
{
|
|
return 1;
|
|
}
|