aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-01-22 04:09:36 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-31 11:07:46 -0500
commit843985e953ddcc3d57a62641b377c8d3222859e2 (patch)
tree47d1271f6ccc68b5edf0c225061fda9caa7b72b6 /tools
parent5aed9d24934be5b7fec1b66cc2a5f29fab4ec11e (diff)
perf gtk/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: Pekka Enberg <penberg@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1358845787-1350-9-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/gtk/hists.c68
1 files changed, 47 insertions, 21 deletions
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index c03da79d524f..38be79d4b5c6 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -8,32 +8,58 @@
8 8
9#define MAX_COLUMNS 32 9#define MAX_COLUMNS 32
10 10
11#define HPP__COLOR_FN(_name, _field) \ 11static int perf_gtk__percent_color_snprintf(char *buf, size_t size,
12static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ 12 double percent)
13 struct hist_entry *he) \ 13{
14 int ret = 0;
15 const char *markup;
16
17 markup = perf_gtk__get_percent_color(percent);
18 if (markup)
19 ret += scnprintf(buf, size, markup);
20
21 ret += scnprintf(buf + ret, size - ret, "%6.2f%%", percent);
22
23 if (markup)
24 ret += scnprintf(buf + ret, size - ret, "</span>");
25
26 return ret;
27}
28
29
30static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
31 u64 (*get_field)(struct hist_entry *))
32{
33 int ret;
34 double percent = 0.0;
35 struct hists *hists = he->hists;
36
37 if (hists->stats.total_period)
38 percent = 100.0 * get_field(he) / hists->stats.total_period;
39
40 ret = perf_gtk__percent_color_snprintf(hpp->buf, hpp->size, percent);
41 return ret;
42}
43
44#define __HPP_COLOR_PERCENT_FN(_type, _field) \
45static u64 he_get_##_field(struct hist_entry *he) \
14{ \ 46{ \
15 struct hists *hists = he->hists; \ 47 return he->stat._field; \
16 double percent = 100.0 * he->stat._field / hists->stats.total_period; \ 48} \
17 const char *markup; \
18 int ret = 0; \
19 \
20 markup = perf_gtk__get_percent_color(percent); \
21 if (markup) \
22 ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
23 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
24 if (markup) \
25 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
26 \ 49 \
27 return ret; \ 50static int perf_gtk__hpp_color_##_type(struct perf_hpp *hpp, \
51 struct hist_entry *he) \
52{ \
53 return __hpp__color_fmt(hpp, he, he_get_##_field); \
28} 54}
29 55
30HPP__COLOR_FN(overhead, period) 56__HPP_COLOR_PERCENT_FN(overhead, period)
31HPP__COLOR_FN(overhead_sys, period_sys) 57__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
32HPP__COLOR_FN(overhead_us, period_us) 58__HPP_COLOR_PERCENT_FN(overhead_us, period_us)
33HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) 59__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
34HPP__COLOR_FN(overhead_guest_us, period_guest_us) 60__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
35 61
36#undef HPP__COLOR_FN 62#undef __HPP_COLOR_PERCENT_FN
37 63
38 64
39void perf_gtk__init_hpp(void) 65void perf_gtk__init_hpp(void)