2012-03-16 03:09:15 +08:00
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
%option reentrant
|
|
|
|
%option bison-bridge
|
2012-03-16 03:09:15 +08:00
|
|
|
%option prefix="parse_events_"
|
2012-05-21 15:12:52 +08:00
|
|
|
%option stack
|
2012-03-16 03:09:15 +08:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <errno.h>
|
|
|
|
#include "../perf.h"
|
|
|
|
#include "parse-events-bison.h"
|
2012-03-16 03:09:16 +08:00
|
|
|
#include "parse-events.h"
|
2012-03-16 03:09:15 +08:00
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
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)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
2012-08-08 01:43:13 +08:00
|
|
|
u64 num;
|
2012-03-16 03:09:15 +08:00
|
|
|
|
|
|
|
errno = 0;
|
2012-08-08 01:43:13 +08:00
|
|
|
num = strtoull(str, NULL, base);
|
2012-03-16 03:09:15 +08:00
|
|
|
if (errno)
|
|
|
|
return PE_ERROR;
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
yylval->num = num;
|
2012-03-16 03:09:15 +08:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
static int value(yyscan_t scanner, int base)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
2012-06-15 14:31:39 +08:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
return __value(yylval, text, base, PE_VALUE);
|
2012-03-16 03:09:15 +08:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
static int raw(yyscan_t scanner)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
2012-06-15 14:31:39 +08:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
return __value(yylval, text + 1, 16, PE_RAW);
|
2012-03-16 03:09:15 +08:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
static int str(yyscan_t scanner, int token)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
2012-06-15 14:31:39 +08:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
yylval->str = strdup(text);
|
2012-03-16 03:09:15 +08:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
static int sym(yyscan_t scanner, int type, int config)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
2012-06-15 14:31:39 +08:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
|
|
|
|
yylval->num = (type << 16) + config;
|
2012-07-04 06:00:43 +08:00
|
|
|
return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
|
2012-03-16 03:09:15 +08:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
static int term(yyscan_t scanner, int type)
|
2012-03-16 03:09:16 +08:00
|
|
|
{
|
2012-06-15 14:31:39 +08:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
|
|
|
|
yylval->num = type;
|
2012-03-16 03:09:16 +08:00
|
|
|
return PE_TERM;
|
|
|
|
}
|
|
|
|
|
2012-03-16 03:09:15 +08:00
|
|
|
%}
|
|
|
|
|
2012-05-21 15:12:52 +08:00
|
|
|
%x mem
|
|
|
|
|
2012-03-16 03:09:15 +08:00
|
|
|
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_*?]*
|
2012-04-17 19:13:45 +08:00
|
|
|
modifier_event [ukhpGH]{1,8}
|
2012-06-29 15:22:54 +08:00
|
|
|
modifier_bp [rwx]{1,3}
|
2012-03-16 03:09:15 +08:00
|
|
|
|
|
|
|
%%
|
2012-06-15 14:31:40 +08:00
|
|
|
|
|
|
|
%{
|
|
|
|
{
|
|
|
|
int start_token;
|
|
|
|
|
|
|
|
start_token = (int) parse_events_get_extra(yyscanner);
|
|
|
|
if (start_token) {
|
|
|
|
parse_events_set_extra(NULL, yyscanner);
|
|
|
|
return start_token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
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); }
|
2012-03-16 03:09:15 +08:00
|
|
|
|
|
|
|
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 |
|
2012-06-15 14:31:39 +08:00
|
|
|
node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
|
2012-03-16 03:09:15 +08:00
|
|
|
|
|
|
|
load|loads|read |
|
|
|
|
store|stores|write |
|
|
|
|
prefetch|prefetches |
|
|
|
|
speculative-read|speculative-load |
|
|
|
|
refs|Reference|ops|access |
|
2012-06-15 14:31:39 +08:00
|
|
|
misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
|
2012-03-16 03:09:15 +08:00
|
|
|
|
2012-03-16 03:09:16 +08:00
|
|
|
/*
|
|
|
|
* These are event config hardcoded term names to be specified
|
|
|
|
* within xxx/.../ syntax. So far we dont clash with other names,
|
|
|
|
* so we can put them here directly. In case the we have a conflict
|
|
|
|
* in future, this needs to go into '//' condition block.
|
|
|
|
*/
|
2012-06-15 14:31:39 +08:00
|
|
|
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); }
|
|
|
|
branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
|
2012-03-16 03:09:16 +08:00
|
|
|
|
2012-05-21 15:12:52 +08:00
|
|
|
mem: { BEGIN(mem); return PE_PREFIX_MEM; }
|
2012-06-15 14:31:39 +08:00
|
|
|
r{num_raw_hex} { return raw(yyscanner); }
|
|
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
|
|
{num_hex} { return value(yyscanner, 16); }
|
2012-03-16 03:09:15 +08:00
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
|
|
|
|
{name} { return str(yyscanner, PE_NAME); }
|
2012-03-16 03:09:15 +08:00
|
|
|
"/" { return '/'; }
|
|
|
|
- { return '-'; }
|
|
|
|
, { return ','; }
|
|
|
|
: { return ':'; }
|
|
|
|
= { return '='; }
|
2012-07-04 06:00:39 +08:00
|
|
|
\n { }
|
2012-03-16 03:09:15 +08:00
|
|
|
|
2012-05-21 15:12:52 +08:00
|
|
|
<mem>{
|
2012-06-15 14:31:39 +08:00
|
|
|
{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
|
2012-05-21 15:12:52 +08:00
|
|
|
: { return ':'; }
|
2012-06-15 14:31:39 +08:00
|
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
|
|
{num_hex} { return value(yyscanner, 16); }
|
2012-05-21 15:12:52 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-06-15 14:31:39 +08:00
|
|
|
. { unput(*yytext); BEGIN(INITIAL); }
|
2012-05-21 15:12:52 +08:00
|
|
|
/*
|
|
|
|
* We destroy the scanner after reaching EOF,
|
|
|
|
* but anyway just to be sure get back to INIT state.
|
|
|
|
*/
|
|
|
|
<<EOF>> { BEGIN(INITIAL); }
|
|
|
|
}
|
|
|
|
|
2012-03-16 03:09:15 +08:00
|
|
|
%%
|
|
|
|
|
2012-06-15 14:31:39 +08:00
|
|
|
int parse_events_wrap(void *scanner __used)
|
2012-03-16 03:09:15 +08:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|