Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1 | #include <stdio.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2 | #include "../libslang.h" |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 5 | #include <linux/rbtree.h> |
| 6 | |
Namhyung Kim | aca7a94 | 2012-04-04 00:14:26 -0700 | [diff] [blame] | 7 | #include "../../util/evsel.h" |
| 8 | #include "../../util/evlist.h" |
| 9 | #include "../../util/hist.h" |
| 10 | #include "../../util/pstack.h" |
| 11 | #include "../../util/sort.h" |
| 12 | #include "../../util/util.h" |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 13 | #include "../../util/top.h" |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 14 | #include "../../arch/common.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 15 | |
| 16 | #include "../browser.h" |
| 17 | #include "../helpline.h" |
| 18 | #include "../util.h" |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 19 | #include "../ui.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 20 | #include "map.h" |
Jiri Olsa | d755330 | 2014-06-15 10:22:15 +0200 | [diff] [blame] | 21 | #include "annotate.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 23 | struct hist_browser { |
| 24 | struct ui_browser b; |
| 25 | struct hists *hists; |
| 26 | struct hist_entry *he_selection; |
| 27 | struct map_symbol *selection; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 28 | int print_seq; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 29 | bool show_dso; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 30 | bool show_headers; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 31 | float min_pcnt; |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 32 | u64 nr_non_filtered_entries; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 33 | u64 nr_callchain_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 34 | }; |
| 35 | |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 36 | extern void hist_browser__init_hpp(void); |
| 37 | |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 38 | static int hists__browser_title(struct hists *hists, |
| 39 | struct hist_browser_timer *hbt, |
| 40 | char *bf, size_t size); |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 41 | static void hist_browser__update_nr_entries(struct hist_browser *hb); |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 42 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 43 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 44 | float min_pcnt); |
| 45 | |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 46 | static bool hist_browser__has_filter(struct hist_browser *hb) |
| 47 | { |
| 48 | return hists__has_filter(hb->hists) || hb->min_pcnt; |
| 49 | } |
| 50 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 51 | static u32 hist_browser__nr_entries(struct hist_browser *hb) |
| 52 | { |
| 53 | u32 nr_entries; |
| 54 | |
| 55 | if (hist_browser__has_filter(hb)) |
| 56 | nr_entries = hb->nr_non_filtered_entries; |
| 57 | else |
| 58 | nr_entries = hb->hists->nr_entries; |
| 59 | |
| 60 | return nr_entries + hb->nr_callchain_rows; |
| 61 | } |
| 62 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 63 | static void hist_browser__update_rows(struct hist_browser *hb) |
| 64 | { |
| 65 | struct ui_browser *browser = &hb->b; |
| 66 | u16 header_offset = hb->show_headers ? 1 : 0, index_row; |
| 67 | |
| 68 | browser->rows = browser->height - header_offset; |
| 69 | /* |
| 70 | * Verify if we were at the last line and that line isn't |
| 71 | * visibe because we now show the header line(s). |
| 72 | */ |
| 73 | index_row = browser->index - browser->top_idx; |
| 74 | if (index_row >= browser->rows) |
| 75 | browser->index -= index_row - browser->rows + 1; |
| 76 | } |
| 77 | |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 78 | static void hist_browser__refresh_dimensions(struct ui_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 79 | { |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 80 | struct hist_browser *hb = container_of(browser, struct hist_browser, b); |
| 81 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 82 | /* 3 == +/- toggle symbol before actual hist_entry rendering */ |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 83 | browser->width = 3 + (hists__sort_list_width(hb->hists) + sizeof("[k]")); |
| 84 | /* |
| 85 | * FIXME: Just keeping existing behaviour, but this really should be |
| 86 | * before updating browser->width, as it will invalidate the |
| 87 | * calculation above. Fix this and the fallout in another |
| 88 | * changeset. |
| 89 | */ |
| 90 | ui_browser__refresh_dimensions(browser); |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 91 | hist_browser__update_rows(hb); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 92 | } |
| 93 | |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 94 | static void hist_browser__gotorc(struct hist_browser *browser, int row, int column) |
| 95 | { |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 96 | u16 header_offset = browser->show_headers ? 1 : 0; |
| 97 | |
| 98 | ui_browser__gotorc(&browser->b, row + header_offset, column); |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 99 | } |
| 100 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 101 | static void hist_browser__reset(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 102 | { |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 103 | /* |
| 104 | * The hists__remove_entry_filter() already folds non-filtered |
| 105 | * entries so we can assume it has 0 callchain rows. |
| 106 | */ |
| 107 | browser->nr_callchain_rows = 0; |
| 108 | |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 109 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 110 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 111 | hist_browser__refresh_dimensions(&browser->b); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 112 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static char tree__folded_sign(bool unfolded) |
| 116 | { |
| 117 | return unfolded ? '-' : '+'; |
| 118 | } |
| 119 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 120 | static char map_symbol__folded(const struct map_symbol *ms) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 121 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 122 | return ms->has_children ? tree__folded_sign(ms->unfolded) : ' '; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 123 | } |
| 124 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 125 | static char hist_entry__folded(const struct hist_entry *he) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 126 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 127 | return map_symbol__folded(&he->ms); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 128 | } |
| 129 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 130 | static char callchain_list__folded(const struct callchain_list *cl) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 131 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 132 | return map_symbol__folded(&cl->ms); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 133 | } |
| 134 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 135 | static void map_symbol__set_folding(struct map_symbol *ms, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 136 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 137 | ms->unfolded = unfold ? ms->has_children : false; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 138 | } |
| 139 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 140 | static int callchain_node__count_rows_rb_tree(struct callchain_node *node) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 141 | { |
| 142 | int n = 0; |
| 143 | struct rb_node *nd; |
| 144 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 145 | for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 146 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 147 | struct callchain_list *chain; |
| 148 | char folded_sign = ' '; /* No children */ |
| 149 | |
| 150 | list_for_each_entry(chain, &child->val, list) { |
| 151 | ++n; |
| 152 | /* We need this because we may not have children */ |
| 153 | folded_sign = callchain_list__folded(chain); |
| 154 | if (folded_sign == '+') |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | if (folded_sign == '-') /* Have children and they're unfolded */ |
| 159 | n += callchain_node__count_rows_rb_tree(child); |
| 160 | } |
| 161 | |
| 162 | return n; |
| 163 | } |
| 164 | |
| 165 | static int callchain_node__count_rows(struct callchain_node *node) |
| 166 | { |
| 167 | struct callchain_list *chain; |
| 168 | bool unfolded = false; |
| 169 | int n = 0; |
| 170 | |
| 171 | list_for_each_entry(chain, &node->val, list) { |
| 172 | ++n; |
| 173 | unfolded = chain->ms.unfolded; |
| 174 | } |
| 175 | |
| 176 | if (unfolded) |
| 177 | n += callchain_node__count_rows_rb_tree(node); |
| 178 | |
| 179 | return n; |
| 180 | } |
| 181 | |
| 182 | static int callchain__count_rows(struct rb_root *chain) |
| 183 | { |
| 184 | struct rb_node *nd; |
| 185 | int n = 0; |
| 186 | |
| 187 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 188 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 189 | n += callchain_node__count_rows(node); |
| 190 | } |
| 191 | |
| 192 | return n; |
| 193 | } |
| 194 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 195 | static bool map_symbol__toggle_fold(struct map_symbol *ms) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 196 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 197 | if (!ms) |
Jiri Olsa | 8493fe1 | 2012-04-04 22:21:31 +0200 | [diff] [blame] | 198 | return false; |
| 199 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 200 | if (!ms->has_children) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 201 | return false; |
| 202 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 203 | ms->unfolded = !ms->unfolded; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 204 | return true; |
| 205 | } |
| 206 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 207 | static void callchain_node__init_have_children_rb_tree(struct callchain_node *node) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 208 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 209 | struct rb_node *nd = rb_first(&node->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 210 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 211 | for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 212 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 213 | struct callchain_list *chain; |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 214 | bool first = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 215 | |
| 216 | list_for_each_entry(chain, &child->val, list) { |
| 217 | if (first) { |
| 218 | first = false; |
| 219 | chain->ms.has_children = chain->list.next != &child->val || |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 220 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 221 | } else |
| 222 | chain->ms.has_children = chain->list.next == &child->val && |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 223 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | callchain_node__init_have_children_rb_tree(child); |
| 227 | } |
| 228 | } |
| 229 | |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 230 | static void callchain_node__init_have_children(struct callchain_node *node, |
| 231 | bool has_sibling) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 232 | { |
| 233 | struct callchain_list *chain; |
| 234 | |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 235 | chain = list_entry(node->val.next, struct callchain_list, list); |
| 236 | chain->ms.has_children = has_sibling; |
| 237 | |
Namhyung Kim | 82162b5 | 2014-08-13 15:02:41 +0900 | [diff] [blame] | 238 | if (!list_empty(&node->val)) { |
| 239 | chain = list_entry(node->val.prev, struct callchain_list, list); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 240 | chain->ms.has_children = !RB_EMPTY_ROOT(&node->rb_root); |
Namhyung Kim | 82162b5 | 2014-08-13 15:02:41 +0900 | [diff] [blame] | 241 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 242 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 243 | callchain_node__init_have_children_rb_tree(node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 244 | } |
| 245 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 246 | static void callchain__init_have_children(struct rb_root *root) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 247 | { |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 248 | struct rb_node *nd = rb_first(root); |
| 249 | bool has_sibling = nd && rb_next(nd); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 250 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 251 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 252 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 253 | callchain_node__init_have_children(node, has_sibling); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 257 | static void hist_entry__init_have_children(struct hist_entry *he) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 258 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 259 | if (!he->init_have_children) { |
| 260 | he->ms.has_children = !RB_EMPTY_ROOT(&he->sorted_chain); |
| 261 | callchain__init_have_children(&he->sorted_chain); |
| 262 | he->init_have_children = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 266 | static bool hist_browser__toggle_fold(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 267 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 268 | if (map_symbol__toggle_fold(browser->selection)) { |
| 269 | struct hist_entry *he = browser->he_selection; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 270 | |
| 271 | hist_entry__init_have_children(he); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 272 | browser->b.nr_entries -= he->nr_rows; |
| 273 | browser->nr_callchain_rows -= he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 274 | |
| 275 | if (he->ms.unfolded) |
| 276 | he->nr_rows = callchain__count_rows(&he->sorted_chain); |
| 277 | else |
| 278 | he->nr_rows = 0; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 279 | |
| 280 | browser->b.nr_entries += he->nr_rows; |
| 281 | browser->nr_callchain_rows += he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 282 | |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | /* If it doesn't have children, no toggling performed */ |
| 287 | return false; |
| 288 | } |
| 289 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 290 | static int callchain_node__set_folding_rb_tree(struct callchain_node *node, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 291 | { |
| 292 | int n = 0; |
| 293 | struct rb_node *nd; |
| 294 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 295 | for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 296 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 297 | struct callchain_list *chain; |
| 298 | bool has_children = false; |
| 299 | |
| 300 | list_for_each_entry(chain, &child->val, list) { |
| 301 | ++n; |
| 302 | map_symbol__set_folding(&chain->ms, unfold); |
| 303 | has_children = chain->ms.has_children; |
| 304 | } |
| 305 | |
| 306 | if (has_children) |
| 307 | n += callchain_node__set_folding_rb_tree(child, unfold); |
| 308 | } |
| 309 | |
| 310 | return n; |
| 311 | } |
| 312 | |
| 313 | static int callchain_node__set_folding(struct callchain_node *node, bool unfold) |
| 314 | { |
| 315 | struct callchain_list *chain; |
| 316 | bool has_children = false; |
| 317 | int n = 0; |
| 318 | |
| 319 | list_for_each_entry(chain, &node->val, list) { |
| 320 | ++n; |
| 321 | map_symbol__set_folding(&chain->ms, unfold); |
| 322 | has_children = chain->ms.has_children; |
| 323 | } |
| 324 | |
| 325 | if (has_children) |
| 326 | n += callchain_node__set_folding_rb_tree(node, unfold); |
| 327 | |
| 328 | return n; |
| 329 | } |
| 330 | |
| 331 | static int callchain__set_folding(struct rb_root *chain, bool unfold) |
| 332 | { |
| 333 | struct rb_node *nd; |
| 334 | int n = 0; |
| 335 | |
| 336 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 337 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 338 | n += callchain_node__set_folding(node, unfold); |
| 339 | } |
| 340 | |
| 341 | return n; |
| 342 | } |
| 343 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 344 | static void hist_entry__set_folding(struct hist_entry *he, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 345 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 346 | hist_entry__init_have_children(he); |
| 347 | map_symbol__set_folding(&he->ms, unfold); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 348 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 349 | if (he->ms.has_children) { |
| 350 | int n = callchain__set_folding(&he->sorted_chain, unfold); |
| 351 | he->nr_rows = unfold ? n : 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 352 | } else |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 353 | he->nr_rows = 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 354 | } |
| 355 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 356 | static void |
| 357 | __hist_browser__set_folding(struct hist_browser *browser, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 358 | { |
| 359 | struct rb_node *nd; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 360 | struct hists *hists = browser->hists; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 361 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 362 | for (nd = rb_first(&hists->entries); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 363 | (nd = hists__filter_entries(nd, browser->min_pcnt)) != NULL; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 364 | nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 365 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 366 | hist_entry__set_folding(he, unfold); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 367 | browser->nr_callchain_rows += he->nr_rows; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 371 | static void hist_browser__set_folding(struct hist_browser *browser, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 372 | { |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 373 | browser->nr_callchain_rows = 0; |
| 374 | __hist_browser__set_folding(browser, unfold); |
| 375 | |
| 376 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 377 | /* Go to the start, we may be way after valid entries after a collapse */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 378 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 379 | } |
| 380 | |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 381 | static void ui_browser__warn_lost_events(struct ui_browser *browser) |
| 382 | { |
| 383 | ui_browser__warning(browser, 4, |
| 384 | "Events are being lost, check IO/CPU overload!\n\n" |
| 385 | "You may want to run 'perf' using a RT scheduler policy:\n\n" |
| 386 | " perf top -r 80\n\n" |
| 387 | "Or reduce the sampling frequency."); |
| 388 | } |
| 389 | |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 390 | static int hist_browser__run(struct hist_browser *browser, |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 391 | struct hist_browser_timer *hbt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 392 | { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 393 | int key; |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 394 | char title[160]; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 395 | int delay_secs = hbt ? hbt->refresh : 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 396 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 397 | browser->b.entries = &browser->hists->entries; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 398 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 399 | |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 400 | hists__browser_title(browser->hists, hbt, title, sizeof(title)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 401 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 402 | if (ui_browser__show(&browser->b, title, |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 403 | "Press '?' for help on key bindings") < 0) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 404 | return -1; |
| 405 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 406 | while (1) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 407 | key = ui_browser__run(&browser->b, delay_secs); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 408 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 409 | switch (key) { |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 410 | case K_TIMER: { |
| 411 | u64 nr_entries; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 412 | hbt->timer(hbt->arg); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 413 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 414 | if (hist_browser__has_filter(browser)) |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 415 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 416 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 417 | nr_entries = hist_browser__nr_entries(browser); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 418 | ui_browser__update_nr_entries(&browser->b, nr_entries); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 419 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 420 | if (browser->hists->stats.nr_lost_warned != |
| 421 | browser->hists->stats.nr_events[PERF_RECORD_LOST]) { |
| 422 | browser->hists->stats.nr_lost_warned = |
| 423 | browser->hists->stats.nr_events[PERF_RECORD_LOST]; |
| 424 | ui_browser__warn_lost_events(&browser->b); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 425 | } |
| 426 | |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 427 | hists__browser_title(browser->hists, |
| 428 | hbt, title, sizeof(title)); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 429 | ui_browser__show_title(&browser->b, title); |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 430 | continue; |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 431 | } |
Arnaldo Carvalho de Melo | 4694153 | 2010-08-10 15:50:07 -0300 | [diff] [blame] | 432 | case 'D': { /* Debug */ |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 433 | static int seq; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 434 | struct hist_entry *h = rb_entry(browser->b.top, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 435 | struct hist_entry, rb_node); |
| 436 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 437 | ui_helpline__fpush("%d: nr_ent=(%d,%d), rows=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d", |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 438 | seq++, browser->b.nr_entries, |
| 439 | browser->hists->nr_entries, |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 440 | browser->b.rows, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 441 | browser->b.index, |
| 442 | browser->b.top_idx, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 443 | h->row_offset, h->nr_rows); |
| 444 | } |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 445 | break; |
| 446 | case 'C': |
| 447 | /* Collapse the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 448 | hist_browser__set_folding(browser, false); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 449 | break; |
| 450 | case 'E': |
| 451 | /* Expand the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 452 | hist_browser__set_folding(browser, true); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 453 | break; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 454 | case 'H': |
| 455 | browser->show_headers = !browser->show_headers; |
| 456 | hist_browser__update_rows(browser); |
| 457 | break; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 458 | case K_ENTER: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 459 | if (hist_browser__toggle_fold(browser)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 460 | break; |
| 461 | /* fall thru */ |
| 462 | default: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 463 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 464 | } |
| 465 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 466 | out: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 467 | ui_browser__hide(&browser->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 468 | return key; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 469 | } |
| 470 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 471 | struct callchain_print_arg { |
| 472 | /* for hists browser */ |
| 473 | off_t row_offset; |
| 474 | bool is_current_entry; |
| 475 | |
| 476 | /* for file dump */ |
| 477 | FILE *fp; |
| 478 | int printed; |
| 479 | }; |
| 480 | |
| 481 | typedef void (*print_callchain_entry_fn)(struct hist_browser *browser, |
| 482 | struct callchain_list *chain, |
| 483 | const char *str, int offset, |
| 484 | unsigned short row, |
| 485 | struct callchain_print_arg *arg); |
| 486 | |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 487 | static void hist_browser__show_callchain_entry(struct hist_browser *browser, |
| 488 | struct callchain_list *chain, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 489 | const char *str, int offset, |
| 490 | unsigned short row, |
| 491 | struct callchain_print_arg *arg) |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 492 | { |
| 493 | int color, width; |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 494 | char folded_sign = callchain_list__folded(chain); |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 495 | |
| 496 | color = HE_COLORSET_NORMAL; |
| 497 | width = browser->b.width - (offset + 2); |
| 498 | if (ui_browser__is_current_entry(&browser->b, row)) { |
| 499 | browser->selection = &chain->ms; |
| 500 | color = HE_COLORSET_SELECTED; |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 501 | arg->is_current_entry = true; |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | ui_browser__set_color(&browser->b, color); |
| 505 | hist_browser__gotorc(browser, row, 0); |
| 506 | slsmg_write_nstring(" ", offset); |
| 507 | slsmg_printf("%c ", folded_sign); |
| 508 | slsmg_write_nstring(str, width); |
| 509 | } |
| 510 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 511 | static void hist_browser__fprintf_callchain_entry(struct hist_browser *b __maybe_unused, |
| 512 | struct callchain_list *chain, |
| 513 | const char *str, int offset, |
| 514 | unsigned short row __maybe_unused, |
| 515 | struct callchain_print_arg *arg) |
| 516 | { |
| 517 | char folded_sign = callchain_list__folded(chain); |
| 518 | |
| 519 | arg->printed += fprintf(arg->fp, "%*s%c %s\n", offset, " ", |
| 520 | folded_sign, str); |
| 521 | } |
| 522 | |
| 523 | typedef bool (*check_output_full_fn)(struct hist_browser *browser, |
| 524 | unsigned short row); |
| 525 | |
| 526 | static bool hist_browser__check_output_full(struct hist_browser *browser, |
| 527 | unsigned short row) |
| 528 | { |
| 529 | return browser->b.rows == row; |
| 530 | } |
| 531 | |
| 532 | static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_unused, |
| 533 | unsigned short row __maybe_unused) |
| 534 | { |
| 535 | return false; |
| 536 | } |
| 537 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 538 | #define LEVEL_OFFSET_STEP 3 |
| 539 | |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 540 | static int hist_browser__show_callchain(struct hist_browser *browser, |
| 541 | struct rb_root *root, int level, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 542 | unsigned short row, u64 total, |
| 543 | print_callchain_entry_fn print, |
| 544 | struct callchain_print_arg *arg, |
| 545 | check_output_full_fn is_output_full) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 546 | { |
| 547 | struct rb_node *node; |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 548 | int first_row = row, offset = level * LEVEL_OFFSET_STEP; |
Namhyung Kim | 36e15dd | 2014-08-20 17:07:58 +0900 | [diff] [blame] | 549 | u64 new_total; |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 550 | bool need_percent; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 551 | |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 552 | node = rb_first(root); |
Namhyung Kim | c09e31c | 2014-12-24 15:04:36 +0900 | [diff] [blame] | 553 | need_percent = node && rb_next(node); |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 554 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 555 | while (node) { |
| 556 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 557 | struct rb_node *next = rb_next(node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 558 | u64 cumul = callchain_cumul_hits(child); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 559 | struct callchain_list *chain; |
| 560 | char folded_sign = ' '; |
| 561 | int first = true; |
| 562 | int extra_offset = 0; |
| 563 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 564 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 565 | char bf[1024], *alloc_str; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 566 | const char *str; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 567 | bool was_first = first; |
| 568 | |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 569 | if (first) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 570 | first = false; |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 571 | else if (need_percent) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 572 | extra_offset = LEVEL_OFFSET_STEP; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 573 | |
| 574 | folded_sign = callchain_list__folded(chain); |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 575 | if (arg->row_offset != 0) { |
| 576 | arg->row_offset--; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 577 | goto do_next; |
| 578 | } |
| 579 | |
| 580 | alloc_str = NULL; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 581 | str = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 582 | browser->show_dso); |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 583 | |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 584 | if (was_first && need_percent) { |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 585 | double percent = cumul * 100.0 / total; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 586 | |
| 587 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) |
| 588 | str = "Not enough memory!"; |
| 589 | else |
| 590 | str = alloc_str; |
| 591 | } |
| 592 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 593 | print(browser, chain, str, offset + extra_offset, row, arg); |
| 594 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 595 | free(alloc_str); |
| 596 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 597 | if (is_output_full(browser, ++row)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 598 | goto out; |
| 599 | do_next: |
| 600 | if (folded_sign == '+') |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | if (folded_sign == '-') { |
| 605 | const int new_level = level + (extra_offset ? 2 : 1); |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 606 | |
| 607 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 608 | new_total = child->children_hit; |
| 609 | else |
| 610 | new_total = total; |
| 611 | |
| 612 | row += hist_browser__show_callchain(browser, &child->rb_root, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 613 | new_level, row, new_total, |
| 614 | print, arg, is_output_full); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 615 | } |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 616 | if (is_output_full(browser, row)) |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 617 | break; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 618 | node = next; |
| 619 | } |
| 620 | out: |
| 621 | return row - first_row; |
| 622 | } |
| 623 | |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 624 | struct hpp_arg { |
| 625 | struct ui_browser *b; |
| 626 | char folded_sign; |
| 627 | bool current_entry; |
| 628 | }; |
| 629 | |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 630 | static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...) |
| 631 | { |
| 632 | struct hpp_arg *arg = hpp->ptr; |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 633 | int ret, len; |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 634 | va_list args; |
| 635 | double percent; |
| 636 | |
| 637 | va_start(args, fmt); |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 638 | len = va_arg(args, int); |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 639 | percent = va_arg(args, double); |
| 640 | va_end(args); |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 641 | |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 642 | ui_browser__set_percent_color(arg->b, percent, arg->current_entry); |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 643 | |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 644 | ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent); |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 645 | slsmg_printf("%s", hpp->buf); |
| 646 | |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 647 | advance_hpp(hpp, ret); |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 648 | return ret; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 649 | } |
| 650 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 651 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 652 | static u64 __hpp_get_##_field(struct hist_entry *he) \ |
| 653 | { \ |
| 654 | return he->stat._field; \ |
| 655 | } \ |
| 656 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 657 | static int \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 658 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 659 | struct perf_hpp *hpp, \ |
| 660 | struct hist_entry *he) \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 661 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 662 | return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \ |
| 663 | __hpp__slsmg_color_printf, true); \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 664 | } |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 665 | |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 666 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
| 667 | static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ |
| 668 | { \ |
| 669 | return he->stat_acc->_field; \ |
| 670 | } \ |
| 671 | \ |
| 672 | static int \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 673 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 674 | struct perf_hpp *hpp, \ |
| 675 | struct hist_entry *he) \ |
| 676 | { \ |
| 677 | if (!symbol_conf.cumulate_callchain) { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 678 | int len = fmt->user_len ?: fmt->len; \ |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 679 | int ret = scnprintf(hpp->buf, hpp->size, \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 680 | "%*s", len, "N/A"); \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 681 | slsmg_printf("%s", hpp->buf); \ |
| 682 | \ |
| 683 | return ret; \ |
| 684 | } \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 685 | return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \ |
| 686 | " %*.2f%%", __hpp__slsmg_color_printf, true); \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 687 | } |
| 688 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 689 | __HPP_COLOR_PERCENT_FN(overhead, period) |
| 690 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) |
| 691 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) |
| 692 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) |
| 693 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 694 | __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period) |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 695 | |
| 696 | #undef __HPP_COLOR_PERCENT_FN |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 697 | #undef __HPP_COLOR_ACC_PERCENT_FN |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 698 | |
| 699 | void hist_browser__init_hpp(void) |
| 700 | { |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 701 | perf_hpp__format[PERF_HPP__OVERHEAD].color = |
| 702 | hist_browser__hpp_color_overhead; |
| 703 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color = |
| 704 | hist_browser__hpp_color_overhead_sys; |
| 705 | perf_hpp__format[PERF_HPP__OVERHEAD_US].color = |
| 706 | hist_browser__hpp_color_overhead_us; |
| 707 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color = |
| 708 | hist_browser__hpp_color_overhead_guest_sys; |
| 709 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = |
| 710 | hist_browser__hpp_color_overhead_guest_us; |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 711 | perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color = |
| 712 | hist_browser__hpp_color_overhead_acc; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 713 | } |
| 714 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 715 | static int hist_browser__show_entry(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 716 | struct hist_entry *entry, |
| 717 | unsigned short row) |
| 718 | { |
| 719 | char s[256]; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 720 | int printed = 0; |
Namhyung Kim | 67d2591 | 2012-09-12 15:35:06 +0900 | [diff] [blame] | 721 | int width = browser->b.width; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 722 | char folded_sign = ' '; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 723 | bool current_entry = ui_browser__is_current_entry(&browser->b, row); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 724 | off_t row_offset = entry->row_offset; |
Namhyung Kim | 63a1a3d | 2012-10-15 18:14:35 -0300 | [diff] [blame] | 725 | bool first = true; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 726 | struct perf_hpp_fmt *fmt; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 727 | |
| 728 | if (current_entry) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 729 | browser->he_selection = entry; |
| 730 | browser->selection = &entry->ms; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 734 | hist_entry__init_have_children(entry); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 735 | folded_sign = hist_entry__folded(entry); |
| 736 | } |
| 737 | |
| 738 | if (row_offset == 0) { |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 739 | struct hpp_arg arg = { |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 740 | .b = &browser->b, |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 741 | .folded_sign = folded_sign, |
| 742 | .current_entry = current_entry, |
| 743 | }; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 744 | struct perf_hpp hpp = { |
| 745 | .buf = s, |
| 746 | .size = sizeof(s), |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 747 | .ptr = &arg, |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 748 | }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 749 | |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 750 | hist_browser__gotorc(browser, row, 0); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 751 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 752 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 753 | if (perf_hpp__should_skip(fmt)) |
| 754 | continue; |
| 755 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 756 | if (current_entry && browser->b.navkeypressed) { |
| 757 | ui_browser__set_color(&browser->b, |
| 758 | HE_COLORSET_SELECTED); |
| 759 | } else { |
| 760 | ui_browser__set_color(&browser->b, |
| 761 | HE_COLORSET_NORMAL); |
| 762 | } |
| 763 | |
| 764 | if (first) { |
| 765 | if (symbol_conf.use_callchain) { |
| 766 | slsmg_printf("%c ", folded_sign); |
| 767 | width -= 2; |
| 768 | } |
| 769 | first = false; |
| 770 | } else { |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 771 | slsmg_printf(" "); |
| 772 | width -= 2; |
| 773 | } |
| 774 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 775 | if (fmt->color) { |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 776 | width -= fmt->color(fmt, &hpp, entry); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 777 | } else { |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 778 | width -= fmt->entry(fmt, &hpp, entry); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 779 | slsmg_printf("%s", s); |
| 780 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 781 | } |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 782 | |
| 783 | /* The scroll bar isn't being used */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 784 | if (!browser->b.navkeypressed) |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 785 | width += 1; |
| 786 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 787 | slsmg_write_nstring("", width); |
| 788 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 789 | ++row; |
| 790 | ++printed; |
| 791 | } else |
| 792 | --row_offset; |
| 793 | |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 794 | if (folded_sign == '-' && row != browser->b.rows) { |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 795 | u64 total = hists__total_period(entry->hists); |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 796 | struct callchain_print_arg arg = { |
| 797 | .row_offset = row_offset, |
| 798 | .is_current_entry = current_entry, |
| 799 | }; |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 800 | |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 801 | if (callchain_param.mode == CHAIN_GRAPH_REL) { |
| 802 | if (symbol_conf.cumulate_callchain) |
| 803 | total = entry->stat_acc->period; |
| 804 | else |
| 805 | total = entry->stat.period; |
| 806 | } |
| 807 | |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 808 | printed += hist_browser__show_callchain(browser, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 809 | &entry->sorted_chain, 1, row, total, |
| 810 | hist_browser__show_callchain_entry, &arg, |
| 811 | hist_browser__check_output_full); |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 812 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 813 | if (arg.is_current_entry) |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 814 | browser->he_selection = entry; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | return printed; |
| 818 | } |
| 819 | |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 820 | static int advance_hpp_check(struct perf_hpp *hpp, int inc) |
| 821 | { |
| 822 | advance_hpp(hpp, inc); |
| 823 | return hpp->size <= 0; |
| 824 | } |
| 825 | |
| 826 | static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists) |
| 827 | { |
| 828 | struct perf_hpp dummy_hpp = { |
| 829 | .buf = buf, |
| 830 | .size = size, |
| 831 | }; |
| 832 | struct perf_hpp_fmt *fmt; |
| 833 | size_t ret = 0; |
| 834 | |
| 835 | if (symbol_conf.use_callchain) { |
| 836 | ret = scnprintf(buf, size, " "); |
| 837 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | perf_hpp__for_each_format(fmt) { |
| 842 | if (perf_hpp__should_skip(fmt)) |
| 843 | continue; |
| 844 | |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 845 | ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); |
| 846 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 847 | break; |
| 848 | |
| 849 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " "); |
| 850 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 851 | break; |
| 852 | } |
| 853 | |
| 854 | return ret; |
| 855 | } |
| 856 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 857 | static void hist_browser__show_headers(struct hist_browser *browser) |
| 858 | { |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 859 | char headers[1024]; |
| 860 | |
| 861 | hists__scnprintf_headers(headers, sizeof(headers), browser->hists); |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 862 | ui_browser__gotorc(&browser->b, 0, 0); |
| 863 | ui_browser__set_color(&browser->b, HE_COLORSET_ROOT); |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 864 | slsmg_write_nstring(headers, browser->b.width + 1); |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 865 | } |
| 866 | |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 867 | static void ui_browser__hists_init_top(struct ui_browser *browser) |
| 868 | { |
| 869 | if (browser->top == NULL) { |
| 870 | struct hist_browser *hb; |
| 871 | |
| 872 | hb = container_of(browser, struct hist_browser, b); |
| 873 | browser->top = rb_first(&hb->hists->entries); |
| 874 | } |
| 875 | } |
| 876 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 877 | static unsigned int hist_browser__refresh(struct ui_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 878 | { |
| 879 | unsigned row = 0; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 880 | u16 header_offset = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 881 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 882 | struct hist_browser *hb = container_of(browser, struct hist_browser, b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 883 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 884 | if (hb->show_headers) { |
| 885 | hist_browser__show_headers(hb); |
| 886 | header_offset = 1; |
| 887 | } |
| 888 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 889 | ui_browser__hists_init_top(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 890 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 891 | for (nd = browser->top; nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 892 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 893 | float percent; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 894 | |
| 895 | if (h->filtered) |
| 896 | continue; |
| 897 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 898 | percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 899 | if (percent < hb->min_pcnt) |
| 900 | continue; |
| 901 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 902 | row += hist_browser__show_entry(hb, h, row); |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 903 | if (row == browser->rows) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 904 | break; |
| 905 | } |
| 906 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 907 | return row + header_offset; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 908 | } |
| 909 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 910 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 911 | float min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 912 | { |
| 913 | while (nd != NULL) { |
| 914 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 915 | float percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 916 | |
Namhyung Kim | c0f1527 | 2014-04-16 11:16:33 +0900 | [diff] [blame] | 917 | if (!h->filtered && percent >= min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 918 | return nd; |
| 919 | |
| 920 | nd = rb_next(nd); |
| 921 | } |
| 922 | |
| 923 | return NULL; |
| 924 | } |
| 925 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 926 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 927 | float min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 928 | { |
| 929 | while (nd != NULL) { |
| 930 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 931 | float percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 932 | |
| 933 | if (!h->filtered && percent >= min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 934 | return nd; |
| 935 | |
| 936 | nd = rb_prev(nd); |
| 937 | } |
| 938 | |
| 939 | return NULL; |
| 940 | } |
| 941 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 942 | static void ui_browser__hists_seek(struct ui_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 943 | off_t offset, int whence) |
| 944 | { |
| 945 | struct hist_entry *h; |
| 946 | struct rb_node *nd; |
| 947 | bool first = true; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 948 | struct hist_browser *hb; |
| 949 | |
| 950 | hb = container_of(browser, struct hist_browser, b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 951 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 952 | if (browser->nr_entries == 0) |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 953 | return; |
| 954 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 955 | ui_browser__hists_init_top(browser); |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 956 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 957 | switch (whence) { |
| 958 | case SEEK_SET: |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 959 | nd = hists__filter_entries(rb_first(browser->entries), |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 960 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 961 | break; |
| 962 | case SEEK_CUR: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 963 | nd = browser->top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 964 | goto do_offset; |
| 965 | case SEEK_END: |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 966 | nd = hists__filter_prev_entries(rb_last(browser->entries), |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 967 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 968 | first = false; |
| 969 | break; |
| 970 | default: |
| 971 | return; |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | * Moves not relative to the first visible entry invalidates its |
| 976 | * row_offset: |
| 977 | */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 978 | h = rb_entry(browser->top, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 979 | h->row_offset = 0; |
| 980 | |
| 981 | /* |
| 982 | * Here we have to check if nd is expanded (+), if it is we can't go |
| 983 | * the next top level hist_entry, instead we must compute an offset of |
| 984 | * what _not_ to show and not change the first visible entry. |
| 985 | * |
| 986 | * This offset increments when we are going from top to bottom and |
| 987 | * decreases when we're going from bottom to top. |
| 988 | * |
| 989 | * As we don't have backpointers to the top level in the callchains |
| 990 | * structure, we need to always print the whole hist_entry callchain, |
| 991 | * skipping the first ones that are before the first visible entry |
| 992 | * and stop when we printed enough lines to fill the screen. |
| 993 | */ |
| 994 | do_offset: |
| 995 | if (offset > 0) { |
| 996 | do { |
| 997 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 998 | if (h->ms.unfolded) { |
| 999 | u16 remaining = h->nr_rows - h->row_offset; |
| 1000 | if (offset > remaining) { |
| 1001 | offset -= remaining; |
| 1002 | h->row_offset = 0; |
| 1003 | } else { |
| 1004 | h->row_offset += offset; |
| 1005 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1006 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1007 | break; |
| 1008 | } |
| 1009 | } |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1010 | nd = hists__filter_entries(rb_next(nd), hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1011 | if (nd == NULL) |
| 1012 | break; |
| 1013 | --offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1014 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1015 | } while (offset != 0); |
| 1016 | } else if (offset < 0) { |
| 1017 | while (1) { |
| 1018 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 1019 | if (h->ms.unfolded) { |
| 1020 | if (first) { |
| 1021 | if (-offset > h->row_offset) { |
| 1022 | offset += h->row_offset; |
| 1023 | h->row_offset = 0; |
| 1024 | } else { |
| 1025 | h->row_offset += offset; |
| 1026 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1027 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1028 | break; |
| 1029 | } |
| 1030 | } else { |
| 1031 | if (-offset > h->nr_rows) { |
| 1032 | offset += h->nr_rows; |
| 1033 | h->row_offset = 0; |
| 1034 | } else { |
| 1035 | h->row_offset = h->nr_rows + offset; |
| 1036 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1037 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1043 | nd = hists__filter_prev_entries(rb_prev(nd), |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1044 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1045 | if (nd == NULL) |
| 1046 | break; |
| 1047 | ++offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1048 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1049 | if (offset == 0) { |
| 1050 | /* |
| 1051 | * Last unfiltered hist_entry, check if it is |
| 1052 | * unfolded, if it is then we should have |
| 1053 | * row_offset at its last entry. |
| 1054 | */ |
| 1055 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 1056 | if (h->ms.unfolded) |
| 1057 | h->row_offset = h->nr_rows; |
| 1058 | break; |
| 1059 | } |
| 1060 | first = false; |
| 1061 | } |
| 1062 | } else { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1063 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1064 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 1065 | h->row_offset = 0; |
| 1066 | } |
| 1067 | } |
| 1068 | |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1069 | static int hist_browser__fprintf_callchain(struct hist_browser *browser, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1070 | struct hist_entry *he, FILE *fp) |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1071 | { |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1072 | u64 total = hists__total_period(he->hists); |
| 1073 | struct callchain_print_arg arg = { |
| 1074 | .fp = fp, |
| 1075 | }; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1076 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1077 | if (symbol_conf.cumulate_callchain) |
| 1078 | total = he->stat_acc->period; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1079 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1080 | hist_browser__show_callchain(browser, &he->sorted_chain, 1, 0, total, |
| 1081 | hist_browser__fprintf_callchain_entry, &arg, |
| 1082 | hist_browser__check_dump_full); |
| 1083 | return arg.printed; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | static int hist_browser__fprintf_entry(struct hist_browser *browser, |
| 1087 | struct hist_entry *he, FILE *fp) |
| 1088 | { |
| 1089 | char s[8192]; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1090 | int printed = 0; |
| 1091 | char folded_sign = ' '; |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1092 | struct perf_hpp hpp = { |
| 1093 | .buf = s, |
| 1094 | .size = sizeof(s), |
| 1095 | }; |
| 1096 | struct perf_hpp_fmt *fmt; |
| 1097 | bool first = true; |
| 1098 | int ret; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1099 | |
| 1100 | if (symbol_conf.use_callchain) |
| 1101 | folded_sign = hist_entry__folded(he); |
| 1102 | |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1103 | if (symbol_conf.use_callchain) |
| 1104 | printed += fprintf(fp, "%c ", folded_sign); |
| 1105 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1106 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1107 | if (perf_hpp__should_skip(fmt)) |
| 1108 | continue; |
| 1109 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1110 | if (!first) { |
| 1111 | ret = scnprintf(hpp.buf, hpp.size, " "); |
| 1112 | advance_hpp(&hpp, ret); |
| 1113 | } else |
| 1114 | first = false; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1115 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1116 | ret = fmt->entry(fmt, &hpp, he); |
| 1117 | advance_hpp(&hpp, ret); |
| 1118 | } |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1119 | printed += fprintf(fp, "%s\n", rtrim(s)); |
| 1120 | |
| 1121 | if (folded_sign == '-') |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1122 | printed += hist_browser__fprintf_callchain(browser, he, fp); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1123 | |
| 1124 | return printed; |
| 1125 | } |
| 1126 | |
| 1127 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) |
| 1128 | { |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1129 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries), |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1130 | browser->min_pcnt); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1131 | int printed = 0; |
| 1132 | |
| 1133 | while (nd) { |
| 1134 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1135 | |
| 1136 | printed += hist_browser__fprintf_entry(browser, h, fp); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1137 | nd = hists__filter_entries(rb_next(nd), browser->min_pcnt); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | return printed; |
| 1141 | } |
| 1142 | |
| 1143 | static int hist_browser__dump(struct hist_browser *browser) |
| 1144 | { |
| 1145 | char filename[64]; |
| 1146 | FILE *fp; |
| 1147 | |
| 1148 | while (1) { |
| 1149 | scnprintf(filename, sizeof(filename), "perf.hist.%d", browser->print_seq); |
| 1150 | if (access(filename, F_OK)) |
| 1151 | break; |
| 1152 | /* |
| 1153 | * XXX: Just an arbitrary lazy upper limit |
| 1154 | */ |
| 1155 | if (++browser->print_seq == 8192) { |
| 1156 | ui_helpline__fpush("Too many perf.hist.N files, nothing written!"); |
| 1157 | return -1; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | fp = fopen(filename, "w"); |
| 1162 | if (fp == NULL) { |
| 1163 | char bf[64]; |
Kirill A. Shutemov | 4cc49d4 | 2012-07-24 00:06:54 +0300 | [diff] [blame] | 1164 | const char *err = strerror_r(errno, bf, sizeof(bf)); |
| 1165 | ui_helpline__fpush("Couldn't write to %s: %s", filename, err); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1166 | return -1; |
| 1167 | } |
| 1168 | |
| 1169 | ++browser->print_seq; |
| 1170 | hist_browser__fprintf(browser, fp); |
| 1171 | fclose(fp); |
| 1172 | ui_helpline__fpush("%s written!", filename); |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1177 | static struct hist_browser *hist_browser__new(struct hists *hists) |
| 1178 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1179 | struct hist_browser *browser = zalloc(sizeof(*browser)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1180 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1181 | if (browser) { |
| 1182 | browser->hists = hists; |
| 1183 | browser->b.refresh = hist_browser__refresh; |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 1184 | browser->b.refresh_dimensions = hist_browser__refresh_dimensions; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1185 | browser->b.seek = ui_browser__hists_seek; |
| 1186 | browser->b.use_navkeypressed = true; |
Jiri Olsa | c830236 | 2014-06-27 18:26:58 +0200 | [diff] [blame] | 1187 | browser->show_headers = symbol_conf.show_hist_headers; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1188 | } |
| 1189 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1190 | return browser; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1191 | } |
| 1192 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1193 | static void hist_browser__delete(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1194 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1195 | free(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1196 | } |
| 1197 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1198 | static struct hist_entry *hist_browser__selected_entry(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1199 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1200 | return browser->he_selection; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1201 | } |
| 1202 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1203 | static struct thread *hist_browser__selected_thread(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1204 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1205 | return browser->he_selection->thread; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1206 | } |
| 1207 | |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 1208 | /* Check whether the browser is for 'top' or 'report' */ |
| 1209 | static inline bool is_report_browser(void *timer) |
| 1210 | { |
| 1211 | return timer == NULL; |
| 1212 | } |
| 1213 | |
| 1214 | static int hists__browser_title(struct hists *hists, |
| 1215 | struct hist_browser_timer *hbt, |
| 1216 | char *bf, size_t size) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1217 | { |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1218 | char unit; |
| 1219 | int printed; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1220 | const struct dso *dso = hists->dso_filter; |
| 1221 | const struct thread *thread = hists->thread_filter; |
| 1222 | unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 1223 | u64 nr_events = hists->stats.total_period; |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1224 | struct perf_evsel *evsel = hists_to_evsel(hists); |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 1225 | const char *ev_name = perf_evsel__name(evsel); |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1226 | char buf[512]; |
| 1227 | size_t buflen = sizeof(buf); |
| 1228 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1229 | if (symbol_conf.filter_relative) { |
| 1230 | nr_samples = hists->stats.nr_non_filtered_samples; |
| 1231 | nr_events = hists->stats.total_non_filtered_period; |
| 1232 | } |
| 1233 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 1234 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1235 | struct perf_evsel *pos; |
| 1236 | |
| 1237 | perf_evsel__group_desc(evsel, buf, buflen); |
| 1238 | ev_name = buf; |
| 1239 | |
| 1240 | for_each_group_member(pos, evsel) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1241 | struct hists *pos_hists = evsel__hists(pos); |
| 1242 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1243 | if (symbol_conf.filter_relative) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1244 | nr_samples += pos_hists->stats.nr_non_filtered_samples; |
| 1245 | nr_events += pos_hists->stats.total_non_filtered_period; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1246 | } else { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1247 | nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 1248 | nr_events += pos_hists->stats.total_period; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1249 | } |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1250 | } |
| 1251 | } |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1252 | |
Ashay Rane | cc68628 | 2012-04-05 21:01:01 -0500 | [diff] [blame] | 1253 | nr_samples = convert_unit(nr_samples, &unit); |
| 1254 | printed = scnprintf(bf, size, |
Tom Huynh | e641f69 | 2014-12-02 11:37:22 -0600 | [diff] [blame] | 1255 | "Samples: %lu%c of event '%s', Event count (approx.): %" PRIu64, |
Ashay Rane | cc68628 | 2012-04-05 21:01:01 -0500 | [diff] [blame] | 1256 | nr_samples, unit, ev_name, nr_events); |
| 1257 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1258 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1259 | if (hists->uid_filter_str) |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 1260 | printed += snprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1261 | ", UID: %s", hists->uid_filter_str); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1262 | if (thread) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1263 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1264 | ", Thread: %s(%d)", |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 1265 | (thread->comm_set ? thread__comm_str(thread) : ""), |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1266 | thread->tid); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1267 | if (dso) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1268 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1269 | ", DSO: %s", dso->short_name); |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 1270 | if (!is_report_browser(hbt)) { |
| 1271 | struct perf_top *top = hbt->arg; |
| 1272 | |
| 1273 | if (top->zero) |
| 1274 | printed += scnprintf(bf + printed, size - printed, " [z]"); |
| 1275 | } |
| 1276 | |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1277 | return printed; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1278 | } |
| 1279 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1280 | static inline void free_popup_options(char **options, int n) |
| 1281 | { |
| 1282 | int i; |
| 1283 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1284 | for (i = 0; i < n; ++i) |
| 1285 | zfree(&options[i]); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1288 | /* |
| 1289 | * Only runtime switching of perf data file will make "input_name" point |
| 1290 | * to a malloced buffer. So add "is_input_name_malloced" flag to decide |
| 1291 | * whether we need to call free() for current "input_name" during the switch. |
| 1292 | */ |
| 1293 | static bool is_input_name_malloced = false; |
| 1294 | |
| 1295 | static int switch_data_file(void) |
| 1296 | { |
| 1297 | char *pwd, *options[32], *abs_path[32], *tmp; |
| 1298 | DIR *pwd_dir; |
| 1299 | int nr_options = 0, choice = -1, ret = -1; |
| 1300 | struct dirent *dent; |
| 1301 | |
| 1302 | pwd = getenv("PWD"); |
| 1303 | if (!pwd) |
| 1304 | return ret; |
| 1305 | |
| 1306 | pwd_dir = opendir(pwd); |
| 1307 | if (!pwd_dir) |
| 1308 | return ret; |
| 1309 | |
| 1310 | memset(options, 0, sizeof(options)); |
| 1311 | memset(options, 0, sizeof(abs_path)); |
| 1312 | |
| 1313 | while ((dent = readdir(pwd_dir))) { |
| 1314 | char path[PATH_MAX]; |
| 1315 | u64 magic; |
| 1316 | char *name = dent->d_name; |
| 1317 | FILE *file; |
| 1318 | |
| 1319 | if (!(dent->d_type == DT_REG)) |
| 1320 | continue; |
| 1321 | |
| 1322 | snprintf(path, sizeof(path), "%s/%s", pwd, name); |
| 1323 | |
| 1324 | file = fopen(path, "r"); |
| 1325 | if (!file) |
| 1326 | continue; |
| 1327 | |
| 1328 | if (fread(&magic, 1, 8, file) < 8) |
| 1329 | goto close_file_and_continue; |
| 1330 | |
| 1331 | if (is_perf_magic(magic)) { |
| 1332 | options[nr_options] = strdup(name); |
| 1333 | if (!options[nr_options]) |
| 1334 | goto close_file_and_continue; |
| 1335 | |
| 1336 | abs_path[nr_options] = strdup(path); |
| 1337 | if (!abs_path[nr_options]) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 1338 | zfree(&options[nr_options]); |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1339 | ui__warning("Can't search all data files due to memory shortage.\n"); |
| 1340 | fclose(file); |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | nr_options++; |
| 1345 | } |
| 1346 | |
| 1347 | close_file_and_continue: |
| 1348 | fclose(file); |
| 1349 | if (nr_options >= 32) { |
| 1350 | ui__warning("Too many perf data files in PWD!\n" |
| 1351 | "Only the first 32 files will be listed.\n"); |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | closedir(pwd_dir); |
| 1356 | |
| 1357 | if (nr_options) { |
| 1358 | choice = ui__popup_menu(nr_options, options); |
| 1359 | if (choice < nr_options && choice >= 0) { |
| 1360 | tmp = strdup(abs_path[choice]); |
| 1361 | if (tmp) { |
| 1362 | if (is_input_name_malloced) |
| 1363 | free((void *)input_name); |
| 1364 | input_name = tmp; |
| 1365 | is_input_name_malloced = true; |
| 1366 | ret = 0; |
| 1367 | } else |
| 1368 | ui__warning("Data switch failed due to memory shortage!\n"); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | free_popup_options(options, nr_options); |
| 1373 | free_popup_options(abs_path, nr_options); |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 1377 | static void hist_browser__update_nr_entries(struct hist_browser *hb) |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1378 | { |
| 1379 | u64 nr_entries = 0; |
| 1380 | struct rb_node *nd = rb_first(&hb->hists->entries); |
| 1381 | |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 1382 | if (hb->min_pcnt == 0) { |
| 1383 | hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries; |
| 1384 | return; |
| 1385 | } |
| 1386 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1387 | while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) { |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1388 | nr_entries++; |
Namhyung Kim | c481f93 | 2014-04-22 13:56:11 +0900 | [diff] [blame] | 1389 | nd = rb_next(nd); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1390 | } |
| 1391 | |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 1392 | hb->nr_non_filtered_entries = nr_entries; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1393 | } |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1394 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1395 | static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 1396 | const char *helpline, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1397 | bool left_exits, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1398 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1399 | float min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1400 | struct perf_session_env *env) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1401 | { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1402 | struct hists *hists = evsel__hists(evsel); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1403 | struct hist_browser *browser = hist_browser__new(hists); |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1404 | struct branch_info *bi; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1405 | struct pstack *fstack; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1406 | char *options[16]; |
| 1407 | int nr_options = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1408 | int key = -1; |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1409 | char buf[64]; |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1410 | char script_opt[64]; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1411 | int delay_secs = hbt ? hbt->refresh : 0; |
Namhyung Kim | 59dc9f2 | 2014-07-31 14:47:41 +0900 | [diff] [blame] | 1412 | struct perf_hpp_fmt *fmt; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1413 | |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 1414 | #define HIST_BROWSER_HELP_COMMON \ |
| 1415 | "h/?/F1 Show this window\n" \ |
| 1416 | "UP/DOWN/PGUP\n" \ |
| 1417 | "PGDN/SPACE Navigate\n" \ |
| 1418 | "q/ESC/CTRL+C Exit browser\n\n" \ |
| 1419 | "For multiple event sessions:\n\n" \ |
| 1420 | "TAB/UNTAB Switch events\n\n" \ |
| 1421 | "For symbolic views (--sort has sym):\n\n" \ |
| 1422 | "-> Zoom into DSO/Threads & Annotate current symbol\n" \ |
| 1423 | "<- Zoom out\n" \ |
| 1424 | "a Annotate current symbol\n" \ |
| 1425 | "C Collapse all callchains\n" \ |
| 1426 | "d Zoom into current DSO\n" \ |
| 1427 | "E Expand all callchains\n" \ |
Namhyung Kim | 105eb30 | 2014-02-10 11:20:10 +0900 | [diff] [blame] | 1428 | "F Toggle percentage of filtered entries\n" \ |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1429 | "H Display column headers\n" \ |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 1430 | |
| 1431 | /* help messages are sorted by lexical order of the hotkey */ |
| 1432 | const char report_help[] = HIST_BROWSER_HELP_COMMON |
Namhyung Kim | 6dd6013 | 2013-12-26 14:37:59 +0900 | [diff] [blame] | 1433 | "i Show header information\n" |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 1434 | "P Print histograms to perf.hist.N\n" |
| 1435 | "r Run available scripts\n" |
| 1436 | "s Switch to another data file in PWD\n" |
| 1437 | "t Zoom into current Thread\n" |
| 1438 | "V Verbose (DSO names in callchains, etc)\n" |
| 1439 | "/ Filter symbol by name"; |
| 1440 | const char top_help[] = HIST_BROWSER_HELP_COMMON |
| 1441 | "P Print histograms to perf.hist.N\n" |
| 1442 | "t Zoom into current Thread\n" |
| 1443 | "V Verbose (DSO names in callchains, etc)\n" |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 1444 | "z Toggle zeroing of samples\n" |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 1445 | "/ Filter symbol by name"; |
| 1446 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1447 | if (browser == NULL) |
| 1448 | return -1; |
| 1449 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1450 | if (min_pcnt) { |
| 1451 | browser->min_pcnt = min_pcnt; |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 1452 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1453 | } |
| 1454 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1455 | fstack = pstack__new(2); |
| 1456 | if (fstack == NULL) |
| 1457 | goto out; |
| 1458 | |
| 1459 | ui_helpline__push(helpline); |
| 1460 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1461 | memset(options, 0, sizeof(options)); |
| 1462 | |
Namhyung Kim | 59dc9f2 | 2014-07-31 14:47:41 +0900 | [diff] [blame] | 1463 | perf_hpp__for_each_format(fmt) |
| 1464 | perf_hpp__reset_width(fmt, hists); |
| 1465 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1466 | if (symbol_conf.col_width_list_str) |
| 1467 | perf_hpp__set_user_width(symbol_conf.col_width_list_str); |
| 1468 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1469 | while (1) { |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1470 | const struct thread *thread = NULL; |
| 1471 | const struct dso *dso = NULL; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1472 | int choice = 0, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1473 | annotate = -2, zoom_dso = -2, zoom_thread = -2, |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1474 | annotate_f = -2, annotate_t = -2, browse_map = -2; |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1475 | int scripts_comm = -2, scripts_symbol = -2, |
| 1476 | scripts_all = -2, switch_data = -2; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1477 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1478 | nr_options = 0; |
| 1479 | |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 1480 | key = hist_browser__run(browser, hbt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1481 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1482 | if (browser->he_selection != NULL) { |
| 1483 | thread = hist_browser__selected_thread(browser); |
| 1484 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
| 1485 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1486 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1487 | case K_TAB: |
| 1488 | case K_UNTAB: |
David Ahern | e4419b8 | 2011-10-19 11:37:47 -0600 | [diff] [blame] | 1489 | if (nr_events == 1) |
| 1490 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1491 | /* |
| 1492 | * Exit the browser, let hists__browser_tree |
| 1493 | * go to the next or previous |
| 1494 | */ |
| 1495 | goto out_free_stack; |
| 1496 | case 'a': |
Arnaldo Carvalho de Melo | 9c796ec | 2013-04-26 14:28:46 -0300 | [diff] [blame] | 1497 | if (!sort__has_sym) { |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1498 | ui_browser__warning(&browser->b, delay_secs * 2, |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 1499 | "Annotation is only available for symbolic views, " |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1500 | "include \"sym*\" in --sort to use it."); |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 1501 | continue; |
| 1502 | } |
| 1503 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1504 | if (browser->selection == NULL || |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 1505 | browser->selection->sym == NULL || |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1506 | browser->selection->map->dso->annotate_warned) |
| 1507 | continue; |
| 1508 | goto do_annotate; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1509 | case 'P': |
| 1510 | hist_browser__dump(browser); |
| 1511 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1512 | case 'd': |
| 1513 | goto zoom_dso; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 1514 | case 'V': |
| 1515 | browser->show_dso = !browser->show_dso; |
| 1516 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1517 | case 't': |
| 1518 | goto zoom_thread; |
Arnaldo Carvalho de Melo | 5a5626b | 2012-05-09 12:21:22 -0300 | [diff] [blame] | 1519 | case '/': |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1520 | if (ui_browser__input_window("Symbol to show", |
| 1521 | "Please enter the name of symbol you want to see", |
| 1522 | buf, "ENTER: OK, ESC: Cancel", |
| 1523 | delay_secs * 2) == K_ENTER) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1524 | hists->symbol_filter_str = *buf ? buf : NULL; |
| 1525 | hists__filter_by_symbol(hists); |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1526 | hist_browser__reset(browser); |
| 1527 | } |
| 1528 | continue; |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1529 | case 'r': |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1530 | if (is_report_browser(hbt)) |
Feng Tang | c77d8d7 | 2012-11-01 00:00:55 +0800 | [diff] [blame] | 1531 | goto do_scripts; |
| 1532 | continue; |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1533 | case 's': |
| 1534 | if (is_report_browser(hbt)) |
| 1535 | goto do_data_switch; |
| 1536 | continue; |
Namhyung Kim | 6dd6013 | 2013-12-26 14:37:59 +0900 | [diff] [blame] | 1537 | case 'i': |
| 1538 | /* env->arch is NULL for live-mode (i.e. perf top) */ |
| 1539 | if (env->arch) |
| 1540 | tui__header_window(env); |
| 1541 | continue; |
Namhyung Kim | 105eb30 | 2014-02-10 11:20:10 +0900 | [diff] [blame] | 1542 | case 'F': |
| 1543 | symbol_conf.filter_relative ^= 1; |
| 1544 | continue; |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 1545 | case 'z': |
| 1546 | if (!is_report_browser(hbt)) { |
| 1547 | struct perf_top *top = hbt->arg; |
| 1548 | |
| 1549 | top->zero = !top->zero; |
| 1550 | } |
| 1551 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1552 | case K_F1: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1553 | case 'h': |
| 1554 | case '?': |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1555 | ui_browser__help_window(&browser->b, |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 1556 | is_report_browser(hbt) ? report_help : top_help); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1557 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1558 | case K_ENTER: |
| 1559 | case K_RIGHT: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1560 | /* menu */ |
| 1561 | break; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1562 | case K_LEFT: { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1563 | const void *top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1564 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1565 | if (pstack__empty(fstack)) { |
| 1566 | /* |
| 1567 | * Go back to the perf_evsel_menu__run or other user |
| 1568 | */ |
| 1569 | if (left_exits) |
| 1570 | goto out_free_stack; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1571 | continue; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1572 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1573 | top = pstack__pop(fstack); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1574 | if (top == &browser->hists->dso_filter) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1575 | goto zoom_out_dso; |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1576 | if (top == &browser->hists->thread_filter) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1577 | goto zoom_out_thread; |
| 1578 | continue; |
| 1579 | } |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1580 | case K_ESC: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1581 | if (!left_exits && |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1582 | !ui_browser__dialog_yesno(&browser->b, |
| 1583 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1584 | continue; |
| 1585 | /* Fall thru */ |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1586 | case 'q': |
| 1587 | case CTRL('c'): |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1588 | goto out_free_stack; |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1589 | default: |
| 1590 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1591 | } |
| 1592 | |
Arnaldo Carvalho de Melo | 9c796ec | 2013-04-26 14:28:46 -0300 | [diff] [blame] | 1593 | if (!sort__has_sym) |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 1594 | goto add_exit_option; |
| 1595 | |
Namhyung Kim | 55369fc | 2013-04-01 20:35:20 +0900 | [diff] [blame] | 1596 | if (sort__mode == SORT_MODE__BRANCH) { |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1597 | bi = browser->he_selection->branch_info; |
| 1598 | if (browser->selection != NULL && |
| 1599 | bi && |
| 1600 | bi->from.sym != NULL && |
| 1601 | !bi->from.map->dso->annotate_warned && |
| 1602 | asprintf(&options[nr_options], "Annotate %s", |
| 1603 | bi->from.sym->name) > 0) |
| 1604 | annotate_f = nr_options++; |
| 1605 | |
| 1606 | if (browser->selection != NULL && |
| 1607 | bi && |
| 1608 | bi->to.sym != NULL && |
| 1609 | !bi->to.map->dso->annotate_warned && |
Stephane Eranian | 8bcd65f | 2012-03-12 16:13:29 +0100 | [diff] [blame] | 1610 | (bi->to.sym != bi->from.sym || |
| 1611 | bi->to.map->dso != bi->from.map->dso) && |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1612 | asprintf(&options[nr_options], "Annotate %s", |
| 1613 | bi->to.sym->name) > 0) |
| 1614 | annotate_t = nr_options++; |
| 1615 | } else { |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1616 | if (browser->selection != NULL && |
| 1617 | browser->selection->sym != NULL && |
Jiri Olsa | d755330 | 2014-06-15 10:22:15 +0200 | [diff] [blame] | 1618 | !browser->selection->map->dso->annotate_warned) { |
| 1619 | struct annotation *notes; |
| 1620 | |
| 1621 | notes = symbol__annotation(browser->selection->sym); |
| 1622 | |
| 1623 | if (notes->src && |
| 1624 | asprintf(&options[nr_options], "Annotate %s", |
| 1625 | browser->selection->sym->name) > 0) |
| 1626 | annotate = nr_options++; |
| 1627 | } |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1628 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1629 | |
| 1630 | if (thread != NULL && |
| 1631 | asprintf(&options[nr_options], "Zoom %s %s(%d) thread", |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1632 | (browser->hists->thread_filter ? "out of" : "into"), |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 1633 | (thread->comm_set ? thread__comm_str(thread) : ""), |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1634 | thread->tid) > 0) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1635 | zoom_thread = nr_options++; |
| 1636 | |
| 1637 | if (dso != NULL && |
| 1638 | asprintf(&options[nr_options], "Zoom %s %s DSO", |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1639 | (browser->hists->dso_filter ? "out of" : "into"), |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1640 | (dso->kernel ? "the Kernel" : dso->short_name)) > 0) |
| 1641 | zoom_dso = nr_options++; |
| 1642 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1643 | if (browser->selection != NULL && |
| 1644 | browser->selection->map != NULL && |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1645 | asprintf(&options[nr_options], "Browse map details") > 0) |
| 1646 | browse_map = nr_options++; |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1647 | |
| 1648 | /* perf script support */ |
| 1649 | if (browser->he_selection) { |
| 1650 | struct symbol *sym; |
| 1651 | |
| 1652 | if (asprintf(&options[nr_options], "Run scripts for samples of thread [%s]", |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 1653 | thread__comm_str(browser->he_selection->thread)) > 0) |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1654 | scripts_comm = nr_options++; |
| 1655 | |
| 1656 | sym = browser->he_selection->ms.sym; |
| 1657 | if (sym && sym->namelen && |
| 1658 | asprintf(&options[nr_options], "Run scripts for samples of symbol [%s]", |
| 1659 | sym->name) > 0) |
| 1660 | scripts_symbol = nr_options++; |
| 1661 | } |
| 1662 | |
| 1663 | if (asprintf(&options[nr_options], "Run scripts for all samples") > 0) |
| 1664 | scripts_all = nr_options++; |
| 1665 | |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1666 | if (is_report_browser(hbt) && asprintf(&options[nr_options], |
| 1667 | "Switch to another data file in PWD") > 0) |
| 1668 | switch_data = nr_options++; |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 1669 | add_exit_option: |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1670 | options[nr_options++] = (char *)"Exit"; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1671 | retry_popup_menu: |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 1672 | choice = ui__popup_menu(nr_options, options); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1673 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1674 | if (choice == nr_options - 1) |
| 1675 | break; |
| 1676 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1677 | if (choice == -1) { |
| 1678 | free_popup_options(options, nr_options - 1); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1679 | continue; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1680 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1681 | |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1682 | if (choice == annotate || choice == annotate_t || choice == annotate_f) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1683 | struct hist_entry *he; |
Jiri Olsa | d755330 | 2014-06-15 10:22:15 +0200 | [diff] [blame] | 1684 | struct annotation *notes; |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1685 | int err; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1686 | do_annotate: |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1687 | if (!objdump_path && perf_session_env__lookup_objdump(env)) |
| 1688 | continue; |
| 1689 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1690 | he = hist_browser__selected_entry(browser); |
| 1691 | if (he == NULL) |
| 1692 | continue; |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1693 | |
| 1694 | /* |
| 1695 | * we stash the branch_info symbol + map into the |
| 1696 | * the ms so we don't have to rewrite all the annotation |
| 1697 | * code to use branch_info. |
| 1698 | * in branch mode, the ms struct is not used |
| 1699 | */ |
| 1700 | if (choice == annotate_f) { |
| 1701 | he->ms.sym = he->branch_info->from.sym; |
| 1702 | he->ms.map = he->branch_info->from.map; |
| 1703 | } else if (choice == annotate_t) { |
| 1704 | he->ms.sym = he->branch_info->to.sym; |
| 1705 | he->ms.map = he->branch_info->to.map; |
| 1706 | } |
| 1707 | |
Jiri Olsa | d755330 | 2014-06-15 10:22:15 +0200 | [diff] [blame] | 1708 | notes = symbol__annotation(he->ms.sym); |
| 1709 | if (!notes->src) |
| 1710 | continue; |
| 1711 | |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 1712 | /* |
| 1713 | * Don't let this be freed, say, by hists__decay_entry. |
| 1714 | */ |
| 1715 | he->used = true; |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1716 | err = hist_entry__tui_annotate(he, evsel, hbt); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 1717 | he->used = false; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1718 | /* |
| 1719 | * offer option to annotate the other branch source or target |
| 1720 | * (if they exists) when returning from annotate |
| 1721 | */ |
| 1722 | if ((err == 'q' || err == CTRL('c')) |
| 1723 | && annotate_t != -2 && annotate_f != -2) |
| 1724 | goto retry_popup_menu; |
| 1725 | |
Arnaldo Carvalho de Melo | 900e14a | 2011-10-11 16:15:39 -0300 | [diff] [blame] | 1726 | ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1727 | if (err) |
| 1728 | ui_browser__handle_resize(&browser->b); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1729 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1730 | } else if (choice == browse_map) |
| 1731 | map__browse(browser->selection->map); |
| 1732 | else if (choice == zoom_dso) { |
| 1733 | zoom_dso: |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1734 | if (browser->hists->dso_filter) { |
| 1735 | pstack__remove(fstack, &browser->hists->dso_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1736 | zoom_out_dso: |
| 1737 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1738 | browser->hists->dso_filter = NULL; |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1739 | perf_hpp__set_elide(HISTC_DSO, false); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1740 | } else { |
| 1741 | if (dso == NULL) |
| 1742 | continue; |
| 1743 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", |
| 1744 | dso->kernel ? "the Kernel" : dso->short_name); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1745 | browser->hists->dso_filter = dso; |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1746 | perf_hpp__set_elide(HISTC_DSO, true); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1747 | pstack__push(fstack, &browser->hists->dso_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1748 | } |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1749 | hists__filter_by_dso(hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1750 | hist_browser__reset(browser); |
| 1751 | } else if (choice == zoom_thread) { |
| 1752 | zoom_thread: |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1753 | if (browser->hists->thread_filter) { |
| 1754 | pstack__remove(fstack, &browser->hists->thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1755 | zoom_out_thread: |
| 1756 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1757 | browser->hists->thread_filter = NULL; |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1758 | perf_hpp__set_elide(HISTC_THREAD, false); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1759 | } else { |
| 1760 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 1761 | thread->comm_set ? thread__comm_str(thread) : "", |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1762 | thread->tid); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1763 | browser->hists->thread_filter = thread; |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1764 | perf_hpp__set_elide(HISTC_THREAD, false); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1765 | pstack__push(fstack, &browser->hists->thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1766 | } |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1767 | hists__filter_by_thread(hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1768 | hist_browser__reset(browser); |
| 1769 | } |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1770 | /* perf scripts support */ |
| 1771 | else if (choice == scripts_all || choice == scripts_comm || |
| 1772 | choice == scripts_symbol) { |
| 1773 | do_scripts: |
| 1774 | memset(script_opt, 0, 64); |
| 1775 | |
| 1776 | if (choice == scripts_comm) |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 1777 | sprintf(script_opt, " -c %s ", thread__comm_str(browser->he_selection->thread)); |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 1778 | |
| 1779 | if (choice == scripts_symbol) |
| 1780 | sprintf(script_opt, " -S %s ", browser->he_selection->ms.sym->name); |
| 1781 | |
| 1782 | script_browse(script_opt); |
| 1783 | } |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1784 | /* Switch to another data file */ |
| 1785 | else if (choice == switch_data) { |
| 1786 | do_data_switch: |
| 1787 | if (!switch_data_file()) { |
| 1788 | key = K_SWITCH_INPUT_DATA; |
| 1789 | break; |
| 1790 | } else |
| 1791 | ui__warning("Won't switch the data files due to\n" |
| 1792 | "no valid data file get selected!\n"); |
| 1793 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1794 | } |
| 1795 | out_free_stack: |
| 1796 | pstack__delete(fstack); |
| 1797 | out: |
| 1798 | hist_browser__delete(browser); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1799 | free_popup_options(options, nr_options - 1); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1800 | return key; |
| 1801 | } |
| 1802 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1803 | struct perf_evsel_menu { |
| 1804 | struct ui_browser b; |
| 1805 | struct perf_evsel *selection; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1806 | bool lost_events, lost_events_warned; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1807 | float min_pcnt; |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1808 | struct perf_session_env *env; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1809 | }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1810 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1811 | static void perf_evsel_menu__write(struct ui_browser *browser, |
| 1812 | void *entry, int row) |
| 1813 | { |
| 1814 | struct perf_evsel_menu *menu = container_of(browser, |
| 1815 | struct perf_evsel_menu, b); |
| 1816 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1817 | struct hists *hists = evsel__hists(evsel); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1818 | bool current_entry = ui_browser__is_current_entry(browser, row); |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1819 | unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1820 | const char *ev_name = perf_evsel__name(evsel); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1821 | char bf[256], unit; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1822 | const char *warn = " "; |
| 1823 | size_t printed; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1824 | |
| 1825 | ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : |
| 1826 | HE_COLORSET_NORMAL); |
| 1827 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 1828 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1829 | struct perf_evsel *pos; |
| 1830 | |
| 1831 | ev_name = perf_evsel__group_name(evsel); |
| 1832 | |
| 1833 | for_each_group_member(pos, evsel) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1834 | struct hists *pos_hists = evsel__hists(pos); |
| 1835 | nr_events += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1839 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1840 | printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events, |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1841 | unit, unit == ' ' ? "" : " ", ev_name); |
| 1842 | slsmg_printf("%s", bf); |
| 1843 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1844 | nr_events = hists->stats.nr_events[PERF_RECORD_LOST]; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1845 | if (nr_events != 0) { |
| 1846 | menu->lost_events = true; |
| 1847 | if (!current_entry) |
| 1848 | ui_browser__set_color(browser, HE_COLORSET_TOP); |
| 1849 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1850 | printed += scnprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!", |
| 1851 | nr_events, unit, unit == ' ' ? "" : " "); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1852 | warn = bf; |
| 1853 | } |
| 1854 | |
| 1855 | slsmg_write_nstring(warn, browser->width - printed); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1856 | |
| 1857 | if (current_entry) |
| 1858 | menu->selection = evsel; |
| 1859 | } |
| 1860 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1861 | static int perf_evsel_menu__run(struct perf_evsel_menu *menu, |
| 1862 | int nr_events, const char *help, |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1863 | struct hist_browser_timer *hbt) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1864 | { |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1865 | struct perf_evlist *evlist = menu->b.priv; |
| 1866 | struct perf_evsel *pos; |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 1867 | const char *title = "Available samples"; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1868 | int delay_secs = hbt ? hbt->refresh : 0; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1869 | int key; |
| 1870 | |
| 1871 | if (ui_browser__show(&menu->b, title, |
| 1872 | "ESC: exit, ENTER|->: Browse histograms") < 0) |
| 1873 | return -1; |
| 1874 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1875 | while (1) { |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 1876 | key = ui_browser__run(&menu->b, delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1877 | |
| 1878 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1879 | case K_TIMER: |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1880 | hbt->timer(hbt->arg); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1881 | |
| 1882 | if (!menu->lost_events_warned && menu->lost_events) { |
| 1883 | ui_browser__warn_lost_events(&menu->b); |
| 1884 | menu->lost_events_warned = true; |
| 1885 | } |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1886 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1887 | case K_RIGHT: |
| 1888 | case K_ENTER: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1889 | if (!menu->selection) |
| 1890 | continue; |
| 1891 | pos = menu->selection; |
| 1892 | browse_hists: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1893 | perf_evlist__set_selected(evlist, pos); |
| 1894 | /* |
| 1895 | * Give the calling tool a chance to populate the non |
| 1896 | * default evsel resorted hists tree. |
| 1897 | */ |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 1898 | if (hbt) |
| 1899 | hbt->timer(hbt->arg); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1900 | key = perf_evsel__hists_browse(pos, nr_events, help, |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 1901 | true, hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1902 | menu->min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1903 | menu->env); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1904 | ui_browser__show_title(&menu->b, title); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1905 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1906 | case K_TAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1907 | if (pos->node.next == &evlist->entries) |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 1908 | pos = perf_evlist__first(evlist); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1909 | else |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 1910 | pos = perf_evsel__next(pos); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1911 | goto browse_hists; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1912 | case K_UNTAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1913 | if (pos->node.prev == &evlist->entries) |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 1914 | pos = perf_evlist__last(evlist); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1915 | else |
Arnaldo Carvalho de Melo | d87fcb4 | 2013-11-13 15:56:40 -0300 | [diff] [blame] | 1916 | pos = perf_evsel__prev(pos); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1917 | goto browse_hists; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1918 | case K_ESC: |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1919 | if (!ui_browser__dialog_yesno(&menu->b, |
| 1920 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1921 | continue; |
| 1922 | /* Fall thru */ |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 1923 | case K_SWITCH_INPUT_DATA: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1924 | case 'q': |
| 1925 | case CTRL('c'): |
| 1926 | goto out; |
| 1927 | default: |
| 1928 | continue; |
| 1929 | } |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1930 | case K_LEFT: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1931 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1932 | case K_ESC: |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1933 | if (!ui_browser__dialog_yesno(&menu->b, |
| 1934 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1935 | continue; |
| 1936 | /* Fall thru */ |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1937 | case 'q': |
| 1938 | case CTRL('c'): |
| 1939 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1940 | default: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1941 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1945 | out: |
| 1946 | ui_browser__hide(&menu->b); |
| 1947 | return key; |
| 1948 | } |
| 1949 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1950 | static bool filter_group_entries(struct ui_browser *browser __maybe_unused, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 1951 | void *entry) |
| 1952 | { |
| 1953 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); |
| 1954 | |
| 1955 | if (symbol_conf.event_group && !perf_evsel__is_group_leader(evsel)) |
| 1956 | return true; |
| 1957 | |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1961 | static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 1962 | int nr_entries, const char *help, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1963 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1964 | float min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1965 | struct perf_session_env *env) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1966 | { |
| 1967 | struct perf_evsel *pos; |
| 1968 | struct perf_evsel_menu menu = { |
| 1969 | .b = { |
| 1970 | .entries = &evlist->entries, |
| 1971 | .refresh = ui_browser__list_head_refresh, |
| 1972 | .seek = ui_browser__list_head_seek, |
| 1973 | .write = perf_evsel_menu__write, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 1974 | .filter = filter_group_entries, |
| 1975 | .nr_entries = nr_entries, |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1976 | .priv = evlist, |
| 1977 | }, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1978 | .min_pcnt = min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1979 | .env = env, |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1980 | }; |
| 1981 | |
| 1982 | ui_helpline__push("Press ESC to exit"); |
| 1983 | |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 1984 | evlist__for_each(evlist, pos) { |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1985 | const char *ev_name = perf_evsel__name(pos); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1986 | size_t line_len = strlen(ev_name) + 7; |
| 1987 | |
| 1988 | if (menu.b.width < line_len) |
| 1989 | menu.b.width = line_len; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1990 | } |
| 1991 | |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 1992 | return perf_evsel_menu__run(&menu, nr_entries, help, hbt); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1993 | } |
| 1994 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1995 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1996 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1997 | float min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 1998 | struct perf_session_env *env) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1999 | { |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 2000 | int nr_entries = evlist->nr_entries; |
| 2001 | |
| 2002 | single_entry: |
| 2003 | if (nr_entries == 1) { |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 2004 | struct perf_evsel *first = perf_evlist__first(evlist); |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 2005 | |
| 2006 | return perf_evsel__hists_browse(first, nr_entries, help, |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 2007 | false, hbt, min_pcnt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2008 | env); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 2009 | } |
| 2010 | |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 2011 | if (symbol_conf.event_group) { |
| 2012 | struct perf_evsel *pos; |
| 2013 | |
| 2014 | nr_entries = 0; |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 2015 | evlist__for_each(evlist, pos) { |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 2016 | if (perf_evsel__is_group_leader(pos)) |
| 2017 | nr_entries++; |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 2018 | } |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 2019 | |
| 2020 | if (nr_entries == 1) |
| 2021 | goto single_entry; |
| 2022 | } |
| 2023 | |
| 2024 | return __perf_evlist__tui_browse_hists(evlist, nr_entries, help, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2025 | hbt, min_pcnt, env); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2026 | } |