diff options
Diffstat (limited to 'tools/perf')
36 files changed, 1241 insertions, 557 deletions
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 2780d9ce48b..b715cb71592 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt @@ -77,7 +77,8 @@ OPTIONS -F:: --funcs:: - Show available functions in given module or kernel. + Show available functions in given module or kernel. With -x/--exec, + can also list functions in a user space executable / shared library. --filter=FILTER:: (Only for --vars and --funcs) Set filter. FILTER is a combination of glob @@ -98,6 +99,15 @@ OPTIONS --max-probes:: Set the maximum number of probe points for an event. Default is 128. +-x:: +--exec=PATH:: + Specify path to the executable or shared library file for user + space tracing. Can also be used with --funcs option. + +In absence of -m/-x options, perf probe checks if the first argument after +the options is an absolute path name. If its an absolute path, perf probe +uses it as a target module/target user space binary to probe. + PROBE SYNTAX ------------ Probe points are defined by following syntax. @@ -182,6 +192,13 @@ Delete all probes on schedule(). ./perf probe --del='schedule*' +Add probes at zfree() function on /bin/zsh + + ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree + +Add probes at malloc() function on libc + + ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc SEE ALSO -------- diff --git a/tools/perf/Documentation/perfconfig.example b/tools/perf/Documentation/perfconfig.example index 42c6fd2ae85..767ea2436e1 100644 --- a/tools/perf/Documentation/perfconfig.example +++ b/tools/perf/Documentation/perfconfig.example @@ -19,3 +19,11 @@ # Default, disable using /dev/null dir = /root/.debug + +[annotate] + + # Defaults + hide_src_code = false + use_offset = true + jump_arrows = true + show_nr_jumps = false diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 5476bc0a1ea..b4b572e8c10 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -1,4 +1,6 @@ tools/perf +tools/scripts +tools/lib/traceevent include/linux/const.h include/linux/perf_event.h include/linux/rbtree.h diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 1d3d513beb9..0eee64cfe9a 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -80,7 +80,7 @@ ifeq ("$(origin DEBUG)", "command line") PERF_DEBUG = $(DEBUG) endif ifndef PERF_DEBUG - CFLAGS_OPTIMIZE = -O6 + CFLAGS_OPTIMIZE = -O6 -D_FORTIFY_SOURCE=2 endif ifdef PARSER_DEBUG @@ -89,7 +89,7 @@ ifdef PARSER_DEBUG PARSER_DEBUG_CFLAGS := -DPARSER_DEBUG endif -CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) +CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) EXTLIBS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE ALL_LDFLAGS = $(LDFLAGS) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 806e0a28663..67522cf8740 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -215,7 +215,7 @@ static int __cmd_annotate(struct perf_annotate *ann) } if (total_nr_samples == 0) { - ui__warning("The %s file has no samples!\n", session->filename); + ui__error("The %s file has no samples!\n", session->filename); goto out_delete; } out_delete: diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index e52d77ec708..acd78dc2834 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c @@ -116,7 +116,7 @@ static const char * const evlist_usage[] = { int cmd_evlist(int argc, const char **argv, const char *prefix __used) { struct perf_attr_details details = { .verbose = false, }; - const char *input_name; + const char *input_name = NULL; const struct option options[] = { OPT_STRING('i', "input", &input_name, "file", "Input file name"), diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 4935c09dd5b..e215ae61b2a 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -54,6 +54,7 @@ static struct { bool show_ext_vars; bool show_funcs; bool mod_events; + bool uprobes; int nevents; struct perf_probe_event events[MAX_PROBES]; struct strlist *dellist; @@ -75,6 +76,8 @@ static int parse_probe_event(const char *str) return -1; } + pev->uprobes = params.uprobes; + /* Parse a perf-probe command into event */ ret = parse_perf_probe_command(str, pev); pr_debug("%d arguments\n", pev->nargs); @@ -82,21 +85,58 @@ static int parse_probe_event(const char *str) return ret; } +static int set_target(const char *ptr) +{ + int found = 0; + const char *buf; + + /* + * The first argument after options can be an absolute path + * to an executable / library or kernel module. + * + * TODO: Support relative path, and $PATH, $LD_LIBRARY_PATH, + * short module name. + */ + if (!params.target && ptr && *ptr == '/') { + params.target = ptr; + found = 1; + buf = ptr + (strlen(ptr) - 3); + + if (strcmp(buf, ".ko")) + params.uprobes = true; + + } + + return found; +} + static int parse_probe_event_argv(int argc, const char **argv) { - int i, len, ret; + int i, len, ret, found_target; char *buf; + found_target = set_target(argv[0]); + if (found_target && argc == 1) + return 0; + /* Bind up rest arguments */ len = 0; - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { + if (i == 0 && found_target) + continue; + len += strlen(argv[i]) + 1; + } buf = zalloc(len + 1); if (buf == NULL) return -ENOMEM; len = 0; - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { + if (i == 0 && found_target) + continue; + len += sprintf(&buf[len], "%s ", argv[i]); + } params.mod_events = true; ret = parse_probe_event(buf); free(buf); @@ -125,6 +165,28 @@ static int opt_del_probe_event(const struct option *opt __used, return 0; } +static int opt_set_target(const struct option *opt, const char *str, + int unset __used) +{ + int ret = -ENOENT; + + if (str && !params.target) { + if (!strcmp(opt->long_name, "exec")) + params.uprobes = true; +#ifdef DWARF_SUPPORT + else if (!strcmp(opt->long_name, "module")) + params.uprobes = false; +#endif + else + return ret; + + params.target = str; + ret = 0; + } + + return ret; +} + #ifdef DWARF_SUPPORT static int opt_show_lines(const struct option *opt __used, const char *str, int unset __used) @@ -246,9 +308,9 @@ static const struct option options[] = { "file", "vmlinux pathname"), OPT_STRING('s', "source", &symbol_conf.source_prefix, "directory", "path to kernel source"), - OPT_STRING('m', "module", ¶ms.target, - "modname|path", - "target module name (for online) or path (for offline)"), + OPT_CALLBACK('m', "module", NULL, "modname|path", + "target module name (for online) or path (for offline)", + opt_set_target), #endif OPT__DRY_RUN(&probe_event_dry_run), OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, @@ -260,6 +322,8 @@ static const struct option options[] = { "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n" "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)", opt_set_filter), + OPT_CALLBACK('x', "exec", NULL, "executable|path", + "target executable name or path", opt_set_target), OPT_END() }; @@ -310,6 +374,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) pr_err(" Error: Don't use --list with --funcs.\n"); usage_with_options(probe_usage, options); } + if (params.uprobes) { + pr_warning(" Error: Don't use --list with --exec.\n"); + usage_with_options(probe_usage, options); + } ret = show_perf_probe_events(); if (ret < 0) pr_err(" Error: Failed to show event list. (%d)\n", @@ -333,8 +401,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) if (!params.filter) params.filter = strfilter__new(DEFAULT_FUNC_FILTER, NULL); - ret = show_available_funcs(params.target, - params.filter); + ret = show_available_funcs(params.target, params.filter, + params.uprobes); strfilter__delete(params.filter); if (ret < 0) pr_err(" Error: Failed to show functions." @@ -343,7 +411,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) } #ifdef DWARF_SUPPORT - if (params.show_lines) { + if (params.show_lines && !params.uprobes) { if (params.mod_events) { pr_err(" Error: Don't use --line with" " --add/--del.\n"); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e5cb08427e1..f95840d04e4 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -264,7 +264,7 @@ try_again: } if (err == ENOENT) { - ui__warning("The %s event is not supported.\n", + ui__error("The %s event is not supported.\n", event_name(pos)); exit(EXIT_FAILURE); } @@ -858,8 +858,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) usage_with_options(record_usage, record_options); if (rec->force && rec->append_file) { - fprintf(stderr, "Can't overwrite and append at the same time." - " You need to choose between -f and -A"); + ui__error("Can't overwrite and append at the same time." + " You need to choose between -f and -A"); usage_with_options(record_usage, record_options); } else if (rec->append_file) { rec->write_mode = WRITE_APPEND; @@ -868,8 +868,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) } if (nr_cgroups && !rec->opts.target.system_wide) { - fprintf(stderr, "cgroup monitoring only available in" - " system-wide mode\n"); + ui__error("cgroup monitoring only available in" + " system-wide mode\n"); usage_with_options(record_usage, record_options); } @@ -905,7 +905,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) int saved_errno = errno; perf_target__strerror(&rec->opts.target, err, errbuf, BUFSIZ); - ui__warning("%s", errbuf); + ui__error("%s", errbuf); err = -saved_errno; goto out_free_fd; @@ -933,7 +933,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) else if (rec->opts.freq) { rec->opts.default_interval = rec->opts.freq; } else { - fprintf(stderr, "frequency and count are zero, aborting\n"); + ui__error("frequency and count are zero, aborting\n"); err = -EINVAL; goto out_free_fd; } diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index d58e41445d0..25249f76329 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -152,7 +152,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, if (symbol_conf.use_callchain) { err = callchain_append(he->callchain, - &evsel->hists.callchain_cursor, + &callchain_cursor, sample->period); if (err) return err; @@ -162,7 +162,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, * so we don't allocated the extra space needed because the stdio * code will not use it. */ - if (al->sym != NULL && use_browser > 0) { + if (he->ms.sym != NULL && use_browser > 0) { struct annotation *notes = symbol__annotation(he->ms.sym); assert(evsel != NULL); @@ -251,13 +251,13 @@ static int perf_report__setup_sample_type(struct perf_report *rep) if (!(self->sample_type & PERF_SAMPLE_CALLCHAIN)) { if (sort__has_parent) { - ui__warning("Selected --sort parent, but no " + ui__error("Selected --sort parent, but no " "callchain data. Did you call " "'perf record' without -g?\n"); return -EINVAL; } if (symbol_conf.use_callchain) { - ui__warning("Selected -g but no callchain data. Did " + ui__error("Selected -g but no callchain data. Did " "you call 'perf record' without -g?\n"); return -1; } @@ -266,17 +266,15 @@ static int perf_report__setup_sample_type(struct perf_report *rep) !symbol_conf.use_callchain) { symbol_conf.use_callchain = true; if (callchain_register_param(&callchain_param) < 0) { - ui__warning("Can't register callchain " - "params.\n"); + ui__error("Can't register callchain params.\n"); return -EINVAL; } } if (sort__branch_mode == 1) { if (!(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) { - fprintf(stderr, "selected -b but no branch data." - " Did you call perf record without" - " -b?\n"); + ui__error("Selected -b but no branch data. " + "Did you call perf record without -b?\n"); return -1; } } @@ -420,7 +418,7 @@ static int __cmd_report(struct perf_report *rep) } if (nr_samples == 0) { - ui__warning("The %s file has no samples!\n", session->filename); + ui__error("The %s file has no samples!\n", session->filename); goto out_delete; } diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 62ae30d34fa..262589991ea 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1129,7 +1129,7 @@ static int add_default_attributes(void) return 0; if (!evsel_list->nr_entries) { - if (perf_evlist__add_attrs_array(evsel_list, default_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, default_attrs) < 0) return -1; } @@ -1139,21 +1139,21 @@ static int add_default_attributes(void) return 0; /* Append detailed run extra attributes: */ - if (perf_evlist__add_attrs_array(evsel_list, detailed_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, detailed_attrs) < 0) return -1; if (detailed_run < 2) return 0; /* Append very detailed run extra attributes: */ - if (perf_evlist__add_attrs_array(evsel_list, very_detailed_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, very_detailed_attrs) < 0) return -1; if (detailed_run < 3) return 0; /* Append very, very detailed run extra attributes: */ - return perf_evlist__add_attrs_array(evsel_list, very_very_detailed_attrs); + return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); } int cmd_stat(int argc, const char **argv, const char *prefix __used) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 6031dce0429..6bb0277b7df 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -787,7 +787,7 @@ static void perf_event__process_sample(struct perf_tool *tool, } if (symbol_conf.use_callchain) { - err = callchain_append(he->callchain, &evsel->hists.callchain_cursor, + err = callchain_append(he->callchain, &callchain_cursor, sample->period); if (err) return; @@ -953,22 +953,22 @@ try_again: attr->config = PERF_COUNT_SW_CPU_CLOCK; if (counter->name) { free(counter->name); - counter->name = strdup(event_name(counter)); + counter->name = NULL; } goto try_again; } if (err == ENOENT) { - ui__warning("The %s event is not supported.\n", + ui__error("The %s event is not supported.\n", event_name(counter)); goto out_err; } else if (err == EMFILE) { - ui__warning("Too many events are opened.\n" + ui__error("Too many events are opened.\n" "Try again after reducing the number of events\n"); goto out_err; } - ui__warning("The sys_perf_event_open() syscall " + ui__error("The sys_perf_event_open() syscall " "returned with %d (%s). /bin/dmesg " "may provide additional information.\n" "No CONFIG_PERF_EVENTS=y kernel support " @@ -978,7 +978,7 @@ try_again: } if (perf_evlist__mmap(evlist, top->mmap_pages, false) < 0) { - ui__warning("Failed to mmap with %d (%s)\n", + ui__error("Failed to mmap with %d (%s)\n", errno, strerror(errno)); goto out_err; } @@ -994,12 +994,12 @@ static int perf_top__setup_sample_type(struct perf_top *top) { if (!top->sort_has_symbols) { if (symbol_conf.use_callchain) { - ui__warning("Selected -g but \"sym\" not present in --sort/-s."); + ui__error("Selected -g but \"sym\" not present in --sort/-s."); return -EINVAL; } } else if (!top->dont_use_callchains && callchain_param.mode != CHAIN_NONE) { if (callchain_register_param(&callchain_param) < 0) { - ui__warning("Can't register callchain params.\n"); + ui__error("Can't register callchain params.\n"); return -EINVAL; } } @@ -1041,7 +1041,7 @@ static int __cmd_top(struct perf_top *top) if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui : display_thread), top)) { - printf("Could not create display thread.\n"); + ui__error("Could not create display thread.\n"); exit(-1); } @@ -1050,7 +1050,7 @@ static int __cmd_top(struct perf_top *top) param.sched_priority = top->realtime_prio; if (sched_setscheduler(0, SCHED_FIFO, ¶m)) { - printf("Could not set realtime priority.\n"); + ui__error("Could not set realtime priority.\n"); exit(-1); } } @@ -1274,7 +1274,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) int saved_errno = errno; perf_target__strerror(&top.target, status, errbuf, BUFSIZ); - ui__warning("%s", errbuf); + ui__error("%s", errbuf); status = -saved_errno; goto out_delete_evlist; @@ -1288,7 +1288,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) if (!top.evlist->nr_entries && perf_evlist__add_default(top.evlist) < 0) { - pr_err("Not enough memory for event selector list\n"); + ui__error("Not enough memory for event selector list\n"); return -ENOMEM; } @@ -1305,7 +1305,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) else if (top.freq) { top.default_interval = top.freq; } else { - fprintf(stderr, "frequency and count are zero, aborting\n"); + ui__error("frequency and count are zero, aborting\n"); exit(EXIT_FAILURE); } diff --git a/tools/perf/design.txt b/tools/perf/design.txt index bd0bb1b1279..67e5d0cace8 100644 --- a/tools/perf/design.txt +++ b/tools/perf/design.txt @@ -409,14 +409,15 @@ Counters can be enabled and disabled in two ways: via ioctl and via prctl. When a counter is disabled, it doesn't count or generate events but does continue to exist and maintain its count value. -An individual counter or counter group can be enabled with +An individual counter can be enabled with - ioctl(fd, PERF_EVENT_IOC_ENABLE); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); or disabled with - ioctl(fd, PERF_EVENT_IOC_DISABLE); + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); +For a counter group, pass PERF_IOC_FLAG_GROUP as the third argument. Enabling or disabling the leader of a group enables or disables the whole group; that is, while the group leader is disabled, none of the counters in the group will count. Enabling or disabling a member of a diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 14f1034f14f..f960ccb2edc 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -227,7 +227,7 @@ struct perf_record_opts { unsigned int freq; unsigned int mmap_pages; unsigned int user_freq; - int branch_stack; + u64 branch_stack; u64 default_interval; u64 user_interval; }; diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index cde4d0f0ddb..1818a531f1d 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c @@ -35,16 +35,16 @@ int ui_browser__set_color(struct ui_browser *browser, int color) return ret; } -void ui_browser__set_percent_color(struct ui_browser *self, +void ui_browser__set_percent_color(struct ui_browser *browser, double percent, bool current) { - int color = ui_browser__percent_color(self, percent, current); - ui_browser__set_color(self, color); + int color = ui_browser__percent_color(browser, percent, current); + ui_browser__set_color(browser, color); } -void ui_browser__gotorc(struct ui_browser *self, int y, int x) +void ui_browser__gotorc(struct ui_browser *browser, int y, int x) { - SLsmg_gotorc(self->y + y, self->x + x); + SLsmg_gotorc(browser->y + y, browser->x + x); } static struct list_head * @@ -73,23 +73,23 @@ ui_browser__list_head_filter_prev_entries(struct ui_browser *browser, return NULL; } -void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) +void ui_browser__list_head_seek(struct ui_browser *browser, off_t offset, int whence) { - struct list_head *head = self->entries; + struct list_head *head = browser->entries; struct list_head *pos; - if (self->nr_entries == 0) + if (browser->nr_entries == 0) return; switch (whence) { case SEEK_SET: - pos = ui_browser__list_head_filter_entries(self, head->next); + pos = ui_browser__list_head_filter_entries(browser, head->next); break; case SEEK_CUR: - pos = self->top; + pos = browser->top; break; case SEEK_END: - pos = ui_browser__list_head_filter_prev_entries(self, head->prev); + pos = ui_browser__list_head_filter_prev_entries(browser, head->prev); break; default: return; @@ -99,18 +99,18 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc if (offset > 0) { while (offset-- != 0) - pos = ui_browser__list_head_filter_entries(self, pos->next); + pos = ui_browser__list_head_filter_entries(browser, pos->next); } else { while (offset++ != 0) - pos = ui_browser__list_head_filter_prev_entries(self, pos->prev); + pos = ui_browser__list_head_filter_prev_entries(browser, pos->prev); } - self->top = pos; + browser->top = pos; } -void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) +void ui_browser__rb_tree_seek(struct ui_browser *browser, off_t offset, int whence) { - struct rb_root *root = self->entries; + struct rb_root *root = browser->entries; struct rb_node *nd; switch (whence) { @@ -118,7 +118,7 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) nd = rb_first(root); break; case SEEK_CUR: - nd = self->top; + nd = browser->top; break; case SEEK_END: nd = rb_last(root); @@ -135,23 +135,23 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) nd = rb_prev(nd); } - self->top = nd; + browser->top = nd; } -unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) +unsigned int ui_browser__rb_tree_refresh(struct ui_browser *browser) { struct rb_node *nd; int row = 0; - if (self->top == NULL) - self->top = rb_first(self->entries); + if (browser->top == NULL) + browser->top = rb_first(browser->entries); - nd = self->top; + nd = browser->top; while (nd != NULL) { - ui_browser__gotorc(self, row, 0); - self->write(self, nd, row); - if (++row == self->height) + ui_browser__gotorc(browser, row, 0); + browser->write(browser, nd, row); + if (++row == browser->height) break; nd = rb_next(nd); } @@ -159,17 +159,17 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) return row; } -bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row) +bool ui_browser__is_current_entry(struct ui_browser *browser, unsigned row) { - return self->top_idx + row == self->index; + return browser->top_idx + row == browser->index; } -void ui_browser__refresh_dimensions(struct ui_browser *self) +void ui_browser__refresh_dimensions(struct ui_browser *browser) { - self->width = SLtt_Screen_Cols - 1; - self->height = SLtt_Screen_Rows - 2; - self->y = 1; - self->x = 0; + browser->width = SLtt_Screen_Cols - 1; + browser->height = SLtt_Screen_Rows - 2; + browser->y = 1; + browser->x = 0; } void ui_browser__handle_resize(struct ui_browser *browser) @@ -225,10 +225,10 @@ bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text) return key == K_ENTER || toupper(key) == 'Y'; } -void ui_browser__reset_index(struct ui_browser *self) +void ui_browser__reset_index(struct ui_browser *browser) { - self->index = self->top_idx = 0; - self->seek(self, 0, SEEK_SET); + browser->index = browser->top_idx = 0; + browser->seek(browser, 0, SEEK_SET); } void __ui_browser__show_title(struct ui_browser *browser, const char *title) @@ -245,26 +245,26 @@ void ui_browser__show_title(struct ui_browser *browser, const char *title) pthread_mutex_unlock(&ui__lock); } -int ui_browser__show(struct ui_browser *self, const char *title, +int ui_browser__show(struct ui_browser *browser, const char *title, const char *helpline, ...) { int err; va_list ap; - ui_browser__refresh_dimensions(self); + ui_browser__refresh_dimensions(browser); pthread_mutex_lock(&ui__lock); - __ui_browser__show_title(self, title); + __ui_browser__show_title(browser, title); - self->title = title; - free(self->helpline); - self->helpline = NULL; + browser->title = title; + free(browser->helpline); + browser->helpline = NULL; va_start(ap, helpline); - err = vasprintf(&self->helpline, helpline, ap); + err = vasprintf(&browser->helpline, helpline, ap); va_end(ap); if (err > 0) - ui_helpline__push(self->helpline); + ui_helpline__push(browser->helpline); pthread_mutex_unlock(&ui__lock); return err ? 0 : -1; } @@ -350,7 +350,7 @@ void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries) browser->seek(browser, browser->top_idx, SEEK_SET); } -int ui_browser__run(struct ui_browser *self, int delay_secs) +int ui_browser__run(struct ui_browser *browser, int delay_secs) { int err, key; @@ -358,7 +358,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) off_t offset; pthread_mutex_lock(&ui__lock); - err = __ui_browser__refresh(self); + err = __ui_browser__refresh(browser); SLsmg_refresh(); pthread_mutex_unlock(&ui__lock); if (err < 0) @@ -368,18 +368,18 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) if (key == K_RESIZE) { ui__refresh_dimensions(false); - ui_browser__refresh_dimensions(self); - __ui_browser__show_title(self, self->title); - ui_helpline__puts(self->helpline); + ui_browser__refresh_dimensions(browser); + __ui_browser__show_title(browser, browser->title); + ui_helpline__puts(browser->helpline); continue; } - if (self->use_navkeypressed && !self->navkeypressed) { + if (browser->use_navkeypressed && !browser->navkeypressed) { if (key == K_DOWN || key == K_UP || key == K_PGDN || key == K_PGUP || key == K_HOME || key == K_END || key == ' ') { - self->navkeypressed = true; + browser->navkeypressed = true; continue; } else return key; @@ -387,59 +387,59 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) switch (key) { case K_DOWN: - if (self->index == self->nr_entries - 1) + if (browser->index == browser->nr_entries - 1) break; - ++self->index; - if (self->index == self->top_idx + self->height) { - ++self->top_idx; - self->seek(self, +1, SEEK_CUR); + ++browser->index; + if (browser->index == browser->top_idx + browser->height) { + ++browser->top_idx; + browser->seek(browser, +1, SEEK_CUR); } break; case K_UP: - if (self->index == 0) + if (browser->index == 0) break; - --self->index; - if (self->index < self->top_idx) { - --self->top_idx; - self->seek(self, -1, SEEK_CUR); + --browser->index; + if (browser->index < browser->top_idx) { + --browser->top_idx; + browser->seek(browser, -1, SEEK_CUR); } break; case K_PGDN: case ' ': - if (self->top_idx + self->height > self->nr_entries - 1) + if (browser->top_idx + browser->height > browser->nr_entries - 1) break; - offset = self->height; - if (self->index + offset > self->nr_entries - 1) - offset = self->nr_entries - 1 - self->index; - self->index += offset; - self->top_idx += offset; - self->seek(self, +offset, SEEK_CUR); + offset = browser->height; + if (browser->index + offset > browser->nr_entries - 1) + offset = browser->nr_entries - 1 - browser->index; + browser->index += offset; + browser->top_idx += offset; + browser->seek(browser, +offset, SEEK_CUR); break; case K_PGUP: - if (self->top_idx == 0) + if (browser->top_idx == 0) break; - if (self->top_idx < self->height) - offset = self->top_idx; + if (browser->top_idx < browser->height) + offset = browser->top_idx; else - offset = self->height; + offset = browser->height; - self->index -= offset; - self->top_idx -= offset; - self->seek(self, -offset, SEEK_CUR); + browser->index -= offset; + browser->top_idx -= offset; + browser->seek(browser, -offset, SEEK_CUR); break; case K_HOME: - ui_browser__reset_index(self); + ui_browser__reset_index(browser); break; case K_END: - offset = self->height - 1; - if (offset >= self->nr_entries) - offset = self->nr_entries - 1; + offset = browser->height - 1; + if (offset >= browser->nr_entries) + offset = browser->nr_entries - 1; - self->index = self->nr_entries - 1; - self->top_idx = self->index - offset; - self->seek(self, -offset, SEEK_END); + browser->index = browser->nr_entries - 1; + browser->top_idx = browser->index - offset; + browser->seek(browser, -offset, SEEK_END); break; default: return key; @@ -448,22 +448,22 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) return -1; } -unsigned int ui_browser__list_head_refresh(struct ui_browser *self) +unsigned int ui_browser__list_head_refresh(struct ui_browser *browser) { struct list_head *pos; - struct list_head *head = self->entries; + struct list_head *head = browser->entries; int row = 0; - if (self->top == NULL || self->top == self->entries) - self->top = ui_browser__list_head_filter_entries(self, head->next); + if (browser->top == NULL || browser->top == browser->entries) + browser->top = ui_browser__list_head_filter_entries(browser, head->next); - pos = self->top; + pos = browser->top; list_for_each_from(pos, head) { - if (!self->filter || !self->filter(self, pos)) { - ui_browser__gotorc(self, row, 0); - self->write(self, pos, row); - if (++row == self->height) + if (!browser->filter || !browser->filter(browser, pos)) { + ui_browser__gotorc(browser, row, 0); + browser->write(browser, pos, row); + if (++row == browser->height) break; } } @@ -708,4 +708,6 @@ void ui_browser__init(void) struct ui_browser__colorset *c = &ui_browser__colorsets[i++]; sltt_set_color(c->colorset, c->name, c->fg, c->bg); } + + annotate_browser__init(); } diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h index dd96d822990..af70314605e 100644 --- a/tools/perf/ui/browser.h +++ b/tools/perf/ui/browser.h @@ -69,4 +69,5 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc unsigned int ui_browser__list_head_refresh(struct ui_browser *self); void ui_browser__init(void); +void annotate_browser__init(void); #endif /* _PERF_UI_BROWSER_H_ */ diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 6e0ef79be16..34b1c46eaf4 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -19,6 +19,16 @@ struct browser_disasm_line { int jump_sources; }; +static struct annotate_browser_opt { + bool hide_src_code, + use_offset, + jump_arrows, + show_nr_jumps; +} annotate_browser__opts = { + .use_offset = true, + .jump_arrows = true, +}; + struct annotate_browser { struct ui_browser b; struct rb_root entries; @@ -30,10 +40,6 @@ struct annotate_browser { int nr_entries; int max_jump_sources; int nr_jumps; - bool hide_src_code; - bool use_offset; - bool jump_arrows; - bool show_nr_jumps; bool searching_backwards; u8 addr_width; u8 jumps_width; @@ -48,11 +54,9 @@ static inline struct browser_disasm_line *disasm_line__browser(struct disasm_lin return (struct browser_disasm_line *)(dl + 1); } -static bool disasm_line__filter(struct ui_browser *browser, void *entry) +static bool disasm_line__filter(struct ui_browser *browser __used, void *entry) { - struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); - - if (ab->hide_src_code) { + if (annotate_browser__opts.hide_src_code) { struct disasm_line *dl = list_entry(entry, struct disasm_line, node); return dl->offset == -1; } @@ -79,30 +83,30 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br return ui_browser__set_color(&browser->b, color); } -static void annotate_browser__write(struct ui_browser *self, void *entry, int row) +static void annotate_browser__write(struct ui_browser *browser, void *entry, int row) { - struct annotate_browser *ab = container_of(self, struct annotate_browser, b); + struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); struct disasm_line *dl = list_entry(entry, struct disasm_line, node); struct browser_disasm_line *bdl = disasm_line__browser(dl); - bool current_entry = ui_browser__is_current_entry(self, row); - bool change_color = (!ab->hide_src_code && - (!current_entry || (self->use_navkeypressed && - !self->navkeypressed))); - int width = self->width, printed; + bool current_entry = ui_browser__is_current_entry(browser, row); + bool change_color = (!annotate_browser__opts.hide_src_code && + (!current_entry || (browser->use_navkeypressed && + !browser->navkeypressed))); + int width = browser->width, printed; char bf[256]; if (dl->offset != -1 && bdl->percent != 0.0) { - ui_browser__set_percent_color(self, bdl->percent, current_entry); + ui_browser__set_percent_color(browser, bdl->percent, current_entry); slsmg_printf("%6.2f ", bdl->percent); } else { - ui_browser__set_percent_color(self, 0, current_entry); + ui_browser__set_percent_color(browser, 0, current_entry); slsmg_write_nstring(" ", 7); } SLsmg_write_char(' '); /* The scroll bar isn't being used */ - if (!self->navkeypressed) + if (!browser->navkeypressed) width += 1; if (!*dl->line) @@ -116,14 +120,14 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro u64 addr = dl->offset; int color = -1; - if (!ab->use_offset) + if (!annotate_browser__opts.use_offset) addr += ab->start; - if (!ab->use_offset) { + if (!annotate_browser__opts.use_offset) { printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); } else { if (bdl->jump_sources) { - if (ab->show_nr_jumps) { + if (annotate_browser__opts.show_nr_jumps) { int prev; printed = scnprintf(bf, sizeof(bf), "%*d ", ab->jumps_width, @@ -131,7 +135,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro prev = annotate_browser__set_jumps_percent_color(ab, bdl->jump_sources, current_entry); slsmg_write_nstring(bf, printed); - ui_browser__set_color(self, prev); + ui_browser__set_color(browser, prev); } printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", @@ -143,19 +147,19 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro } if (change_color) - color = ui_browser__set_color(self, HE_COLORSET_ADDR); + color = ui_browser__set_color(browser, HE_COLORSET_ADDR); slsmg_write_nstring(bf, printed); if (change_color) - ui_browser__set_color(self, color); + ui_browser__set_color(browser, color); if (dl->ins && dl->ins->ops->scnprintf) { if (ins__is_jump(dl->ins)) { bool fwd = dl->ops.target.offset > (u64)dl->offset; - ui_browser__write_graph(self, fwd ? SLSMG_DARROW_CHAR : + ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR : SLSMG_UARROW_CHAR); SLsmg_write_char(' '); } else if (ins__is_call(dl->ins)) { - ui_browser__write_graph(self, SLSMG_RARROW_CHAR); + ui_browser__write_graph(browser, SLSMG_RARROW_CHAR); SLsmg_write_char(' '); } else { slsmg_write_nstring(" ", 2); @@ -164,12 +168,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro if (strcmp(dl->name, "retq")) { slsmg_write_nstring(" ", 2); } else { - ui_browser__write_graph(self, SLSMG_LARROW_CHAR); + ui_browser__write_graph(browser, SLSMG_LARROW_CHAR); SLsmg_write_char(' '); } } - disasm_line__scnprintf(dl, bf, sizeof(bf), !ab->use_offset); + disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset); slsmg_write_nstring(bf, width - 10 - printed); } @@ -184,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) struct browser_disasm_line *btarget, *bcursor; unsigned int from, to; - if (!cursor->ins || !ins__is_jump(cursor->ins) || + if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) || !disasm_line__has_offset(cursor)) return; @@ -195,7 +199,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) bcursor = disasm_line__browser(cursor); btarget = disasm_line__browser(target); - if (ab->hide_src_code) { + if (annotate_browser__opts.hide_src_code) { from = bcursor->idx_asm; to = btarget->idx_asm; } else { @@ -209,10 +213,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) static unsigned int annotate_browser__refresh(struct ui_browser *browser) { - struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); int ret = ui_browser__list_head_refresh(browser); - if (ab->jump_arrows) + if (annotate_browser__opts.jump_arrows) annotate_browser__draw_current_jump(browser); ui_browser__set_color(browser, HE_COLORSET_NORMAL); @@ -272,27 +275,27 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_l rb_insert_color(&bdl->rb_node, root); } -static void annotate_browser__set_top(struct annotate_browser *self, +static void annotate_browser__set_top(struct annotate_browser *browser, struct disasm_line *pos, u32 idx) { unsigned back; - ui_browser__refresh_dimensions(&self->b); - back = self->b.height / 2; - self->b.top_idx = self->b.index = idx; + ui_browser__refresh_dimensions(&browser->b); + back = browser->b.height / 2; + browser->b.top_idx = browser->b.index = idx; - while (self->b.top_idx != 0 && back != 0) { + while (browser->b.top_idx != 0 && back != 0) { pos = list_entry(pos->node.prev, struct disasm_line, node); - if (disasm_line__filter(&self->b, &pos->node)) + if (disasm_line__filter(&browser->b, &pos->node)) continue; - --self->b.top_idx; + --browser->b.top_idx; --back; } - self->b.top = pos; - self->b.navkeypressed = true; + browser->b.top = pos; + browser->b.navkeypressed = true; } static void annotate_browser__set_rb_top(struct annotate_browser *browser, @@ -300,10 +303,14 @@ static void annotate_browser__set_rb_top(struct annotate_browser *browser, { struct browser_disasm_line *bpos; struct disasm_line *pos; + u32 idx; bpos = rb_entry(nd, struct browser_disasm_line, rb_node); pos = ((struct disasm_line *)bpos) - 1; - annotate_browser__set_top(browser, pos, bpos->idx); + idx = bpos->idx; + if (annotate_browser__opts.hide_src_code) + idx = bpos->idx_asm; + annotate_browser__set_top(browser, pos, idx); browser->curr_hot = nd; } @@ -343,12 +350,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) dl = list_entry(browser->b.top, struct disasm_line, node); bdl = disasm_line__browser(dl); - if (browser->hide_src_code) { + if (annotate_browser__opts.hide_src_code) { if (bdl->idx_asm < offset) offset = bdl->idx; browser->b.nr_entries = browser->nr_entries; - browser->hide_src_code = false; + annotate_browser__opts.hide_src_code = false; browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.top_idx = bdl->idx - offset; browser->b.index = bdl->idx; @@ -363,7 +370,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) offset = bdl->idx_asm; browser->b.nr_entries = browser->nr_asm_entries; - browser->hide_src_code = true; + annotate_browser__opts.hide_src_code = true; browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.top_idx = bdl->idx_asm - offset; browser->b.index = bdl->idx_asm; @@ -372,6 +379,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) return true; } +static void annotate_browser__init_asm_mode(struct annotate_browser *browser) +{ + ui_browser__reset_index(&browser->b); + browser->b.nr_entries = browser->nr_asm_entries; +} + static bool annotate_browser__callq(struct annotate_browser *browser, int evidx, void (*timer)(void *arg), void *arg, int delay_secs) @@ -574,33 +587,46 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser, return __annotate_browser__search_reverse(browser); } -static int annotate_browser__run(struct annotate_browser *self, int evidx, +static void annotate_browser__update_addr_width(struct annotate_browser *browser) +{ + if (annotate_browser__opts.use_offset) + browser->target_width = browser->min_addr_width; + else + browser->target_width = browser->max_addr_width; + + browser->addr_width = browser->target_width; + + if (annotate_browser__opts.show_nr_jumps) + browser->addr_width += browser->jumps_width + 1; +} + +static int annotate_browser__run(struct annotate_browser *browser, int evidx, void(*timer)(void *arg), void *arg, int delay_secs) { struct rb_node *nd = NULL; - struct map_symbol *ms = self->b.priv; + struct map_symbol *ms = browser->b.priv; struct symbol *sym = ms->sym; const char *help = "Press 'h' for help on key bindings"; int key; - if (ui_browser__show(&self->b, sym->name, help) < 0) + if (ui_browser__show(&browser->b, sym->name, help) < 0) return -1; - annotate_browser__calc_percent(self, evidx); + annotate_browser__calc_percent(browser, evidx); - if (self->curr_hot) { - annotate_browser__set_rb_top(self, self->curr_hot); - self->b.navkeypressed = false; + if (browser->curr_hot) { + annotate_browser__set_rb_top(browser, browser->curr_hot); + browser->b.navkeypressed = false; } - nd = self->curr_hot; + nd = browser->curr_hot; while (1) { - key = ui_browser__run(&self->b, delay_secs); + key = ui_browser__run(&browser->b, delay_secs); if (delay_secs != 0) { - annotate_browser__calc_percent(self, evidx); + annotate_browser__calc_percent(browser, evidx); /* * Current line focus got out of the list of most active * lines, NULL it so that if TAB|UNTAB is pressed, we @@ -622,27 +648,27 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, if (nd != NULL) { nd = rb_prev(nd); if (nd == NULL) - nd = rb_last(&self->entries); + nd = rb_last(&browser->entries); } else - nd = self->curr_hot; + nd = browser->curr_hot; break; case K_UNTAB: if (nd != NULL) nd = rb_next(nd); if (nd == NULL) - nd = rb_first(&self->entries); + nd = rb_first(&browser->entries); else - nd = self->curr_hot; + nd = browser->curr_hot; break; case K_F1: case 'h': - ui_browser__help_window(&self->b, + ui_browser__help_window(&browser->b, "UP/DOWN/PGUP\n" "PGDN/SPACE Navigate\n" "q/ESC/CTRL+C Exit\n\n" "-> Go to target\n" "<- Exit\n" - "h Cycle thru hottest instructions\n" + "H Cycle thru hottest instructions\n" "j Toggle showing jump to target arrows\n" "J Toggle showing number of jump sources on targets\n" "n Search next string\n" @@ -652,57 +678,62 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, "? Search previous string\n"); continue; case 'H': - nd = self->curr_hot; + nd = browser->curr_hot; break; case 's': - if (annotate_browser__toggle_source(self)) + if (annotate_browser__toggle_source(browser)) ui_helpline__puts(help); continue; case 'o': - self->use_offset = !self->use_offset; - if (self->use_offset) - self->target_width = self->min_addr_width; - else - self->target_width = self->max_addr_width; -update_addr_width: - self->addr_width = self->target_width; - if (self->show_nr_jumps) - self->addr_width += self->jumps_width + 1; + annotate_browser__opts.use_offset = !annotate_browser__opts.use_offset; + annotate_browser__update_addr_width(browser); continue; case 'j': - self->jump_arrows = !self->jump_arrows; + annotate_browser__opts.jump_arrows = !annotate_browser__opts.jump_arrows; continue; case 'J': - self->show_nr_jumps = !self->show_nr_jumps; - goto update_addr_width; + annotate_browser__opts.show_nr_jumps = !annotate_browser__opts.show_nr_jumps; + annotate_browser__update_addr_width(browser); + continue; case '/': - if (annotate_browser__search(self, delay_secs)) { + if (annotate_browser__search(browser, delay_secs)) { show_help: ui_helpline__puts(help); } continue; case 'n': - if (self->searching_backwards ? - annotate_browser__continue_search_reverse(self, delay_secs) : - annotate_browser__continue_search(self, delay_secs)) + if (browser->searching_backwards ? + annotate_browser__continue_search_reverse(browser, delay_secs) : + annotate_browser__continue_search(browser, delay_secs)) goto show_help; continue; case '?': - if (annotate_browser__search_reverse(self, delay_secs)) + if (annotate_browser__search_reverse(browser, delay_secs)) goto show_help; continue; + case 'D': { + static int seq; + ui_helpline__pop(); + ui_helpline__fpush("%d: nr_ent=%d, height=%d, idx=%d, top_idx=%d, nr_asm_entries=%d", + seq++, browser->b.nr_entries, + browser->b.height, + browser->b.index, + browser->b.top_idx, + browser->nr_asm_entries); + } + continue; case K_ENTER: case K_RIGHT: - if (self->selection == NULL) + if (browser->selection == NULL) ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org"); - else if (self->selection->offset == -1) + else if (browser->selection->offset == -1) ui_helpline__puts("Actions are only available for assembly lines."); - else if (!self->selection->ins) { - if (strcmp(self->selection->name, "retq")) + else if (!browser->selection->ins) { + if (strcmp(browser->selection->name, "retq")) goto show_sup_ins; goto out; - } else if (!(annotate_browser__jump(self) || - annotate_browser__callq(self, evidx, timer, arg, delay_secs))) { + } else if (!(annotate_browser__jump(browser) || + annotate_browser__callq(browser, evidx, timer, arg, delay_secs))) { show_sup_ins: ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); } @@ -717,10 +748,10 @@ show_sup_ins: } if (nd != NULL) - annotate_browser__set_rb_top(self, nd); + annotate_browser__set_rb_top(browser, nd); } out: - ui_browser__hide(&self->b); + ui_browser__hide(&browser->b); return key; } @@ -797,8 +828,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, .priv = &ms, .use_navkeypressed = true, }, - .use_offset = true, - .jump_arrows = true, }; int ret = -1; @@ -855,6 +884,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, browser.b.nr_entries = browser.nr_entries; browser.b.entries = ¬es->src->source, browser.b.width += 18; /* Percentage */ + + if (annotate_browser__opts.hide_src_code) + annotate_browser__init_asm_mode(&browser); + + annotate_browser__update_addr_width(&browser); + ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs); list_for_each_entry_safe(pos, n, ¬es->src->source, node) { list_del(&pos->node); @@ -865,3 +900,52 @@ out_free_offsets: free(browser.offsets); return ret; } + +#define ANNOTATE_CFG(n) \ + { .name = #n, .value = &annotate_browser__opts.n, } + +/* + * Keep the entries sorted, they are bsearch'ed + */ +static struct annotate__config { + const char *name; + bool *value; +} annotate__configs[] = { + ANNOTATE_CFG(hide_src_code), + ANNOTATE_CFG(jump_arrows), + ANNOTATE_CFG(show_nr_jumps), + ANNOTATE_CFG(use_offset), +}; + +#undef ANNOTATE_CFG + +static int annotate_config__cmp(const void *name, const void *cfgp) +{ + const struct annotate__config *cfg = cfgp; + + return strcmp(name, cfg->name); +} + +static int annotate__config(const char *var, const char *value, void *data __used) +{ + struct annotate__config *cfg; + const char *name; + + if (prefixcmp(var, "annotate.") != 0) + return 0; + + name = var + 9; + cfg = bsearch(name, annotate__configs, ARRAY_SIZE(annotate__configs), + sizeof(struct annotate__config), annotate_config__cmp); + + if (cfg == NULL) + return -1; + + *cfg->value = perf_config_bool(name, value); + return 0; +} + +void annotate_browser__init(void) +{ + perf_config(annotate__config, NULL); +} diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index a372a4b0263..53f6697d014 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -26,21 +26,21 @@ struct hist_browser { bool has_symbols; }; -static int hists__browser_title(struct hists *self, char *bf, size_t size, +static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name); -static void hist_browser__refresh_dimensions(struct hist_browser *self) +static void hist_browser__refresh_dimensions(struct hist_browser *browser) { /* 3 == +/- toggle symbol before actual hist_entry rendering */ - self->b.width = 3 + (hists__sort_list_width(self->hists) + + browser->b.width = 3 + (hists__sort_list_width(browser->hists) + sizeof("[k]")); } -static void hist_browser__reset(struct hist_browser *self) +static void hist_browser__reset(struct hist_browser *browser) { - self->b.nr_entries = self->hists->nr_entries; - hist_browser__refresh_dimensions(self); - ui_browser__reset_index(&self->b); + browser->b.nr_entries = browser->hists->nr_entries; + hist_browser__refresh_dimensions(browser); + ui_browser__reset_index(&browser->b); } static char tree__folded_sign(bool unfolded) @@ -48,32 +48,32 @@ static char tree__folded_sign(bool unfolded) return unfolded ? '-' : '+'; } -static char map_symbol__folded(const struct map_symbol *self) +static char map_symbol__folded(const struct map_symbol *ms) { - return self->has_children ? tree__folded_sign(self->unfolded) : ' '; + return ms->has_children ? tree__folded_sign(ms->unfolded) : ' '; } -static char hist_entry__folded(const struct hist_entry *self) +static char hist_entry__folded(const struct hist_entry *he) { - return map_symbol__folded(&self->ms); + return map_symbol__folded(&he->ms); } -static char callchain_list__folded(const struct callchain_list *self) +static char callchain_list__folded(const struct callchain_list *cl) { - return map_symbol__folded(&self->ms); + return map_symbol__folded(&cl->ms); } -static void map_symbol__set_folding(struct map_symbol *self, bool unfold) +static void map_symbol__set_folding(struct map_symbol *ms, bool unfold) { - self->unfolded = unfold ? self->has_children : false; + ms->unfolded = unfold ? ms->has_children : false; } -static int callchain_node__count_rows_rb_tree(struct callchain_node *self) +static int callchain_node__count_rows_rb_tree(struct callchain_node *node) { int n = 0; struct rb_node *nd; - for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { + for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); struct callchain_list *chain; char folded_sign = ' '; /* No children */ @@ -123,23 +123,23 @@ static int callchain__count_rows(struct rb_root *chain) return n; } -static bool map_symbol__toggle_fold(struct map_symbol *self) +static bool map_symbol__toggle_fold(struct map_symbol *ms) { - if (!self) + if (!ms) return false; - if (!self->has_children) + if (!ms->has_children) return false; - self->unfolded = !self->unfolded; + ms->unfolded = !ms->unfolded; return true; } -static void callchain_node__init_have_children_rb_tree(struct callchain_node *self) +static void callchain_node__init_have_children_rb_tree(struct callchain_node *node) { - struct rb_node *nd = rb_first(&self->rb_root); + struct rb_node *nd = rb_first(&node->rb_root); - for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { + for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); struct callchain_list *chain; bool first = true; @@ -158,49 +158,49 @@ static void callchain_node__init_have_children_rb_tree(struct callchain_node *se } } -static void callchain_node__init_have_children(struct callchain_node *self) +static void callchain_node__init_have_children(struct callchain_node *node) { struct callchain_list *chain; - list_for_each_entry(chain, &self->val, list) - chain->ms.has_children = !RB_EMPTY_ROOT(&self->rb_root); + list_for_each_entry(chain, &node->val, list) + chain->ms.has_children = !RB_EMPTY_ROOT(&node->rb_root); - callchain_node__init_have_children_rb_tree(self); + callchain_node__init_have_children_rb_tree(node); } -static void callchain__init_have_children(struct rb_root *self) +static void callchain__init_have_children(struct rb_root *root) { struct rb_node *nd; - for (nd = rb_first(self); nd; nd = rb_next(nd)) { + for (nd = rb_first(root); nd; nd = rb_next(nd)) { struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); callchain_node__init_have_children(node); } } -static void hist_entry__init_have_children(struct hist_entry *self) +static void hist_entry__init_have_children(struct hist_entry *he) { - if (!self->init_have_children) { - self->ms.has_children = !RB_EMPTY_ROOT(&self->sorted_chain); - callchain__init_have_children(&self->sorted_chain); - self->init_have_children = true; + if (!he->init_have_children) { + he->ms.has_children = !RB_EMPTY_ROOT(&he->sorted_chain); + callchain__init_have_children(&he->sorted_chain); + he->init_have_children = true; } } -static bool hist_browser__toggle_fold(struct hist_browser *self) +static bool hist_browser__toggle_fold(struct hist_browser *browser) { - if (map_symbol__toggle_fold(self->selection)) { - struct hist_entry *he = self->he_selection; + if (map_symbol__toggle_fold(browser->selection)) { + struct hist_entry *he = browser->he_selection; hist_entry__init_have_children(he); - self->hists->nr_entries -= he->nr_rows; + browser->hists->nr_entries -= he->nr_rows; if (he->ms.unfolded) he->nr_rows = callchain__count_rows(&he->sorted_chain); else he->nr_rows = 0; - self->hists->nr_entries += he->nr_rows; - self->b.nr_entries = self->hists->nr_entries; + browser->hists->nr_entries += he->nr_rows; + browser->b.nr_entries = browser->hists->nr_entries; return true; } @@ -209,12 +209,12 @@ static bool hist_browser__toggle_fold(struct hist_browser *self) return false; } -static int callchain_node__set_folding_rb_tree(struct callchain_node *self, bool unfold) +static int callchain_node__set_folding_rb_tree(struct callchain_node *node, bool unfold) { int n = 0; struct rb_node *nd; - for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { + for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); struct callchain_list *chain; bool has_children = false; @@ -263,37 +263,37 @@ static int callchain__set_folding(struct rb_root *chain, bool unfold) return n; } -static void hist_entry__set_folding(struct hist_entry *self, bool unfold) +static void hist_entry__set_folding(struct hist_entry *he, bool unfold) { - hist_entry__init_have_children(self); - map_symbol__set_folding(&self->ms, unfold); + hist_entry__init_have_children(he); + map_symbol__set_folding(&he->ms, unfold); - if (self->ms.has_children) { - int n = callchain__set_folding(&self->sorted_chain, unfold); - self->nr_rows = unfold ? n : 0; + if (he->ms.has_children) { + int n = callchain__set_folding(&he->sorted_chain, unfold); + he->nr_rows = unfold ? n : 0; } else - self->nr_rows = 0; + he->nr_rows = 0; } -static void hists__set_folding(struct hists *self, bool unfold) +static void hists__set_folding(struct hists *hists, bool unfold) { struct rb_node *nd; - self->nr_entries = 0; + hists->nr_entries = 0; - for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { + for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); hist_entry__set_folding(he, unfold); - self->nr_entries += 1 + he->nr_rows; + hists->nr_entries += 1 + he->nr_rows; } } -static void hist_browser__set_folding(struct hist_browser *self, bool unfold) +static void hist_browser__set_folding(struct hist_browser *browser, bool unfold) { - hists__set_folding(self->hists, unfold); - self->b.nr_entries = self->hists->nr_entries; + hists__set_folding(browser->hists, unfold); + browser->b.nr_entries = browser->hists->nr_entries; /* Go to the start, we may be way after valid entries after a collapse */ - ui_browser__reset_index(&self->b); + ui_browser__reset_index(&browser->b); } static void ui_browser__warn_lost_events(struct ui_browser *browser) @@ -305,64 +305,64 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser) "Or reduce the sampling frequency."); } -static int hist_browser__run(struct hist_browser *self, const char *ev_name, +static int hist_browser__run(struct hist_browser *browser, const char *ev_name, void(*timer)(void *arg), void *arg, int delay_secs) { int key; char title[160]; - self->b.entries = &self->hists->entries; - self->b.nr_entries = self->hists->nr_entries; + browser->b.entries = &browser->hists->entries; + browser->b.nr_entries = browser->hists->nr_entries; - hist_browser__refresh_dimensions(self); - hists__browser_title(self->hists, title, sizeof(title), ev_name); + hist_browser__refresh_dimensions(browser); + hists__browser_title(browser->hists, title, sizeof(title), ev_name); - if (ui_browser__show(&self->b, title, + if (ui_browser__show(&browser->b, title, "Press '?' for help on key bindings") < 0) return -1; while (1) { - key = ui_browser__run(&self->b, delay_secs); + key = ui_browser__run(&browser->b, delay_secs); switch (key) { case K_TIMER: timer(arg); - ui_browser__update_nr_entries(&self->b, self->hists->nr_entries); + ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); - if (self->hists->stats.nr_lost_warned != - self->hists->stats.nr_events[PERF_RECORD_LOST]) { - self->hists->stats.nr_lost_warned = - self->hists->stats.nr_events[PERF_RECORD_LOST]; - ui_browser__warn_lost_events(&self->b); + if (browser->hists->stats.nr_lost_warned != + browser->hists->stats.nr_events[PERF_RECORD_LOST]) { + browser->hists->stats.nr_lost_warned = + browser->hists->stats.nr_events[PERF_RECORD_LOST]; + ui_browser__warn_lost_events(&browser->b); } - hists__browser_title(self->hists, title, sizeof(title), ev_name); - ui_browser__show_title(&self->b, title); + hists__browser_title(browser->hists, title, sizeof(title), ev_name); + ui_browser__show_title(&browser->b, title); continue; case 'D': { /* Debug */ static int seq; - struct hist_entry *h = rb_entry(self->b.top, + struct hist_entry *h = rb_entry(browser->b.top, struct hist_entry, rb_node); ui_helpline__pop(); ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d", - seq++, self->b.nr_entries, - self->hists->nr_entries, - self->b.height, - self->b.index, - self->b.top_idx, + seq++, browser->b.nr_entries, + browser->hists->nr_entries, + browser->b.height, + browser->b.index, + browser->b.top_idx, h->row_offset, h->nr_rows); } break; case 'C': /* Collapse the whole world. */ - hist_browser__set_folding(self, false); + hist_browser__set_folding(browser, false); break; case 'E': /* Expand the whole world. */ - hist_browser__set_folding(self, true); + hist_browser__set_folding(browser, true); break; case K_ENTER: - if (hist_browser__toggle_fold(self)) + if (hist_browser__toggle_fold(browser)) break; /* fall thru */ default: @@ -370,23 +370,23 @@ static int hist_browser__run(struct hist_browser *self, const char *ev_name, } } out: - ui_browser__hide(&self->b); + ui_browser__hide(&browser->b); return key; } -static char *callchain_list__sym_name(struct callchain_list *self, +static char *callchain_list__sym_name(struct callchain_list *cl, char *bf, size_t bfsize) { - if (self->ms.sym) - return self->ms.sym->name; + if (cl->ms.sym) + return cl->ms.sym->name; - snprintf(bf, bfsize, "%#" PRIx64, self->ip); + snprintf(bf, bfsize, "%#" PRIx64, cl->ip); return bf; } #define LEVEL_OFFSET_STEP 3 -static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self, +static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *browser, struct callchain_node *chain_node, u64 total, int level, unsigned short row, @@ -444,21 +444,21 @@ static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self, } color = HE_COLORSET_NORMAL; - width = self->b.width - (offset + extra_offset + 2); - if (ui_browser__is_current_entry(&self->b, row)) { - self->selection = &chain->ms; + width = browser->b.width - (offset + extra_offset + 2); + if (ui_browser__is_current_entry(&browser->b, row)) { + browser->selection = &chain->ms; color = HE_COLORSET_SELECTED; *is_current_entry = true; } - ui_browser__set_color(&self->b, color); - ui_browser__gotorc(&self->b, row, 0); + ui_browser__set_color(&browser->b, color); + ui_browser__gotorc(&browser->b, row, 0); slsmg_write_nstring(" ", offset + extra_offset); slsmg_printf("%c ", folded_sign); slsmg_write_nstring(str, width); free(alloc_str); - if (++row == self->b.height) + if (++row == browser->b.height) goto out; do_next: if (folded_sign == '+') @@ -467,11 +467,11 @@ do_next: if (folded_sign == '-') { const int new_level = level + (extra_offset ? 2 : 1); - row += hist_browser__show_callchain_node_rb_tree(self, child, new_total, + row += hist_browser__show_callchain_node_rb_tree(browser, child, new_total, new_level, row, row_offset, is_current_entry); } - if (row == self->b.height) + if (row == browser->b.height) goto out; node = next; } @@ -479,7 +479,7 @@ out: return row - first_row; } -static int hist_browser__show_callchain_node(struct hist_browser *self, +static int hist_browser__show_callchain_node(struct hist_browser *browser, struct callchain_node *node, int level, unsigned short row, off_t *row_offset, @@ -488,7 +488,7 @@ static int hist_browser__show_callchain_node(struct hist_browser *self, struct callchain_list *chain; int first_row = row, offset = level * LEVEL_OFFSET_STEP, - width = self->b.width - offset; + width = browser->b.width - offset; char folded_sign = ' '; list_for_each_entry(chain, &node->val, list) { @@ -503,26 +503,26 @@ static int hist_browser__show_callchain_node(struct hist_browser *self, } color = HE_COLORSET_NORMAL; - if (ui_browser__is_current_entry(&self->b, row)) { - self->selection = &chain->ms; + if (ui_browser__is_current_entry(&browser->b, row)) { + browser->selection = &chain->ms; color = HE_COLORSET_SELECTED; *is_current_entry = true; } s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); - ui_browser__gotorc(&self->b, row, 0); - ui_browser__set_color(&self->b, color); + ui_browser__gotorc(&browser->b, row, 0); + ui_browser__set_color(&browser->b, color); slsmg_write_nstring(" ", offset); slsmg_printf("%c ", folded_sign); slsmg_write_nstring(s, width - 2); - if (++row == self->b.height) + if (++row == browser->b.height) goto out; } if (folded_sign == '-') - row += hist_browser__show_callchain_node_rb_tree(self, node, - self->hists->stats.total_period, + row += hist_browser__show_callchain_node_rb_tree(browser, node, + browser->hists->stats.total_period, level + 1, row, row_offset, is_current_entry); @@ -530,7 +530,7 @@ out: return row - first_row; } -static int hist_browser__show_callchain(struct hist_browser *self, +static int hist_browser__show_callchain(struct hist_browser *browser, struct rb_root *chain, int level, unsigned short row, off_t *row_offset, @@ -542,31 +542,31 @@ static int hist_browser__show_callchain(struct hist_browser *self, for (nd = rb_first(chain); nd; nd = rb_next(nd)) { struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); - row += hist_browser__show_callchain_node(self, node, level, + row += hist_browser__show_callchain_node(browser, node, level, row, row_offset, is_current_entry); - if (row == self->b.height) + if (row == browser->b.height) break; } return row - first_row; } -static int hist_browser__show_entry(struct hist_browser *self, +static int hist_browser__show_entry(struct hist_browser *browser, struct hist_entry *entry, unsigned short row) { char s[256]; double percent; int printed = 0; - int width = self->b.width - 6; /* The percentage */ + int width = browser->b.width - 6; /* The percentage */ char folded_sign = ' '; - bool current_entry = ui_browser__is_current_entry(&self->b, row); + bool current_entry = ui_browser__is_current_entry(&browser->b, row); off_t row_offset = entry->row_offset; if (current_entry) { - self->he_selection = entry; - self->selection = &entry->ms; + browser->he_selection = entry; + browser->selection = &entry->ms; } if (symbol_conf.use_callchain) { @@ -575,11 +575,11 @@ static int hist_browser__show_entry(struct hist_browser *self, } if (row_offset == 0) { - hist_entry__snprintf(entry, s, sizeof(s), self->hists); - percent = (entry->period * 100.0) / self->hists->stats.total_period; + hist_entry__snprintf(entry, s, sizeof(s), browser->hists); + percent = (entry->period * 100.0) / browser->hists->stats.total_period; - ui_browser__set_percent_color(&self->b, percent, current_entry); - ui_browser__gotorc(&self->b, row, 0); + ui_browser__set_percent_color(&browser->b, percent, current_entry); + ui_browser__gotorc(&browser->b, row, 0); if (symbol_conf.use_callchain) { slsmg_printf("%c ", folded_sign); width -= 2; @@ -588,11 +588,11 @@ static int hist_browser__show_entry(struct hist_browser *self, slsmg_printf(" %5.2f%%", percent); /* The scroll bar isn't being used */ - if (!self->b.navkeypressed) + if (!browser->b.navkeypressed) width += 1; - if (!current_entry || !self->b.navkeypressed) - ui_browser__set_color(&self->b, HE_COLORSET_NORMAL); + if (!current_entry || !browser->b.navkeypressed) + ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); if (symbol_conf.show_nr_samples) { slsmg_printf(" %11u", entry->nr_events); @@ -610,12 +610,12 @@ static int hist_browser__show_entry(struct hist_browser *self, } else --row_offset; - if (folded_sign == '-' && row != self->b.height) { - printed += hist_browser__show_callchain(self, &entry->sorted_chain, + if (folded_sign == '-' && row != browser->b.height) { + printed += hist_browser__show_callchain(browser, &entry->sorted_chain, 1, row, &row_offset, ¤t_entry); if (current_entry) - self->he_selection = entry; + browser->he_selection = entry; } return printed; @@ -631,22 +631,22 @@ static void ui_browser__hists_init_top(struct ui_browser *browser) } } -static unsigned int hist_browser__refresh(struct ui_browser *self) +static unsigned int hist_browser__refresh(struct ui_browser *browser) { unsigned row = 0; struct rb_node *nd; - struct hist_browser *hb = container_of(self, struct hist_browser, b); + struct hist_browser *hb = container_of(browser, struct hist_browser, b); - ui_browser__hists_init_top(self); + ui_browser__hists_init_top(browser); - for (nd = self->top; nd; nd = rb_next(nd)) { + for (nd = browser->top; nd; nd = rb_next(nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); if (h->filtered) continue; row += hist_browser__show_entry(hb, h, row); - if (row == self->height) + if (row == browser->height) break; } @@ -679,27 +679,27 @@ static struct rb_node *hists__filter_prev_entries(struct rb_node *nd) return NULL; } -static void ui_browser__hists_seek(struct ui_browser *self, +static void ui_browser__hists_seek(struct ui_browser *browser, off_t offset, int whence) { struct hist_entry *h; struct rb_node *nd; bool first = true; - if (self->nr_entries == 0) + if (browser->nr_entries == 0) return; - ui_browser__hists_init_top(self); + ui_browser__hists_init_top(browser); switch (whence) { case SEEK_SET: - nd = hists__filter_entries(rb_first(self->entries)); + nd = hists__filter_entries(rb_first(browser->entries)); break; case SEEK_CUR: - nd = self->top; + nd = browser->top; goto do_offset; case SEEK_END: - nd = hists__filter_prev_entries(rb_last(self->entries)); + nd = hists__filter_prev_entries(rb_last(browser->entries)); first = false; break; default: @@ -710,7 +710,7 @@ static void ui_browser__hists_seek(struct ui_browser *self, * Moves not relative to the first visible entry invalidates its * row_offset: */ - h = rb_entry(self->top, struct hist_entry, rb_node); + h = rb_entry(browser->top, struct hist_entry, rb_node); h->row_offset = 0; /* @@ -738,7 +738,7 @@ do_offset: } else { h->row_offset += offset; offset = 0; - self->top = nd; + browser->top = nd; break; } } @@ -746,7 +746,7 @@ do_offset: if (nd == NULL) break; --offset; - self->top = nd; + browser->top = nd; } while (offset != 0); } else if (offset < 0) { while (1) { @@ -759,7 +759,7 @@ do_offset: } else { h->row_offset += offset; offset = 0; - self->top = nd; + browser->top = nd; break; } } else { @@ -769,7 +769,7 @@ do_offset: } else { h->row_offset = h->nr_rows + offset; offset = 0; - self->top = nd; + browser->top = nd; break; } } @@ -779,7 +779,7 @@ do_offset: if (nd == NULL) break; ++offset; - self->top = nd; + browser->top = nd; if (offset == 0) { /* * Last unfiltered hist_entry, check if it is @@ -794,7 +794,7 @@ do_offset: first = false; } } else { - self->top = nd; + browser->top = nd; h = rb_entry(nd, struct hist_entry, rb_node); h->row_offset = 0; } @@ -802,46 +802,46 @@ do_offset: static struct hist_browser *hist_browser__new(struct hists *hists) { - struct hist_browser *self = zalloc(sizeof(*self)); + struct hist_browser *browser = zalloc(sizeof(*browser)); - if (self) { - self->hists = hists; - self->b.refresh = hist_browser__refresh; - self->b.seek = ui_browser__hists_seek; - self->b.use_navkeypressed = true; + if (browser) { + browser->hists = hists; + browser->b.refresh = hist_browser__refresh; + browser->b.seek = ui_browser__hists_seek; + browser->b.use_navkeypressed = true; if (sort__branch_mode == 1) - self->has_symbols = sort_sym_from.list.next != NULL; + browser->has_symbols = sort_sym_from.list.next != NULL; else - self->has_symbols = sort_sym.list.next != NULL; + browser->has_symbols = sort_sym.list.next != NULL; } - return self; + return browser; } -static void hist_browser__delete(struct hist_browser *self) +static void hist_browser__delete(struct hist_browser *browser) { - free(self); + free(browser); } -static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self) +static struct hist_entry *hist_browser__selected_entry(struct hist_browser *browser) { - return self->he_selection; + return browser->he_selection; } -static struct thread *hist_browser__selected_thread(struct hist_browser *self) +static struct thread *hist_browser__selected_thread(struct hist_browser *browser) { - return self->he_selection->thread; + return browser->he_selection->thread; } -static int hists__browser_title(struct hists *self, char *bf, size_t size, +static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name) { char unit; int printed; - const struct dso *dso = self->dso_filter; - const struct thread *thread = self->thread_filter; - unsigned long nr_samples = self->stats.nr_events[PERF_RECORD_SAMPLE]; - u64 nr_events = self->stats.total_period; + const struct dso *dso = hists->dso_filter; + const struct thread *thread = hists->thread_filter; + unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; + u64 nr_events = hists->stats.total_period; nr_samples = convert_unit(nr_samples, &unit); printed = scnprintf(bf, size, @@ -849,9 +849,9 @@ static int hists__browser_title(struct hists *self, char *bf, size_t size, nr_samples, unit, ev_name, nr_events); - if (self->uid_filter_str) + if (hists->uid_filter_str) printed += snprintf(bf + printed, size - printed, - ", UID: %s", self->uid_filter_str); + ", UID: %s", hists->uid_filter_str); if (thread) printed += scnprintf(bf + printed, size - printed, ", Thread: %s(%d)", @@ -879,8 +879,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, void(*timer)(void *arg), void *arg, int delay_secs) { - struct hists *self = &evsel->hists; - struct hist_browser *browser = hist_browser__new(self); + struct hists *hists = &evsel->hists; + struct hist_browser *browser = hist_browser__new(hists); struct branch_info *bi; struct pstack *fstack; char *options[16]; @@ -946,8 +946,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, "Please enter the name of symbol you want to see", buf, "ENTER: OK, ESC: Cancel", delay_secs * 2) == K_ENTER) { - self->symbol_filter_str = *buf ? buf : NULL; - hists__filter_by_symbol(self); + hists->symbol_filter_str = *buf ? buf : NULL; + hists__filter_by_symbol(hists); hist_browser__reset(browser); } continue; @@ -1128,7 +1128,7 @@ zoom_out_dso: sort_dso.elide = true; pstack__push(fstack, &browser->hists->dso_filter); } - hists__filter_by_dso(self); + hists__filter_by_dso(hists); hist_browser__reset(browser); } else if (choice == zoom_thread) { zoom_thread: @@ -1146,7 +1146,7 @@ zoom_out_thread: sort_thread.elide = true; pstack__push(fstack, &browser->hists->thread_filter); } - hists__filter_by_thread(self); + hists__filter_by_thread(hists); hist_browser__reset(browser); } } diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index 9f5f888f73e..791fb15ce35 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c @@ -22,6 +22,7 @@ void setup_browser(bool fallback_to_pager) break; /* fall through */ default: + use_browser = 0; if (fallback_to_pager) setup_pager(); break; diff --git a/tools/perf/util/PERF-VERSION-GEN b/tools/perf/util/PERF-VERSION-GEN index ad73300f7ba..95264f30417 100755 --- a/tools/perf/util/PERF-VERSION-GEN +++ b/tools/perf/util/PERF-VERSION-GEN @@ -12,7 +12,7 @@ LF=' # First check if there is a .git to get the version from git describe # otherwise try to get the version from the kernel makefile if test -d ../../.git -o -f ../../.git && - VN=$(git describe --abbrev=4 HEAD 2>/dev/null) && + VN=$(git describe --match 'v[0-9].[0-9]*' --abbrev=4 HEAD 2>/dev/null) && case "$VN" in *$LF*) (exit 1) ;; v[0-9]*) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 9f7106a8d9a..3a6bff47614 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -18,6 +18,8 @@ #include "util.h" #include "callchain.h" +__thread struct callchain_cursor callchain_cursor; + bool ip_callchain__valid(struct ip_callchain *chain, const union perf_event *event) { diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 7f9c0f1ae3a..3bdb407f9cd 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -76,6 +76,8 @@ struct callchain_cursor { struct callchain_cursor_node *curr; }; +extern __thread struct callchain_cursor callchain_cursor; + static inline void callchain_init(struct callchain_root *root) { INIT_LIST_HEAD(&root->node.siblings); diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 0deac6a14b6..6faa3a18bfb 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -120,7 +120,7 @@ static char *parse_value(void) static inline int iskeychar(int c) { - return isalnum(c) || c == '-'; + return isalnum(c) || c == '-' || c == '_'; } static int get_value(config_fn_t fn, void *data, char *name, unsigned int len) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4ac5f5ae4ce..7400fb3fc50 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -159,6 +159,17 @@ out_delete_partial_list: return -1; } +int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, + struct perf_event_attr *attrs, size_t nr_attrs) +{ + size_t i; + + for (i = 0; i < nr_attrs; i++) + event_attr_init(attrs + i); + + return perf_evlist__add_attrs(evlist, attrs, nr_attrs); +} + static int trace_event__id(const char *evname) { char *filename, *colon; @@ -263,7 +274,8 @@ void perf_evlist__disable(struct perf_evlist *evlist) for (cpu = 0; cpu < evlist->cpus->nr; cpu++) { list_for_each_entry(pos, &evlist->entries, node) { for (thread = 0; thread < evlist->threads->nr; thread++) - ioctl(FD(pos, cpu, thread), PERF_EVENT_IOC_DISABLE); + ioctl(FD(pos, cpu, thread), + PERF_EVENT_IOC_DISABLE, 0); } } } @@ -276,7 +288,8 @@ void perf_evlist__enable(struct perf_evlist *evlist) for (cpu = 0; cpu < evlist->cpus->nr; cpu++) { list_for_each_entry(pos, &evlist->entries, node) { for (thread = 0; thread < evlist->threads->nr; thread++) - ioctl(FD(pos, cpu, thread), PERF_EVENT_IOC_ENABLE); + ioctl(FD(pos, cpu, thread), + PERF_EVENT_IOC_ENABLE, 0); } } } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 58abb63ac13..989bee9624c 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -54,6 +54,8 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); int perf_evlist__add_default(struct perf_evlist *evlist); int perf_evlist__add_attrs(struct perf_evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); +int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, + struct perf_event_attr *attrs, size_t nr_attrs); int perf_evlist__add_tracepoints(struct perf_evlist *evlist, const char *tracepoints[], size_t nr_tracepoints); int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, @@ -62,6 +64,8 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, #define perf_evlist__add_attrs_array(evlist, array) \ perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) +#define perf_evlist__add_default_attrs(evlist, array) \ + __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) #define perf_evlist__add_tracepoints_array(evlist, array) \ perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array)) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 57e4ce57bbc..9f6cebd798e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -15,6 +15,7 @@ #include "cpumap.h" #include "thread_map.h" #include "target.h" +#include "../../include/linux/perf_event.h" #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) @@ -64,6 +65,95 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) return evsel; } +static const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { + "cycles", + "instructions", + "cache-references", + "cache-misses", + "branches", + "branch-misses", + "bus-cycles", + "stalled-cycles-frontend", + "stalled-cycles-backend", + "ref-cycles", +}; + +const char *__perf_evsel__hw_name(u64 config) +{ + if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config]) + return perf_evsel__hw_names[config]; + + return "unknown-hardware"; +} + +static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) +{ + int colon = 0; + struct perf_event_attr *attr = &evsel->attr; + int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(attr->config)); + bool exclude_guest_default = false; + +#define MOD_PRINT(context, mod) do { \ + if (!attr->exclude_##context) { \ + if (!colon) colon = r++; \ + r += scnprintf(bf + r, size - r, "%c", mod); \ + } } while(0) + + if (attr->exclude_kernel || attr->exclude_user || attr->exclude_hv) { + MOD_PRINT(kernel, 'k'); + MOD_PRINT(user, 'u'); + MOD_PRINT(hv, 'h'); + exclude_guest_default = true; + } + + if (attr->precise_ip) { + if (!colon) + colon = r++; + r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); + exclude_guest_default = true; + } + + if (attr->exclude_host || attr->exclude_guest == exclude_guest_default) { + MOD_PRINT(host, 'H'); + MOD_PRINT(guest, 'G'); + } +#undef MOD_PRINT + if (colon) + bf[colon] = ':'; + return r; +} + +int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size) +{ + int ret; + + switch (evsel->attr.type) { + case PERF_TYPE_RAW: + ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config); + break; + + case PERF_TYPE_HARDWARE: + ret = perf_evsel__hw_name(evsel, bf, size); + break; + default: + /* + * FIXME + * + * This is the minimal perf_evsel__name so that we can + * reconstruct event names taking into account event modifiers. + * + * The old event_name uses it now for raw anr hw events, so that + * we don't drag all the parsing stuff into the python binding. + * + * On the next devel cycle the rest of the event naming will be + * brought here. + */ + return 0; + } + + return ret; +} + void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, struct perf_evsel *first) { @@ -404,16 +494,24 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel, } static int perf_event__parse_id_sample(const union perf_event *event, u64 type, - struct perf_sample *sample) + struct perf_sample *sample, + bool swapped) { const u64 *array = event->sample.array; + union u64_swap u; array += ((event->header.size - sizeof(event->header)) / sizeof(u64)) - 1; if (type & PERF_SAMPLE_CPU) { - u32 *p = (u32 *)array; - sample->cpu = *p; + u.val64 = *array; + if (swapped) { + /* undo swap of u64, then swap on individual u32s */ + u.val64 = bswap_64(u.val64); + u.val32[0] = bswap_32(u.val32[0]); + } + + sample->cpu = u.val32[0]; array--; } @@ -433,9 +531,16 @@ static int perf_event__parse_id_sample(const union perf_event *event, u64 type, } if (type & PERF_SAMPLE_TID) { - u32 *p = (u32 *)array; - sample->pid = p[0]; - sample->tid = p[1]; + u.val64 = *array; + if (swapped) { + /* undo swap of u64, then swap on individual u32s */ + u.val64 = bswap_64(u.val64); + u.val32[0] = bswap_32(u.val32[0]); + u.val32[1] = bswap_32(u.val32[1]); + } + + sample->pid = u.val32[0]; + sample->tid = u.val32[1]; } return 0; @@ -472,7 +577,7 @@ int perf_event__parse_sample(const union perf_event *event, u64 type, if (event->header.type != PERF_RECORD_SAMPLE) { if (!sample_id_all) return 0; - return perf_event__parse_id_sample(event, type, data); + return perf_event__parse_id_sample(event, type, data, swapped); } array = event->sample.array; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3d6b3e4cb66..4ba8b564e6f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -83,6 +83,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, struct perf_evsel *first); +const char* __perf_evsel__hw_name(u64 config); +int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size); + int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 1293b5ebea4..514e2a4b367 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -378,7 +378,7 @@ void hist_entry__free(struct hist_entry *he) * collapse the histogram */ -static bool hists__collapse_insert_entry(struct hists *hists, +static bool hists__collapse_insert_entry(struct hists *hists __used, struct rb_root *root, struct hist_entry *he) { @@ -397,8 +397,9 @@ static bool hists__collapse_insert_entry(struct hists *hists, iter->period += he->period; iter->nr_events += he->nr_events; if (symbol_conf.use_callchain) { - callchain_cursor_reset(&hists->callchain_cursor); - callchain_merge(&hists->callchain_cursor, iter->callchain, + callchain_cursor_reset(&callchain_cursor); + callchain_merge(&callchain_cursor, + iter->callchain, he->callchain); } hist_entry__free(he); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index cfc64e293f9..34bb556d621 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -67,8 +67,6 @@ struct hists { struct events_stats stats; u64 event_stream; u16 col_len[HISTC_NR_COLS]; - /* Best would be to reuse the session callchain cursor */ - struct callchain_cursor callchain_cursor; }; struct hist_entry *__hists__add_entry(struct hists *self, diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c index 1915de20dca..3322b8446e8 100644 --- a/tools/perf/util/pager.c +++ b/tools/perf/util/pager.c @@ -57,6 +57,10 @@ void setup_pager(void) } if (!pager) pager = getenv("PAGER"); + if (!pager) { + if (!access("/usr/bin/pager", X_OK)) + pager = "/usr/bin/pager"; + } if (!pager) pager = "less"; else if (!*pager || !strcmp(pager, "cat")) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index fac7d59309b..05dbc8b3c76 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -62,19 +62,6 @@ static struct event_symbol event_symbols[] = { #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) -static const char *hw_event_names[PERF_COUNT_HW_MAX] = { - "cycles", - "instructions", - "cache-references", - "cache-misses", - "branches", - "branch-misses", - "bus-cycles", - "stalled-cycles-frontend", - "stalled-cycles-backend", - "ref-cycles", -}; - static const char *sw_event_names[PERF_COUNT_SW_MAX] = { "cpu-clock", "task-clock", @@ -300,6 +287,16 @@ const char *event_name(struct perf_evsel *evsel) u64 config = evsel->attr.config; int type = evsel->attr.type; + if (type == PERF_TYPE_RAW || type == PERF_TYPE_HARDWARE) { + /* + * XXX minimal fix, see comment on perf_evsen__name, this static buffer + * will go away together with event_name in the next devel cycle. + */ + static char bf[128]; + perf_evsel__name(evsel, bf, sizeof(bf)); + return bf; + } + if (evsel->name) return evsel->name; @@ -317,9 +314,7 @@ const char *__event_name(int type, u64 config) switch (type) { case PERF_TYPE_HARDWARE: - if (config < PERF_COUNT_HW_MAX && hw_event_names[config]) - return hw_event_names[config]; - return "unknown-hardware"; + return __perf_evsel__hw_name(config); case PERF_TYPE_HW_CACHE: { u8 cache_type, cache_op, cache_result; diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 8a8ee64e72d..0dda25d82d0 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -44,6 +44,7 @@ #include "trace-event.h" /* For __unused */ #include "probe-event.h" #include "probe-finder.h" +#include "session.h" #define MAX_CMDLEN 256 #define MAX_PROBE_ARGS 128 @@ -70,6 +71,8 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) } static char *synthesize_perf_probe_point(struct perf_probe_point *pp); +static int convert_name_to_addr(struct perf_probe_event *pev, + const char *exec); static struct machine machine; /* Initialize symbol maps and path of vmlinux/modules */ @@ -170,6 +173,34 @@ const char *kernel_get_module_path(const char *module) return (dso) ? dso->long_name : NULL; } +static int init_user_exec(void) +{ + int ret = 0; + + symbol_conf.try_vmlinux_path = false; + symbol_conf.sort_by_name = true; + ret = symbol__init(); + + if (ret < 0) + pr_debug("Failed to init symbol map.\n"); + + return ret; +} + +static int convert_to_perf_probe_point(struct probe_trace_point *tp, + struct perf_probe_point *pp) +{ + pp->function = strdup(tp->symbol); + + if (pp->function == NULL) + return -ENOMEM; + + pp->offset = tp->offset; + pp->retprobe = tp->retprobe; + + return 0; +} + #ifdef DWARF_SUPPORT /* Open new debuginfo of given module */ static struct debuginfo *open_debuginfo(const char *module) @@ -224,10 +255,7 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, if (ret <= 0) { pr_debug("Failed to find corresponding probes from " "debuginfo. Use kprobe event information.\n"); - pp->function = strdup(tp->symbol); - if (pp->function == NULL) - return -ENOMEM; - pp->offset = tp->offset; + return convert_to_perf_probe_point(tp, pp); } pp->retprobe = tp->retprobe; @@ -275,9 +303,20 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev, int max_tevs, const char *target) { bool need_dwarf = perf_probe_event_need_dwarf(pev); - struct debuginfo *dinfo = open_debuginfo(target); + struct debuginfo *dinfo; int ntevs, ret = 0; + if (pev->uprobes) { + if (need_dwarf) { + pr_warning("Debuginfo-analysis is not yet supported" + " with -x/--exec option.\n"); + return -ENOSYS; + } + return convert_name_to_addr(pev, target); + } + + dinfo = open_debuginfo(target); + if (!dinfo) { if (need_dwarf) { pr_warning("Failed to open debuginfo file.\n"); @@ -603,23 +642,22 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, pr_err("Failed to find symbol %s in kernel.\n", tp->symbol); return -ENOENT; } - pp->function = strdup(tp->symbol); - if (pp->function == NULL) - return -ENOMEM; - pp->offset = tp->offset; - pp->retprobe = tp->retprobe; - return 0; + return convert_to_perf_probe_point(tp, pp); } static int try_to_find_probe_trace_events(struct perf_probe_event *pev, struct probe_trace_event **tevs __unused, - int max_tevs __unused, const char *mod __unused) + int max_tevs __unused, const char *target) { if (perf_probe_event_need_dwarf(pev)) { pr_warning("Debuginfo-analysis is not supported.\n"); return -ENOSYS; } + + if (pev->uprobes) + return convert_name_to_addr(pev, target); + return 0; } @@ -1341,11 +1379,18 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev) if (buf == NULL) return NULL; - len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu", - tp->retprobe ? 'r' : 'p', - tev->group, tev->event, - tp->module ?: "", tp->module ? ":" : "", - tp->symbol, tp->offset); + if (tev->uprobes) + len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s:%s", + tp->retprobe ? 'r' : 'p', + tev->group, tev->event, + tp->module, tp->symbol); + else + len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu", + tp->retprobe ? 'r' : 'p', + tev->group, tev->event, + tp->module ?: "", tp->module ? ":" : "", + tp->symbol, tp->offset); + if (len <= 0) goto error; @@ -1364,7 +1409,7 @@ error: } static int convert_to_perf_probe_event(struct probe_trace_event *tev, - struct perf_probe_event *pev) + struct perf_probe_event *pev, bool is_kprobe) { char buf[64] = ""; int i, ret; @@ -1376,7 +1421,11 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev, return -ENOMEM; /* Convert trace_point to probe_point */ - ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point); + if (is_kprobe) + ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point); + else + ret = convert_to_perf_probe_point(&tev->point, &pev->point); + if (ret < 0) return ret; @@ -1472,7 +1521,26 @@ static void clear_probe_trace_event(struct probe_trace_event *tev) memset(tev, 0, sizeof(*tev)); } -static int open_kprobe_events(bool readwrite) +static void print_warn_msg(const char *file, bool is_kprobe) +{ + + if (errno == ENOENT) { + const char *config; + + if (!is_kprobe) + config = "CONFIG_UPROBE_EVENTS"; + else + config = "CONFIG_KPROBE_EVENTS"; + + pr_warning("%s file does not exist - please rebuild kernel" + " with %s.\n", file, config); + } else + pr_warning("Failed to open %s file: %s\n", file, + strerror(errno)); +} + +static int open_probe_events(const char *trace_file, bool readwrite, + bool is_kprobe) { char buf[PATH_MAX]; const char *__debugfs; @@ -1484,27 +1552,31 @@ static int open_kprobe_events(bool readwrite) return -ENOENT; } - ret = e_snprintf(buf, PATH_MAX, "%stracing/kprobe_events", __debugfs); + ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file); if (ret >= 0) { pr_debug("Opening %s write=%d\n", buf, readwrite); if (readwrite && !probe_event_dry_run) ret = open(buf, O_RDWR, O_APPEND); else ret = open(buf, O_RDONLY, 0); - } - if (ret < 0) { - if (errno == ENOENT) - pr_warning("kprobe_events file does not exist - please" - " rebuild kernel with CONFIG_KPROBE_EVENT.\n"); - else - pr_warning("Failed to open kprobe_events file: %s\n", - strerror(errno)); + if (ret < 0) + print_warn_msg(buf, is_kprobe); } return ret; } -/* Get raw string list of current kprobe_events */ +static int open_kprobe_events(bool readwrite) +{ + return open_probe_events("tracing/kprobe_events", readwrite, true); +} + +static int open_uprobe_events(bool readwrite) +{ + return open_probe_events("tracing/uprobe_events", readwrite, false); +} + +/* Get raw string list of current kprobe_events or uprobe_events */ static struct strlist *get_probe_trace_command_rawlist(int fd) { int ret, idx; @@ -1569,36 +1641,26 @@ static int show_perf_probe_event(struct perf_probe_event *pev) return ret; } -/* List up current perf-probe events */ -int show_perf_probe_events(void) +static int __show_perf_probe_events(int fd, bool is_kprobe) { - int fd, ret; + int ret = 0; struct probe_trace_event tev; struct perf_probe_event pev; struct strlist *rawlist; struct str_node *ent; - setup_pager(); - ret = init_vmlinux(); - if (ret < 0) - return ret; - memset(&tev, 0, sizeof(tev)); memset(&pev, 0, sizeof(pev)); - fd = open_kprobe_events(false); - if (fd < 0) - return fd; - rawlist = get_probe_trace_command_rawlist(fd); - close(fd); if (!rawlist) return -ENOENT; strlist__for_each(ent, rawlist) { ret = parse_probe_trace_command(ent->s, &tev); if (ret >= 0) { - ret = convert_to_perf_probe_event(&tev, &pev); + ret = convert_to_perf_probe_event(&tev, &pev, + is_kprobe); if (ret >= 0) ret = show_perf_probe_event(&pev); } @@ -1612,6 +1674,33 @@ int show_perf_probe_events(void) return ret; } +/* List up current perf-probe events */ +int show_perf_probe_events(void) +{ + int fd, ret; + + setup_pager(); + fd = open_kprobe_events(false); + + if (fd < 0) + return fd; + + ret = init_vmlinux(); + if (ret < 0) + return ret; + + ret = __show_perf_probe_events(fd, true); + close(fd); + + fd = open_uprobe_events(false); + if (fd >= 0) { + ret = __show_perf_probe_events(fd, false); + close(fd); + } + + return ret; +} + /* Get current perf-probe event names */ static struct strlist *get_probe_trace_event_names(int fd, bool include_group) { @@ -1717,7 +1806,11 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, const char *event, *group; struct strlist *namelist; - fd = open_kprobe_events(true); + if (pev->uprobes) + fd = open_uprobe_events(true); + else + fd = open_kprobe_events(true); + if (fd < 0) return fd; /* Get current event names */ @@ -1829,6 +1922,8 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, tev->point.offset = pev->point.offset; tev->point.retprobe = pev->point.retprobe; tev->nargs = pev->nargs; + tev->uprobes = pev->uprobes; + if (tev->nargs) { tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); @@ -1859,6 +1954,9 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, } } + if (pev->uprobes) + return 1; + /* Currently just checking function name from symbol map */ sym = __find_kernel_function_by_name(tev->point.symbol, NULL); if (!sym) { @@ -1894,12 +1992,18 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, int i, j, ret; struct __event_package *pkgs; + ret = 0; pkgs = zalloc(sizeof(struct __event_package) * npevs); + if (pkgs == NULL) return -ENOMEM; - /* Init vmlinux path */ - ret = init_vmlinux(); + if (!pevs->uprobes) + /* Init vmlinux path */ + ret = init_vmlinux(); + else + ret = init_user_exec(); + if (ret < 0) { free(pkgs); return ret; @@ -1971,23 +2075,15 @@ error: return ret; } -static int del_trace_probe_event(int fd, const char *group, - const char *event, struct strlist *namelist) +static int del_trace_probe_event(int fd, const char *buf, + struct strlist *namelist) { - char buf[128]; struct str_node *ent, *n; - int found = 0, ret = 0; - - ret = e_snprintf(buf, 128, "%s:%s", group, event); - if (ret < 0) { - pr_err("Failed to copy event.\n"); - return ret; - } + int ret = -1; if (strpbrk(buf, "*?")) { /* Glob-exp */ strlist__for_each_safe(ent, n, namelist) if (strglobmatch(ent->s, buf)) { - found++; ret = __del_trace_probe_event(fd, ent); if (ret < 0) break; @@ -1996,40 +2092,43 @@ static int del_trace_probe_event(int fd, const char *group, } else { ent = strlist__find(namelist, buf); if (ent) { - found++; ret = __del_trace_probe_event(fd, ent); if (ret >= 0) strlist__remove(namelist, ent); } } - if (found == 0 && ret >= 0) - pr_info("Info: Event \"%s\" does not exist.\n", buf); return ret; } int del_perf_probe_events(struct strlist *dellist) { - int fd, ret = 0; + int ret = -1, ufd = -1, kfd = -1; + char buf[128]; const char *group, *event; char *p, *str; struct str_node *ent; - struct strlist *namelist; - - fd = open_kprobe_events(true); - if (fd < 0) - return fd; + struct strlist *namelist = NULL, *unamelist = NULL; /* Get current event names */ - namelist = get_probe_trace_event_names(fd, true); - if (namelist == NULL) - return -EINVAL; + kfd = open_kprobe_events(true); + if (kfd < 0) + return kfd; + + namelist = get_probe_trace_event_names(kfd, true); + ufd = open_uprobe_events(true); + + if (ufd >= 0) + unamelist = get_probe_trace_event_names(ufd, true); + + if (namelist == NULL && unamelist == NULL) + goto error; strlist__for_each(ent, dellist) { str = strdup(ent->s); if (str == NULL) { ret = -ENOMEM; - break; + goto error; } pr_debug("Parsing: %s\n", str); p = strchr(str, ':'); @@ -2041,17 +2140,42 @@ int del_perf_probe_events(struct strlist *dellist) group = "*"; event = str; } + + ret = e_snprintf(buf, 128, "%s:%s", group, event); + if (ret < 0) { + pr_err("Failed to copy event."); + free(str); + goto error; + } + pr_debug("Group: %s, Event: %s\n", group, event); - ret = del_trace_probe_event(fd, group, event, namelist); + + if (namelist) + ret = del_trace_probe_event(kfd, buf, namelist); + + if (unamelist && ret != 0) + ret = del_trace_probe_event(ufd, buf, unamelist); + + if (ret != 0) + pr_info("Info: Event \"%s\" does not exist.\n", buf); + free(str); - if (ret < 0) - break; } - strlist__delete(namelist); - close(fd); + +error: + if (kfd >= 0) { + strlist__delete(namelist); + close(kfd); + } + + if (ufd >= 0) { + strlist__delete(unamelist); + close(ufd); + } return ret; } + /* TODO: don't use a global variable for filter ... */ static struct strfilter *available_func_filter; @@ -2068,30 +2192,152 @@ static int filter_available_functions(struct map *map __unused, return 1; } -int show_available_funcs(const char *target, struct strfilter *_filter) +static int __show_available_funcs(struct map *map) +{ + if (map__load(map, filter_available_functions)) { + pr_err("Failed to load map.\n"); + return -EINVAL; + } + if (!dso__sorted_by_name(map->dso, map->type)) + dso__sort_by_name(map->dso, map->type); + + dso__fprintf_symbols_by_name(map->dso, map->type, stdout); + return 0; +} + +static int available_kernel_funcs(const char *module) { struct map *map; int ret; - setup_pager(); - ret = init_vmlinux(); if (ret < 0) return ret; - map = kernel_get_module_map(target); + map = kernel_get_module_map(module); if (!map) { - pr_err("Failed to find %s map.\n", (target) ? : "kernel"); + pr_err("Failed to find %s map.\n", (module) ? : "kernel"); return -EINVAL; } + return __show_available_funcs(map); +} + +static int available_user_funcs(const char *target) +{ + struct map *map; + int ret; + + ret = init_user_exec(); + if (ret < 0) + return ret; + + map = dso__new_map(target); + ret = __show_available_funcs(map); + dso__delete(map->dso); + map__delete(map); + return ret; +} + +int show_available_funcs(const char *target, struct strfilter *_filter, + bool user) +{ + setup_pager(); available_func_filter = _filter; + + if (!user) + return available_kernel_funcs(target); + + return available_user_funcs(target); +} + +/* + * uprobe_events only accepts address: + * Convert function and any offset to address + */ +static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) +{ + struct perf_probe_point *pp = &pev->point; + struct symbol *sym; + struct map *map = NULL; + char *function = NULL, *name = NULL; + int ret = -EINVAL; + unsigned long long vaddr = 0; + + if (!pp->function) { + pr_warning("No function specified for uprobes"); + goto out; + } + + function = strdup(pp->function); + if (!function) { + pr_warning("Failed to allocate memory by strdup.\n"); + ret = -ENOMEM; + goto out; + } + + name = realpath(exec, NULL); + if (!name) { + pr_warning("Cannot find realpath for %s.\n", exec); + goto out; + } + map = dso__new_map(name); + if (!map) { + pr_warning("Cannot find appropriate DSO for %s.\n", exec); + goto out; + } + available_func_filter = strfilter__new(function, NULL); if (map__load(map, filter_available_functions)) { pr_err("Failed to load map.\n"); - return -EINVAL; + goto out; } - if (!dso__sorted_by_name(map->dso, map->type)) - dso__sort_by_name(map->dso, map->type); - dso__fprintf_symbols_by_name(map->dso, map->type, stdout); - return 0; + sym = map__find_symbol_by_name(map, function, NULL); + if (!sym) { + pr_warning("Cannot find %s in DSO %s\n", function, exec); + goto out; + } + + if (map->start > sym->start) + vaddr = map->start; + vaddr += sym->start + pp->offset + map->pgoff; + pp->offset = 0; + + if (!pev->event) { + pev->event = function; + function = NULL; + } + if (!pev->group) { + char *ptr1, *ptr2; + + pev->group = zalloc(sizeof(char *) * 64); + ptr1 = strdup(basename(exec)); + if (ptr1) { + ptr2 = strpbrk(ptr1, "-._"); + if (ptr2) + *ptr2 = '\0'; + e_snprintf(pev->group, 64, "%s_%s", PERFPROBE_GROUP, + ptr1); + free(ptr1); + } + } + free(pp->function); + pp->function = zalloc(sizeof(char *) * MAX_PROBE_ARGS); + if (!pp->function) { + ret = -ENOMEM; + pr_warning("Failed to allocate memory by zalloc.\n"); + goto out; + } + e_snprintf(pp->function, MAX_PROBE_ARGS, "0x%llx", vaddr); + ret = 0; + +out: + if (map) { + dso__delete(map->dso); + map__delete(map); + } + if (function) + free(function); + if (name) + free(name); + return ret; } diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index a7dee835f49..f9f3de8b422 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h @@ -7,7 +7,7 @@ extern bool probe_event_dry_run; -/* kprobe-tracer tracing point */ +/* kprobe-tracer and uprobe-tracer tracing point */ struct probe_trace_point { char *symbol; /* Base symbol */ char *module; /* Module name */ @@ -21,7 +21,7 @@ struct probe_trace_arg_ref { long offset; /* Offset value */ }; -/* kprobe-tracer tracing argument */ +/* kprobe-tracer and uprobe-tracer tracing argument */ struct probe_trace_arg { char *name; /* Argument name */ char *value; /* Base value */ @@ -29,12 +29,13 @@ struct probe_trace_arg { struct probe_trace_arg_ref *ref; /* Referencing offset */ }; -/* kprobe-tracer tracing event (point + arg) */ +/* kprobe-tracer and uprobe-tracer tracing event (point + arg) */ struct probe_trace_event { char *event; /* Event name */ char *group; /* Group name */ struct probe_trace_point point; /* Trace point */ int nargs; /* Number of args */ + bool uprobes; /* uprobes only */ struct probe_trace_arg *args; /* Arguments */ }; @@ -70,6 +71,7 @@ struct perf_probe_event { char *group; /* Group name */ struct perf_probe_point point; /* Probe point */ int nargs; /* Number of arguments */ + bool uprobes; struct perf_probe_arg *args; /* Arguments */ }; @@ -129,8 +131,8 @@ extern int show_line_range(struct line_range *lr, const char *module); extern int show_available_vars(struct perf_probe_event *pevs, int npevs, int max_probe_points, const char *module, struct strfilter *filter, bool externs); -extern int show_available_funcs(const char *module, struct strfilter *filter); - +extern int show_available_funcs(const char *module, struct strfilter *filter, + bool user); /* Maximum index number of event-name postfix */ #define MAX_EVENT_INDEX 1024 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 93d355d2710..2600916efa8 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -288,7 +288,8 @@ struct branch_info *machine__resolve_bstack(struct machine *self, return bi; } -int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, +int machine__resolve_callchain(struct machine *self, + struct perf_evsel *evsel __used, struct thread *thread, struct ip_callchain *chain, struct symbol **parent) @@ -297,7 +298,12 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, unsigned int i; int err; - callchain_cursor_reset(&evsel->hists.callchain_cursor); + callchain_cursor_reset(&callchain_cursor); + + if (chain->nr > PERF_MAX_STACK_DEPTH) { + pr_warning("corrupted callchain. skipping...\n"); + return 0; + } for (i = 0; i < chain->nr; i++) { u64 ip; @@ -317,7 +323,14 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, case PERF_CONTEXT_USER: cpumode = PERF_RECORD_MISC_USER; break; default: - break; + pr_debug("invalid callchain context: " + "%"PRId64"\n", (s64) ip); + /* + * It seems the callchain is corrupted. + * Discard all. + */ + callchain_cursor_reset(&callchain_cursor); + return 0; } continue; } @@ -333,7 +346,7 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, break; } - err = callchain_cursor_append(&evsel->hists.callchain_cursor, + err = callchain_cursor_append(&callchain_cursor, ip, al.map, al.sym); if (err) return err; @@ -441,37 +454,65 @@ void mem_bswap_64(void *src, int byte_size) } } -static void perf_event__all64_swap(union perf_event *event) +static void swap_sample_id_all(union perf_event *event, void *data) +{ + void *end = (void *) event + event->header.size; + int size = end - data; + + BUG_ON(size % sizeof(u64)); + mem_bswap_64(data, size); +} + +static void perf_event__all64_swap(union perf_event *event, + bool sample_id_all __used) { struct perf_event_header *hdr = &event->header; mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr)); } -static void perf_event__comm_swap(union perf_event *event) +static void perf_event__comm_swap(union perf_event *event, bool sample_id_all) { event->comm.pid = bswap_32(event->comm.pid); event->comm.tid = bswap_32(event->comm.tid); + + if (sample_id_all) { + void *data = &event->comm.comm; + + data += ALIGN(strlen(data) + 1, sizeof(u64)); + swap_sample_id_all(event, data); + } } -static void perf_event__mmap_swap(union perf_event *event) +static void perf_event__mmap_swap(union perf_event *event, + bool sample_id_all) { event->mmap.pid = bswap_32(event->mmap.pid); event->mmap.tid = bswap_32(event->mmap.tid); event->mmap.start = bswap_64(event->mmap.start); event->mmap.len = bswap_64(event->mmap.len); event->mmap.pgoff = bswap_64(event->mmap.pgoff); + + if (sample_id_all) { + void *data = &event->mmap.filename; + + data += ALIGN(strlen(data) + 1, sizeof(u64)); + swap_sample_id_all(event, data); + } } -static void perf_event__task_swap(union perf_event *event) +static void perf_event__task_swap(union perf_event *event, bool sample_id_all) { event->fork.pid = bswap_32(event->fork.pid); event->fork.tid = bswap_32(event->fork.tid); event->fork.ppid = bswap_32(event->fork.ppid); event->fork.ptid = bswap_32(event->fork.ptid); event->fork.time = bswap_64(event->fork.time); + + if (sample_id_all) + swap_sample_id_all(event, &event->fork + 1); } -static void perf_event__read_swap(union perf_event *event) +static void perf_event__read_swap(union perf_event *event, bool sample_id_all) { event->read.pid = bswap_32(event->read.pid); event->read.tid = bswap_32(event->read.tid); @@ -479,6 +520,9 @@ static void perf_event__read_swap(union perf_event *event) event->read.time_enabled = bswap_64(event->read.time_enabled); event->read.time_running = bswap_64(event->read.time_running); event->read.id = bswap_64(event->read.id); + + if (sample_id_all) + swap_sample_id_all(event, &event->read + 1); } static u8 revbyte(u8 b) @@ -530,7 +574,8 @@ void perf_event__attr_swap(struct perf_event_attr *attr) swap_bitfield((u8 *) (&attr->read_format + 1), sizeof(u64)); } -static void perf_event__hdr_attr_swap(union perf_event *event) +static void perf_event__hdr_attr_swap(union perf_event *event, + bool sample_id_all __used) { size_t size; @@ -541,18 +586,21 @@ static void perf_event__hdr_attr_swap(union perf_event *event) mem_bswap_64(event->attr.id, size); } -static void perf_event__event_type_swap(union perf_event *event) +static void perf_event__event_type_swap(union perf_event *event, + bool sample_id_all __used) { event->event_type.event_type.event_id = bswap_64(event->event_type.event_type.event_id); } -static void perf_event__tracing_data_swap(union perf_event *event) +static void perf_event__tracing_data_swap(union perf_event *event, + bool sample_id_all __used) { event->tracing_data.size = bswap_32(event->tracing_data.size); } -typedef void (*perf_event__swap_op)(union perf_event *event); +typedef void (*perf_event__swap_op)(union perf_event *event, + bool sample_id_all); static perf_event__swap_op perf_event__swap_ops[] = { [PERF_RECORD_MMAP] = perf_event__mmap_swap, @@ -986,6 +1034,15 @@ static int perf_session__process_user_event(struct perf_session *session, union } } +static void event_swap(union perf_event *event, bool sample_id_all) +{ + perf_event__swap_op swap; + + swap = perf_event__swap_ops[event->header.type]; + if (swap) + swap(event, sample_id_all); +} + static int perf_session__process_event(struct perf_session *session, union perf_event *event, struct perf_tool *tool, @@ -994,9 +1051,8 @@ static int perf_session__process_event(struct perf_session *session, struct perf_sample sample; int ret; - if (session->header.needs_swap && - perf_event__swap_ops[event->header.type]) - perf_event__swap_ops[event->header.type](event); + if (session->header.needs_swap) + event_swap(event, session->sample_id_all); if (event->header.type >= PERF_RECORD_HEADER_MAX) return -EINVAL; @@ -1428,7 +1484,6 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, int print_sym, int print_dso, int print_symoffset) { struct addr_location al; - struct callchain_cursor *cursor = &evsel->hists.callchain_cursor; struct callchain_cursor_node *node; if (perf_event__preprocess_sample(event, machine, &al, sample, @@ -1446,10 +1501,10 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, error("Failed to resolve callchain. Skipping\n"); return; } - callchain_cursor_commit(cursor); + callchain_cursor_commit(&callchain_cursor); while (1) { - node = callchain_cursor_current(cursor); + node = callchain_cursor_current(&callchain_cursor); if (!node) break; @@ -1460,12 +1515,12 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, } if (print_dso) { printf(" ("); - map__fprintf_dsoname(al.map, stdout); + map__fprintf_dsoname(node->map, stdout); printf(")"); } printf("\n"); - callchain_cursor_advance(cursor); + callchain_cursor_advance(&callchain_cursor); } } else { diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index ab9867b2b43..3e2e5ea0f03 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -323,6 +323,7 @@ struct dso *dso__new(const char *name) dso->sorted_by_name = 0; dso->has_build_id = 0; dso->kernel = DSO_TYPE_USER; + dso->needs_swap = DSO_SWAP__UNSET; INIT_LIST_HEAD(&dso->node); } @@ -1156,6 +1157,33 @@ static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) return -1; } +static int dso__swap_init(struct dso *dso, unsigned char eidata) +{ + static unsigned int const endian = 1; + + dso->needs_swap = DSO_SWAP__NO; + + switch (eidata) { + case ELFDATA2LSB: + /* We are big endian, DSO is little endian. */ + if (*(unsigned char const *)&endian != 1) + dso->needs_swap = DSO_SWAP__YES; + break; + + case ELFDATA2MSB: + /* We are little endian, DSO is big endian. */ + if (*(unsigned char const *)&endian != 0) + dso->needs_swap = DSO_SWAP__YES; + break; + + default: + pr_err("unrecognized DSO data encoding %d\n", eidata); + return -EINVAL; + } + + return 0; +} + static int dso__load_sym(struct dso *dso, struct map *map, const char *name, int fd, symbol_filter_t filter, int kmodule, int want_symtab) @@ -1187,6 +1215,9 @@ static int dso__load_sym(struct dso *dso, struct map *map, const char *name, goto out_elf_end; } + if (dso__swap_init(dso, ehdr.e_ident[EI_DATA])) + goto out_elf_end; + /* Always reject images with a mismatched build-id: */ if (dso->has_build_id) { u8 build_id[BUILD_ID_SIZE]; @@ -1272,7 +1303,7 @@ static int dso__load_sym(struct dso *dso, struct map *map, const char *name, if (opdsec && sym.st_shndx == opdidx) { u32 offset = sym.st_value - opdshdr.sh_addr; u64 *opd = opddata->d_buf + offset; - sym.st_value = *opd; + sym.st_value = DSO__SWAP(dso, u64, *opd); sym.st_shndx = elf_addr_to_index(elf, sym.st_value); } @@ -2783,3 +2814,14 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type, return ret; } + +struct map *dso__new_map(const char *name) +{ + struct map *map = NULL; + struct dso *dso = dso__new(name); + + if (dso) + map = map__new2(0, dso, MAP__FUNCTION); + + return map; +} diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 1f003884f1a..af0752b1aca 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -9,6 +9,7 @@ #include <linux/list.h> #include <linux/rbtree.h> #include <stdio.h> +#include <byteswap.h> #ifdef HAVE_CPLUS_DEMANGLE extern char *cplus_demangle(const char *, int); @@ -160,11 +161,18 @@ enum dso_kernel_type { DSO_TYPE_GUEST_KERNEL }; +enum dso_swap_type { + DSO_SWAP__UNSET, + DSO_SWAP__NO, + DSO_SWAP__YES, +}; + struct dso { struct list_head node; struct rb_root symbols[MAP__NR_TYPES]; struct rb_root symbol_names[MAP__NR_TYPES]; enum dso_kernel_type kernel; + enum dso_swap_type needs_swap; u8 adjust_symbols:1; u8 has_build_id:1; u8 hit:1; @@ -182,6 +190,28 @@ struct dso { char name[0]; }; +#define DSO__SWAP(dso, type, val) \ +({ \ + type ____r = val; \ + BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \ + if (dso->needs_swap == DSO_SWAP__YES) { \ + switch (sizeof(____r)) { \ + case 2: \ + ____r = bswap_16(val); \ + break; \ + case 4: \ + ____r = bswap_32(val); \ + break; \ + case 8: \ + ____r = bswap_64(val); \ + break; \ + default: \ + BUG_ON(1); \ + } \ + } \ + ____r; \ +}) + struct dso *dso__new(const char *name); void dso__delete(struct dso *dso); @@ -242,6 +272,7 @@ void dso__set_long_name(struct dso *dso, char *name); void dso__set_build_id(struct dso *dso, void *build_id); void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine); +struct map *dso__new_map(const char *name); struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, u64 addr); struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 84d9bd78200..9b5f856cc28 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -188,28 +188,27 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str) nt = realloc(threads, (sizeof(*threads) + sizeof(pid_t) * total_tasks)); if (nt == NULL) - goto out_free_threads; + goto out_free_namelist; threads = nt; - if (threads) { - for (i = 0; i < items; i++) - threads->map[j++] = atoi(namelist[i]->d_name); - threads->nr = total_tasks; - } - - for (i = 0; i < items; i++) + for (i = 0; i < items; i++) { + threads->map[j++] = atoi(namelist[i]->d_name); free(namelist[i]); + } + threads->nr = total_tasks; free(namelist); - - if (!threads) - break; } out: strlist__delete(slist); return threads; +out_free_namelist: + for (i = 0; i < items; i++) + free(namelist[i]); + free(namelist); + out_free_threads: free(threads); threads = NULL; |