Commit f5951d56 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf hists browser: Use perf_hpp__format functions

Override hpp->color functions for TUI. Because line coloring is done
outside of the function, it just sets the percent value and pass it.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1346640790-17197-5-git-send-email-namhyung@kernel.org
[ committer note: Keep previous layout by showing the overhead at column 1 ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7e62ef44
...@@ -28,6 +28,8 @@ struct hist_browser { ...@@ -28,6 +28,8 @@ struct hist_browser {
bool has_symbols; bool has_symbols;
}; };
extern void hist_browser__init_hpp(void);
static int hists__browser_title(struct hists *hists, char *bf, size_t size, static int hists__browser_title(struct hists *hists, char *bf, size_t size,
const char *ev_name); const char *ev_name);
...@@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, ...@@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
return row - first_row; return row - first_row;
} }
#define HPP__COLOR_FN(_name, _field) \
static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \
struct hist_entry *he) \
{ \
double percent = 100.0 * he->_field / hpp->total_period; \
*(double *)hpp->ptr = percent; \
return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); \
}
HPP__COLOR_FN(overhead, period)
HPP__COLOR_FN(overhead_sys, period_sys)
HPP__COLOR_FN(overhead_us, period_us)
HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
HPP__COLOR_FN(overhead_guest_us, period_guest_us)
#undef HPP__COLOR_FN
void hist_browser__init_hpp(void)
{
perf_hpp__init(false, false);
perf_hpp__format[PERF_HPP__OVERHEAD].color =
hist_browser__hpp_color_overhead;
perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
hist_browser__hpp_color_overhead_sys;
perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
hist_browser__hpp_color_overhead_us;
perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
hist_browser__hpp_color_overhead_guest_sys;
perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
hist_browser__hpp_color_overhead_guest_us;
}
static int hist_browser__show_entry(struct hist_browser *browser, static int hist_browser__show_entry(struct hist_browser *browser,
struct hist_entry *entry, struct hist_entry *entry,
unsigned short row) unsigned short row)
{ {
char s[256]; char s[256];
double percent; double percent;
int printed = 0; int i, printed = 0;
int width = browser->b.width - 6; /* The percentage */ int width = browser->b.width - 1;
char folded_sign = ' '; char folded_sign = ' ';
bool current_entry = ui_browser__is_current_entry(&browser->b, row); bool current_entry = ui_browser__is_current_entry(&browser->b, row);
off_t row_offset = entry->row_offset; off_t row_offset = entry->row_offset;
...@@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, ...@@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser,
} }
if (row_offset == 0) { if (row_offset == 0) {
hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); struct perf_hpp hpp = {
percent = (entry->period * 100.0) / browser->hists->stats.total_period; .buf = s,
.size = sizeof(s),
.total_period = browser->hists->stats.total_period,
};
ui_browser__set_percent_color(&browser->b, percent, current_entry); ui_browser__gotorc(&browser->b, row, 1);
ui_browser__gotorc(&browser->b, row, 0);
if (symbol_conf.use_callchain) {
slsmg_printf("%c ", folded_sign);
width -= 2;
}
slsmg_printf(" %5.2f%%", percent); for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
if (!perf_hpp__format[i].cond)
continue;
/* The scroll bar isn't being used */ if (i) {
if (!browser->b.navkeypressed) slsmg_printf(" ");
width += 1; width -= 2;
}
if (!current_entry || !browser->b.navkeypressed) if (perf_hpp__format[i].color) {
ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); hpp.ptr = &percent;
/* It will set percent for us. See HPP__COLOR_FN above. */
width -= perf_hpp__format[i].color(&hpp, entry);
if (symbol_conf.show_nr_samples) { ui_browser__set_percent_color(&browser->b, percent, current_entry);
slsmg_printf(" %11u", entry->nr_events);
width -= 12; if (i == 0 && symbol_conf.use_callchain) {
} slsmg_printf("%c ", folded_sign);
width -= 2;
}
slsmg_printf("%s", s);
if (symbol_conf.show_total_period) { if (!current_entry || !browser->b.navkeypressed)
slsmg_printf(" %12" PRIu64, entry->period); ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
width -= 13; } else {
width -= perf_hpp__format[i].entry(&hpp, entry);
slsmg_printf("%s", s);
}
} }
/* The scroll bar isn't being used */
if (!browser->b.navkeypressed)
width += 1;
hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
slsmg_write_nstring(s, width); slsmg_write_nstring(s, width);
++row; ++row;
++printed; ++printed;
......
...@@ -15,6 +15,8 @@ static volatile int ui__need_resize; ...@@ -15,6 +15,8 @@ static volatile int ui__need_resize;
extern struct perf_error_ops perf_tui_eops; extern struct perf_error_ops perf_tui_eops;
extern void hist_browser__init_hpp(void);
void ui__refresh_dimensions(bool force) void ui__refresh_dimensions(bool force)
{ {
if (force || ui__need_resize) { if (force || ui__need_resize) {
...@@ -124,6 +126,8 @@ int ui__init(void) ...@@ -124,6 +126,8 @@ int ui__init(void)
signal(SIGTERM, ui__signal); signal(SIGTERM, ui__signal);
perf_error__register(&perf_tui_eops); perf_error__register(&perf_tui_eops);
hist_browser__init_hpp();
out: out:
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment