Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
On Sat, 08 Sep 2012 23:05:43 +0900, Namhyung Kim wrote: > On Fri, 7 Sep 2012 17:32:18 -0700, Arnaldo Carvalho de Melo wrote: >> I folded the patch below so that we have the lines starting at column 1 >> like before, i.e. we were using " %5.2f" for the overhead and now you >> changed it to "%5.2f". > > Looks good to me. It wasn't good actually :-/ Simply because it cannot refresh the character at column 0 anymore. I will send a fix soon. Thanks, Namhyung -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
On Sat, 08 Sep 2012 23:05:43 +0900, Namhyung Kim wrote: On Fri, 7 Sep 2012 17:32:18 -0700, Arnaldo Carvalho de Melo wrote: I folded the patch below so that we have the lines starting at column 1 like before, i.e. we were using %5.2f for the overhead and now you changed it to %5.2f. Looks good to me. It wasn't good actually :-/ Simply because it cannot refresh the character at column 0 anymore. I will send a fix soon. Thanks, Namhyung -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
On Fri, 7 Sep 2012 17:32:18 -0700, Arnaldo Carvalho de Melo wrote: > Em Mon, Sep 03, 2012 at 11:53:09AM +0900, Namhyung Kim escreveu: >> From: Namhyung Kim >> >> 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: Namhyung Kim >> --- >> tools/perf/ui/browsers/hists.c | 94 >> -- >> tools/perf/ui/tui/setup.c | 4 ++ >> 2 files changed, 76 insertions(+), 22 deletions(-) >> >> diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c >> index 81bd8c2af730..144d7be2872e 100644 >> --- a/tools/perf/ui/browsers/hists.c >> +++ b/tools/perf/ui/browsers/hists.c >> @@ -28,6 +28,8 @@ struct hist_browser { >> bool has_symbols; >> }; >> >> +extern void hist_browser__init_hpp(void); > > I folded the patch below so that we have the lines starting at column 1 > like before, i.e. we were using " %5.2f" for the overhead and now you > changed it to "%5.2f". Looks good to me. Thanks, Namhyung > > diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c > index 144d7be..5a5739b 100644 > --- a/tools/perf/ui/browsers/hists.c > +++ b/tools/perf/ui/browsers/hists.c > @@ -605,7 +605,7 @@ static int hist_browser__show_entry(struct hist_browser > *browser, > char s[256]; > double percent; > int i, printed = 0; > - int width = browser->b.width; > + int width = browser->b.width - 1; > char folded_sign = ' '; > bool current_entry = ui_browser__is_current_entry(>b, row); > off_t row_offset = entry->row_offset; > @@ -627,7 +627,7 @@ static int hist_browser__show_entry(struct hist_browser > *browser, > .total_period = browser->hists->stats.total_period, > }; > > - ui_browser__gotorc(>b, row, 0); > + ui_browser__gotorc(>b, row, 1); > > for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { > if (!perf_hpp__format[i].cond) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
On Fri, 7 Sep 2012 17:32:18 -0700, Arnaldo Carvalho de Melo wrote: Em Mon, Sep 03, 2012 at 11:53:09AM +0900, Namhyung Kim escreveu: From: Namhyung Kim namhyung@lge.com 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: Namhyung Kim namhy...@kernel.org --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); I folded the patch below so that we have the lines starting at column 1 like before, i.e. we were using %5.2f for the overhead and now you changed it to %5.2f. Looks good to me. Thanks, Namhyung diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 144d7be..5a5739b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -605,7 +605,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, char s[256]; double percent; int i, printed = 0; - int width = browser-b.width; + int width = browser-b.width - 1; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(browser-b, row); off_t row_offset = entry-row_offset; @@ -627,7 +627,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, .total_period = browser-hists-stats.total_period, }; - ui_browser__gotorc(browser-b, row, 0); + ui_browser__gotorc(browser-b, row, 1); for (i = 0; i PERF_HPP__MAX_INDEX; i++) { if (!perf_hpp__format[i].cond) -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
Em Mon, Sep 03, 2012 at 11:53:09AM +0900, Namhyung Kim escreveu: > From: Namhyung Kim > > 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: Namhyung Kim > --- > tools/perf/ui/browsers/hists.c | 94 > -- > tools/perf/ui/tui/setup.c | 4 ++ > 2 files changed, 76 insertions(+), 22 deletions(-) > > diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c > index 81bd8c2af730..144d7be2872e 100644 > --- a/tools/perf/ui/browsers/hists.c > +++ b/tools/perf/ui/browsers/hists.c > @@ -28,6 +28,8 @@ struct hist_browser { > bool has_symbols; > }; > > +extern void hist_browser__init_hpp(void); I folded the patch below so that we have the lines starting at column 1 like before, i.e. we were using " %5.2f" for the overhead and now you changed it to "%5.2f". - Arnaldo diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 144d7be..5a5739b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -605,7 +605,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, char s[256]; double percent; int i, printed = 0; - int width = browser->b.width; + int width = browser->b.width - 1; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(>b, row); off_t row_offset = entry->row_offset; @@ -627,7 +627,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, .total_period = browser->hists->stats.total_period, }; - ui_browser__gotorc(>b, row, 0); + ui_browser__gotorc(>b, row, 1); for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { if (!perf_hpp__format[i].cond) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
Em Mon, Sep 03, 2012 at 11:53:09AM +0900, Namhyung Kim escreveu: From: Namhyung Kim namhyung@lge.com 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: Namhyung Kim namhy...@kernel.org --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); I folded the patch below so that we have the lines starting at column 1 like before, i.e. we were using %5.2f for the overhead and now you changed it to %5.2f. - Arnaldo diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 144d7be..5a5739b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -605,7 +605,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, char s[256]; double percent; int i, printed = 0; - int width = browser-b.width; + int width = browser-b.width - 1; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(browser-b, row); off_t row_offset = entry-row_offset; @@ -627,7 +627,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, .total_period = browser-hists-stats.total_period, }; - ui_browser__gotorc(browser-b, row, 0); + ui_browser__gotorc(browser-b, row, 1); for (i = 0; i PERF_HPP__MAX_INDEX; i++) { if (!perf_hpp__format[i].cond) -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
From: Namhyung Kim 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: Namhyung Kim --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); + static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name); @@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, 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, struct hist_entry *entry, unsigned short row) { char s[256]; double percent; - int printed = 0; - int width = browser->b.width - 6; /* The percentage */ + int i, printed = 0; + int width = browser->b.width; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(>b, row); off_t row_offset = entry->row_offset; @@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, } if (row_offset == 0) { - hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); - percent = (entry->period * 100.0) / browser->hists->stats.total_period; + struct perf_hpp hpp = { + .buf= s, + .size = sizeof(s), + .total_period = browser->hists->stats.total_period, + }; - ui_browser__set_percent_color(>b, percent, current_entry); ui_browser__gotorc(>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 (!browser->b.navkeypressed) - width += 1; + if (i) { + slsmg_printf(" "); + width -= 2; + } - if (!current_entry || !browser->b.navkeypressed) - ui_browser__set_color(>b, HE_COLORSET_NORMAL); + if (perf_hpp__format[i].color) { + hpp.ptr = + /* It will set percent for us. See HPP__COLOR_FN above. */ + width -= perf_hpp__format[i].color(, entry); - if (symbol_conf.show_nr_samples) { - slsmg_printf(" %11u", entry->nr_events); - width -= 12; - } + ui_browser__set_percent_color(>b, percent, current_entry); + +
[PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
From: Namhyung Kim namhyung@lge.com 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: Namhyung Kim namhy...@kernel.org --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); + static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name); @@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, 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, struct hist_entry *entry, unsigned short row) { char s[256]; double percent; - int printed = 0; - int width = browser-b.width - 6; /* The percentage */ + int i, printed = 0; + int width = browser-b.width; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(browser-b, row); off_t row_offset = entry-row_offset; @@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, } if (row_offset == 0) { - hist_entry__sort_snprintf(entry, s, sizeof(s), browser-hists); - percent = (entry-period * 100.0) / browser-hists-stats.total_period; + struct perf_hpp hpp = { + .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, 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 (!browser-b.navkeypressed) - width += 1; + if (i) { + slsmg_printf( ); + width -= 2; + } - if (!current_entry || !browser-b.navkeypressed) - ui_browser__set_color(browser-b, HE_COLORSET_NORMAL); + if (perf_hpp__format[i].color) { + 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) { - slsmg_printf( %11u, entry-nr_events); - width -= 12; - } +
[PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
From: Namhyung Kim 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: Namhyung Kim --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); + static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name); @@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, 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, struct hist_entry *entry, unsigned short row) { char s[256]; double percent; - int printed = 0; - int width = browser->b.width - 6; /* The percentage */ + int i, printed = 0; + int width = browser->b.width; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(>b, row); off_t row_offset = entry->row_offset; @@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, } if (row_offset == 0) { - hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); - percent = (entry->period * 100.0) / browser->hists->stats.total_period; + struct perf_hpp hpp = { + .buf= s, + .size = sizeof(s), + .total_period = browser->hists->stats.total_period, + }; - ui_browser__set_percent_color(>b, percent, current_entry); ui_browser__gotorc(>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 (!browser->b.navkeypressed) - width += 1; + if (i) { + slsmg_printf(" "); + width -= 2; + } - if (!current_entry || !browser->b.navkeypressed) - ui_browser__set_color(>b, HE_COLORSET_NORMAL); + if (perf_hpp__format[i].color) { + hpp.ptr = + /* It will set percent for us. See HPP__COLOR_FN above. */ + width -= perf_hpp__format[i].color(, entry); - if (symbol_conf.show_nr_samples) { - slsmg_printf(" %11u", entry->nr_events); - width -= 12; - } + ui_browser__set_percent_color(>b, percent, current_entry); + +
[PATCH 4/5] perf ui/browser: Use perf_hpp__format functions
From: Namhyung Kim namhyung@lge.com 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: Namhyung Kim namhy...@kernel.org --- tools/perf/ui/browsers/hists.c | 94 -- tools/perf/ui/tui/setup.c | 4 ++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..144d7be2872e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -28,6 +28,8 @@ struct hist_browser { bool has_symbols; }; +extern void hist_browser__init_hpp(void); + static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name); @@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, 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, struct hist_entry *entry, unsigned short row) { char s[256]; double percent; - int printed = 0; - int width = browser-b.width - 6; /* The percentage */ + int i, printed = 0; + int width = browser-b.width; char folded_sign = ' '; bool current_entry = ui_browser__is_current_entry(browser-b, row); off_t row_offset = entry-row_offset; @@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, } if (row_offset == 0) { - hist_entry__sort_snprintf(entry, s, sizeof(s), browser-hists); - percent = (entry-period * 100.0) / browser-hists-stats.total_period; + struct perf_hpp hpp = { + .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, 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 (!browser-b.navkeypressed) - width += 1; + if (i) { + slsmg_printf( ); + width -= 2; + } - if (!current_entry || !browser-b.navkeypressed) - ui_browser__set_color(browser-b, HE_COLORSET_NORMAL); + if (perf_hpp__format[i].color) { + 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) { - slsmg_printf( %11u, entry-nr_events); - width -= 12; - } +