aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/browsers/hists.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/ui/browsers/hists.c')
-rw-r--r--tools/perf/ui/browsers/hists.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 57b82c26cd05..46242deee8d2 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -567,23 +567,41 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
567 return row - first_row; 567 return row - first_row;
568} 568}
569 569
570#define HPP__COLOR_FN(_name, _field) \ 570static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
571static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ 571 u64 (*get_field)(struct hist_entry *))
572 struct hist_entry *he) \ 572{
573 int ret;
574 double percent = 0.0;
575 struct hists *hists = he->hists;
576
577 if (hists->stats.total_period)
578 percent = 100.0 * get_field(he) / hists->stats.total_period;
579
580 *(double *)hpp->ptr = percent;
581
582 ret = scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
583 return ret;
584}
585
586#define __HPP_COLOR_PERCENT_FN(_type, _field) \
587static u64 __hpp_get_##_field(struct hist_entry *he) \
588{ \
589 return he->stat._field; \
590} \
591 \
592static int hist_browser__hpp_color_##_type(struct perf_hpp *hpp, \
593 struct hist_entry *he) \
573{ \ 594{ \
574 struct hists *hists = he->hists; \ 595 return __hpp__color_fmt(hpp, he, __hpp_get_##_field); \
575 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
576 *(double *)hpp->ptr = percent; \
577 return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \
578} 596}
579 597
580HPP__COLOR_FN(overhead, period) 598__HPP_COLOR_PERCENT_FN(overhead, period)
581HPP__COLOR_FN(overhead_sys, period_sys) 599__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
582HPP__COLOR_FN(overhead_us, period_us) 600__HPP_COLOR_PERCENT_FN(overhead_us, period_us)
583HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) 601__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
584HPP__COLOR_FN(overhead_guest_us, period_guest_us) 602__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
585 603
586#undef HPP__COLOR_FN 604#undef __HPP_COLOR_PERCENT_FN
587 605
588void hist_browser__init_hpp(void) 606void hist_browser__init_hpp(void)
589{ 607{
@@ -646,7 +664,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
646 664
647 if (fmt->color) { 665 if (fmt->color) {
648 hpp.ptr = &percent; 666 hpp.ptr = &percent;
649 /* It will set percent for us. See HPP__COLOR_FN above. */ 667 /* It will set percent for us. See __hpp__color_fmt above. */
650 width -= fmt->color(&hpp, entry); 668 width -= fmt->color(&hpp, entry);
651 669
652 ui_browser__set_percent_color(&browser->b, percent, current_entry); 670 ui_browser__set_percent_color(&browser->b, percent, current_entry);