6 #include "../helpline.h"
11 static int __percent_color_snprintf(char *buf
, size_t size
, double percent
)
16 markup
= perf_gtk__get_percent_color(percent
);
18 ret
+= scnprintf(buf
, size
, markup
);
20 ret
+= scnprintf(buf
+ ret
, size
- ret
, " %6.2f%%", percent
);
23 ret
+= scnprintf(buf
+ ret
, size
- ret
, "</span>");
29 static int __hpp__color_fmt(struct perf_hpp
*hpp
, struct hist_entry
*he
,
30 u64 (*get_field
)(struct hist_entry
*))
34 struct hists
*hists
= he
->hists
;
35 struct perf_evsel
*evsel
= hists_to_evsel(hists
);
37 if (hists
->stats
.total_period
)
38 percent
= 100.0 * get_field(he
) / hists
->stats
.total_period
;
40 ret
= __percent_color_snprintf(hpp
->buf
, hpp
->size
, percent
);
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
;
47 prev_idx
= perf_evsel__group_idx(evsel
);
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
;
53 evsel
= hists_to_evsel(pair
->hists
);
54 idx_delta
= perf_evsel__group_idx(evsel
) - prev_idx
- 1;
58 * zero-fill group members in the middle which
61 ret
+= __percent_color_snprintf(hpp
->buf
+ ret
,
66 percent
= 100.0 * period
/ total
;
67 ret
+= __percent_color_snprintf(hpp
->buf
+ ret
,
71 prev_idx
= perf_evsel__group_idx(evsel
);
74 idx_delta
= nr_members
- prev_idx
- 1;
78 * zero-fill group members at last which have no sample
80 ret
+= __percent_color_snprintf(hpp
->buf
+ ret
,
88 #define __HPP_COLOR_PERCENT_FN(_type, _field) \
89 static u64 he_get_##_field(struct hist_entry *he) \
91 return he->stat._field; \
94 static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
95 struct perf_hpp *hpp, \
96 struct hist_entry *he) \
98 return __hpp__color_fmt(hpp, he, he_get_##_field); \
101 __HPP_COLOR_PERCENT_FN(overhead
, period
)
102 __HPP_COLOR_PERCENT_FN(overhead_sys
, period_sys
)
103 __HPP_COLOR_PERCENT_FN(overhead_us
, period_us
)
104 __HPP_COLOR_PERCENT_FN(overhead_guest_sys
, period_guest_sys
)
105 __HPP_COLOR_PERCENT_FN(overhead_guest_us
, period_guest_us
)
107 #undef __HPP_COLOR_PERCENT_FN
110 void perf_gtk__init_hpp(void)
114 perf_hpp__format
[PERF_HPP__OVERHEAD
].color
=
115 perf_gtk__hpp_color_overhead
;
116 perf_hpp__format
[PERF_HPP__OVERHEAD_SYS
].color
=
117 perf_gtk__hpp_color_overhead_sys
;
118 perf_hpp__format
[PERF_HPP__OVERHEAD_US
].color
=
119 perf_gtk__hpp_color_overhead_us
;
120 perf_hpp__format
[PERF_HPP__OVERHEAD_GUEST_SYS
].color
=
121 perf_gtk__hpp_color_overhead_guest_sys
;
122 perf_hpp__format
[PERF_HPP__OVERHEAD_GUEST_US
].color
=
123 perf_gtk__hpp_color_overhead_guest_us
;
126 static void callchain_list__sym_name(struct callchain_list
*cl
,
127 char *bf
, size_t bfsize
)
130 scnprintf(bf
, bfsize
, "%s", cl
->ms
.sym
->name
);
132 scnprintf(bf
, bfsize
, "%#" PRIx64
, cl
->ip
);
135 static void perf_gtk__add_callchain(struct rb_root
*root
, GtkTreeStore
*store
,
136 GtkTreeIter
*parent
, int col
, u64 total
)
139 bool has_single_node
= (rb_first(root
) == rb_last(root
));
141 for (nd
= rb_first(root
); nd
; nd
= rb_next(nd
)) {
142 struct callchain_node
*node
;
143 struct callchain_list
*chain
;
144 GtkTreeIter iter
, new_parent
;
145 bool need_new_parent
;
147 u64 hits
, child_total
;
149 node
= rb_entry(nd
, struct callchain_node
, rb_node
);
151 hits
= callchain_cumul_hits(node
);
152 percent
= 100.0 * hits
/ total
;
154 new_parent
= *parent
;
155 need_new_parent
= !has_single_node
&& (node
->val_nr
> 1);
157 list_for_each_entry(chain
, &node
->val
, list
) {
160 gtk_tree_store_append(store
, &iter
, &new_parent
);
162 scnprintf(buf
, sizeof(buf
), "%5.2f%%", percent
);
163 gtk_tree_store_set(store
, &iter
, 0, buf
, -1);
165 callchain_list__sym_name(chain
, buf
, sizeof(buf
));
166 gtk_tree_store_set(store
, &iter
, col
, buf
, -1);
168 if (need_new_parent
) {
170 * Only show the top-most symbol in a callchain
171 * if it's not the only callchain.
174 need_new_parent
= false;
178 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
179 child_total
= node
->children_hit
;
183 /* Now 'iter' contains info of the last callchain_list */
184 perf_gtk__add_callchain(&node
->rb_root
, store
, &iter
, col
,
189 static void on_row_activated(GtkTreeView
*view
, GtkTreePath
*path
,
190 GtkTreeViewColumn
*col __maybe_unused
,
191 gpointer user_data __maybe_unused
)
193 bool expanded
= gtk_tree_view_row_expanded(view
, path
);
196 gtk_tree_view_collapse_row(view
, path
);
198 gtk_tree_view_expand_row(view
, path
, FALSE
);
201 static void perf_gtk__show_hists(GtkWidget
*window
, struct hists
*hists
,
204 struct perf_hpp_fmt
*fmt
;
205 GType col_types
[MAX_COLUMNS
];
206 GtkCellRenderer
*renderer
;
207 struct sort_entry
*se
;
216 struct perf_hpp hpp
= {
219 .ptr
= hists_to_evsel(hists
),
224 perf_hpp__for_each_format(fmt
)
225 col_types
[nr_cols
++] = G_TYPE_STRING
;
227 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
234 col_types
[nr_cols
++] = G_TYPE_STRING
;
237 store
= gtk_tree_store_newv(nr_cols
, col_types
);
239 view
= gtk_tree_view_new();
241 renderer
= gtk_cell_renderer_text_new();
245 perf_hpp__for_each_format(fmt
) {
246 fmt
->header(fmt
, &hpp
);
248 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view
),
254 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
258 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view
),
264 for (col_idx
= 0; col_idx
< nr_cols
; col_idx
++) {
265 GtkTreeViewColumn
*column
;
267 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(view
), col_idx
);
268 gtk_tree_view_column_set_resizable(column
, TRUE
);
270 if (col_idx
== sym_col
) {
271 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(view
),
276 gtk_tree_view_set_model(GTK_TREE_VIEW(view
), GTK_TREE_MODEL(store
));
278 g_object_unref(GTK_TREE_MODEL(store
));
280 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
281 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
283 float percent
= h
->stat
.period
* 100.0 /
284 hists
->stats
.total_period
;
289 if (percent
< min_pcnt
)
292 gtk_tree_store_append(store
, &iter
, NULL
);
296 perf_hpp__for_each_format(fmt
) {
298 fmt
->color(fmt
, &hpp
, h
);
300 fmt
->entry(fmt
, &hpp
, h
);
302 gtk_tree_store_set(store
, &iter
, col_idx
++, s
, -1);
305 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
309 se
->se_snprintf(h
, s
, ARRAY_SIZE(s
),
310 hists__col_len(hists
, se
->se_width_idx
));
312 gtk_tree_store_set(store
, &iter
, col_idx
++, s
, -1);
315 if (symbol_conf
.use_callchain
&& sort__has_sym
) {
318 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
319 total
= h
->stat
.period
;
321 total
= hists
->stats
.total_period
;
323 perf_gtk__add_callchain(&h
->sorted_chain
, store
, &iter
,
328 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view
), TRUE
);
330 g_signal_connect(view
, "row-activated",
331 G_CALLBACK(on_row_activated
), NULL
);
332 gtk_container_add(GTK_CONTAINER(window
), view
);
335 int perf_evlist__gtk_browse_hists(struct perf_evlist
*evlist
,
337 struct hist_browser_timer
*hbt __maybe_unused
,
340 struct perf_evsel
*pos
;
347 signal(SIGSEGV
, perf_gtk__signal
);
348 signal(SIGFPE
, perf_gtk__signal
);
349 signal(SIGINT
, perf_gtk__signal
);
350 signal(SIGQUIT
, perf_gtk__signal
);
351 signal(SIGTERM
, perf_gtk__signal
);
353 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
355 gtk_window_set_title(GTK_WINDOW(window
), "perf report");
357 g_signal_connect(window
, "delete_event", gtk_main_quit
, NULL
);
359 pgctx
= perf_gtk__activate_context(window
);
363 vbox
= gtk_vbox_new(FALSE
, 0);
365 notebook
= gtk_notebook_new();
367 gtk_box_pack_start(GTK_BOX(vbox
), notebook
, TRUE
, TRUE
, 0);
369 info_bar
= perf_gtk__setup_info_bar();
371 gtk_box_pack_start(GTK_BOX(vbox
), info_bar
, FALSE
, FALSE
, 0);
373 statbar
= perf_gtk__setup_statusbar();
374 gtk_box_pack_start(GTK_BOX(vbox
), statbar
, FALSE
, FALSE
, 0);
376 gtk_container_add(GTK_CONTAINER(window
), vbox
);
378 evlist__for_each(evlist
, pos
) {
379 struct hists
*hists
= &pos
->hists
;
380 const char *evname
= perf_evsel__name(pos
);
381 GtkWidget
*scrolled_window
;
382 GtkWidget
*tab_label
;
384 size_t size
= sizeof(buf
);
386 if (symbol_conf
.event_group
) {
387 if (!perf_evsel__is_group_leader(pos
))
390 if (pos
->nr_members
> 1) {
391 perf_evsel__group_desc(pos
, buf
, size
);
396 scrolled_window
= gtk_scrolled_window_new(NULL
, NULL
);
398 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window
),
399 GTK_POLICY_AUTOMATIC
,
400 GTK_POLICY_AUTOMATIC
);
402 perf_gtk__show_hists(scrolled_window
, hists
, min_pcnt
);
404 tab_label
= gtk_label_new(evname
);
406 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), scrolled_window
, tab_label
);
409 gtk_widget_show_all(window
);
411 perf_gtk__resize_window(window
);
413 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
415 ui_helpline__push(help
);
419 perf_gtk__deactivate_context(&pgctx
);