aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-01-22 04:09:35 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-31 11:07:46 -0500
commit5aed9d24934be5b7fec1b66cc2a5f29fab4ec11e (patch)
treed46484bda42163897be565be4103fef70de5581f /tools
parent4fb71074a570aab9ba8a30b7a756a3c637a14c03 (diff)
perf hists browser: Convert hpp helpers to a function
The hpp helpers do same job for each field so it was implemented as macro in order to access those fields easily. But it gets cumbersome to maintain a large function in a macro as the function grows. Factor it out to a function with a little helper macro to access field. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1358845787-1350-8-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-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);