aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2012-12-21 03:20:13 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:40:16 -0500
commit0da41ce954840a74e7a0de9c8268bf855147e902 (patch)
tree7707066ce5dbc7dc225dd08a79e7822b2b8b5f30 /tools/perf/ui
parentc91368c4889a0ee5dd06552adbb50ae54f5096fd (diff)
perf ui/gtk: Factor out common browser routines
Separate out common codes for setting up a browser, and move report/hist browser codes into hists.c. The common codes can be used for annotation browser. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Pekka Enberg <penberg@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1356078018-31905-2-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.c227
-rw-r--r--tools/perf/ui/gtk/gtk.h9
-rw-r--r--tools/perf/ui/gtk/hists.c226
3 files changed, 239 insertions, 223 deletions
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index e59ba337f494..c95012cdb438 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -8,15 +8,13 @@
8 8
9#include <signal.h> 9#include <signal.h>
10 10
11#define MAX_COLUMNS 32 11void perf_gtk__signal(int sig)
12
13static void perf_gtk__signal(int sig)
14{ 12{
15 perf_gtk__exit(false); 13 perf_gtk__exit(false);
16 psignal(sig, "perf"); 14 psignal(sig, "perf");
17} 15}
18 16
19static void perf_gtk__resize_window(GtkWidget *window) 17void perf_gtk__resize_window(GtkWidget *window)
20{ 18{
21 GdkRectangle rect; 19 GdkRectangle rect;
22 GdkScreen *screen; 20 GdkScreen *screen;
@@ -36,7 +34,7 @@ static void perf_gtk__resize_window(GtkWidget *window)
36 gtk_window_resize(GTK_WINDOW(window), width, height); 34 gtk_window_resize(GTK_WINDOW(window), width, height);
37} 35}
38 36
39static const char *perf_gtk__get_percent_color(double percent) 37const char *perf_gtk__get_percent_color(double percent)
40{ 38{
41 if (percent >= MIN_RED) 39 if (percent >= MIN_RED)
42 return "<span fgcolor='red'>"; 40 return "<span fgcolor='red'>";
@@ -45,147 +43,8 @@ static const char *perf_gtk__get_percent_color(double percent)
45 return NULL; 43 return NULL;
46} 44}
47 45
48#define HPP__COLOR_FN(_name, _field) \
49static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
50 struct hist_entry *he) \
51{ \
52 struct hists *hists = he->hists; \
53 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
54 const char *markup; \
55 int ret = 0; \
56 \
57 markup = perf_gtk__get_percent_color(percent); \
58 if (markup) \
59 ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
60 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
61 if (markup) \
62 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
63 \
64 return ret; \
65}
66
67HPP__COLOR_FN(overhead, period)
68HPP__COLOR_FN(overhead_sys, period_sys)
69HPP__COLOR_FN(overhead_us, period_us)
70HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
71HPP__COLOR_FN(overhead_guest_us, period_guest_us)
72
73#undef HPP__COLOR_FN
74
75void perf_gtk__init_hpp(void)
76{
77 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
78
79 perf_hpp__init();
80
81 perf_hpp__format[PERF_HPP__OVERHEAD].color =
82 perf_gtk__hpp_color_overhead;
83 perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
84 perf_gtk__hpp_color_overhead_sys;
85 perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
86 perf_gtk__hpp_color_overhead_us;
87 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
88 perf_gtk__hpp_color_overhead_guest_sys;
89 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
90 perf_gtk__hpp_color_overhead_guest_us;
91}
92
93static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
94{
95 struct perf_hpp_fmt *fmt;
96 GType col_types[MAX_COLUMNS];
97 GtkCellRenderer *renderer;
98 struct sort_entry *se;
99 GtkListStore *store;
100 struct rb_node *nd;
101 GtkWidget *view;
102 int col_idx;
103 int nr_cols;
104 char s[512];
105
106 struct perf_hpp hpp = {
107 .buf = s,
108 .size = sizeof(s),
109 };
110
111 nr_cols = 0;
112
113 perf_hpp__for_each_format(fmt)
114 col_types[nr_cols++] = G_TYPE_STRING;
115
116 list_for_each_entry(se, &hist_entry__sort_list, list) {
117 if (se->elide)
118 continue;
119
120 col_types[nr_cols++] = G_TYPE_STRING;
121 }
122
123 store = gtk_list_store_newv(nr_cols, col_types);
124
125 view = gtk_tree_view_new();
126
127 renderer = gtk_cell_renderer_text_new();
128
129 col_idx = 0;
130
131 perf_hpp__for_each_format(fmt) {
132 fmt->header(&hpp);
133 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
134 -1, s,
135 renderer, "markup",
136 col_idx++, NULL);
137 }
138
139 list_for_each_entry(se, &hist_entry__sort_list, list) {
140 if (se->elide)
141 continue;
142
143 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
144 -1, se->se_header,
145 renderer, "text",
146 col_idx++, NULL);
147 }
148
149 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
150
151 g_object_unref(GTK_TREE_MODEL(store));
152
153 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
154 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
155 GtkTreeIter iter;
156
157 if (h->filtered)
158 continue;
159
160 gtk_list_store_append(store, &iter);
161
162 col_idx = 0;
163
164 perf_hpp__for_each_format(fmt) {
165 if (fmt->color)
166 fmt->color(&hpp, h);
167 else
168 fmt->entry(&hpp, h);
169
170 gtk_list_store_set(store, &iter, col_idx++, s, -1);
171 }
172
173 list_for_each_entry(se, &hist_entry__sort_list, list) {
174 if (se->elide)
175 continue;
176
177 se->se_snprintf(h, s, ARRAY_SIZE(s),
178 hists__col_len(hists, se->se_width_idx));
179
180 gtk_list_store_set(store, &iter, col_idx++, s, -1);
181 }
182 }
183
184 gtk_container_add(GTK_CONTAINER(window), view);
185}
186
187#ifdef HAVE_GTK_INFO_BAR 46#ifdef HAVE_GTK_INFO_BAR
188static GtkWidget *perf_gtk__setup_info_bar(void) 47GtkWidget *perf_gtk__setup_info_bar(void)
189{ 48{
190 GtkWidget *info_bar; 49 GtkWidget *info_bar;
191 GtkWidget *label; 50 GtkWidget *label;
@@ -212,7 +71,7 @@ static GtkWidget *perf_gtk__setup_info_bar(void)
212} 71}
213#endif 72#endif
214 73
215static GtkWidget *perf_gtk__setup_statusbar(void) 74GtkWidget *perf_gtk__setup_statusbar(void)
216{ 75{
217 GtkWidget *stbar; 76 GtkWidget *stbar;
218 unsigned ctxid; 77 unsigned ctxid;
@@ -226,79 +85,3 @@ static GtkWidget *perf_gtk__setup_statusbar(void)
226 85
227 return stbar; 86 return stbar;
228} 87}
229
230int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
231 const char *help,
232 struct hist_browser_timer *hbt __maybe_unused)
233{
234 struct perf_evsel *pos;
235 GtkWidget *vbox;
236 GtkWidget *notebook;
237 GtkWidget *info_bar;
238 GtkWidget *statbar;
239 GtkWidget *window;
240
241 signal(SIGSEGV, perf_gtk__signal);
242 signal(SIGFPE, perf_gtk__signal);
243 signal(SIGINT, perf_gtk__signal);
244 signal(SIGQUIT, perf_gtk__signal);
245 signal(SIGTERM, perf_gtk__signal);
246
247 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
248
249 gtk_window_set_title(GTK_WINDOW(window), "perf report");
250
251 g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
252
253 pgctx = perf_gtk__activate_context(window);
254 if (!pgctx)
255 return -1;
256
257 vbox = gtk_vbox_new(FALSE, 0);
258
259 notebook = gtk_notebook_new();
260
261 list_for_each_entry(pos, &evlist->entries, node) {
262 struct hists *hists = &pos->hists;
263 const char *evname = perf_evsel__name(pos);
264 GtkWidget *scrolled_window;
265 GtkWidget *tab_label;
266
267 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
268
269 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
270 GTK_POLICY_AUTOMATIC,
271 GTK_POLICY_AUTOMATIC);
272
273 perf_gtk__show_hists(scrolled_window, hists);
274
275 tab_label = gtk_label_new(evname);
276
277 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label);
278 }
279
280 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
281
282 info_bar = perf_gtk__setup_info_bar();
283 if (info_bar)
284 gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
285
286 statbar = perf_gtk__setup_statusbar();
287 gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
288
289 gtk_container_add(GTK_CONTAINER(window), vbox);
290
291 gtk_widget_show_all(window);
292
293 perf_gtk__resize_window(window);
294
295 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
296
297 ui_helpline__push(help);
298
299 gtk_main();
300
301 perf_gtk__deactivate_context(&pgctx);
302
303 return 0;
304}
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 856320e2cc05..5d3693754828 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -33,7 +33,14 @@ void perf_gtk__init_helpline(void);
33void perf_gtk__init_progress(void); 33void perf_gtk__init_progress(void);
34void perf_gtk__init_hpp(void); 34void perf_gtk__init_hpp(void);
35 35
36#ifndef HAVE_GTK_INFO_BAR 36void perf_gtk__signal(int sig);
37void perf_gtk__resize_window(GtkWidget *window);
38const char *perf_gtk__get_percent_color(double percent);
39GtkWidget *perf_gtk__setup_statusbar(void);
40
41#ifdef HAVE_GTK_INFO_BAR
42GtkWidget *perf_gtk__setup_info_bar(void);
43#else
37static inline GtkWidget *perf_gtk__setup_info_bar(void) 44static inline GtkWidget *perf_gtk__setup_info_bar(void)
38{ 45{
39 return NULL; 46 return NULL;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
new file mode 100644
index 000000000000..26912f86e032
--- /dev/null
+++ b/tools/perf/ui/gtk/hists.c
@@ -0,0 +1,226 @@
1#include "../evlist.h"
2#include "../cache.h"
3#include "../evsel.h"
4#include "../sort.h"
5#include "../hist.h"
6#include "../helpline.h"
7#include "gtk.h"
8
9#define MAX_COLUMNS 32
10
11#define HPP__COLOR_FN(_name, _field) \
12static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
13 struct hist_entry *he) \
14{ \
15 struct hists *hists = he->hists; \
16 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
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 \
27 return ret; \
28}
29
30HPP__COLOR_FN(overhead, period)
31HPP__COLOR_FN(overhead_sys, period_sys)
32HPP__COLOR_FN(overhead_us, period_us)
33HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
34HPP__COLOR_FN(overhead_guest_us, period_guest_us)
35
36#undef HPP__COLOR_FN
37
38
39void perf_gtk__init_hpp(void)
40{
41 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
42
43 perf_hpp__init();
44
45 perf_hpp__format[PERF_HPP__OVERHEAD].color =
46 perf_gtk__hpp_color_overhead;
47 perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
48 perf_gtk__hpp_color_overhead_sys;
49 perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
50 perf_gtk__hpp_color_overhead_us;
51 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
52 perf_gtk__hpp_color_overhead_guest_sys;
53 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
54 perf_gtk__hpp_color_overhead_guest_us;
55}
56
57static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
58{
59 struct perf_hpp_fmt *fmt;
60 GType col_types[MAX_COLUMNS];
61 GtkCellRenderer *renderer;
62 struct sort_entry *se;
63 GtkListStore *store;
64 struct rb_node *nd;
65 GtkWidget *view;
66 int col_idx;
67 int nr_cols;
68 char s[512];
69
70 struct perf_hpp hpp = {
71 .buf = s,
72 .size = sizeof(s),
73 };
74
75 nr_cols = 0;
76
77 perf_hpp__for_each_format(fmt)
78 col_types[nr_cols++] = G_TYPE_STRING;
79
80 list_for_each_entry(se, &hist_entry__sort_list, list) {
81 if (se->elide)
82 continue;
83
84 col_types[nr_cols++] = G_TYPE_STRING;
85 }
86
87 store = gtk_list_store_newv(nr_cols, col_types);
88
89 view = gtk_tree_view_new();
90
91 renderer = gtk_cell_renderer_text_new();
92
93 col_idx = 0;
94
95 perf_hpp__for_each_format(fmt) {
96 fmt->header(&hpp);
97
98 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
99 -1, s,
100 renderer, "markup",
101 col_idx++, NULL);
102 }
103
104 list_for_each_entry(se, &hist_entry__sort_list, list) {
105 if (se->elide)
106 continue;
107
108 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
109 -1, se->se_header,
110 renderer, "text",
111 col_idx++, NULL);
112 }
113
114 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
115
116 g_object_unref(GTK_TREE_MODEL(store));
117
118 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
119 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
120 GtkTreeIter iter;
121
122 if (h->filtered)
123 continue;
124
125 gtk_list_store_append(store, &iter);
126
127 col_idx = 0;
128
129 perf_hpp__for_each_format(fmt) {
130 if (fmt->color)
131 fmt->color(&hpp, h);
132 else
133 fmt->entry(&hpp, h);
134
135 gtk_list_store_set(store, &iter, col_idx++, s, -1);
136 }
137
138 list_for_each_entry(se, &hist_entry__sort_list, list) {
139 if (se->elide)
140 continue;
141
142 se->se_snprintf(h, s, ARRAY_SIZE(s),
143 hists__col_len(hists, se->se_width_idx));
144
145 gtk_list_store_set(store, &iter, col_idx++, s, -1);
146 }
147 }
148
149 gtk_container_add(GTK_CONTAINER(window), view);
150}
151
152int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
153 const char *help,
154 struct hist_browser_timer *hbt __maybe_unused)
155{
156 struct perf_evsel *pos;
157 GtkWidget *vbox;
158 GtkWidget *notebook;
159 GtkWidget *info_bar;
160 GtkWidget *statbar;
161 GtkWidget *window;
162
163 signal(SIGSEGV, perf_gtk__signal);
164 signal(SIGFPE, perf_gtk__signal);
165 signal(SIGINT, perf_gtk__signal);
166 signal(SIGQUIT, perf_gtk__signal);
167 signal(SIGTERM, perf_gtk__signal);
168
169 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
170
171 gtk_window_set_title(GTK_WINDOW(window), "perf report");
172
173 g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
174
175 pgctx = perf_gtk__activate_context(window);
176 if (!pgctx)
177 return -1;
178
179 vbox = gtk_vbox_new(FALSE, 0);
180
181 notebook = gtk_notebook_new();
182
183 list_for_each_entry(pos, &evlist->entries, node) {
184 struct hists *hists = &pos->hists;
185 const char *evname = perf_evsel__name(pos);
186 GtkWidget *scrolled_window;
187 GtkWidget *tab_label;
188
189 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
190
191 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
192 GTK_POLICY_AUTOMATIC,
193 GTK_POLICY_AUTOMATIC);
194
195 perf_gtk__show_hists(scrolled_window, hists);
196
197 tab_label = gtk_label_new(evname);
198
199 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label);
200 }
201
202 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
203
204 info_bar = perf_gtk__setup_info_bar();
205 if (info_bar)
206 gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
207
208 statbar = perf_gtk__setup_statusbar();
209 gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
210
211 gtk_container_add(GTK_CONTAINER(window), vbox);
212
213 gtk_widget_show_all(window);
214
215 perf_gtk__resize_window(window);
216
217 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
218
219 ui_helpline__push(help);
220
221 gtk_main();
222
223 perf_gtk__deactivate_context(&pgctx);
224
225 return 0;
226}