aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
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)