diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/ui/gtk/hists.c | 68 |
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) \ | 11 | static int perf_gtk__percent_color_snprintf(char *buf, size_t size, |
12 | static 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 | |||
30 | static 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) \ | ||
45 | static 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; \ | 50 | static 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 | ||
30 | HPP__COLOR_FN(overhead, period) | 56 | __HPP_COLOR_PERCENT_FN(overhead, period) |
31 | HPP__COLOR_FN(overhead_sys, period_sys) | 57 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) |
32 | HPP__COLOR_FN(overhead_us, period_us) | 58 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) |
33 | HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) | 59 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) |
34 | HPP__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 | ||
39 | void perf_gtk__init_hpp(void) | 65 | void perf_gtk__init_hpp(void) |