4 #include "../libslang.h"
8 #include <linux/rbtree.h>
10 #include "../../evsel.h"
11 #include "../../evlist.h"
12 #include "../../hist.h"
13 #include "../../pstack.h"
14 #include "../../sort.h"
15 #include "../../util.h"
17 #include "../browser.h"
18 #include "../helpline.h"
26 struct hist_entry
*he_selection
;
27 struct map_symbol
*selection
;
31 static int hists__browser_title(struct hists
*self
, char *bf
, size_t size
,
34 static void hist_browser__refresh_dimensions(struct hist_browser
*self
)
36 /* 3 == +/- toggle symbol before actual hist_entry rendering */
37 self
->b
.width
= 3 + (hists__sort_list_width(self
->hists
) +
41 static void hist_browser__reset(struct hist_browser
*self
)
43 self
->b
.nr_entries
= self
->hists
->nr_entries
;
44 hist_browser__refresh_dimensions(self
);
45 ui_browser__reset_index(&self
->b
);
48 static char tree__folded_sign(bool unfolded
)
50 return unfolded
? '-' : '+';
53 static char map_symbol__folded(const struct map_symbol
*self
)
55 return self
->has_children
? tree__folded_sign(self
->unfolded
) : ' ';
58 static char hist_entry__folded(const struct hist_entry
*self
)
60 return map_symbol__folded(&self
->ms
);
63 static char callchain_list__folded(const struct callchain_list
*self
)
65 return map_symbol__folded(&self
->ms
);
68 static void map_symbol__set_folding(struct map_symbol
*self
, bool unfold
)
70 self
->unfolded
= unfold
? self
->has_children
: false;
73 static int callchain_node__count_rows_rb_tree(struct callchain_node
*self
)
78 for (nd
= rb_first(&self
->rb_root
); nd
; nd
= rb_next(nd
)) {
79 struct callchain_node
*child
= rb_entry(nd
, struct callchain_node
, rb_node
);
80 struct callchain_list
*chain
;
81 char folded_sign
= ' '; /* No children */
83 list_for_each_entry(chain
, &child
->val
, list
) {
85 /* We need this because we may not have children */
86 folded_sign
= callchain_list__folded(chain
);
87 if (folded_sign
== '+')
91 if (folded_sign
== '-') /* Have children and they're unfolded */
92 n
+= callchain_node__count_rows_rb_tree(child
);
98 static int callchain_node__count_rows(struct callchain_node
*node
)
100 struct callchain_list
*chain
;
101 bool unfolded
= false;
104 list_for_each_entry(chain
, &node
->val
, list
) {
106 unfolded
= chain
->ms
.unfolded
;
110 n
+= callchain_node__count_rows_rb_tree(node
);
115 static int callchain__count_rows(struct rb_root
*chain
)
120 for (nd
= rb_first(chain
); nd
; nd
= rb_next(nd
)) {
121 struct callchain_node
*node
= rb_entry(nd
, struct callchain_node
, rb_node
);
122 n
+= callchain_node__count_rows(node
);
128 static bool map_symbol__toggle_fold(struct map_symbol
*self
)
130 if (!self
->has_children
)
133 self
->unfolded
= !self
->unfolded
;
137 static void callchain_node__init_have_children_rb_tree(struct callchain_node
*self
)
139 struct rb_node
*nd
= rb_first(&self
->rb_root
);
141 for (nd
= rb_first(&self
->rb_root
); nd
; nd
= rb_next(nd
)) {
142 struct callchain_node
*child
= rb_entry(nd
, struct callchain_node
, rb_node
);
143 struct callchain_list
*chain
;
146 list_for_each_entry(chain
, &child
->val
, list
) {
149 chain
->ms
.has_children
= chain
->list
.next
!= &child
->val
||
150 !RB_EMPTY_ROOT(&child
->rb_root
);
152 chain
->ms
.has_children
= chain
->list
.next
== &child
->val
&&
153 !RB_EMPTY_ROOT(&child
->rb_root
);
156 callchain_node__init_have_children_rb_tree(child
);
160 static void callchain_node__init_have_children(struct callchain_node
*self
)
162 struct callchain_list
*chain
;
164 list_for_each_entry(chain
, &self
->val
, list
)
165 chain
->ms
.has_children
= !RB_EMPTY_ROOT(&self
->rb_root
);
167 callchain_node__init_have_children_rb_tree(self
);
170 static void callchain__init_have_children(struct rb_root
*self
)
174 for (nd
= rb_first(self
); nd
; nd
= rb_next(nd
)) {
175 struct callchain_node
*node
= rb_entry(nd
, struct callchain_node
, rb_node
);
176 callchain_node__init_have_children(node
);
180 static void hist_entry__init_have_children(struct hist_entry
*self
)
182 if (!self
->init_have_children
) {
183 self
->ms
.has_children
= !RB_EMPTY_ROOT(&self
->sorted_chain
);
184 callchain__init_have_children(&self
->sorted_chain
);
185 self
->init_have_children
= true;
189 static bool hist_browser__toggle_fold(struct hist_browser
*self
)
191 if (map_symbol__toggle_fold(self
->selection
)) {
192 struct hist_entry
*he
= self
->he_selection
;
194 hist_entry__init_have_children(he
);
195 self
->hists
->nr_entries
-= he
->nr_rows
;
198 he
->nr_rows
= callchain__count_rows(&he
->sorted_chain
);
201 self
->hists
->nr_entries
+= he
->nr_rows
;
202 self
->b
.nr_entries
= self
->hists
->nr_entries
;
207 /* If it doesn't have children, no toggling performed */
211 static int callchain_node__set_folding_rb_tree(struct callchain_node
*self
, bool unfold
)
216 for (nd
= rb_first(&self
->rb_root
); nd
; nd
= rb_next(nd
)) {
217 struct callchain_node
*child
= rb_entry(nd
, struct callchain_node
, rb_node
);
218 struct callchain_list
*chain
;
219 bool has_children
= false;
221 list_for_each_entry(chain
, &child
->val
, list
) {
223 map_symbol__set_folding(&chain
->ms
, unfold
);
224 has_children
= chain
->ms
.has_children
;
228 n
+= callchain_node__set_folding_rb_tree(child
, unfold
);
234 static int callchain_node__set_folding(struct callchain_node
*node
, bool unfold
)
236 struct callchain_list
*chain
;
237 bool has_children
= false;
240 list_for_each_entry(chain
, &node
->val
, list
) {
242 map_symbol__set_folding(&chain
->ms
, unfold
);
243 has_children
= chain
->ms
.has_children
;
247 n
+= callchain_node__set_folding_rb_tree(node
, unfold
);
252 static int callchain__set_folding(struct rb_root
*chain
, bool unfold
)
257 for (nd
= rb_first(chain
); nd
; nd
= rb_next(nd
)) {
258 struct callchain_node
*node
= rb_entry(nd
, struct callchain_node
, rb_node
);
259 n
+= callchain_node__set_folding(node
, unfold
);
265 static void hist_entry__set_folding(struct hist_entry
*self
, bool unfold
)
267 hist_entry__init_have_children(self
);
268 map_symbol__set_folding(&self
->ms
, unfold
);
270 if (self
->ms
.has_children
) {
271 int n
= callchain__set_folding(&self
->sorted_chain
, unfold
);
272 self
->nr_rows
= unfold
? n
: 0;
277 static void hists__set_folding(struct hists
*self
, bool unfold
)
281 self
->nr_entries
= 0;
283 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
284 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
285 hist_entry__set_folding(he
, unfold
);
286 self
->nr_entries
+= 1 + he
->nr_rows
;
290 static void hist_browser__set_folding(struct hist_browser
*self
, bool unfold
)
292 hists__set_folding(self
->hists
, unfold
);
293 self
->b
.nr_entries
= self
->hists
->nr_entries
;
294 /* Go to the start, we may be way after valid entries after a collapse */
295 ui_browser__reset_index(&self
->b
);
298 static void ui_browser__warn_lost_events(struct ui_browser
*browser
)
300 ui_browser__warning(browser
, 4,
301 "Events are being lost, check IO/CPU overload!\n\n"
302 "You may want to run 'perf' using a RT scheduler policy:\n\n"
303 " perf top -r 80\n\n"
304 "Or reduce the sampling frequency.");
307 static int hist_browser__run(struct hist_browser
*self
, const char *ev_name
,
308 void(*timer
)(void *arg
), void *arg
, int delay_secs
)
313 self
->b
.entries
= &self
->hists
->entries
;
314 self
->b
.nr_entries
= self
->hists
->nr_entries
;
316 hist_browser__refresh_dimensions(self
);
317 hists__browser_title(self
->hists
, title
, sizeof(title
), ev_name
);
319 if (ui_browser__show(&self
->b
, title
,
320 "Press '?' for help on key bindings") < 0)
324 key
= ui_browser__run(&self
->b
, delay_secs
);
329 ui_browser__update_nr_entries(&self
->b
, self
->hists
->nr_entries
);
331 if (self
->hists
->stats
.nr_lost_warned
!=
332 self
->hists
->stats
.nr_events
[PERF_RECORD_LOST
]) {
333 self
->hists
->stats
.nr_lost_warned
=
334 self
->hists
->stats
.nr_events
[PERF_RECORD_LOST
];
335 ui_browser__warn_lost_events(&self
->b
);
338 hists__browser_title(self
->hists
, title
, sizeof(title
), ev_name
);
339 ui_browser__show_title(&self
->b
, title
);
341 case 'D': { /* Debug */
343 struct hist_entry
*h
= rb_entry(self
->b
.top
,
344 struct hist_entry
, rb_node
);
346 ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
347 seq
++, self
->b
.nr_entries
,
348 self
->hists
->nr_entries
,
352 h
->row_offset
, h
->nr_rows
);
356 /* Collapse the whole world. */
357 hist_browser__set_folding(self
, false);
360 /* Expand the whole world. */
361 hist_browser__set_folding(self
, true);
364 if (hist_browser__toggle_fold(self
))
372 ui_browser__hide(&self
->b
);
376 static char *callchain_list__sym_name(struct callchain_list
*self
,
377 char *bf
, size_t bfsize
)
380 return self
->ms
.sym
->name
;
382 snprintf(bf
, bfsize
, "%#" PRIx64
, self
->ip
);
386 #define LEVEL_OFFSET_STEP 3
388 static int hist_browser__show_callchain_node_rb_tree(struct hist_browser
*self
,
389 struct callchain_node
*chain_node
,
390 u64 total
, int level
,
393 bool *is_current_entry
)
395 struct rb_node
*node
;
396 int first_row
= row
, width
, offset
= level
* LEVEL_OFFSET_STEP
;
397 u64 new_total
, remaining
;
399 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
400 new_total
= chain_node
->children_hit
;
404 remaining
= new_total
;
405 node
= rb_first(&chain_node
->rb_root
);
407 struct callchain_node
*child
= rb_entry(node
, struct callchain_node
, rb_node
);
408 struct rb_node
*next
= rb_next(node
);
409 u64 cumul
= callchain_cumul_hits(child
);
410 struct callchain_list
*chain
;
411 char folded_sign
= ' ';
413 int extra_offset
= 0;
417 list_for_each_entry(chain
, &child
->val
, list
) {
418 char ipstr
[BITS_PER_LONG
/ 4 + 1], *alloc_str
;
421 bool was_first
= first
;
426 extra_offset
= LEVEL_OFFSET_STEP
;
428 folded_sign
= callchain_list__folded(chain
);
429 if (*row_offset
!= 0) {
435 str
= callchain_list__sym_name(chain
, ipstr
, sizeof(ipstr
));
437 double percent
= cumul
* 100.0 / new_total
;
439 if (asprintf(&alloc_str
, "%2.2f%% %s", percent
, str
) < 0)
440 str
= "Not enough memory!";
445 color
= HE_COLORSET_NORMAL
;
446 width
= self
->b
.width
- (offset
+ extra_offset
+ 2);
447 if (ui_browser__is_current_entry(&self
->b
, row
)) {
448 self
->selection
= &chain
->ms
;
449 color
= HE_COLORSET_SELECTED
;
450 *is_current_entry
= true;
453 ui_browser__set_color(&self
->b
, color
);
454 ui_browser__gotorc(&self
->b
, row
, 0);
455 slsmg_write_nstring(" ", offset
+ extra_offset
);
456 slsmg_printf("%c ", folded_sign
);
457 slsmg_write_nstring(str
, width
);
460 if (++row
== self
->b
.height
)
463 if (folded_sign
== '+')
467 if (folded_sign
== '-') {
468 const int new_level
= level
+ (extra_offset
? 2 : 1);
469 row
+= hist_browser__show_callchain_node_rb_tree(self
, child
, new_total
,
470 new_level
, row
, row_offset
,
473 if (row
== self
->b
.height
)
478 return row
- first_row
;
481 static int hist_browser__show_callchain_node(struct hist_browser
*self
,
482 struct callchain_node
*node
,
483 int level
, unsigned short row
,
485 bool *is_current_entry
)
487 struct callchain_list
*chain
;
489 offset
= level
* LEVEL_OFFSET_STEP
,
490 width
= self
->b
.width
- offset
;
491 char folded_sign
= ' ';
493 list_for_each_entry(chain
, &node
->val
, list
) {
494 char ipstr
[BITS_PER_LONG
/ 4 + 1], *s
;
497 folded_sign
= callchain_list__folded(chain
);
499 if (*row_offset
!= 0) {
504 color
= HE_COLORSET_NORMAL
;
505 if (ui_browser__is_current_entry(&self
->b
, row
)) {
506 self
->selection
= &chain
->ms
;
507 color
= HE_COLORSET_SELECTED
;
508 *is_current_entry
= true;
511 s
= callchain_list__sym_name(chain
, ipstr
, sizeof(ipstr
));
512 ui_browser__gotorc(&self
->b
, row
, 0);
513 ui_browser__set_color(&self
->b
, color
);
514 slsmg_write_nstring(" ", offset
);
515 slsmg_printf("%c ", folded_sign
);
516 slsmg_write_nstring(s
, width
- 2);
518 if (++row
== self
->b
.height
)
522 if (folded_sign
== '-')
523 row
+= hist_browser__show_callchain_node_rb_tree(self
, node
,
524 self
->hists
->stats
.total_period
,
529 return row
- first_row
;
532 static int hist_browser__show_callchain(struct hist_browser
*self
,
533 struct rb_root
*chain
,
534 int level
, unsigned short row
,
536 bool *is_current_entry
)
541 for (nd
= rb_first(chain
); nd
; nd
= rb_next(nd
)) {
542 struct callchain_node
*node
= rb_entry(nd
, struct callchain_node
, rb_node
);
544 row
+= hist_browser__show_callchain_node(self
, node
, level
,
547 if (row
== self
->b
.height
)
551 return row
- first_row
;
554 static int hist_browser__show_entry(struct hist_browser
*self
,
555 struct hist_entry
*entry
,
561 int width
= self
->b
.width
- 6; /* The percentage */
562 char folded_sign
= ' ';
563 bool current_entry
= ui_browser__is_current_entry(&self
->b
, row
);
564 off_t row_offset
= entry
->row_offset
;
567 self
->he_selection
= entry
;
568 self
->selection
= &entry
->ms
;
571 if (symbol_conf
.use_callchain
) {
572 hist_entry__init_have_children(entry
);
573 folded_sign
= hist_entry__folded(entry
);
576 if (row_offset
== 0) {
577 hist_entry__snprintf(entry
, s
, sizeof(s
), self
->hists
);
578 percent
= (entry
->period
* 100.0) / self
->hists
->stats
.total_period
;
580 ui_browser__set_percent_color(&self
->b
, percent
, current_entry
);
581 ui_browser__gotorc(&self
->b
, row
, 0);
582 if (symbol_conf
.use_callchain
) {
583 slsmg_printf("%c ", folded_sign
);
587 slsmg_printf(" %5.2f%%", percent
);
589 /* The scroll bar isn't being used */
590 if (!self
->b
.navkeypressed
)
593 if (!current_entry
|| !self
->b
.navkeypressed
)
594 ui_browser__set_color(&self
->b
, HE_COLORSET_NORMAL
);
596 if (symbol_conf
.show_nr_samples
) {
597 slsmg_printf(" %11u", entry
->nr_events
);
601 if (symbol_conf
.show_total_period
) {
602 slsmg_printf(" %12" PRIu64
, entry
->period
);
606 slsmg_write_nstring(s
, width
);
612 if (folded_sign
== '-' && row
!= self
->b
.height
) {
613 printed
+= hist_browser__show_callchain(self
, &entry
->sorted_chain
,
617 self
->he_selection
= entry
;
623 static void ui_browser__hists_init_top(struct ui_browser
*browser
)
625 if (browser
->top
== NULL
) {
626 struct hist_browser
*hb
;
628 hb
= container_of(browser
, struct hist_browser
, b
);
629 browser
->top
= rb_first(&hb
->hists
->entries
);
633 static unsigned int hist_browser__refresh(struct ui_browser
*self
)
637 struct hist_browser
*hb
= container_of(self
, struct hist_browser
, b
);
639 ui_browser__hists_init_top(self
);
641 for (nd
= self
->top
; nd
; nd
= rb_next(nd
)) {
642 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
647 row
+= hist_browser__show_entry(hb
, h
, row
);
648 if (row
== self
->height
)
655 static struct rb_node
*hists__filter_entries(struct rb_node
*nd
)
658 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
668 static struct rb_node
*hists__filter_prev_entries(struct rb_node
*nd
)
671 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
681 static void ui_browser__hists_seek(struct ui_browser
*self
,
682 off_t offset
, int whence
)
684 struct hist_entry
*h
;
688 if (self
->nr_entries
== 0)
691 ui_browser__hists_init_top(self
);
695 nd
= hists__filter_entries(rb_first(self
->entries
));
701 nd
= hists__filter_prev_entries(rb_last(self
->entries
));
709 * Moves not relative to the first visible entry invalidates its
712 h
= rb_entry(self
->top
, struct hist_entry
, rb_node
);
716 * Here we have to check if nd is expanded (+), if it is we can't go
717 * the next top level hist_entry, instead we must compute an offset of
718 * what _not_ to show and not change the first visible entry.
720 * This offset increments when we are going from top to bottom and
721 * decreases when we're going from bottom to top.
723 * As we don't have backpointers to the top level in the callchains
724 * structure, we need to always print the whole hist_entry callchain,
725 * skipping the first ones that are before the first visible entry
726 * and stop when we printed enough lines to fill the screen.
731 h
= rb_entry(nd
, struct hist_entry
, rb_node
);
732 if (h
->ms
.unfolded
) {
733 u16 remaining
= h
->nr_rows
- h
->row_offset
;
734 if (offset
> remaining
) {
738 h
->row_offset
+= offset
;
744 nd
= hists__filter_entries(rb_next(nd
));
749 } while (offset
!= 0);
750 } else if (offset
< 0) {
752 h
= rb_entry(nd
, struct hist_entry
, rb_node
);
753 if (h
->ms
.unfolded
) {
755 if (-offset
> h
->row_offset
) {
756 offset
+= h
->row_offset
;
759 h
->row_offset
+= offset
;
765 if (-offset
> h
->nr_rows
) {
766 offset
+= h
->nr_rows
;
769 h
->row_offset
= h
->nr_rows
+ offset
;
777 nd
= hists__filter_prev_entries(rb_prev(nd
));
784 * Last unfiltered hist_entry, check if it is
785 * unfolded, if it is then we should have
786 * row_offset at its last entry.
788 h
= rb_entry(nd
, struct hist_entry
, rb_node
);
790 h
->row_offset
= h
->nr_rows
;
797 h
= rb_entry(nd
, struct hist_entry
, rb_node
);
802 static struct hist_browser
*hist_browser__new(struct hists
*hists
)
804 struct hist_browser
*self
= zalloc(sizeof(*self
));
808 self
->b
.refresh
= hist_browser__refresh
;
809 self
->b
.seek
= ui_browser__hists_seek
;
810 self
->b
.use_navkeypressed
= true,
811 self
->has_symbols
= sort_sym
.list
.next
!= NULL
;
817 static void hist_browser__delete(struct hist_browser
*self
)
822 static struct hist_entry
*hist_browser__selected_entry(struct hist_browser
*self
)
824 return self
->he_selection
;
827 static struct thread
*hist_browser__selected_thread(struct hist_browser
*self
)
829 return self
->he_selection
->thread
;
832 static int hists__browser_title(struct hists
*self
, char *bf
, size_t size
,
837 const struct dso
*dso
= self
->dso_filter
;
838 const struct thread
*thread
= self
->thread_filter
;
839 unsigned long nr_events
= self
->stats
.nr_events
[PERF_RECORD_SAMPLE
];
841 nr_events
= convert_unit(nr_events
, &unit
);
842 printed
= snprintf(bf
, size
, "Events: %lu%c %s", nr_events
, unit
, ev_name
);
845 printed
+= snprintf(bf
+ printed
, size
- printed
,
847 (thread
->comm_set
? thread
->comm
: ""),
850 printed
+= snprintf(bf
+ printed
, size
- printed
,
851 ", DSO: %s", dso
->short_name
);
855 static int perf_evsel__hists_browse(struct perf_evsel
*evsel
, int nr_events
,
856 const char *helpline
, const char *ev_name
,
858 void(*timer
)(void *arg
), void *arg
,
861 struct hists
*self
= &evsel
->hists
;
862 struct hist_browser
*browser
= hist_browser__new(self
);
863 struct pstack
*fstack
;
869 fstack
= pstack__new(2);
873 ui_helpline__push(helpline
);
876 const struct thread
*thread
= NULL
;
877 const struct dso
*dso
= NULL
;
879 int nr_options
= 0, choice
= 0, i
,
880 annotate
= -2, zoom_dso
= -2, zoom_thread
= -2,
883 key
= hist_browser__run(browser
, ev_name
, timer
, arg
, delay_secs
);
885 if (browser
->he_selection
!= NULL
) {
886 thread
= hist_browser__selected_thread(browser
);
887 dso
= browser
->selection
->map
? browser
->selection
->map
->dso
: NULL
;
896 * Exit the browser, let hists__browser_tree
897 * go to the next or previous
901 if (!browser
->has_symbols
) {
902 ui_browser__warning(&browser
->b
, delay_secs
* 2,
903 "Annotation is only available for symbolic views, "
904 "include \"sym\" in --sort to use it.");
908 if (browser
->selection
== NULL
||
909 browser
->selection
->sym
== NULL
||
910 browser
->selection
->map
->dso
->annotate_warned
)
920 ui_browser__help_window(&browser
->b
,
921 "h/?/F1 Show this window\n"
923 "PGDN/SPACE Navigate\n"
924 "q/ESC/CTRL+C Exit browser\n\n"
925 "For multiple event sessions:\n\n"
926 "TAB/UNTAB Switch events\n\n"
927 "For symbolic views (--sort has sym):\n\n"
928 "-> Zoom into DSO/Threads & Annotate current symbol\n"
930 "a Annotate current symbol\n"
931 "C Collapse all callchains\n"
932 "E Expand all callchains\n"
933 "d Zoom into current DSO\n"
934 "t Zoom into current Thread");
943 if (pstack__empty(fstack
)) {
945 * Go back to the perf_evsel_menu__run or other user
951 top
= pstack__pop(fstack
);
952 if (top
== &browser
->hists
->dso_filter
)
954 if (top
== &browser
->hists
->thread_filter
)
955 goto zoom_out_thread
;
960 !ui_browser__dialog_yesno(&browser
->b
,
961 "Do you really want to exit?"))
971 if (!browser
->has_symbols
)
972 goto add_exit_option
;
974 if (browser
->selection
!= NULL
&&
975 browser
->selection
->sym
!= NULL
&&
976 !browser
->selection
->map
->dso
->annotate_warned
&&
977 asprintf(&options
[nr_options
], "Annotate %s",
978 browser
->selection
->sym
->name
) > 0)
979 annotate
= nr_options
++;
981 if (thread
!= NULL
&&
982 asprintf(&options
[nr_options
], "Zoom %s %s(%d) thread",
983 (browser
->hists
->thread_filter
? "out of" : "into"),
984 (thread
->comm_set
? thread
->comm
: ""),
986 zoom_thread
= nr_options
++;
989 asprintf(&options
[nr_options
], "Zoom %s %s DSO",
990 (browser
->hists
->dso_filter
? "out of" : "into"),
991 (dso
->kernel
? "the Kernel" : dso
->short_name
)) > 0)
992 zoom_dso
= nr_options
++;
994 if (browser
->selection
!= NULL
&&
995 browser
->selection
->map
!= NULL
&&
996 asprintf(&options
[nr_options
], "Browse map details") > 0)
997 browse_map
= nr_options
++;
999 options
[nr_options
++] = (char *)"Exit";
1001 choice
= ui__popup_menu(nr_options
, options
);
1003 for (i
= 0; i
< nr_options
- 1; ++i
)
1006 if (choice
== nr_options
- 1)
1012 if (choice
== annotate
) {
1013 struct hist_entry
*he
;
1016 he
= hist_browser__selected_entry(browser
);
1020 * Don't let this be freed, say, by hists__decay_entry.
1023 err
= hist_entry__tui_annotate(he
, evsel
->idx
,
1024 timer
, arg
, delay_secs
);
1026 ui_browser__update_nr_entries(&browser
->b
, browser
->hists
->nr_entries
);
1028 ui_browser__handle_resize(&browser
->b
);
1029 } else if (choice
== browse_map
)
1030 map__browse(browser
->selection
->map
);
1031 else if (choice
== zoom_dso
) {
1033 if (browser
->hists
->dso_filter
) {
1034 pstack__remove(fstack
, &browser
->hists
->dso_filter
);
1037 browser
->hists
->dso_filter
= NULL
;
1038 sort_dso
.elide
= false;
1042 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
1043 dso
->kernel
? "the Kernel" : dso
->short_name
);
1044 browser
->hists
->dso_filter
= dso
;
1045 sort_dso
.elide
= true;
1046 pstack__push(fstack
, &browser
->hists
->dso_filter
);
1048 hists__filter_by_dso(self
);
1049 hist_browser__reset(browser
);
1050 } else if (choice
== zoom_thread
) {
1052 if (browser
->hists
->thread_filter
) {
1053 pstack__remove(fstack
, &browser
->hists
->thread_filter
);
1056 browser
->hists
->thread_filter
= NULL
;
1057 sort_thread
.elide
= false;
1059 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
1060 thread
->comm_set
? thread
->comm
: "",
1062 browser
->hists
->thread_filter
= thread
;
1063 sort_thread
.elide
= true;
1064 pstack__push(fstack
, &browser
->hists
->thread_filter
);
1066 hists__filter_by_thread(self
);
1067 hist_browser__reset(browser
);
1071 pstack__delete(fstack
);
1073 hist_browser__delete(browser
);
1077 struct perf_evsel_menu
{
1078 struct ui_browser b
;
1079 struct perf_evsel
*selection
;
1080 bool lost_events
, lost_events_warned
;
1083 static void perf_evsel_menu__write(struct ui_browser
*browser
,
1084 void *entry
, int row
)
1086 struct perf_evsel_menu
*menu
= container_of(browser
,
1087 struct perf_evsel_menu
, b
);
1088 struct perf_evsel
*evsel
= list_entry(entry
, struct perf_evsel
, node
);
1089 bool current_entry
= ui_browser__is_current_entry(browser
, row
);
1090 unsigned long nr_events
= evsel
->hists
.stats
.nr_events
[PERF_RECORD_SAMPLE
];
1091 const char *ev_name
= event_name(evsel
);
1093 const char *warn
= " ";
1096 ui_browser__set_color(browser
, current_entry
? HE_COLORSET_SELECTED
:
1097 HE_COLORSET_NORMAL
);
1099 nr_events
= convert_unit(nr_events
, &unit
);
1100 printed
= snprintf(bf
, sizeof(bf
), "%lu%c%s%s", nr_events
,
1101 unit
, unit
== ' ' ? "" : " ", ev_name
);
1102 slsmg_printf("%s", bf
);
1104 nr_events
= evsel
->hists
.stats
.nr_events
[PERF_RECORD_LOST
];
1105 if (nr_events
!= 0) {
1106 menu
->lost_events
= true;
1108 ui_browser__set_color(browser
, HE_COLORSET_TOP
);
1109 nr_events
= convert_unit(nr_events
, &unit
);
1110 snprintf(bf
, sizeof(bf
), ": %ld%c%schunks LOST!", nr_events
,
1111 unit
, unit
== ' ' ? "" : " ");
1115 slsmg_write_nstring(warn
, browser
->width
- printed
);
1118 menu
->selection
= evsel
;
1121 static int perf_evsel_menu__run(struct perf_evsel_menu
*menu
,
1122 int nr_events
, const char *help
,
1123 void(*timer
)(void *arg
), void *arg
, int delay_secs
)
1125 struct perf_evlist
*evlist
= menu
->b
.priv
;
1126 struct perf_evsel
*pos
;
1127 const char *ev_name
, *title
= "Available samples";
1130 if (ui_browser__show(&menu
->b
, title
,
1131 "ESC: exit, ENTER|->: Browse histograms") < 0)
1135 key
= ui_browser__run(&menu
->b
, delay_secs
);
1141 if (!menu
->lost_events_warned
&& menu
->lost_events
) {
1142 ui_browser__warn_lost_events(&menu
->b
);
1143 menu
->lost_events_warned
= true;
1148 if (!menu
->selection
)
1150 pos
= menu
->selection
;
1152 perf_evlist__set_selected(evlist
, pos
);
1154 * Give the calling tool a chance to populate the non
1155 * default evsel resorted hists tree.
1159 ev_name
= event_name(pos
);
1160 key
= perf_evsel__hists_browse(pos
, nr_events
, help
,
1161 ev_name
, true, timer
,
1163 ui_browser__show_title(&menu
->b
, title
);
1166 if (pos
->node
.next
== &evlist
->entries
)
1167 pos
= list_entry(evlist
->entries
.next
, struct perf_evsel
, node
);
1169 pos
= list_entry(pos
->node
.next
, struct perf_evsel
, node
);
1172 if (pos
->node
.prev
== &evlist
->entries
)
1173 pos
= list_entry(evlist
->entries
.prev
, struct perf_evsel
, node
);
1175 pos
= list_entry(pos
->node
.prev
, struct perf_evsel
, node
);
1178 if (!ui_browser__dialog_yesno(&menu
->b
,
1179 "Do you really want to exit?"))
1191 if (!ui_browser__dialog_yesno(&menu
->b
,
1192 "Do you really want to exit?"))
1204 ui_browser__hide(&menu
->b
);
1208 static int __perf_evlist__tui_browse_hists(struct perf_evlist
*evlist
,
1210 void(*timer
)(void *arg
), void *arg
,
1213 struct perf_evsel
*pos
;
1214 struct perf_evsel_menu menu
= {
1216 .entries
= &evlist
->entries
,
1217 .refresh
= ui_browser__list_head_refresh
,
1218 .seek
= ui_browser__list_head_seek
,
1219 .write
= perf_evsel_menu__write
,
1220 .nr_entries
= evlist
->nr_entries
,
1225 ui_helpline__push("Press ESC to exit");
1227 list_for_each_entry(pos
, &evlist
->entries
, node
) {
1228 const char *ev_name
= event_name(pos
);
1229 size_t line_len
= strlen(ev_name
) + 7;
1231 if (menu
.b
.width
< line_len
)
1232 menu
.b
.width
= line_len
;
1234 * Cache the evsel name, tracepoints have a _high_ cost per
1235 * event_name() call.
1237 if (pos
->name
== NULL
)
1238 pos
->name
= strdup(ev_name
);
1241 return perf_evsel_menu__run(&menu
, evlist
->nr_entries
, help
, timer
,
1245 int perf_evlist__tui_browse_hists(struct perf_evlist
*evlist
, const char *help
,
1246 void(*timer
)(void *arg
), void *arg
,
1250 if (evlist
->nr_entries
== 1) {
1251 struct perf_evsel
*first
= list_entry(evlist
->entries
.next
,
1252 struct perf_evsel
, node
);
1253 const char *ev_name
= event_name(first
);
1254 return perf_evsel__hists_browse(first
, evlist
->nr_entries
, help
,
1255 ev_name
, false, timer
, arg
,
1259 return __perf_evlist__tui_browse_hists(evlist
, help
,
1260 timer
, arg
, delay_secs
);