diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-09-02 22:53:10 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-08 12:20:21 -0400 |
commit | 12ceaded6b276c13d905cf09f0c1a1322022ea58 (patch) | |
tree | bb80f32aa40b54aa9d0b23a18d8c4b4c9fb25a77 /tools/perf/ui | |
parent | f5951d56a2ab4181b96806a4746895aaa5a3d72e (diff) |
perf gtk/browser: Use perf_hpp__format functions
Now we can support color using pango markup with this change.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1346640790-17197-6-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui')
-rw-r--r-- | tools/perf/ui/gtk/browser.c | 101 | ||||
-rw-r--r-- | tools/perf/ui/gtk/gtk.h | 1 | ||||
-rw-r--r-- | tools/perf/ui/gtk/setup.c | 1 |
3 files changed, 87 insertions, 16 deletions
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 26b5b652a8cd..3c16ab50e0f8 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c | |||
@@ -36,6 +36,57 @@ static void perf_gtk__resize_window(GtkWidget *window) | |||
36 | gtk_window_resize(GTK_WINDOW(window), width, height); | 36 | gtk_window_resize(GTK_WINDOW(window), width, height); |
37 | } | 37 | } |
38 | 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, "%5.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 | |||
39 | static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | 90 | static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) |
40 | { | 91 | { |
41 | GType col_types[MAX_COLUMNS]; | 92 | GType col_types[MAX_COLUMNS]; |
@@ -43,15 +94,25 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
43 | struct sort_entry *se; | 94 | struct sort_entry *se; |
44 | GtkListStore *store; | 95 | GtkListStore *store; |
45 | struct rb_node *nd; | 96 | struct rb_node *nd; |
46 | u64 total_period; | ||
47 | GtkWidget *view; | 97 | GtkWidget *view; |
48 | int col_idx; | 98 | int i, col_idx; |
49 | 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 | }; | ||
50 | 107 | ||
51 | nr_cols = 0; | 108 | nr_cols = 0; |
52 | 109 | ||
53 | /* The percentage column */ | 110 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
54 | 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 | } | ||
55 | 116 | ||
56 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 117 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
57 | if (se->elide) | 118 | if (se->elide) |
@@ -68,11 +129,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
68 | 129 | ||
69 | col_idx = 0; | 130 | col_idx = 0; |
70 | 131 | ||
71 | /* The percentage column */ | 132 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
72 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), | 133 | if (!perf_hpp__format[i].cond) |
73 | -1, "Overhead (%)", | 134 | continue; |
74 | renderer, "text", | 135 | |
75 | 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 | } | ||
76 | 143 | ||
77 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 144 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
78 | if (se->elide) | 145 | if (se->elide) |
@@ -88,13 +155,9 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
88 | 155 | ||
89 | g_object_unref(GTK_TREE_MODEL(store)); | 156 | g_object_unref(GTK_TREE_MODEL(store)); |
90 | 157 | ||
91 | total_period = hists->stats.total_period; | ||
92 | |||
93 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | 158 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
94 | 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); |
95 | GtkTreeIter iter; | 160 | GtkTreeIter iter; |
96 | double percent; | ||
97 | char s[512]; | ||
98 | 161 | ||
99 | if (h->filtered) | 162 | if (h->filtered) |
100 | continue; | 163 | continue; |
@@ -103,11 +166,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
103 | 166 | ||
104 | col_idx = 0; | 167 | col_idx = 0; |
105 | 168 | ||
106 | 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; | ||
107 | 172 | ||
108 | 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); | ||
109 | 177 | ||
110 | gtk_list_store_set(store, &iter, col_idx++, s, -1); | 178 | gtk_list_store_set(store, &iter, col_idx++, s, -1); |
179 | } | ||
111 | 180 | ||
112 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 181 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
113 | if (se->elide) | 182 | if (se->elide) |
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h index 793cb6116ddf..687af0bba187 100644 --- a/tools/perf/ui/gtk/gtk.h +++ b/tools/perf/ui/gtk/gtk.h | |||
@@ -30,6 +30,7 @@ struct perf_gtk_context *perf_gtk__activate_context(GtkWidget *window); | |||
30 | int perf_gtk__deactivate_context(struct perf_gtk_context **ctx); | 30 | int perf_gtk__deactivate_context(struct perf_gtk_context **ctx); |
31 | 31 | ||
32 | void perf_gtk__init_helpline(void); | 32 | void perf_gtk__init_helpline(void); |
33 | void perf_gtk__init_hpp(void); | ||
33 | 34 | ||
34 | #ifndef HAVE_GTK_INFO_BAR | 35 | #ifndef HAVE_GTK_INFO_BAR |
35 | static inline GtkWidget *perf_gtk__setup_info_bar(void) | 36 | static inline GtkWidget *perf_gtk__setup_info_bar(void) |
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c index ec1ee26b485a..26429437e19e 100644 --- a/tools/perf/ui/gtk/setup.c +++ b/tools/perf/ui/gtk/setup.c | |||
@@ -8,6 +8,7 @@ int perf_gtk__init(void) | |||
8 | { | 8 | { |
9 | perf_error__register(&perf_gtk_eops); | 9 | perf_error__register(&perf_gtk_eops); |
10 | perf_gtk__init_helpline(); | 10 | perf_gtk__init_helpline(); |
11 | perf_gtk__init_hpp(); | ||
11 | return gtk_init_check(NULL, NULL) ? 0 : -1; | 12 | return gtk_init_check(NULL, NULL) ? 0 : -1; |
12 | } | 13 | } |
13 | 14 | ||