diff options
Diffstat (limited to 'tools/perf/ui/gtk/browser.c')
| -rw-r--r-- | tools/perf/ui/gtk/browser.c | 111 |
1 files changed, 92 insertions, 19 deletions
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index ec12e0b4ded6..7ff99ec1d95e 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include "../evsel.h" | 3 | #include "../evsel.h" |
| 4 | #include "../sort.h" | 4 | #include "../sort.h" |
| 5 | #include "../hist.h" | 5 | #include "../hist.h" |
| 6 | #include "../helpline.h" | ||
| 6 | #include "gtk.h" | 7 | #include "gtk.h" |
| 7 | 8 | ||
| 8 | #include <signal.h> | 9 | #include <signal.h> |
| @@ -35,6 +36,57 @@ static void perf_gtk__resize_window(GtkWidget *window) | |||
| 35 | gtk_window_resize(GTK_WINDOW(window), width, height); | 36 | gtk_window_resize(GTK_WINDOW(window), width, height); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 39 | static const char *perf_gtk__get_percent_color(double percent) | ||
| 40 | { | ||
| 41 | if (percent >= MIN_RED) | ||
| 42 | return "<span fgcolor='red'>"; | ||
| 43 | if (percent >= MIN_GREEN) | ||
| 44 | return "<span fgcolor='dark green'>"; | ||
| 45 | return NULL; | ||
| 46 | } | ||
| 47 | |||
| 48 | #define HPP__COLOR_FN(_name, _field) \ | ||
| 49 | static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ | ||
| 50 | struct hist_entry *he) \ | ||
| 51 | { \ | ||
| 52 | double percent = 100.0 * he->_field / hpp->total_period; \ | ||
| 53 | const char *markup; \ | ||
| 54 | int ret = 0; \ | ||
| 55 | \ | ||
| 56 | markup = perf_gtk__get_percent_color(percent); \ | ||
| 57 | if (markup) \ | ||
| 58 | ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \ | ||
| 59 | ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \ | ||
| 60 | if (markup) \ | ||
| 61 | ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \ | ||
| 62 | \ | ||
| 63 | return ret; \ | ||
| 64 | } | ||
| 65 | |||
| 66 | HPP__COLOR_FN(overhead, period) | ||
| 67 | HPP__COLOR_FN(overhead_sys, period_sys) | ||
| 68 | HPP__COLOR_FN(overhead_us, period_us) | ||
| 69 | HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) | ||
| 70 | HPP__COLOR_FN(overhead_guest_us, period_guest_us) | ||
| 71 | |||
| 72 | #undef HPP__COLOR_FN | ||
| 73 | |||
| 74 | void perf_gtk__init_hpp(void) | ||
| 75 | { | ||
| 76 | perf_hpp__init(false, false); | ||
| 77 | |||
| 78 | perf_hpp__format[PERF_HPP__OVERHEAD].color = | ||
| 79 | perf_gtk__hpp_color_overhead; | ||
| 80 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color = | ||
| 81 | perf_gtk__hpp_color_overhead_sys; | ||
| 82 | perf_hpp__format[PERF_HPP__OVERHEAD_US].color = | ||
| 83 | perf_gtk__hpp_color_overhead_us; | ||
| 84 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color = | ||
| 85 | perf_gtk__hpp_color_overhead_guest_sys; | ||
| 86 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = | ||
| 87 | perf_gtk__hpp_color_overhead_guest_us; | ||
| 88 | } | ||
| 89 | |||
| 38 | static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | 90 | static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) |
| 39 | { | 91 | { |
| 40 | GType col_types[MAX_COLUMNS]; | 92 | GType col_types[MAX_COLUMNS]; |
| @@ -42,15 +94,25 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
| 42 | struct sort_entry *se; | 94 | struct sort_entry *se; |
| 43 | GtkListStore *store; | 95 | GtkListStore *store; |
| 44 | struct rb_node *nd; | 96 | struct rb_node *nd; |
| 45 | u64 total_period; | ||
| 46 | GtkWidget *view; | 97 | GtkWidget *view; |
| 47 | int col_idx; | 98 | int i, col_idx; |
| 48 | int nr_cols; | 99 | int nr_cols; |
| 100 | char s[512]; | ||
| 101 | |||
| 102 | struct perf_hpp hpp = { | ||
| 103 | .buf = s, | ||
| 104 | .size = sizeof(s), | ||
| 105 | .total_period = hists->stats.total_period, | ||
| 106 | }; | ||
| 49 | 107 | ||
| 50 | nr_cols = 0; | 108 | nr_cols = 0; |
| 51 | 109 | ||
| 52 | /* The percentage column */ | 110 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 53 | col_types[nr_cols++] = G_TYPE_STRING; | 111 | if (!perf_hpp__format[i].cond) |
| 112 | continue; | ||
| 113 | |||
| 114 | col_types[nr_cols++] = G_TYPE_STRING; | ||
| 115 | } | ||
| 54 | 116 | ||
| 55 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 117 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 56 | if (se->elide) | 118 | if (se->elide) |
| @@ -67,11 +129,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
| 67 | 129 | ||
| 68 | col_idx = 0; | 130 | col_idx = 0; |
| 69 | 131 | ||
| 70 | /* The percentage column */ | 132 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 71 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), | 133 | if (!perf_hpp__format[i].cond) |
| 72 | -1, "Overhead (%)", | 134 | continue; |
| 73 | renderer, "text", | 135 | |
| 74 | col_idx++, NULL); | 136 | perf_hpp__format[i].header(&hpp); |
| 137 | |||
| 138 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), | ||
| 139 | -1, s, | ||
| 140 | renderer, "markup", | ||
| 141 | col_idx++, NULL); | ||
| 142 | } | ||
| 75 | 143 | ||
| 76 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 144 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 77 | if (se->elide) | 145 | if (se->elide) |
| @@ -87,13 +155,9 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
| 87 | 155 | ||
| 88 | g_object_unref(GTK_TREE_MODEL(store)); | 156 | g_object_unref(GTK_TREE_MODEL(store)); |
| 89 | 157 | ||
| 90 | total_period = hists->stats.total_period; | ||
| 91 | |||
| 92 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | 158 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 93 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 159 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 94 | GtkTreeIter iter; | 160 | GtkTreeIter iter; |
| 95 | double percent; | ||
| 96 | char s[512]; | ||
| 97 | 161 | ||
| 98 | if (h->filtered) | 162 | if (h->filtered) |
| 99 | continue; | 163 | continue; |
| @@ -102,11 +166,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
| 102 | 166 | ||
| 103 | col_idx = 0; | 167 | col_idx = 0; |
| 104 | 168 | ||
| 105 | percent = (h->period * 100.0) / total_period; | 169 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 170 | if (!perf_hpp__format[i].cond) | ||
| 171 | continue; | ||
| 106 | 172 | ||
| 107 | snprintf(s, ARRAY_SIZE(s), "%.2f", percent); | 173 | if (perf_hpp__format[i].color) |
| 174 | perf_hpp__format[i].color(&hpp, h); | ||
| 175 | else | ||
| 176 | perf_hpp__format[i].entry(&hpp, h); | ||
| 108 | 177 | ||
| 109 | gtk_list_store_set(store, &iter, col_idx++, s, -1); | 178 | gtk_list_store_set(store, &iter, col_idx++, s, -1); |
| 179 | } | ||
| 110 | 180 | ||
| 111 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 181 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 112 | if (se->elide) | 182 | if (se->elide) |
| @@ -166,9 +236,10 @@ static GtkWidget *perf_gtk__setup_statusbar(void) | |||
| 166 | } | 236 | } |
| 167 | 237 | ||
| 168 | int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | 238 | int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, |
| 169 | const char *help __used, | 239 | const char *help, |
| 170 | void (*timer) (void *arg)__used, | 240 | void (*timer) (void *arg)__maybe_unused, |
| 171 | void *arg __used, int delay_secs __used) | 241 | void *arg __maybe_unused, |
| 242 | int delay_secs __maybe_unused) | ||
| 172 | { | 243 | { |
| 173 | struct perf_evsel *pos; | 244 | struct perf_evsel *pos; |
| 174 | GtkWidget *vbox; | 245 | GtkWidget *vbox; |
| @@ -233,6 +304,8 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | |||
| 233 | 304 | ||
| 234 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | 305 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
| 235 | 306 | ||
| 307 | ui_helpline__push(help); | ||
| 308 | |||
| 236 | gtk_main(); | 309 | gtk_main(); |
| 237 | 310 | ||
| 238 | perf_gtk__deactivate_context(&pgctx); | 311 | perf_gtk__deactivate_context(&pgctx); |
