6 #include "../helpline.h"
11 #define MAX_COLUMNS 32
13 static void perf_gtk__signal(
int sig)
19 static void perf_gtk__resize_window(GtkWidget *
window)
27 screen = gtk_widget_get_screen(window);
29 monitor = gdk_screen_get_monitor_at_window(screen, window->window);
31 gdk_screen_get_monitor_geometry(screen, monitor, &rect);
33 width = rect.width * 3 / 4;
34 height = rect.height * 3 / 4;
36 gtk_window_resize(GTK_WINDOW(window), width, height);
39 static const char *perf_gtk__get_percent_color(
double percent)
42 return "<span fgcolor='red'>";
44 return "<span fgcolor='dark green'>";
48 #define HPP__COLOR_FN(_name, _field) \
49 static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
50 struct hist_entry *he) \
52 struct hists *hists = he->hists; \
53 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
57 markup = perf_gtk__get_percent_color(percent); \
59 ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
60 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
62 ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
80 perf_gtk__hpp_color_overhead;
82 perf_gtk__hpp_color_overhead_sys;
84 perf_gtk__hpp_color_overhead_us;
86 perf_gtk__hpp_color_overhead_guest_sys;
88 perf_gtk__hpp_color_overhead_guest_us;
91 static void perf_gtk__show_hists(GtkWidget *window,
struct hists *
hists)
94 GtkCellRenderer *renderer;
114 col_types[nr_cols++] = G_TYPE_STRING;
121 col_types[nr_cols++] = G_TYPE_STRING;
124 store = gtk_list_store_newv(nr_cols, col_types);
126 view = gtk_tree_view_new();
128 renderer = gtk_cell_renderer_text_new();
138 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
148 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
154 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
156 g_object_unref(GTK_TREE_MODEL(store));
165 gtk_list_store_append(store, &iter);
178 gtk_list_store_set(store, &iter, col_idx++, s, -1);
188 gtk_list_store_set(store, &iter, col_idx++, s, -1);
192 gtk_container_add(GTK_CONTAINER(window), view);
195 #ifdef HAVE_GTK_INFO_BAR
196 static GtkWidget *perf_gtk__setup_info_bar(
void)
200 GtkWidget *content_area;
202 info_bar = gtk_info_bar_new();
203 gtk_widget_set_no_show_all(info_bar,
TRUE);
205 label = gtk_label_new(
"");
206 gtk_widget_show(label);
208 content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar));
209 gtk_container_add(GTK_CONTAINER(content_area), label);
211 gtk_info_bar_add_button(GTK_INFO_BAR(info_bar), GTK_STOCK_OK,
213 g_signal_connect(info_bar,
"response",
214 G_CALLBACK(gtk_widget_hide),
NULL);
216 pgctx->info_bar = info_bar;
223 static GtkWidget *perf_gtk__setup_statusbar(
void)
228 stbar = gtk_statusbar_new();
230 ctxid = gtk_statusbar_get_context_id(GTK_STATUSBAR(stbar),
232 pgctx->statbar = stbar;
233 pgctx->statbar_ctx_id = ctxid;
241 void *arg __maybe_unused,
242 int delay_secs __maybe_unused)
251 signal(
SIGSEGV, perf_gtk__signal);
252 signal(
SIGFPE, perf_gtk__signal);
253 signal(
SIGINT, perf_gtk__signal);
254 signal(
SIGQUIT, perf_gtk__signal);
255 signal(
SIGTERM, perf_gtk__signal);
257 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
259 gtk_window_set_title(GTK_WINDOW(window),
"perf report");
261 g_signal_connect(window,
"delete_event", gtk_main_quit,
NULL);
267 vbox = gtk_vbox_new(
FALSE, 0);
269 notebook = gtk_notebook_new();
272 struct hists *hists = &pos->
hists;
274 GtkWidget *scrolled_window;
275 GtkWidget *tab_label;
277 scrolled_window = gtk_scrolled_window_new(
NULL,
NULL);
279 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
280 GTK_POLICY_AUTOMATIC,
281 GTK_POLICY_AUTOMATIC);
283 perf_gtk__show_hists(scrolled_window, hists);
285 tab_label = gtk_label_new(evname);
287 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label);
290 gtk_box_pack_start(GTK_BOX(vbox), notebook,
TRUE,
TRUE, 0);
292 info_bar = perf_gtk__setup_info_bar();
294 gtk_box_pack_start(GTK_BOX(vbox), info_bar,
FALSE,
FALSE, 0);
296 statbar = perf_gtk__setup_statusbar();
297 gtk_box_pack_start(GTK_BOX(vbox), statbar,
FALSE,
FALSE, 0);
299 gtk_container_add(GTK_CONTAINER(window), vbox);
301 gtk_widget_show_all(window);
303 perf_gtk__resize_window(window);
305 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);