diff options
Diffstat (limited to 'tools/perf/ui/gtk')
| -rw-r--r-- | tools/perf/ui/gtk/hists.c | 78 |
1 files changed, 13 insertions, 65 deletions
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 5b95c44f3435..e395ef9b0ae0 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
| @@ -8,16 +8,24 @@ | |||
| 8 | 8 | ||
| 9 | #define MAX_COLUMNS 32 | 9 | #define MAX_COLUMNS 32 |
| 10 | 10 | ||
| 11 | static int __percent_color_snprintf(char *buf, size_t size, double percent) | 11 | static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 12 | { | 12 | { |
| 13 | int ret = 0; | 13 | int ret = 0; |
| 14 | va_list args; | ||
| 15 | double percent; | ||
| 14 | const char *markup; | 16 | const char *markup; |
| 17 | char *buf = hpp->buf; | ||
| 18 | size_t size = hpp->size; | ||
| 19 | |||
| 20 | va_start(args, fmt); | ||
| 21 | percent = va_arg(args, double); | ||
| 22 | va_end(args); | ||
| 15 | 23 | ||
| 16 | markup = perf_gtk__get_percent_color(percent); | 24 | markup = perf_gtk__get_percent_color(percent); |
| 17 | if (markup) | 25 | if (markup) |
| 18 | ret += scnprintf(buf, size, markup); | 26 | ret += scnprintf(buf, size, markup); |
| 19 | 27 | ||
| 20 | ret += scnprintf(buf + ret, size - ret, " %6.2f%%", percent); | 28 | ret += scnprintf(buf + ret, size - ret, fmt, percent); |
| 21 | 29 | ||
| 22 | if (markup) | 30 | if (markup) |
| 23 | ret += scnprintf(buf + ret, size - ret, "</span>"); | 31 | ret += scnprintf(buf + ret, size - ret, "</span>"); |
| @@ -25,66 +33,6 @@ static int __percent_color_snprintf(char *buf, size_t size, double percent) | |||
| 25 | return ret; | 33 | return ret; |
| 26 | } | 34 | } |
| 27 | 35 | ||
| 28 | |||
| 29 | static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he, | ||
| 30 | u64 (*get_field)(struct hist_entry *)) | ||
| 31 | { | ||
| 32 | int ret; | ||
| 33 | double percent = 0.0; | ||
| 34 | struct hists *hists = he->hists; | ||
| 35 | struct perf_evsel *evsel = hists_to_evsel(hists); | ||
| 36 | |||
| 37 | if (hists->stats.total_period) | ||
| 38 | percent = 100.0 * get_field(he) / hists->stats.total_period; | ||
| 39 | |||
| 40 | ret = __percent_color_snprintf(hpp->buf, hpp->size, percent); | ||
| 41 | |||
| 42 | if (perf_evsel__is_group_event(evsel)) { | ||
| 43 | int prev_idx, idx_delta; | ||
| 44 | struct hist_entry *pair; | ||
| 45 | int nr_members = evsel->nr_members; | ||
| 46 | |||
| 47 | prev_idx = perf_evsel__group_idx(evsel); | ||
| 48 | |||
| 49 | list_for_each_entry(pair, &he->pairs.head, pairs.node) { | ||
| 50 | u64 period = get_field(pair); | ||
| 51 | u64 total = pair->hists->stats.total_period; | ||
| 52 | |||
| 53 | evsel = hists_to_evsel(pair->hists); | ||
| 54 | idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; | ||
| 55 | |||
| 56 | while (idx_delta--) { | ||
| 57 | /* | ||
| 58 | * zero-fill group members in the middle which | ||
| 59 | * have no sample | ||
| 60 | */ | ||
| 61 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
| 62 | hpp->size - ret, | ||
| 63 | 0.0); | ||
| 64 | } | ||
| 65 | |||
| 66 | percent = 100.0 * period / total; | ||
| 67 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
| 68 | hpp->size - ret, | ||
| 69 | percent); | ||
| 70 | |||
| 71 | prev_idx = perf_evsel__group_idx(evsel); | ||
| 72 | } | ||
| 73 | |||
| 74 | idx_delta = nr_members - prev_idx - 1; | ||
| 75 | |||
| 76 | while (idx_delta--) { | ||
| 77 | /* | ||
| 78 | * zero-fill group members at last which have no sample | ||
| 79 | */ | ||
| 80 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
| 81 | hpp->size - ret, | ||
| 82 | 0.0); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | return ret; | ||
| 86 | } | ||
| 87 | |||
| 88 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ | 36 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 89 | static u64 he_get_##_field(struct hist_entry *he) \ | 37 | static u64 he_get_##_field(struct hist_entry *he) \ |
| 90 | { \ | 38 | { \ |
| @@ -95,7 +43,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, | |||
| 95 | struct perf_hpp *hpp, \ | 43 | struct perf_hpp *hpp, \ |
| 96 | struct hist_entry *he) \ | 44 | struct hist_entry *he) \ |
| 97 | { \ | 45 | { \ |
| 98 | return __hpp__color_fmt(hpp, he, he_get_##_field); \ | 46 | return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \ |
| 47 | __percent_color_snprintf, true); \ | ||
| 99 | } | 48 | } |
| 100 | 49 | ||
| 101 | __HPP_COLOR_PERCENT_FN(overhead, period) | 50 | __HPP_COLOR_PERCENT_FN(overhead, period) |
| @@ -216,7 +165,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
| 216 | struct perf_hpp hpp = { | 165 | struct perf_hpp hpp = { |
| 217 | .buf = s, | 166 | .buf = s, |
| 218 | .size = sizeof(s), | 167 | .size = sizeof(s), |
| 219 | .ptr = hists_to_evsel(hists), | ||
| 220 | }; | 168 | }; |
| 221 | 169 | ||
| 222 | nr_cols = 0; | 170 | nr_cols = 0; |
| @@ -243,7 +191,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
| 243 | col_idx = 0; | 191 | col_idx = 0; |
| 244 | 192 | ||
| 245 | perf_hpp__for_each_format(fmt) { | 193 | perf_hpp__for_each_format(fmt) { |
| 246 | fmt->header(fmt, &hpp); | 194 | fmt->header(fmt, &hpp, hists_to_evsel(hists)); |
| 247 | 195 | ||
| 248 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), | 196 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), |
| 249 | -1, ltrim(s), | 197 | -1, ltrim(s), |
