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"
25 struct hist_entry *he_selection;
26 struct map_symbol *selection;
27 const struct thread *thread_filter;
28 const struct dso *dso_filter;
32 static int hists__browser_title(struct hists *self, char *bf, size_t size,
33 const char *ev_name, const struct dso *dso,
34 const struct thread *thread);
36 static void hist_browser__refresh_dimensions(struct hist_browser *self)
38 /* 3 == +/- toggle symbol before actual hist_entry rendering */
39 self->b.width = 3 + (hists__sort_list_width(self->hists) +
43 static void hist_browser__reset(struct hist_browser *self)
45 self->b.nr_entries = self->hists->nr_entries;
46 hist_browser__refresh_dimensions(self);
47 ui_browser__reset_index(&self->b);
50 static char tree__folded_sign(bool unfolded)
52 return unfolded ? '-' : '+';
55 static char map_symbol__folded(const struct map_symbol *self)
57 return self->has_children ? tree__folded_sign(self->unfolded) : ' ';
60 static char hist_entry__folded(const struct hist_entry *self)
62 return map_symbol__folded(&self->ms);
65 static char callchain_list__folded(const struct callchain_list *self)
67 return map_symbol__folded(&self->ms);
70 static void map_symbol__set_folding(struct map_symbol *self, bool unfold)
72 self->unfolded = unfold ? self->has_children : false;
75 static int callchain_node__count_rows_rb_tree(struct callchain_node *self)
80 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
81 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
82 struct callchain_list *chain;
83 char folded_sign = ' '; /* No children */
85 list_for_each_entry(chain, &child->val, list) {
87 /* We need this because we may not have children */
88 folded_sign = callchain_list__folded(chain);
89 if (folded_sign == '+')
93 if (folded_sign == '-') /* Have children and they're unfolded */
94 n += callchain_node__count_rows_rb_tree(child);
100 static int callchain_node__count_rows(struct callchain_node *node)
102 struct callchain_list *chain;
103 bool unfolded = false;
106 list_for_each_entry(chain, &node->val, list) {
108 unfolded = chain->ms.unfolded;
112 n += callchain_node__count_rows_rb_tree(node);
117 static int callchain__count_rows(struct rb_root *chain)
122 for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
123 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
124 n += callchain_node__count_rows(node);
130 static bool map_symbol__toggle_fold(struct map_symbol *self)
132 if (!self->has_children)
135 self->unfolded = !self->unfolded;
139 static void callchain_node__init_have_children_rb_tree(struct callchain_node *self)
141 struct rb_node *nd = rb_first(&self->rb_root);
143 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
144 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
145 struct callchain_list *chain;
148 list_for_each_entry(chain, &child->val, list) {
151 chain->ms.has_children = chain->list.next != &child->val ||
152 !RB_EMPTY_ROOT(&child->rb_root);
154 chain->ms.has_children = chain->list.next == &child->val &&
155 !RB_EMPTY_ROOT(&child->rb_root);
158 callchain_node__init_have_children_rb_tree(child);
162 static void callchain_node__init_have_children(struct callchain_node *self)
164 struct callchain_list *chain;
166 list_for_each_entry(chain, &self->val, list)
167 chain->ms.has_children = !RB_EMPTY_ROOT(&self->rb_root);
169 callchain_node__init_have_children_rb_tree(self);
172 static void callchain__init_have_children(struct rb_root *self)
176 for (nd = rb_first(self); nd; nd = rb_next(nd)) {
177 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
178 callchain_node__init_have_children(node);
182 static void hist_entry__init_have_children(struct hist_entry *self)
184 if (!self->init_have_children) {
185 self->ms.has_children = !RB_EMPTY_ROOT(&self->sorted_chain);
186 callchain__init_have_children(&self->sorted_chain);
187 self->init_have_children = true;
191 static bool hist_browser__toggle_fold(struct hist_browser *self)
193 if (map_symbol__toggle_fold(self->selection)) {
194 struct hist_entry *he = self->he_selection;
196 hist_entry__init_have_children(he);
197 self->hists->nr_entries -= he->nr_rows;
200 he->nr_rows = callchain__count_rows(&he->sorted_chain);
203 self->hists->nr_entries += he->nr_rows;
204 self->b.nr_entries = self->hists->nr_entries;
209 /* If it doesn't have children, no toggling performed */
213 static int callchain_node__set_folding_rb_tree(struct callchain_node *self, bool unfold)
218 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
219 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
220 struct callchain_list *chain;
221 bool has_children = false;
223 list_for_each_entry(chain, &child->val, list) {
225 map_symbol__set_folding(&chain->ms, unfold);
226 has_children = chain->ms.has_children;
230 n += callchain_node__set_folding_rb_tree(child, unfold);
236 static int callchain_node__set_folding(struct callchain_node *node, bool unfold)
238 struct callchain_list *chain;
239 bool has_children = false;
242 list_for_each_entry(chain, &node->val, list) {
244 map_symbol__set_folding(&chain->ms, unfold);
245 has_children = chain->ms.has_children;
249 n += callchain_node__set_folding_rb_tree(node, unfold);
254 static int callchain__set_folding(struct rb_root *chain, bool unfold)
259 for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
260 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
261 n += callchain_node__set_folding(node, unfold);
267 static void hist_entry__set_folding(struct hist_entry *self, bool unfold)
269 hist_entry__init_have_children(self);
270 map_symbol__set_folding(&self->ms, unfold);
272 if (self->ms.has_children) {
273 int n = callchain__set_folding(&self->sorted_chain, unfold);
274 self->nr_rows = unfold ? n : 0;
279 static void hists__set_folding(struct hists *self, bool unfold)
283 self->nr_entries = 0;
285 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
286 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
287 hist_entry__set_folding(he, unfold);
288 self->nr_entries += 1 + he->nr_rows;
292 static void hist_browser__set_folding(struct hist_browser *self, bool unfold)
294 hists__set_folding(self->hists, unfold);
295 self->b.nr_entries = self->hists->nr_entries;
296 /* Go to the start, we may be way after valid entries after a collapse */
297 ui_browser__reset_index(&self->b);
300 static int hist_browser__run(struct hist_browser *self, const char *ev_name,
301 void(*timer)(void *arg), void *arg, int delay_secs)
306 self->b.entries = &self->hists->entries;
307 self->b.nr_entries = self->hists->nr_entries;
309 hist_browser__refresh_dimensions(self);
310 hists__browser_title(self->hists, title, sizeof(title), ev_name,
311 self->dso_filter, self->thread_filter);
313 if (ui_browser__show(&self->b, title,
314 "Press '?' for help on key bindings") < 0)
318 key = ui_browser__run(&self->b, delay_secs);
322 /* FIXME we need to check if it was es.reason == NEWT_EXIT_TIMER */
324 ui_browser__update_nr_entries(&self->b, self->hists->nr_entries);
325 hists__browser_title(self->hists, title, sizeof(title),
326 ev_name, self->dso_filter,
327 self->thread_filter);
328 ui_browser__show_title(&self->b, title);
330 case 'D': { /* Debug */
332 struct hist_entry *h = rb_entry(self->b.top,
333 struct hist_entry, rb_node);
335 ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
336 seq++, self->b.nr_entries,
337 self->hists->nr_entries,
341 h->row_offset, h->nr_rows);
345 /* Collapse the whole world. */
346 hist_browser__set_folding(self, false);
349 /* Expand the whole world. */
350 hist_browser__set_folding(self, true);
353 if (hist_browser__toggle_fold(self))
361 ui_browser__hide(&self->b);
365 static char *callchain_list__sym_name(struct callchain_list *self,
366 char *bf, size_t bfsize)
369 return self->ms.sym->name;
371 snprintf(bf, bfsize, "%#" PRIx64, self->ip);
375 #define LEVEL_OFFSET_STEP 3
377 static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self,
378 struct callchain_node *chain_node,
379 u64 total, int level,
382 bool *is_current_entry)
384 struct rb_node *node;
385 int first_row = row, width, offset = level * LEVEL_OFFSET_STEP;
386 u64 new_total, remaining;
388 if (callchain_param.mode == CHAIN_GRAPH_REL)
389 new_total = chain_node->children_hit;
393 remaining = new_total;
394 node = rb_first(&chain_node->rb_root);
396 struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
397 struct rb_node *next = rb_next(node);
398 u64 cumul = callchain_cumul_hits(child);
399 struct callchain_list *chain;
400 char folded_sign = ' ';
402 int extra_offset = 0;
406 list_for_each_entry(chain, &child->val, list) {
407 char ipstr[BITS_PER_LONG / 4 + 1], *alloc_str;
410 bool was_first = first;
415 extra_offset = LEVEL_OFFSET_STEP;
417 folded_sign = callchain_list__folded(chain);
418 if (*row_offset != 0) {
424 str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
426 double percent = cumul * 100.0 / new_total;
428 if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0)
429 str = "Not enough memory!";
434 color = HE_COLORSET_NORMAL;
435 width = self->b.width - (offset + extra_offset + 2);
436 if (ui_browser__is_current_entry(&self->b, row)) {
437 self->selection = &chain->ms;
438 color = HE_COLORSET_SELECTED;
439 *is_current_entry = true;
442 ui_browser__set_color(&self->b, color);
443 ui_browser__gotorc(&self->b, row, 0);
444 slsmg_write_nstring(" ", offset + extra_offset);
445 slsmg_printf("%c ", folded_sign);
446 slsmg_write_nstring(str, width);
449 if (++row == self->b.height)
452 if (folded_sign == '+')
456 if (folded_sign == '-') {
457 const int new_level = level + (extra_offset ? 2 : 1);
458 row += hist_browser__show_callchain_node_rb_tree(self, child, new_total,
459 new_level, row, row_offset,
462 if (row == self->b.height)
467 return row - first_row;
470 static int hist_browser__show_callchain_node(struct hist_browser *self,
471 struct callchain_node *node,
472 int level, unsigned short row,
474 bool *is_current_entry)
476 struct callchain_list *chain;
478 offset = level * LEVEL_OFFSET_STEP,
479 width = self->b.width - offset;
480 char folded_sign = ' ';
482 list_for_each_entry(chain, &node->val, list) {
483 char ipstr[BITS_PER_LONG / 4 + 1], *s;
486 folded_sign = callchain_list__folded(chain);
488 if (*row_offset != 0) {
493 color = HE_COLORSET_NORMAL;
494 if (ui_browser__is_current_entry(&self->b, row)) {
495 self->selection = &chain->ms;
496 color = HE_COLORSET_SELECTED;
497 *is_current_entry = true;
500 s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
501 ui_browser__gotorc(&self->b, row, 0);
502 ui_browser__set_color(&self->b, color);
503 slsmg_write_nstring(" ", offset);
504 slsmg_printf("%c ", folded_sign);
505 slsmg_write_nstring(s, width - 2);
507 if (++row == self->b.height)
511 if (folded_sign == '-')
512 row += hist_browser__show_callchain_node_rb_tree(self, node,
513 self->hists->stats.total_period,
518 return row - first_row;
521 static int hist_browser__show_callchain(struct hist_browser *self,
522 struct rb_root *chain,
523 int level, unsigned short row,
525 bool *is_current_entry)
530 for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
531 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
533 row += hist_browser__show_callchain_node(self, node, level,
536 if (row == self->b.height)
540 return row - first_row;
543 static int hist_browser__show_entry(struct hist_browser *self,
544 struct hist_entry *entry,
550 int color, width = self->b.width;
551 char folded_sign = ' ';
552 bool current_entry = ui_browser__is_current_entry(&self->b, row);
553 off_t row_offset = entry->row_offset;
556 self->he_selection = entry;
557 self->selection = &entry->ms;
560 if (symbol_conf.use_callchain) {
561 hist_entry__init_have_children(entry);
562 folded_sign = hist_entry__folded(entry);
565 if (row_offset == 0) {
566 hist_entry__snprintf(entry, s, sizeof(s), self->hists, NULL, false,
567 0, false, self->hists->stats.total_period);
568 percent = (entry->period * 100.0) / self->hists->stats.total_period;
570 color = HE_COLORSET_SELECTED;
571 if (!current_entry) {
572 if (percent >= MIN_RED)
573 color = HE_COLORSET_TOP;
574 else if (percent >= MIN_GREEN)
575 color = HE_COLORSET_MEDIUM;
577 color = HE_COLORSET_NORMAL;
580 ui_browser__set_color(&self->b, color);
581 ui_browser__gotorc(&self->b, row, 0);
582 if (symbol_conf.use_callchain) {
583 slsmg_printf("%c ", folded_sign);
586 slsmg_write_nstring(s, width);
592 if (folded_sign == '-' && row != self->b.height) {
593 printed += hist_browser__show_callchain(self, &entry->sorted_chain,
597 self->he_selection = entry;
603 static unsigned int hist_browser__refresh(struct ui_browser *self)
607 struct hist_browser *hb = container_of(self, struct hist_browser, b);
609 if (self->top == NULL)
610 self->top = rb_first(&hb->hists->entries);
612 for (nd = self->top; nd; nd = rb_next(nd)) {
613 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
618 row += hist_browser__show_entry(hb, h, row);
619 if (row == self->height)
626 static struct rb_node *hists__filter_entries(struct rb_node *nd)
629 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
639 static struct rb_node *hists__filter_prev_entries(struct rb_node *nd)
642 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
652 static void ui_browser__hists_seek(struct ui_browser *self,
653 off_t offset, int whence)
655 struct hist_entry *h;
659 if (self->nr_entries == 0)
664 nd = hists__filter_entries(rb_first(self->entries));
670 nd = hists__filter_prev_entries(rb_last(self->entries));
678 * Moves not relative to the first visible entry invalidates its
681 h = rb_entry(self->top, struct hist_entry, rb_node);
685 * Here we have to check if nd is expanded (+), if it is we can't go
686 * the next top level hist_entry, instead we must compute an offset of
687 * what _not_ to show and not change the first visible entry.
689 * This offset increments when we are going from top to bottom and
690 * decreases when we're going from bottom to top.
692 * As we don't have backpointers to the top level in the callchains
693 * structure, we need to always print the whole hist_entry callchain,
694 * skipping the first ones that are before the first visible entry
695 * and stop when we printed enough lines to fill the screen.
700 h = rb_entry(nd, struct hist_entry, rb_node);
701 if (h->ms.unfolded) {
702 u16 remaining = h->nr_rows - h->row_offset;
703 if (offset > remaining) {
707 h->row_offset += offset;
713 nd = hists__filter_entries(rb_next(nd));
718 } while (offset != 0);
719 } else if (offset < 0) {
721 h = rb_entry(nd, struct hist_entry, rb_node);
722 if (h->ms.unfolded) {
724 if (-offset > h->row_offset) {
725 offset += h->row_offset;
728 h->row_offset += offset;
734 if (-offset > h->nr_rows) {
735 offset += h->nr_rows;
738 h->row_offset = h->nr_rows + offset;
746 nd = hists__filter_prev_entries(rb_prev(nd));
753 * Last unfiltered hist_entry, check if it is
754 * unfolded, if it is then we should have
755 * row_offset at its last entry.
757 h = rb_entry(nd, struct hist_entry, rb_node);
759 h->row_offset = h->nr_rows;
766 h = rb_entry(nd, struct hist_entry, rb_node);
771 static struct hist_browser *hist_browser__new(struct hists *hists)
773 struct hist_browser *self = zalloc(sizeof(*self));
777 self->b.refresh = hist_browser__refresh;
778 self->b.seek = ui_browser__hists_seek;
779 self->has_symbols = sort_sym.list.next != NULL;
785 static void hist_browser__delete(struct hist_browser *self)
790 static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self)
792 return self->he_selection;
795 static struct thread *hist_browser__selected_thread(struct hist_browser *self)
797 return self->he_selection->thread;
800 static int hists__browser_title(struct hists *self, char *bf, size_t size,
801 const char *ev_name, const struct dso *dso,
802 const struct thread *thread)
806 unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE];
808 nr_events = convert_unit(nr_events, &unit);
809 printed = snprintf(bf, size, "Events: %lu%c %s", nr_events, unit, ev_name);
812 printed += snprintf(bf + printed, size - printed,
814 (thread->comm_set ? thread->comm : ""),
817 printed += snprintf(bf + printed, size - printed,
818 ", DSO: %s", dso->short_name);
822 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
823 const char *helpline, const char *ev_name,
825 void(*timer)(void *arg), void *arg,
828 struct hists *self = &evsel->hists;
829 struct hist_browser *browser = hist_browser__new(self);
830 struct pstack *fstack;
836 fstack = pstack__new(2);
840 ui_helpline__push(helpline);
843 const struct thread *thread = NULL;
844 const struct dso *dso = NULL;
846 int nr_options = 0, choice = 0, i,
847 annotate = -2, zoom_dso = -2, zoom_thread = -2,
850 key = hist_browser__run(browser, ev_name, timer, arg, delay_secs);
852 if (browser->he_selection != NULL) {
853 thread = hist_browser__selected_thread(browser);
854 dso = browser->selection->map ? browser->selection->map->dso : NULL;
861 * Exit the browser, let hists__browser_tree
862 * go to the next or previous
866 if (browser->selection == NULL ||
867 browser->selection->sym == NULL ||
868 browser->selection->map->dso->annotate_warned)
878 ui__help_window("h/?/F1 Show this window\n"
879 "TAB/UNTAB Switch events\n"
880 "q/CTRL+C Exit browser\n\n"
881 "For symbolic views (--sort has sym):\n\n"
882 "-> Zoom into DSO/Threads & Annotate current symbol\n"
884 "a Annotate current symbol\n"
885 "C Collapse all callchains\n"
886 "E Expand all callchains\n"
887 "d Zoom into current DSO\n"
888 "t Zoom into current Thread\n");
894 case NEWT_KEY_LEFT: {
897 if (pstack__empty(fstack)) {
899 * Go back to the perf_evsel_menu__run or other user
905 top = pstack__pop(fstack);
906 if (top == &browser->dso_filter)
908 if (top == &browser->thread_filter)
909 goto zoom_out_thread;
912 case NEWT_KEY_ESCAPE:
914 !ui__dialog_yesno("Do you really want to exit?"))
924 if (!browser->has_symbols)
925 goto add_exit_option;
927 if (browser->selection != NULL &&
928 browser->selection->sym != NULL &&
929 !browser->selection->map->dso->annotate_warned &&
930 asprintf(&options[nr_options], "Annotate %s",
931 browser->selection->sym->name) > 0)
932 annotate = nr_options++;
934 if (thread != NULL &&
935 asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
936 (browser->thread_filter ? "out of" : "into"),
937 (thread->comm_set ? thread->comm : ""),
939 zoom_thread = nr_options++;
942 asprintf(&options[nr_options], "Zoom %s %s DSO",
943 (browser->dso_filter ? "out of" : "into"),
944 (dso->kernel ? "the Kernel" : dso->short_name)) > 0)
945 zoom_dso = nr_options++;
947 if (browser->selection != NULL &&
948 browser->selection->map != NULL &&
949 asprintf(&options[nr_options], "Browse map details") > 0)
950 browse_map = nr_options++;
952 options[nr_options++] = (char *)"Exit";
954 choice = ui__popup_menu(nr_options, options);
956 for (i = 0; i < nr_options - 1; ++i)
959 if (choice == nr_options - 1)
965 if (choice == annotate) {
966 struct hist_entry *he;
968 he = hist_browser__selected_entry(browser);
972 * Don't let this be freed, say, by hists__decay_entry.
975 hist_entry__tui_annotate(he, evsel->idx, nr_events,
976 timer, arg, delay_secs);
978 ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
979 } else if (choice == browse_map)
980 map__browse(browser->selection->map);
981 else if (choice == zoom_dso) {
983 if (browser->dso_filter) {
984 pstack__remove(fstack, &browser->dso_filter);
987 browser->dso_filter = NULL;
991 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
992 dso->kernel ? "the Kernel" : dso->short_name);
993 browser->dso_filter = dso;
994 pstack__push(fstack, &browser->dso_filter);
996 hists__filter_by_dso(self, browser->dso_filter);
997 hist_browser__reset(browser);
998 } else if (choice == zoom_thread) {
1000 if (browser->thread_filter) {
1001 pstack__remove(fstack, &browser->thread_filter);
1004 browser->thread_filter = NULL;
1006 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
1007 thread->comm_set ? thread->comm : "",
1009 browser->thread_filter = thread;
1010 pstack__push(fstack, &browser->thread_filter);
1012 hists__filter_by_thread(self, browser->thread_filter);
1013 hist_browser__reset(browser);
1017 pstack__delete(fstack);
1019 hist_browser__delete(browser);
1023 struct perf_evsel_menu {
1024 struct ui_browser b;
1025 struct perf_evsel *selection;
1028 static void perf_evsel_menu__write(struct ui_browser *browser,
1029 void *entry, int row)
1031 struct perf_evsel_menu *menu = container_of(browser,
1032 struct perf_evsel_menu, b);
1033 struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node);
1034 bool current_entry = ui_browser__is_current_entry(browser, row);
1035 unsigned long nr_events = evsel->hists.stats.nr_events[PERF_RECORD_SAMPLE];
1036 const char *ev_name = event_name(evsel);
1039 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
1040 HE_COLORSET_NORMAL);
1042 nr_events = convert_unit(nr_events, &unit);
1043 snprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events,
1044 unit, unit == ' ' ? "" : " ", ev_name);
1045 slsmg_write_nstring(bf, browser->width);
1048 menu->selection = evsel;
1051 static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
1052 int nr_events, const char *help,
1053 void(*timer)(void *arg), void *arg, int delay_secs)
1055 struct perf_evlist *evlist = menu->b.priv;
1056 struct perf_evsel *pos;
1057 const char *ev_name, *title = "Available samples";
1060 if (ui_browser__show(&menu->b, title,
1061 "ESC: exit, ENTER|->: Browse histograms") < 0)
1065 key = ui_browser__run(&menu->b, delay_secs);
1069 /* FIXME we need to check if it was es.reason == NEWT_EXIT_TIMER */
1072 case NEWT_KEY_RIGHT:
1073 case NEWT_KEY_ENTER:
1074 if (!menu->selection)
1076 pos = menu->selection;
1077 perf_evlist__set_selected(evlist, pos);
1079 ev_name = event_name(pos);
1080 key = perf_evsel__hists_browse(pos, nr_events, help,
1081 ev_name, true, timer,
1083 ui_browser__show_title(&menu->b, title);
1088 if (pos->node.next == &evlist->entries)
1089 pos = list_entry(evlist->entries.next, struct perf_evsel, node);
1091 pos = list_entry(pos->node.next, struct perf_evsel, node);
1092 perf_evlist__set_selected(evlist, pos);
1094 case NEWT_KEY_UNTAB:
1095 if (pos->node.prev == &evlist->entries)
1096 pos = list_entry(evlist->entries.prev, struct perf_evsel, node);
1098 pos = list_entry(pos->node.prev, struct perf_evsel, node);
1099 perf_evlist__set_selected(evlist, pos);
1101 case NEWT_KEY_ESCAPE:
1102 if (!ui__dialog_yesno("Do you really want to exit?"))
1114 ui_browser__hide(&menu->b);
1118 static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
1120 void(*timer)(void *arg), void *arg,
1123 struct perf_evsel *pos;
1124 struct perf_evsel_menu menu = {
1126 .entries = &evlist->entries,
1127 .refresh = ui_browser__list_head_refresh,
1128 .seek = ui_browser__list_head_seek,
1129 .write = perf_evsel_menu__write,
1130 .nr_entries = evlist->nr_entries,
1135 ui_helpline__push("Press ESC to exit");
1137 list_for_each_entry(pos, &evlist->entries, node) {
1138 const char *ev_name = event_name(pos);
1139 size_t line_len = strlen(ev_name) + 7;
1141 if (menu.b.width < line_len)
1142 menu.b.width = line_len;
1144 * Cache the evsel name, tracepoints have a _high_ cost per
1145 * event_name() call.
1147 if (pos->name == NULL)
1148 pos->name = strdup(ev_name);
1151 return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer,
1155 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
1156 void(*timer)(void *arg), void *arg,
1160 if (evlist->nr_entries == 1) {
1161 struct perf_evsel *first = list_entry(evlist->entries.next,
1162 struct perf_evsel, node);
1163 const char *ev_name = event_name(first);
1164 return perf_evsel__hists_browse(first, evlist->nr_entries, help,
1165 ev_name, false, timer, arg,
1169 return __perf_evlist__tui_browse_hists(evlist, help,
1170 timer, arg, delay_secs);