diff options
Diffstat (limited to 'tools/perf/ui')
-rw-r--r-- | tools/perf/ui/browser.c | 2 | ||||
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 21 | ||||
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 150 | ||||
-rw-r--r-- | tools/perf/ui/browsers/hists.h | 32 | ||||
-rw-r--r-- | tools/perf/ui/gtk/hists.c | 4 | ||||
-rw-r--r-- | tools/perf/ui/gtk/util.c | 1 | ||||
-rw-r--r-- | tools/perf/ui/helpline.c | 1 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 13 | ||||
-rw-r--r-- | tools/perf/ui/setup.c | 7 | ||||
-rw-r--r-- | tools/perf/ui/stdio/hist.c | 133 | ||||
-rw-r--r-- | tools/perf/ui/tui/setup.c | 2 | ||||
-rw-r--r-- | tools/perf/ui/ui.h | 4 |
12 files changed, 227 insertions, 143 deletions
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index af68a9d488bf..3eb3edb307a4 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c @@ -1,5 +1,5 @@ #include "../util.h" -#include "../cache.h" +#include "../config.h" #include "../../perf.h" #include "libslang.h" #include "ui.h" diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 4fc208e82c6f..29dc6d20364e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -8,6 +8,7 @@ #include "../../util/sort.h" #include "../../util/symbol.h" #include "../../util/evsel.h" +#include "../../util/config.h" #include <pthread.h> struct disasm_line_samples { @@ -222,16 +223,14 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int } else if (ins__is_call(dl->ins)) { ui_browser__write_graph(browser, SLSMG_RARROW_CHAR); SLsmg_write_char(' '); + } else if (ins__is_ret(dl->ins)) { + ui_browser__write_graph(browser, SLSMG_LARROW_CHAR); + SLsmg_write_char(' '); } else { ui_browser__write_nstring(browser, " ", 2); } } else { - if (strcmp(dl->name, "retq")) { - ui_browser__write_nstring(browser, " ", 2); - } else { - ui_browser__write_graph(browser, SLSMG_LARROW_CHAR); - SLsmg_write_char(' '); - } + ui_browser__write_nstring(browser, " ", 2); } disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset); @@ -842,14 +841,14 @@ show_help: ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org"); else if (browser->selection->offset == -1) ui_helpline__puts("Actions are only available for assembly lines."); - else if (!browser->selection->ins) { - if (strcmp(browser->selection->name, "retq")) - goto show_sup_ins; + else if (!browser->selection->ins) + goto show_sup_ins; + else if (ins__is_ret(browser->selection->ins)) goto out; - } else if (!(annotate_browser__jump(browser) || + else if (!(annotate_browser__jump(browser) || annotate_browser__callq(browser, evsel, hbt))) { show_sup_ins: - ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); + ui_helpline__puts("Actions are only available for function call/return & jump/branch instructions."); } continue; case 't': diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 538bae880bfe..13d414384739 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -12,35 +12,17 @@ #include "../../util/top.h" #include "../../arch/common.h" -#include "../browser.h" +#include "../browsers/hists.h" #include "../helpline.h" #include "../util.h" #include "../ui.h" #include "map.h" #include "annotate.h" -struct hist_browser { - struct ui_browser b; - struct hists *hists; - struct hist_entry *he_selection; - struct map_symbol *selection; - struct hist_browser_timer *hbt; - struct pstack *pstack; - struct perf_env *env; - int print_seq; - bool show_dso; - bool show_headers; - float min_pcnt; - u64 nr_non_filtered_entries; - u64 nr_hierarchy_entries; - u64 nr_callchain_rows; -}; - extern void hist_browser__init_hpp(void); -static int hists__browser_title(struct hists *hists, - struct hist_browser_timer *hbt, - char *bf, size_t size); +static int perf_evsel_browser_title(struct hist_browser *browser, + char *bf, size_t size); static void hist_browser__update_nr_entries(struct hist_browser *hb); static struct rb_node *hists__filter_entries(struct rb_node *nd, @@ -585,7 +567,12 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser) "Or reduce the sampling frequency."); } -static int hist_browser__run(struct hist_browser *browser, const char *help) +static int hist_browser__title(struct hist_browser *browser, char *bf, size_t size) +{ + return browser->title ? browser->title(browser, bf, size) : 0; +} + +int hist_browser__run(struct hist_browser *browser, const char *help) { int key; char title[160]; @@ -595,7 +582,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *help) browser->b.entries = &browser->hists->entries; browser->b.nr_entries = hist_browser__nr_entries(browser); - hists__browser_title(browser->hists, hbt, title, sizeof(title)); + hist_browser__title(browser, title, sizeof(title)); if (ui_browser__show(&browser->b, title, "%s", help) < 0) return -1; @@ -621,8 +608,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *help) ui_browser__warn_lost_events(&browser->b); } - hists__browser_title(browser->hists, - hbt, title, sizeof(title)); + hist_browser__title(browser, title, sizeof(title)); ui_browser__show_title(&browser->b, title); continue; } @@ -1470,7 +1456,7 @@ static int hist_browser__show_no_entry(struct hist_browser *browser, column++ < browser->b.horiz_scroll) continue; - ret = fmt->width(fmt, NULL, hists_to_evsel(browser->hists)); + ret = fmt->width(fmt, NULL, browser->hists); if (first) { /* for folded sign */ @@ -1531,7 +1517,7 @@ static int hists_browser__scnprintf_headers(struct hist_browser *browser, char * if (perf_hpp__should_skip(fmt, hists) || column++ < browser->b.horiz_scroll) continue; - ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); + ret = fmt->header(fmt, &dummy_hpp, hists); if (advance_hpp_check(&dummy_hpp, ret)) break; @@ -1568,7 +1554,7 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows if (column++ < browser->b.horiz_scroll) continue; - ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); + ret = fmt->header(fmt, &dummy_hpp, hists); if (advance_hpp_check(&dummy_hpp, ret)) break; @@ -1605,7 +1591,7 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows } first_col = false; - ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); + ret = fmt->header(fmt, &dummy_hpp, hists); dummy_hpp.buf[ret] = '\0'; start = trim(dummy_hpp.buf); @@ -1622,21 +1608,38 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows return ret; } -static void hist_browser__show_headers(struct hist_browser *browser) +static void hists_browser__hierarchy_headers(struct hist_browser *browser) { char headers[1024]; - if (symbol_conf.report_hierarchy) - hists_browser__scnprintf_hierarchy_headers(browser, headers, - sizeof(headers)); - else - hists_browser__scnprintf_headers(browser, headers, - sizeof(headers)); + hists_browser__scnprintf_hierarchy_headers(browser, headers, + sizeof(headers)); + + ui_browser__gotorc(&browser->b, 0, 0); + ui_browser__set_color(&browser->b, HE_COLORSET_ROOT); + ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1); +} + +static void hists_browser__headers(struct hist_browser *browser) +{ + char headers[1024]; + + hists_browser__scnprintf_headers(browser, headers, + sizeof(headers)); + ui_browser__gotorc(&browser->b, 0, 0); ui_browser__set_color(&browser->b, HE_COLORSET_ROOT); ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1); } +static void hist_browser__show_headers(struct hist_browser *browser) +{ + if (symbol_conf.report_hierarchy) + hists_browser__hierarchy_headers(browser); + else + hists_browser__headers(browser); +} + static void ui_browser__hists_init_top(struct ui_browser *browser) { if (browser->top == NULL) { @@ -2026,7 +2029,7 @@ static int hist_browser__dump(struct hist_browser *browser) fp = fopen(filename, "w"); if (fp == NULL) { char bf[64]; - const char *err = strerror_r(errno, bf, sizeof(bf)); + const char *err = str_error_r(errno, bf, sizeof(bf)); ui_helpline__fpush("Couldn't write to %s: %s", filename, err); return -1; } @@ -2039,27 +2042,50 @@ static int hist_browser__dump(struct hist_browser *browser) return 0; } -static struct hist_browser *hist_browser__new(struct hists *hists, - struct hist_browser_timer *hbt, - struct perf_env *env) +void hist_browser__init(struct hist_browser *browser, + struct hists *hists) +{ + struct perf_hpp_fmt *fmt; + + browser->hists = hists; + browser->b.refresh = hist_browser__refresh; + browser->b.refresh_dimensions = hist_browser__refresh_dimensions; + browser->b.seek = ui_browser__hists_seek; + browser->b.use_navkeypressed = true; + browser->show_headers = symbol_conf.show_hist_headers; + + hists__for_each_format(hists, fmt) { + perf_hpp__reset_width(fmt, hists); + ++browser->b.columns; + } +} + +struct hist_browser *hist_browser__new(struct hists *hists) { struct hist_browser *browser = zalloc(sizeof(*browser)); + if (browser) + hist_browser__init(browser, hists); + + return browser; +} + +static struct hist_browser * +perf_evsel_browser__new(struct perf_evsel *evsel, + struct hist_browser_timer *hbt, + struct perf_env *env) +{ + struct hist_browser *browser = hist_browser__new(evsel__hists(evsel)); + if (browser) { - browser->hists = hists; - browser->b.refresh = hist_browser__refresh; - browser->b.refresh_dimensions = hist_browser__refresh_dimensions; - browser->b.seek = ui_browser__hists_seek; - browser->b.use_navkeypressed = true; - browser->show_headers = symbol_conf.show_hist_headers; - browser->hbt = hbt; - browser->env = env; + browser->hbt = hbt; + browser->env = env; + browser->title = perf_evsel_browser_title; } - return browser; } -static void hist_browser__delete(struct hist_browser *browser) +void hist_browser__delete(struct hist_browser *browser) { free(browser); } @@ -2080,10 +2106,11 @@ static inline bool is_report_browser(void *timer) return timer == NULL; } -static int hists__browser_title(struct hists *hists, - struct hist_browser_timer *hbt, +static int perf_evsel_browser_title(struct hist_browser *browser, char *bf, size_t size) { + struct hist_browser_timer *hbt = browser->hbt; + struct hists *hists = browser->hists; char unit; int printed; const struct dso *dso = hists->dso_filter; @@ -2640,7 +2667,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, struct perf_env *env) { struct hists *hists = evsel__hists(evsel); - struct hist_browser *browser = hist_browser__new(hists, hbt, env); + struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env); struct branch_info *bi; #define MAX_OPTIONS 16 char *options[MAX_OPTIONS]; @@ -2649,7 +2676,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, int key = -1; char buf[64]; int delay_secs = hbt ? hbt->refresh : 0; - struct perf_hpp_fmt *fmt; #define HIST_BROWSER_HELP_COMMON \ "h/?/F1 Show this window\n" \ @@ -2708,18 +2734,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, memset(options, 0, sizeof(options)); memset(actions, 0, sizeof(actions)); - hists__for_each_format(browser->hists, fmt) { - perf_hpp__reset_width(fmt, hists); - /* - * This is done just once, and activates the horizontal scrolling - * code in the ui_browser code, it would be better to have a the - * counter in the perf_hpp code, but I couldn't find doing it here - * works, FIXME by setting this in hist_browser__new, for now, be - * clever 8-) - */ - ++browser->b.columns; - } - if (symbol_conf.col_width_list_str) perf_hpp__set_user_width(symbol_conf.col_width_list_str); @@ -3185,7 +3199,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, ui_helpline__push("Press ESC to exit"); - evlist__for_each(evlist, pos) { + evlist__for_each_entry(evlist, pos) { const char *ev_name = perf_evsel__name(pos); size_t line_len = strlen(ev_name) + 7; @@ -3216,7 +3230,7 @@ single_entry: struct perf_evsel *pos; nr_entries = 0; - evlist__for_each(evlist, pos) { + evlist__for_each_entry(evlist, pos) { if (perf_evsel__is_group_leader(pos)) nr_entries++; } diff --git a/tools/perf/ui/browsers/hists.h b/tools/perf/ui/browsers/hists.h new file mode 100644 index 000000000000..39bd0f28f211 --- /dev/null +++ b/tools/perf/ui/browsers/hists.h @@ -0,0 +1,32 @@ +#ifndef _PERF_UI_BROWSER_HISTS_H_ +#define _PERF_UI_BROWSER_HISTS_H_ 1 + +#include "ui/browser.h" + +struct hist_browser { + struct ui_browser b; + struct hists *hists; + struct hist_entry *he_selection; + struct map_symbol *selection; + struct hist_browser_timer *hbt; + struct pstack *pstack; + struct perf_env *env; + int print_seq; + bool show_dso; + bool show_headers; + float min_pcnt; + u64 nr_non_filtered_entries; + u64 nr_hierarchy_entries; + u64 nr_callchain_rows; + + /* Get title string. */ + int (*title)(struct hist_browser *browser, + char *bf, size_t size); +}; + +struct hist_browser *hist_browser__new(struct hists *hists); +void hist_browser__delete(struct hist_browser *browser); +int hist_browser__run(struct hist_browser *browser, const char *help); +void hist_browser__init(struct hist_browser *browser, + struct hists *hists); +#endif /* _PERF_UI_BROWSER_HISTS_H_ */ diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 932adfaa05af..c5f3677f6679 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c @@ -549,7 +549,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists, strcat(buf, "+"); first_col = false; - fmt->header(fmt, &hpp, hists_to_evsel(hists)); + fmt->header(fmt, &hpp, hists); strcat(buf, ltrim(rtrim(hpp.buf))); } } @@ -627,7 +627,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, gtk_container_add(GTK_CONTAINER(window), vbox); - evlist__for_each(evlist, pos) { + evlist__for_each_entry(evlist, pos) { struct hists *hists = evsel__hists(pos); const char *evname = perf_evsel__name(pos); GtkWidget *scrolled_window; diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c index 52e7fc48af9f..00b91921edb1 100644 --- a/tools/perf/ui/gtk/util.c +++ b/tools/perf/ui/gtk/util.c @@ -1,4 +1,5 @@ #include "../util.h" +#include "../../util/util.h" #include "../../util/debug.h" #include "gtk.h" diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/helpline.c index 700fb3cfa1c7..5b74a7eba210 100644 --- a/tools/perf/ui/helpline.c +++ b/tools/perf/ui/helpline.c @@ -5,6 +5,7 @@ #include "../debug.h" #include "helpline.h" #include "ui.h" +#include "../util.h" char ui_helpline__current[512]; diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index af07ffb129ca..4274969ddc89 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -215,9 +215,10 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b, static int hpp__width_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp __maybe_unused, - struct perf_evsel *evsel) + struct hists *hists) { int len = fmt->user_len ?: fmt->len; + struct perf_evsel *evsel = hists_to_evsel(hists); if (symbol_conf.event_group) len = max(len, evsel->nr_members * fmt->len); @@ -229,9 +230,9 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt, } static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, - struct perf_evsel *evsel) + struct hists *hists) { - int len = hpp__width_fn(fmt, hpp, evsel); + int len = hpp__width_fn(fmt, hpp, hists); return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name); } @@ -632,7 +633,7 @@ unsigned int hists__sort_list_width(struct hists *hists) else ret += 2; - ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); + ret += fmt->width(fmt, &dummy_hpp, hists); } if (verbose && hists__has(hists, sym)) /* Addr + origin */ @@ -657,7 +658,7 @@ unsigned int hists__overhead_width(struct hists *hists) else ret += 2; - ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); + ret += fmt->width(fmt, &dummy_hpp, hists); } return ret; @@ -765,7 +766,7 @@ int perf_hpp__setup_hists_formats(struct perf_hpp_list *list, if (!symbol_conf.report_hierarchy) return 0; - evlist__for_each(evlist, evsel) { + evlist__for_each_entry(evlist, evsel) { hists = evsel__hists(evsel); perf_hpp_list__for_each_sort_list(list, fmt) { diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index ba51fa8a1176..1f6b0994f4f4 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c @@ -60,6 +60,13 @@ static inline int setup_gtk_browser(void) { return -1; } static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {} #endif +int stdio__config_color(const struct option *opt __maybe_unused, + const char *mode, int unset __maybe_unused) +{ + perf_use_color_default = perf_config_colorbool("color.ui", mode, -1); + return 0; +} + void setup_browser(bool fallback_to_pager) { if (use_browser < 2 && (!isatty(1) || dump_trace)) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 560eb47d56f9..f04a63112079 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -492,14 +492,15 @@ out: } static int hist_entry__fprintf(struct hist_entry *he, size_t size, - struct hists *hists, - char *bf, size_t bfsz, FILE *fp) + char *bf, size_t bfsz, FILE *fp, + bool use_callchain) { int ret; struct perf_hpp hpp = { .buf = bf, .size = size, }; + struct hists *hists = he->hists; u64 total_period = hists->stats.total_period; if (size == 0 || size > bfsz) @@ -512,7 +513,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ret = fprintf(fp, "%s\n", bf); - if (symbol_conf.use_callchain) + if (use_callchain) ret += hist_entry_callchain__fprintf(he, total_period, 0, fp); return ret; @@ -548,7 +549,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp, struct perf_hpp_list_node, list); perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { - fmt->header(fmt, hpp, hists_to_evsel(hists)); + fmt->header(fmt, hpp, hists); fprintf(fp, "%s%s", hpp->buf, sep ?: " "); } @@ -568,7 +569,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp, header_width += fprintf(fp, "+"); first_col = false; - fmt->header(fmt, hpp, hists_to_evsel(hists)); + fmt->header(fmt, hpp, hists); header_width += fprintf(fp, "%s", trim(hpp->buf)); } @@ -589,7 +590,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp, fprintf(fp, "%s", sep ?: ".."); first_col = false; - width = fmt->width(fmt, hpp, hists_to_evsel(hists)); + width = fmt->width(fmt, hpp, hists); fprintf(fp, "%.*s", width, dots); } @@ -606,7 +607,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp, width++; /* for '+' sign between column header */ first_col = false; - width += fmt->width(fmt, hpp, hists_to_evsel(hists)); + width += fmt->width(fmt, hpp, hists); } if (width > header_width) @@ -622,47 +623,31 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp, return 2; } -size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, - int max_cols, float min_pcnt, FILE *fp) +static int +hists__fprintf_hierarchy_headers(struct hists *hists, + struct perf_hpp *hpp, + FILE *fp) { - struct perf_hpp_fmt *fmt; struct perf_hpp_list_node *fmt_node; - struct rb_node *nd; - size_t ret = 0; - unsigned int width; - const char *sep = symbol_conf.field_sep; - int nr_rows = 0; - char bf[96]; - struct perf_hpp dummy_hpp = { - .buf = bf, - .size = sizeof(bf), - }; - bool first = true; - size_t linesz; - char *line = NULL; - unsigned indent; - - init_rem_hits(); - - hists__for_each_format(hists, fmt) - perf_hpp__reset_width(fmt, hists); - - if (symbol_conf.col_width_list_str) - perf_hpp__set_user_width(symbol_conf.col_width_list_str); + struct perf_hpp_fmt *fmt; - if (!show_header) - goto print_entries; + list_for_each_entry(fmt_node, &hists->hpp_formats, list) { + perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) + perf_hpp__reset_width(fmt, hists); + } - fprintf(fp, "# "); + return print_hierarchy_header(hists, hpp, symbol_conf.field_sep, fp); +} - if (symbol_conf.report_hierarchy) { - list_for_each_entry(fmt_node, &hists->hpp_formats, list) { - perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) - perf_hpp__reset_width(fmt, hists); - } - nr_rows += print_hierarchy_header(hists, &dummy_hpp, sep, fp); - goto print_entries; - } +static int +hists__fprintf_standard_headers(struct hists *hists, + struct perf_hpp *hpp, + FILE *fp) +{ + struct perf_hpp_fmt *fmt; + unsigned int width; + const char *sep = symbol_conf.field_sep; + bool first = true; hists__for_each_format(hists, fmt) { if (perf_hpp__should_skip(fmt, hists)) @@ -673,16 +658,14 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, else first = false; - fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); - fprintf(fp, "%s", bf); + fmt->header(fmt, hpp, hists); + fprintf(fp, "%s", hpp->buf); } fprintf(fp, "\n"); - if (max_rows && ++nr_rows >= max_rows) - goto out; if (sep) - goto print_entries; + return 1; first = true; @@ -699,20 +682,60 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, else first = false; - width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); + width = fmt->width(fmt, hpp, hists); for (i = 0; i < width; i++) fprintf(fp, "."); } fprintf(fp, "\n"); - if (max_rows && ++nr_rows >= max_rows) - goto out; - fprintf(fp, "#\n"); - if (max_rows && ++nr_rows >= max_rows) + return 3; +} + +static int hists__fprintf_headers(struct hists *hists, FILE *fp) +{ + char bf[96]; + struct perf_hpp dummy_hpp = { + .buf = bf, + .size = sizeof(bf), + }; + + fprintf(fp, "# "); + + if (symbol_conf.report_hierarchy) + return hists__fprintf_hierarchy_headers(hists, &dummy_hpp, fp); + else + return hists__fprintf_standard_headers(hists, &dummy_hpp, fp); + +} + +size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, + int max_cols, float min_pcnt, FILE *fp, + bool use_callchain) +{ + struct perf_hpp_fmt *fmt; + struct rb_node *nd; + size_t ret = 0; + const char *sep = symbol_conf.field_sep; + int nr_rows = 0; + size_t linesz; + char *line = NULL; + unsigned indent; + + init_rem_hits(); + + hists__for_each_format(hists, fmt) + perf_hpp__reset_width(fmt, hists); + + if (symbol_conf.col_width_list_str) + perf_hpp__set_user_width(symbol_conf.col_width_list_str); + + if (show_header) + nr_rows += hists__fprintf_headers(hists, fp); + + if (max_rows && nr_rows >= max_rows) goto out; -print_entries: linesz = hists__sort_list_width(hists) + 3 + 1; linesz += perf_hpp__color_overhead(); line = malloc(linesz); @@ -734,7 +757,7 @@ print_entries: if (percent < min_pcnt) continue; - ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp); + ret += hist_entry__fprintf(h, max_cols, line, linesz, fp, use_callchain); if (max_rows && ++nr_rows >= max_rows) break; diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c index 7dfeba0a91f3..4ea2ba861fc2 100644 --- a/tools/perf/ui/tui/setup.c +++ b/tools/perf/ui/tui/setup.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <signal.h> #include <stdbool.h> #ifdef HAVE_BACKTRACE_SUPPORT @@ -6,6 +7,7 @@ #include "../../util/cache.h" #include "../../util/debug.h" +#include "../../util/util.h" #include "../browser.h" #include "../helpline.h" #include "../ui.h" diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h index ab88383f8be8..4b6fb6c7a542 100644 --- a/tools/perf/ui/ui.h +++ b/tools/perf/ui/ui.h @@ -26,4 +26,8 @@ static inline void ui__exit(bool wait_for_ok __maybe_unused) {} void ui__refresh_dimensions(bool force); +struct option; + +int stdio__config_color(const struct option *opt, const char *mode, int unset); + #endif /* _PERF_UI_H_ */ |