diff --git a/[refs] b/[refs] index 21c5580af2cd..a986503c05a2 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1dc12760854a670d0366dcfd8ad179e3574c1712 +refs/heads/master: e84c282b40251f314c429f39b044785e323f2648 diff --git a/trunk/tools/lib/traceevent/parse-filter.c b/trunk/tools/lib/traceevent/parse-filter.c index dfcfe2c131de..80d872a81f26 100644 --- a/trunk/tools/lib/traceevent/parse-filter.c +++ b/trunk/tools/lib/traceevent/parse-filter.c @@ -1710,18 +1710,43 @@ static int test_num(struct event_format *event, static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record) { - const char *val = record->data + arg->str.field->offset; + struct event_format *event; + struct pevent *pevent; + unsigned long long addr; + const char *val = NULL; + char hex[64]; - /* - * We need to copy the data since we can't be sure the field - * is null terminated. - */ - if (*(val + arg->str.field->size - 1)) { - /* copy it */ - memcpy(arg->str.buffer, val, arg->str.field->size); - /* the buffer is already NULL terminated */ - val = arg->str.buffer; + /* If the field is not a string convert it */ + if (arg->str.field->flags & FIELD_IS_STRING) { + val = record->data + arg->str.field->offset; + + /* + * We need to copy the data since we can't be sure the field + * is null terminated. + */ + if (*(val + arg->str.field->size - 1)) { + /* copy it */ + memcpy(arg->str.buffer, val, arg->str.field->size); + /* the buffer is already NULL terminated */ + val = arg->str.buffer; + } + + } else { + event = arg->str.field->event; + pevent = event->pevent; + addr = get_value(event, arg->str.field, record); + + if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG)) + /* convert to a kernel symbol */ + val = pevent_find_function(pevent, addr); + + if (val == NULL) { + /* just use the hex of the string name */ + snprintf(hex, 64, "0x%llx", addr); + val = hex; + } } + return val; } diff --git a/trunk/tools/perf/util/parse-events-test.c b/trunk/tools/perf/util/parse-events-test.c index 1b997d2b89ce..dd0c306a0698 100644 --- a/trunk/tools/perf/util/parse-events-test.c +++ b/trunk/tools/perf/util/parse-events-test.c @@ -634,6 +634,8 @@ static struct test__event_st test__events[] = { }, }; +#define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st)) + static struct test__event_st test__events_pmu[] = { [0] = { .name = "cpu/config=10,config1,config2=3,period=1000/u", @@ -645,6 +647,9 @@ static struct test__event_st test__events_pmu[] = { }, }; +#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \ + sizeof(struct test__event_st)) + struct test__term { const char *str; __u32 type; @@ -760,17 +765,21 @@ int parse_events__test(void) { int ret; -#define TEST_EVENTS(tests) \ -do { \ - ret = test_events(tests, ARRAY_SIZE(tests)); \ - if (ret) \ - return ret; \ -} while (0) + do { + ret = test_events(test__events, TEST__EVENTS_CNT); + if (ret) + break; + + if (test_pmu()) { + ret = test_events(test__events_pmu, + TEST__EVENTS_PMU_CNT); + if (ret) + break; + } - TEST_EVENTS(test__events); + ret = test_terms(test__terms, TEST__TERMS_CNT); - if (test_pmu()) - TEST_EVENTS(test__events_pmu); + } while (0); - return test_terms(test__terms, ARRAY_SIZE(test__terms)); + return ret; } diff --git a/trunk/tools/perf/util/parse-events.c b/trunk/tools/perf/util/parse-events.c index 1aa721d7c10f..1dc44dc69133 100644 --- a/trunk/tools/perf/util/parse-events.c +++ b/trunk/tools/perf/util/parse-events.c @@ -19,6 +19,8 @@ #define MAX_NAME_LEN 100 struct event_symbol { + u8 type; + u64 config; const char *symbol; const char *alias; }; @@ -28,86 +30,30 @@ extern int parse_events_debug; #endif int parse_events_parse(void *data, void *scanner); -static struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { - [PERF_COUNT_HW_CPU_CYCLES] = { - .symbol = "cpu-cycles", - .alias = "cycles", - }, - [PERF_COUNT_HW_INSTRUCTIONS] = { - .symbol = "instructions", - .alias = "", - }, - [PERF_COUNT_HW_CACHE_REFERENCES] = { - .symbol = "cache-references", - .alias = "", - }, - [PERF_COUNT_HW_CACHE_MISSES] = { - .symbol = "cache-misses", - .alias = "", - }, - [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { - .symbol = "branch-instructions", - .alias = "branches", - }, - [PERF_COUNT_HW_BRANCH_MISSES] = { - .symbol = "branch-misses", - .alias = "", - }, - [PERF_COUNT_HW_BUS_CYCLES] = { - .symbol = "bus-cycles", - .alias = "", - }, - [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = { - .symbol = "stalled-cycles-frontend", - .alias = "idle-cycles-frontend", - }, - [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = { - .symbol = "stalled-cycles-backend", - .alias = "idle-cycles-backend", - }, - [PERF_COUNT_HW_REF_CPU_CYCLES] = { - .symbol = "ref-cycles", - .alias = "", - }, -}; - -static struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { - [PERF_COUNT_SW_CPU_CLOCK] = { - .symbol = "cpu-clock", - .alias = "", - }, - [PERF_COUNT_SW_TASK_CLOCK] = { - .symbol = "task-clock", - .alias = "", - }, - [PERF_COUNT_SW_PAGE_FAULTS] = { - .symbol = "page-faults", - .alias = "faults", - }, - [PERF_COUNT_SW_CONTEXT_SWITCHES] = { - .symbol = "context-switches", - .alias = "cs", - }, - [PERF_COUNT_SW_CPU_MIGRATIONS] = { - .symbol = "cpu-migrations", - .alias = "migrations", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MIN] = { - .symbol = "minor-faults", - .alias = "", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = { - .symbol = "major-faults", - .alias = "", - }, - [PERF_COUNT_SW_ALIGNMENT_FAULTS] = { - .symbol = "alignment-faults", - .alias = "", - }, - [PERF_COUNT_SW_EMULATION_FAULTS] = { - .symbol = "emulation-faults", - .alias = "", - }, +#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x +#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x + +static struct event_symbol event_symbols[] = { + { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, + { CHW(STALLED_CYCLES_FRONTEND), "stalled-cycles-frontend", "idle-cycles-frontend" }, + { CHW(STALLED_CYCLES_BACKEND), "stalled-cycles-backend", "idle-cycles-backend" }, + { CHW(INSTRUCTIONS), "instructions", "" }, + { CHW(CACHE_REFERENCES), "cache-references", "" }, + { CHW(CACHE_MISSES), "cache-misses", "" }, + { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, + { CHW(BRANCH_MISSES), "branch-misses", "" }, + { CHW(BUS_CYCLES), "bus-cycles", "" }, + { CHW(REF_CPU_CYCLES), "ref-cycles", "" }, + + { CSW(CPU_CLOCK), "cpu-clock", "" }, + { CSW(TASK_CLOCK), "task-clock", "" }, + { CSW(PAGE_FAULTS), "page-faults", "faults" }, + { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, + { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, + { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, + { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, + { CSW(ALIGNMENT_FAULTS), "alignment-faults", "" }, + { CSW(EMULATION_FAULTS), "emulation-faults", "" }, }; #define __PERF_EVENT_FIELD(config, name) \ @@ -878,13 +824,16 @@ int is_valid_tracepoint(const char *event_string) return 0; } -static void __print_events_type(u8 type, struct event_symbol *syms, - unsigned max) +void print_events_type(u8 type) { + struct event_symbol *syms = event_symbols; + unsigned int i; char name[64]; - unsigned i; - for (i = 0; i < max ; i++, syms++) { + for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { + if (type != syms->type) + continue; + if (strlen(syms->alias)) snprintf(name, sizeof(name), "%s OR %s", syms->symbol, syms->alias); @@ -896,14 +845,6 @@ static void __print_events_type(u8 type, struct event_symbol *syms, } } -void print_events_type(u8 type) -{ - if (type == PERF_TYPE_SOFTWARE) - __print_events_type(type, event_symbols_sw, PERF_COUNT_SW_MAX); - else - __print_events_type(type, event_symbols_hw, PERF_COUNT_HW_MAX); -} - int print_hwcache_events(const char *event_glob) { unsigned int type, op, i, printed = 0; @@ -931,13 +872,26 @@ int print_hwcache_events(const char *event_glob) return printed; } -static void print_symbol_events(const char *event_glob, unsigned type, - struct event_symbol *syms, unsigned max) +/* + * Print the help text for the event symbols: + */ +void print_events(const char *event_glob) { - unsigned i, printed = 0; + unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0; + struct event_symbol *syms = event_symbols; char name[MAX_NAME_LEN]; - for (i = 0; i < max; i++, syms++) { + printf("\n"); + printf("List of pre-defined events (to be used in -e):\n"); + + for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { + type = syms->type; + + if (type != prev_type && printed) { + printf("\n"); + printed = 0; + ntypes_printed++; + } if (event_glob != NULL && !(strglobmatch(syms->symbol, event_glob) || @@ -948,31 +902,17 @@ static void print_symbol_events(const char *event_glob, unsigned type, snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias); else strncpy(name, syms->symbol, MAX_NAME_LEN); + printf(" %-50s [%s]\n", name, + event_type_descriptors[type]); - printf(" %-50s [%s]\n", name, event_type_descriptors[type]); - - printed++; + prev_type = type; + ++printed; } - if (printed) + if (ntypes_printed) { + printed = 0; printf("\n"); -} - -/* - * Print the help text for the event symbols: - */ -void print_events(const char *event_glob) -{ - - printf("\n"); - printf("List of pre-defined events (to be used in -e):\n"); - - print_symbol_events(event_glob, PERF_TYPE_HARDWARE, - event_symbols_hw, PERF_COUNT_HW_MAX); - - print_symbol_events(event_glob, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); - + } print_hwcache_events(event_glob); if (event_glob != NULL) diff --git a/trunk/tools/perf/util/parse-events.l b/trunk/tools/perf/util/parse-events.l index 384ca74c6b22..a06689474210 100644 --- a/trunk/tools/perf/util/parse-events.l +++ b/trunk/tools/perf/util/parse-events.l @@ -56,7 +56,7 @@ 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; + return PE_VALUE_SYM; } static int term(yyscan_t scanner, int type) @@ -152,7 +152,6 @@ r{num_raw_hex} { return raw(yyscanner); } , { return ','; } : { return ':'; } = { return '='; } -\n { } { {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } diff --git a/trunk/tools/perf/util/parse-events.y b/trunk/tools/perf/util/parse-events.y index 2bc5fbff2b5d..9525c455d27f 100644 --- a/trunk/tools/perf/util/parse-events.y +++ b/trunk/tools/perf/util/parse-events.y @@ -26,15 +26,14 @@ do { \ %} %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM +%token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM %token PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT %token PE_PREFIX_MEM PE_PREFIX_RAW %token PE_ERROR %type PE_VALUE -%type PE_VALUE_SYM_HW -%type PE_VALUE_SYM_SW +%type PE_VALUE_SYM %type PE_RAW %type PE_TERM %type PE_NAME @@ -42,7 +41,6 @@ do { \ %type PE_NAME_CACHE_OP_RESULT %type PE_MODIFIER_EVENT %type PE_MODIFIER_BP -%type value_sym %type event_config %type event_term %type event_pmu @@ -111,13 +109,8 @@ PE_NAME '/' event_config '/' $$ = list; } -value_sym: -PE_VALUE_SYM_HW -| -PE_VALUE_SYM_SW - event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM '/' event_config '/' { struct parse_events_data__events *data = _data; struct list_head *list = NULL; @@ -130,7 +123,7 @@ value_sym '/' event_config '/' $$ = list; } | -value_sym sep_slash_dc +PE_VALUE_SYM sep_slash_dc { struct parse_events_data__events *data = _data; struct list_head *list = NULL;