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> |
| 5 | #include <newt.h> |
| 6 | #include <linux/rbtree.h> |
| 7 | |
Namhyung Kim | aca7a94 | 2012-04-04 00:14:26 -0700 | [diff] [blame] | 8 | #include "../../util/evsel.h" |
| 9 | #include "../../util/evlist.h" |
| 10 | #include "../../util/hist.h" |
| 11 | #include "../../util/pstack.h" |
| 12 | #include "../../util/sort.h" |
| 13 | #include "../../util/util.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 14 | |
| 15 | #include "../browser.h" |
| 16 | #include "../helpline.h" |
| 17 | #include "../util.h" |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 18 | #include "../ui.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 19 | #include "map.h" |
| 20 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 21 | struct hist_browser { |
| 22 | struct ui_browser b; |
| 23 | struct hists *hists; |
| 24 | struct hist_entry *he_selection; |
| 25 | struct map_symbol *selection; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 26 | int print_seq; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 27 | bool show_dso; |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 28 | bool has_symbols; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 29 | }; |
| 30 | |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 31 | extern void hist_browser__init_hpp(void); |
| 32 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 33 | static int hists__browser_title(struct hists *hists, char *bf, size_t size, |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 34 | const char *ev_name); |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 35 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 36 | static void hist_browser__refresh_dimensions(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 37 | { |
| 38 | /* 3 == +/- toggle symbol before actual hist_entry rendering */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 39 | browser->b.width = 3 + (hists__sort_list_width(browser->hists) + |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 40 | sizeof("[k]")); |
| 41 | } |
| 42 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 43 | static void hist_browser__reset(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 44 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 45 | browser->b.nr_entries = browser->hists->nr_entries; |
| 46 | hist_browser__refresh_dimensions(browser); |
| 47 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static char tree__folded_sign(bool unfolded) |
| 51 | { |
| 52 | return unfolded ? '-' : '+'; |
| 53 | } |
| 54 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 55 | static char map_symbol__folded(const struct map_symbol *ms) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 56 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 57 | return ms->has_children ? tree__folded_sign(ms->unfolded) : ' '; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 58 | } |
| 59 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 60 | static char hist_entry__folded(const struct hist_entry *he) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 61 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 62 | return map_symbol__folded(&he->ms); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 63 | } |
| 64 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 65 | static char callchain_list__folded(const struct callchain_list *cl) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 66 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 67 | return map_symbol__folded(&cl->ms); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 68 | } |
| 69 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 70 | 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] | 71 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 72 | ms->unfolded = unfold ? ms->has_children : false; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 73 | } |
| 74 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 75 | 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] | 76 | { |
| 77 | int n = 0; |
| 78 | struct rb_node *nd; |
| 79 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 80 | 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] | 81 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 82 | struct callchain_list *chain; |
| 83 | char folded_sign = ' '; /* No children */ |
| 84 | |
| 85 | list_for_each_entry(chain, &child->val, list) { |
| 86 | ++n; |
| 87 | /* We need this because we may not have children */ |
| 88 | folded_sign = callchain_list__folded(chain); |
| 89 | if (folded_sign == '+') |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | if (folded_sign == '-') /* Have children and they're unfolded */ |
| 94 | n += callchain_node__count_rows_rb_tree(child); |
| 95 | } |
| 96 | |
| 97 | return n; |
| 98 | } |
| 99 | |
| 100 | static int callchain_node__count_rows(struct callchain_node *node) |
| 101 | { |
| 102 | struct callchain_list *chain; |
| 103 | bool unfolded = false; |
| 104 | int n = 0; |
| 105 | |
| 106 | list_for_each_entry(chain, &node->val, list) { |
| 107 | ++n; |
| 108 | unfolded = chain->ms.unfolded; |
| 109 | } |
| 110 | |
| 111 | if (unfolded) |
| 112 | n += callchain_node__count_rows_rb_tree(node); |
| 113 | |
| 114 | return n; |
| 115 | } |
| 116 | |
| 117 | static int callchain__count_rows(struct rb_root *chain) |
| 118 | { |
| 119 | struct rb_node *nd; |
| 120 | int n = 0; |
| 121 | |
| 122 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 123 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 124 | n += callchain_node__count_rows(node); |
| 125 | } |
| 126 | |
| 127 | return n; |
| 128 | } |
| 129 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 130 | static bool map_symbol__toggle_fold(struct map_symbol *ms) |
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 | if (!ms) |
Jiri Olsa | 8493fe1 | 2012-04-04 22:21:31 +0200 | [diff] [blame] | 133 | return false; |
| 134 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 135 | if (!ms->has_children) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 136 | return false; |
| 137 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 138 | ms->unfolded = !ms->unfolded; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 139 | return true; |
| 140 | } |
| 141 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 142 | 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] | 143 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 144 | struct rb_node *nd = rb_first(&node->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 145 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 146 | 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] | 147 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 148 | struct callchain_list *chain; |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 149 | bool first = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 150 | |
| 151 | list_for_each_entry(chain, &child->val, list) { |
| 152 | if (first) { |
| 153 | first = false; |
| 154 | chain->ms.has_children = chain->list.next != &child->val || |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 155 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 156 | } else |
| 157 | chain->ms.has_children = chain->list.next == &child->val && |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 158 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | callchain_node__init_have_children_rb_tree(child); |
| 162 | } |
| 163 | } |
| 164 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 165 | static void callchain_node__init_have_children(struct callchain_node *node) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 166 | { |
| 167 | struct callchain_list *chain; |
| 168 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 169 | list_for_each_entry(chain, &node->val, list) |
| 170 | chain->ms.has_children = !RB_EMPTY_ROOT(&node->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 171 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 172 | callchain_node__init_have_children_rb_tree(node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 173 | } |
| 174 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 175 | static void callchain__init_have_children(struct rb_root *root) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 176 | { |
| 177 | struct rb_node *nd; |
| 178 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 179 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 180 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 181 | callchain_node__init_have_children(node); |
| 182 | } |
| 183 | } |
| 184 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 185 | 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] | 186 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 187 | if (!he->init_have_children) { |
| 188 | he->ms.has_children = !RB_EMPTY_ROOT(&he->sorted_chain); |
| 189 | callchain__init_have_children(&he->sorted_chain); |
| 190 | he->init_have_children = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 194 | static bool hist_browser__toggle_fold(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 195 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 196 | if (map_symbol__toggle_fold(browser->selection)) { |
| 197 | struct hist_entry *he = browser->he_selection; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 198 | |
| 199 | hist_entry__init_have_children(he); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 200 | browser->hists->nr_entries -= he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 201 | |
| 202 | if (he->ms.unfolded) |
| 203 | he->nr_rows = callchain__count_rows(&he->sorted_chain); |
| 204 | else |
| 205 | he->nr_rows = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 206 | browser->hists->nr_entries += he->nr_rows; |
| 207 | browser->b.nr_entries = browser->hists->nr_entries; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | /* If it doesn't have children, no toggling performed */ |
| 213 | return false; |
| 214 | } |
| 215 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 216 | 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] | 217 | { |
| 218 | int n = 0; |
| 219 | struct rb_node *nd; |
| 220 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 221 | 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] | 222 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 223 | struct callchain_list *chain; |
| 224 | bool has_children = false; |
| 225 | |
| 226 | list_for_each_entry(chain, &child->val, list) { |
| 227 | ++n; |
| 228 | map_symbol__set_folding(&chain->ms, unfold); |
| 229 | has_children = chain->ms.has_children; |
| 230 | } |
| 231 | |
| 232 | if (has_children) |
| 233 | n += callchain_node__set_folding_rb_tree(child, unfold); |
| 234 | } |
| 235 | |
| 236 | return n; |
| 237 | } |
| 238 | |
| 239 | static int callchain_node__set_folding(struct callchain_node *node, bool unfold) |
| 240 | { |
| 241 | struct callchain_list *chain; |
| 242 | bool has_children = false; |
| 243 | int n = 0; |
| 244 | |
| 245 | list_for_each_entry(chain, &node->val, list) { |
| 246 | ++n; |
| 247 | map_symbol__set_folding(&chain->ms, unfold); |
| 248 | has_children = chain->ms.has_children; |
| 249 | } |
| 250 | |
| 251 | if (has_children) |
| 252 | n += callchain_node__set_folding_rb_tree(node, unfold); |
| 253 | |
| 254 | return n; |
| 255 | } |
| 256 | |
| 257 | static int callchain__set_folding(struct rb_root *chain, bool unfold) |
| 258 | { |
| 259 | struct rb_node *nd; |
| 260 | int n = 0; |
| 261 | |
| 262 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 263 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 264 | n += callchain_node__set_folding(node, unfold); |
| 265 | } |
| 266 | |
| 267 | return n; |
| 268 | } |
| 269 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 270 | 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] | 271 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 272 | hist_entry__init_have_children(he); |
| 273 | map_symbol__set_folding(&he->ms, unfold); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 274 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 275 | if (he->ms.has_children) { |
| 276 | int n = callchain__set_folding(&he->sorted_chain, unfold); |
| 277 | he->nr_rows = unfold ? n : 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 278 | } else |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 279 | he->nr_rows = 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 280 | } |
| 281 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 282 | static void hists__set_folding(struct hists *hists, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 283 | { |
| 284 | struct rb_node *nd; |
| 285 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 286 | hists->nr_entries = 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 287 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 288 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 289 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 290 | hist_entry__set_folding(he, unfold); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 291 | hists->nr_entries += 1 + he->nr_rows; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 295 | 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] | 296 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 297 | hists__set_folding(browser->hists, unfold); |
| 298 | browser->b.nr_entries = browser->hists->nr_entries; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 299 | /* 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] | 300 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 301 | } |
| 302 | |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 303 | static void ui_browser__warn_lost_events(struct ui_browser *browser) |
| 304 | { |
| 305 | ui_browser__warning(browser, 4, |
| 306 | "Events are being lost, check IO/CPU overload!\n\n" |
| 307 | "You may want to run 'perf' using a RT scheduler policy:\n\n" |
| 308 | " perf top -r 80\n\n" |
| 309 | "Or reduce the sampling frequency."); |
| 310 | } |
| 311 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 312 | static int hist_browser__run(struct hist_browser *browser, const char *ev_name, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 313 | void(*timer)(void *arg), void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 314 | { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 315 | int key; |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 316 | char title[160]; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 317 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 318 | browser->b.entries = &browser->hists->entries; |
| 319 | browser->b.nr_entries = browser->hists->nr_entries; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 320 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 321 | hist_browser__refresh_dimensions(browser); |
| 322 | hists__browser_title(browser->hists, title, sizeof(title), ev_name); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 323 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 324 | if (ui_browser__show(&browser->b, title, |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 325 | "Press '?' for help on key bindings") < 0) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 326 | return -1; |
| 327 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 328 | while (1) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 329 | key = ui_browser__run(&browser->b, delay_secs); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 330 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 331 | switch (key) { |
Arnaldo Carvalho de Melo | 13d8f96 | 2011-10-26 08:05:34 -0200 | [diff] [blame] | 332 | case K_TIMER: |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 333 | timer(arg); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 334 | ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 335 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 336 | if (browser->hists->stats.nr_lost_warned != |
| 337 | browser->hists->stats.nr_events[PERF_RECORD_LOST]) { |
| 338 | browser->hists->stats.nr_lost_warned = |
| 339 | browser->hists->stats.nr_events[PERF_RECORD_LOST]; |
| 340 | ui_browser__warn_lost_events(&browser->b); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 341 | } |
| 342 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 343 | hists__browser_title(browser->hists, title, sizeof(title), ev_name); |
| 344 | ui_browser__show_title(&browser->b, title); |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 345 | continue; |
Arnaldo Carvalho de Melo | 4694153 | 2010-08-10 15:50:07 -0300 | [diff] [blame] | 346 | case 'D': { /* Debug */ |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 347 | static int seq; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 348 | struct hist_entry *h = rb_entry(browser->b.top, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 349 | struct hist_entry, rb_node); |
| 350 | ui_helpline__pop(); |
| 351 | ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%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] | 352 | seq++, browser->b.nr_entries, |
| 353 | browser->hists->nr_entries, |
| 354 | browser->b.height, |
| 355 | browser->b.index, |
| 356 | browser->b.top_idx, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 357 | h->row_offset, h->nr_rows); |
| 358 | } |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 359 | break; |
| 360 | case 'C': |
| 361 | /* Collapse the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 362 | hist_browser__set_folding(browser, false); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 363 | break; |
| 364 | case 'E': |
| 365 | /* Expand the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 366 | hist_browser__set_folding(browser, true); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 367 | break; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 368 | case K_ENTER: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 369 | if (hist_browser__toggle_fold(browser)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 370 | break; |
| 371 | /* fall thru */ |
| 372 | default: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 373 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 374 | } |
| 375 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 376 | out: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 377 | ui_browser__hide(&browser->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 378 | return key; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 379 | } |
| 380 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 381 | static char *callchain_list__sym_name(struct callchain_list *cl, |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 382 | char *bf, size_t bfsize, bool show_dso) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 383 | { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 384 | int printed; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 385 | |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 386 | if (cl->ms.sym) |
| 387 | printed = scnprintf(bf, bfsize, "%s", cl->ms.sym->name); |
| 388 | else |
| 389 | printed = scnprintf(bf, bfsize, "%#" PRIx64, cl->ip); |
| 390 | |
| 391 | if (show_dso) |
| 392 | scnprintf(bf + printed, bfsize - printed, " %s", |
| 393 | cl->ms.map ? cl->ms.map->dso->short_name : "unknown"); |
| 394 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 395 | return bf; |
| 396 | } |
| 397 | |
| 398 | #define LEVEL_OFFSET_STEP 3 |
| 399 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 400 | static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 401 | struct callchain_node *chain_node, |
| 402 | u64 total, int level, |
| 403 | unsigned short row, |
| 404 | off_t *row_offset, |
| 405 | bool *is_current_entry) |
| 406 | { |
| 407 | struct rb_node *node; |
| 408 | int first_row = row, width, offset = level * LEVEL_OFFSET_STEP; |
| 409 | u64 new_total, remaining; |
| 410 | |
| 411 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 412 | new_total = chain_node->children_hit; |
| 413 | else |
| 414 | new_total = total; |
| 415 | |
| 416 | remaining = new_total; |
| 417 | node = rb_first(&chain_node->rb_root); |
| 418 | while (node) { |
| 419 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 420 | struct rb_node *next = rb_next(node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 421 | u64 cumul = callchain_cumul_hits(child); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 422 | struct callchain_list *chain; |
| 423 | char folded_sign = ' '; |
| 424 | int first = true; |
| 425 | int extra_offset = 0; |
| 426 | |
| 427 | remaining -= cumul; |
| 428 | |
| 429 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 430 | char bf[1024], *alloc_str; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 431 | const char *str; |
| 432 | int color; |
| 433 | bool was_first = first; |
| 434 | |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 435 | if (first) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 436 | first = false; |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 437 | else |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 438 | extra_offset = LEVEL_OFFSET_STEP; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 439 | |
| 440 | folded_sign = callchain_list__folded(chain); |
| 441 | if (*row_offset != 0) { |
| 442 | --*row_offset; |
| 443 | goto do_next; |
| 444 | } |
| 445 | |
| 446 | alloc_str = NULL; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 447 | str = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 448 | browser->show_dso); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 449 | if (was_first) { |
| 450 | double percent = cumul * 100.0 / new_total; |
| 451 | |
| 452 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) |
| 453 | str = "Not enough memory!"; |
| 454 | else |
| 455 | str = alloc_str; |
| 456 | } |
| 457 | |
| 458 | color = HE_COLORSET_NORMAL; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 459 | width = browser->b.width - (offset + extra_offset + 2); |
| 460 | if (ui_browser__is_current_entry(&browser->b, row)) { |
| 461 | browser->selection = &chain->ms; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 462 | color = HE_COLORSET_SELECTED; |
| 463 | *is_current_entry = true; |
| 464 | } |
| 465 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 466 | ui_browser__set_color(&browser->b, color); |
| 467 | ui_browser__gotorc(&browser->b, row, 0); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 468 | slsmg_write_nstring(" ", offset + extra_offset); |
| 469 | slsmg_printf("%c ", folded_sign); |
| 470 | slsmg_write_nstring(str, width); |
| 471 | free(alloc_str); |
| 472 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 473 | if (++row == browser->b.height) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 474 | goto out; |
| 475 | do_next: |
| 476 | if (folded_sign == '+') |
| 477 | break; |
| 478 | } |
| 479 | |
| 480 | if (folded_sign == '-') { |
| 481 | const int new_level = level + (extra_offset ? 2 : 1); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 482 | row += hist_browser__show_callchain_node_rb_tree(browser, child, new_total, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 483 | new_level, row, row_offset, |
| 484 | is_current_entry); |
| 485 | } |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 486 | if (row == browser->b.height) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 487 | goto out; |
| 488 | node = next; |
| 489 | } |
| 490 | out: |
| 491 | return row - first_row; |
| 492 | } |
| 493 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 494 | static int hist_browser__show_callchain_node(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 495 | struct callchain_node *node, |
| 496 | int level, unsigned short row, |
| 497 | off_t *row_offset, |
| 498 | bool *is_current_entry) |
| 499 | { |
| 500 | struct callchain_list *chain; |
| 501 | int first_row = row, |
| 502 | offset = level * LEVEL_OFFSET_STEP, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 503 | width = browser->b.width - offset; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 504 | char folded_sign = ' '; |
| 505 | |
| 506 | list_for_each_entry(chain, &node->val, list) { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 507 | char bf[1024], *s; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 508 | int color; |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 509 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 510 | folded_sign = callchain_list__folded(chain); |
| 511 | |
| 512 | if (*row_offset != 0) { |
| 513 | --*row_offset; |
| 514 | continue; |
| 515 | } |
| 516 | |
| 517 | color = HE_COLORSET_NORMAL; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 518 | if (ui_browser__is_current_entry(&browser->b, row)) { |
| 519 | browser->selection = &chain->ms; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 520 | color = HE_COLORSET_SELECTED; |
| 521 | *is_current_entry = true; |
| 522 | } |
| 523 | |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 524 | s = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 525 | browser->show_dso); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 526 | ui_browser__gotorc(&browser->b, row, 0); |
| 527 | ui_browser__set_color(&browser->b, color); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 528 | slsmg_write_nstring(" ", offset); |
| 529 | slsmg_printf("%c ", folded_sign); |
| 530 | slsmg_write_nstring(s, width - 2); |
| 531 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 532 | if (++row == browser->b.height) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 533 | goto out; |
| 534 | } |
| 535 | |
| 536 | if (folded_sign == '-') |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 537 | row += hist_browser__show_callchain_node_rb_tree(browser, node, |
| 538 | browser->hists->stats.total_period, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 539 | level + 1, row, |
| 540 | row_offset, |
| 541 | is_current_entry); |
| 542 | out: |
| 543 | return row - first_row; |
| 544 | } |
| 545 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 546 | static int hist_browser__show_callchain(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 547 | struct rb_root *chain, |
| 548 | int level, unsigned short row, |
| 549 | off_t *row_offset, |
| 550 | bool *is_current_entry) |
| 551 | { |
| 552 | struct rb_node *nd; |
| 553 | int first_row = row; |
| 554 | |
| 555 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 556 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 557 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 558 | row += hist_browser__show_callchain_node(browser, node, level, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 559 | row, row_offset, |
| 560 | is_current_entry); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 561 | if (row == browser->b.height) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 562 | break; |
| 563 | } |
| 564 | |
| 565 | return row - first_row; |
| 566 | } |
| 567 | |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 568 | #define HPP__COLOR_FN(_name, _field) \ |
| 569 | static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ |
| 570 | struct hist_entry *he) \ |
| 571 | { \ |
| 572 | double percent = 100.0 * he->_field / hpp->total_period; \ |
| 573 | *(double *)hpp->ptr = percent; \ |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 574 | return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | HPP__COLOR_FN(overhead, period) |
| 578 | HPP__COLOR_FN(overhead_sys, period_sys) |
| 579 | HPP__COLOR_FN(overhead_us, period_us) |
| 580 | HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) |
| 581 | HPP__COLOR_FN(overhead_guest_us, period_guest_us) |
| 582 | |
| 583 | #undef HPP__COLOR_FN |
| 584 | |
| 585 | void hist_browser__init_hpp(void) |
| 586 | { |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame^] | 587 | perf_hpp__init(); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 588 | |
| 589 | perf_hpp__format[PERF_HPP__OVERHEAD].color = |
| 590 | hist_browser__hpp_color_overhead; |
| 591 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color = |
| 592 | hist_browser__hpp_color_overhead_sys; |
| 593 | perf_hpp__format[PERF_HPP__OVERHEAD_US].color = |
| 594 | hist_browser__hpp_color_overhead_us; |
| 595 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color = |
| 596 | hist_browser__hpp_color_overhead_guest_sys; |
| 597 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = |
| 598 | hist_browser__hpp_color_overhead_guest_us; |
| 599 | } |
| 600 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 601 | static int hist_browser__show_entry(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 602 | struct hist_entry *entry, |
| 603 | unsigned short row) |
| 604 | { |
| 605 | char s[256]; |
| 606 | double percent; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 607 | int i, printed = 0; |
Namhyung Kim | 67d2591 | 2012-09-12 15:35:06 +0900 | [diff] [blame] | 608 | int width = browser->b.width; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 609 | char folded_sign = ' '; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 610 | 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] | 611 | off_t row_offset = entry->row_offset; |
| 612 | |
| 613 | if (current_entry) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 614 | browser->he_selection = entry; |
| 615 | browser->selection = &entry->ms; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 619 | hist_entry__init_have_children(entry); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 620 | folded_sign = hist_entry__folded(entry); |
| 621 | } |
| 622 | |
| 623 | if (row_offset == 0) { |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 624 | struct perf_hpp hpp = { |
| 625 | .buf = s, |
| 626 | .size = sizeof(s), |
| 627 | .total_period = browser->hists->stats.total_period, |
| 628 | }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 629 | |
Namhyung Kim | 67d2591 | 2012-09-12 15:35:06 +0900 | [diff] [blame] | 630 | ui_browser__gotorc(&browser->b, row, 0); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 631 | |
| 632 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 633 | if (!perf_hpp__format[i].cond) |
| 634 | continue; |
| 635 | |
| 636 | if (i) { |
| 637 | slsmg_printf(" "); |
| 638 | width -= 2; |
| 639 | } |
| 640 | |
| 641 | if (perf_hpp__format[i].color) { |
| 642 | hpp.ptr = &percent; |
| 643 | /* It will set percent for us. See HPP__COLOR_FN above. */ |
| 644 | width -= perf_hpp__format[i].color(&hpp, entry); |
| 645 | |
| 646 | ui_browser__set_percent_color(&browser->b, percent, current_entry); |
| 647 | |
| 648 | if (i == 0 && symbol_conf.use_callchain) { |
| 649 | slsmg_printf("%c ", folded_sign); |
| 650 | width -= 2; |
| 651 | } |
| 652 | |
| 653 | slsmg_printf("%s", s); |
| 654 | |
| 655 | if (!current_entry || !browser->b.navkeypressed) |
| 656 | ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); |
| 657 | } else { |
| 658 | width -= perf_hpp__format[i].entry(&hpp, entry); |
| 659 | slsmg_printf("%s", s); |
| 660 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 661 | } |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 662 | |
| 663 | /* The scroll bar isn't being used */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 664 | if (!browser->b.navkeypressed) |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 665 | width += 1; |
| 666 | |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 667 | hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 668 | slsmg_write_nstring(s, width); |
| 669 | ++row; |
| 670 | ++printed; |
| 671 | } else |
| 672 | --row_offset; |
| 673 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 674 | if (folded_sign == '-' && row != browser->b.height) { |
| 675 | printed += hist_browser__show_callchain(browser, &entry->sorted_chain, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 676 | 1, row, &row_offset, |
| 677 | ¤t_entry); |
| 678 | if (current_entry) |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 679 | browser->he_selection = entry; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | return printed; |
| 683 | } |
| 684 | |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 685 | static void ui_browser__hists_init_top(struct ui_browser *browser) |
| 686 | { |
| 687 | if (browser->top == NULL) { |
| 688 | struct hist_browser *hb; |
| 689 | |
| 690 | hb = container_of(browser, struct hist_browser, b); |
| 691 | browser->top = rb_first(&hb->hists->entries); |
| 692 | } |
| 693 | } |
| 694 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 695 | static unsigned int hist_browser__refresh(struct ui_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 696 | { |
| 697 | unsigned row = 0; |
| 698 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 699 | 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] | 700 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 701 | ui_browser__hists_init_top(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 702 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 703 | for (nd = browser->top; nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 704 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 705 | |
| 706 | if (h->filtered) |
| 707 | continue; |
| 708 | |
| 709 | row += hist_browser__show_entry(hb, h, row); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 710 | if (row == browser->height) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 711 | break; |
| 712 | } |
| 713 | |
| 714 | return row; |
| 715 | } |
| 716 | |
| 717 | static struct rb_node *hists__filter_entries(struct rb_node *nd) |
| 718 | { |
| 719 | while (nd != NULL) { |
| 720 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 721 | if (!h->filtered) |
| 722 | return nd; |
| 723 | |
| 724 | nd = rb_next(nd); |
| 725 | } |
| 726 | |
| 727 | return NULL; |
| 728 | } |
| 729 | |
| 730 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd) |
| 731 | { |
| 732 | while (nd != NULL) { |
| 733 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 734 | if (!h->filtered) |
| 735 | return nd; |
| 736 | |
| 737 | nd = rb_prev(nd); |
| 738 | } |
| 739 | |
| 740 | return NULL; |
| 741 | } |
| 742 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 743 | static void ui_browser__hists_seek(struct ui_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 744 | off_t offset, int whence) |
| 745 | { |
| 746 | struct hist_entry *h; |
| 747 | struct rb_node *nd; |
| 748 | bool first = true; |
| 749 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 750 | if (browser->nr_entries == 0) |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 751 | return; |
| 752 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 753 | ui_browser__hists_init_top(browser); |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 754 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 755 | switch (whence) { |
| 756 | case SEEK_SET: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 757 | nd = hists__filter_entries(rb_first(browser->entries)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 758 | break; |
| 759 | case SEEK_CUR: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 760 | nd = browser->top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 761 | goto do_offset; |
| 762 | case SEEK_END: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 763 | nd = hists__filter_prev_entries(rb_last(browser->entries)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 764 | first = false; |
| 765 | break; |
| 766 | default: |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Moves not relative to the first visible entry invalidates its |
| 772 | * row_offset: |
| 773 | */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 774 | h = rb_entry(browser->top, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 775 | h->row_offset = 0; |
| 776 | |
| 777 | /* |
| 778 | * Here we have to check if nd is expanded (+), if it is we can't go |
| 779 | * the next top level hist_entry, instead we must compute an offset of |
| 780 | * what _not_ to show and not change the first visible entry. |
| 781 | * |
| 782 | * This offset increments when we are going from top to bottom and |
| 783 | * decreases when we're going from bottom to top. |
| 784 | * |
| 785 | * As we don't have backpointers to the top level in the callchains |
| 786 | * structure, we need to always print the whole hist_entry callchain, |
| 787 | * skipping the first ones that are before the first visible entry |
| 788 | * and stop when we printed enough lines to fill the screen. |
| 789 | */ |
| 790 | do_offset: |
| 791 | if (offset > 0) { |
| 792 | do { |
| 793 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 794 | if (h->ms.unfolded) { |
| 795 | u16 remaining = h->nr_rows - h->row_offset; |
| 796 | if (offset > remaining) { |
| 797 | offset -= remaining; |
| 798 | h->row_offset = 0; |
| 799 | } else { |
| 800 | h->row_offset += offset; |
| 801 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 802 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | } |
| 806 | nd = hists__filter_entries(rb_next(nd)); |
| 807 | if (nd == NULL) |
| 808 | break; |
| 809 | --offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 810 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 811 | } while (offset != 0); |
| 812 | } else if (offset < 0) { |
| 813 | while (1) { |
| 814 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 815 | if (h->ms.unfolded) { |
| 816 | if (first) { |
| 817 | if (-offset > h->row_offset) { |
| 818 | offset += h->row_offset; |
| 819 | h->row_offset = 0; |
| 820 | } else { |
| 821 | h->row_offset += offset; |
| 822 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 823 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 824 | break; |
| 825 | } |
| 826 | } else { |
| 827 | if (-offset > h->nr_rows) { |
| 828 | offset += h->nr_rows; |
| 829 | h->row_offset = 0; |
| 830 | } else { |
| 831 | h->row_offset = h->nr_rows + offset; |
| 832 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 833 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 834 | break; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | nd = hists__filter_prev_entries(rb_prev(nd)); |
| 840 | if (nd == NULL) |
| 841 | break; |
| 842 | ++offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 843 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 844 | if (offset == 0) { |
| 845 | /* |
| 846 | * Last unfiltered hist_entry, check if it is |
| 847 | * unfolded, if it is then we should have |
| 848 | * row_offset at its last entry. |
| 849 | */ |
| 850 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 851 | if (h->ms.unfolded) |
| 852 | h->row_offset = h->nr_rows; |
| 853 | break; |
| 854 | } |
| 855 | first = false; |
| 856 | } |
| 857 | } else { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 858 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 859 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 860 | h->row_offset = 0; |
| 861 | } |
| 862 | } |
| 863 | |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 864 | static int hist_browser__fprintf_callchain_node_rb_tree(struct hist_browser *browser, |
| 865 | struct callchain_node *chain_node, |
| 866 | u64 total, int level, |
| 867 | FILE *fp) |
| 868 | { |
| 869 | struct rb_node *node; |
| 870 | int offset = level * LEVEL_OFFSET_STEP; |
| 871 | u64 new_total, remaining; |
| 872 | int printed = 0; |
| 873 | |
| 874 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 875 | new_total = chain_node->children_hit; |
| 876 | else |
| 877 | new_total = total; |
| 878 | |
| 879 | remaining = new_total; |
| 880 | node = rb_first(&chain_node->rb_root); |
| 881 | while (node) { |
| 882 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 883 | struct rb_node *next = rb_next(node); |
| 884 | u64 cumul = callchain_cumul_hits(child); |
| 885 | struct callchain_list *chain; |
| 886 | char folded_sign = ' '; |
| 887 | int first = true; |
| 888 | int extra_offset = 0; |
| 889 | |
| 890 | remaining -= cumul; |
| 891 | |
| 892 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 893 | char bf[1024], *alloc_str; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 894 | const char *str; |
| 895 | bool was_first = first; |
| 896 | |
| 897 | if (first) |
| 898 | first = false; |
| 899 | else |
| 900 | extra_offset = LEVEL_OFFSET_STEP; |
| 901 | |
| 902 | folded_sign = callchain_list__folded(chain); |
| 903 | |
| 904 | alloc_str = NULL; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 905 | str = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 906 | browser->show_dso); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 907 | if (was_first) { |
| 908 | double percent = cumul * 100.0 / new_total; |
| 909 | |
| 910 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) |
| 911 | str = "Not enough memory!"; |
| 912 | else |
| 913 | str = alloc_str; |
| 914 | } |
| 915 | |
| 916 | printed += fprintf(fp, "%*s%c %s\n", offset + extra_offset, " ", folded_sign, str); |
| 917 | free(alloc_str); |
| 918 | if (folded_sign == '+') |
| 919 | break; |
| 920 | } |
| 921 | |
| 922 | if (folded_sign == '-') { |
| 923 | const int new_level = level + (extra_offset ? 2 : 1); |
| 924 | printed += hist_browser__fprintf_callchain_node_rb_tree(browser, child, new_total, |
| 925 | new_level, fp); |
| 926 | } |
| 927 | |
| 928 | node = next; |
| 929 | } |
| 930 | |
| 931 | return printed; |
| 932 | } |
| 933 | |
| 934 | static int hist_browser__fprintf_callchain_node(struct hist_browser *browser, |
| 935 | struct callchain_node *node, |
| 936 | int level, FILE *fp) |
| 937 | { |
| 938 | struct callchain_list *chain; |
| 939 | int offset = level * LEVEL_OFFSET_STEP; |
| 940 | char folded_sign = ' '; |
| 941 | int printed = 0; |
| 942 | |
| 943 | list_for_each_entry(chain, &node->val, list) { |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 944 | char bf[1024], *s; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 945 | |
| 946 | folded_sign = callchain_list__folded(chain); |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 947 | s = callchain_list__sym_name(chain, bf, sizeof(bf), browser->show_dso); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 948 | printed += fprintf(fp, "%*s%c %s\n", offset, " ", folded_sign, s); |
| 949 | } |
| 950 | |
| 951 | if (folded_sign == '-') |
| 952 | printed += hist_browser__fprintf_callchain_node_rb_tree(browser, node, |
| 953 | browser->hists->stats.total_period, |
| 954 | level + 1, fp); |
| 955 | return printed; |
| 956 | } |
| 957 | |
| 958 | static int hist_browser__fprintf_callchain(struct hist_browser *browser, |
| 959 | struct rb_root *chain, int level, FILE *fp) |
| 960 | { |
| 961 | struct rb_node *nd; |
| 962 | int printed = 0; |
| 963 | |
| 964 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 965 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 966 | |
| 967 | printed += hist_browser__fprintf_callchain_node(browser, node, level, fp); |
| 968 | } |
| 969 | |
| 970 | return printed; |
| 971 | } |
| 972 | |
| 973 | static int hist_browser__fprintf_entry(struct hist_browser *browser, |
| 974 | struct hist_entry *he, FILE *fp) |
| 975 | { |
| 976 | char s[8192]; |
| 977 | double percent; |
| 978 | int printed = 0; |
| 979 | char folded_sign = ' '; |
| 980 | |
| 981 | if (symbol_conf.use_callchain) |
| 982 | folded_sign = hist_entry__folded(he); |
| 983 | |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 984 | hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 985 | percent = (he->period * 100.0) / browser->hists->stats.total_period; |
| 986 | |
| 987 | if (symbol_conf.use_callchain) |
| 988 | printed += fprintf(fp, "%c ", folded_sign); |
| 989 | |
| 990 | printed += fprintf(fp, " %5.2f%%", percent); |
| 991 | |
| 992 | if (symbol_conf.show_nr_samples) |
| 993 | printed += fprintf(fp, " %11u", he->nr_events); |
| 994 | |
| 995 | if (symbol_conf.show_total_period) |
| 996 | printed += fprintf(fp, " %12" PRIu64, he->period); |
| 997 | |
| 998 | printed += fprintf(fp, "%s\n", rtrim(s)); |
| 999 | |
| 1000 | if (folded_sign == '-') |
| 1001 | printed += hist_browser__fprintf_callchain(browser, &he->sorted_chain, 1, fp); |
| 1002 | |
| 1003 | return printed; |
| 1004 | } |
| 1005 | |
| 1006 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) |
| 1007 | { |
| 1008 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries)); |
| 1009 | int printed = 0; |
| 1010 | |
| 1011 | while (nd) { |
| 1012 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1013 | |
| 1014 | printed += hist_browser__fprintf_entry(browser, h, fp); |
| 1015 | nd = hists__filter_entries(rb_next(nd)); |
| 1016 | } |
| 1017 | |
| 1018 | return printed; |
| 1019 | } |
| 1020 | |
| 1021 | static int hist_browser__dump(struct hist_browser *browser) |
| 1022 | { |
| 1023 | char filename[64]; |
| 1024 | FILE *fp; |
| 1025 | |
| 1026 | while (1) { |
| 1027 | scnprintf(filename, sizeof(filename), "perf.hist.%d", browser->print_seq); |
| 1028 | if (access(filename, F_OK)) |
| 1029 | break; |
| 1030 | /* |
| 1031 | * XXX: Just an arbitrary lazy upper limit |
| 1032 | */ |
| 1033 | if (++browser->print_seq == 8192) { |
| 1034 | ui_helpline__fpush("Too many perf.hist.N files, nothing written!"); |
| 1035 | return -1; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | fp = fopen(filename, "w"); |
| 1040 | if (fp == NULL) { |
| 1041 | char bf[64]; |
Kirill A. Shutemov | 4cc49d4 | 2012-07-24 00:06:54 +0300 | [diff] [blame] | 1042 | const char *err = strerror_r(errno, bf, sizeof(bf)); |
| 1043 | 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] | 1044 | return -1; |
| 1045 | } |
| 1046 | |
| 1047 | ++browser->print_seq; |
| 1048 | hist_browser__fprintf(browser, fp); |
| 1049 | fclose(fp); |
| 1050 | ui_helpline__fpush("%s written!", filename); |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1055 | static struct hist_browser *hist_browser__new(struct hists *hists) |
| 1056 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1057 | struct hist_browser *browser = zalloc(sizeof(*browser)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1058 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1059 | if (browser) { |
| 1060 | browser->hists = hists; |
| 1061 | browser->b.refresh = hist_browser__refresh; |
| 1062 | browser->b.seek = ui_browser__hists_seek; |
| 1063 | browser->b.use_navkeypressed = true; |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1064 | if (sort__branch_mode == 1) |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1065 | browser->has_symbols = sort_sym_from.list.next != NULL; |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1066 | else |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1067 | browser->has_symbols = sort_sym.list.next != NULL; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1068 | } |
| 1069 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1070 | return browser; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1071 | } |
| 1072 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1073 | static void hist_browser__delete(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1074 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1075 | free(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1076 | } |
| 1077 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1078 | 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] | 1079 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1080 | return browser->he_selection; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1081 | } |
| 1082 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1083 | 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] | 1084 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1085 | return browser->he_selection->thread; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1086 | } |
| 1087 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1088 | static int hists__browser_title(struct hists *hists, char *bf, size_t size, |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1089 | const char *ev_name) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1090 | { |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1091 | char unit; |
| 1092 | int printed; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1093 | const struct dso *dso = hists->dso_filter; |
| 1094 | const struct thread *thread = hists->thread_filter; |
| 1095 | unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 1096 | u64 nr_events = hists->stats.total_period; |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1097 | |
Ashay Rane | cc68628 | 2012-04-05 21:01:01 -0500 | [diff] [blame] | 1098 | nr_samples = convert_unit(nr_samples, &unit); |
| 1099 | printed = scnprintf(bf, size, |
| 1100 | "Samples: %lu%c of event '%s', Event count (approx.): %lu", |
| 1101 | nr_samples, unit, ev_name, nr_events); |
| 1102 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1103 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1104 | if (hists->uid_filter_str) |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 1105 | printed += snprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1106 | ", UID: %s", hists->uid_filter_str); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1107 | if (thread) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1108 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1109 | ", Thread: %s(%d)", |
| 1110 | (thread->comm_set ? thread->comm : ""), |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1111 | thread->pid); |
| 1112 | if (dso) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1113 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 1114 | ", DSO: %s", dso->short_name); |
| 1115 | return printed; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1116 | } |
| 1117 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1118 | static inline void free_popup_options(char **options, int n) |
| 1119 | { |
| 1120 | int i; |
| 1121 | |
| 1122 | for (i = 0; i < n; ++i) { |
| 1123 | free(options[i]); |
| 1124 | options[i] = NULL; |
| 1125 | } |
| 1126 | } |
| 1127 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1128 | static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1129 | const char *helpline, const char *ev_name, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1130 | bool left_exits, |
| 1131 | void(*timer)(void *arg), void *arg, |
| 1132 | int delay_secs) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1133 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1134 | struct hists *hists = &evsel->hists; |
| 1135 | struct hist_browser *browser = hist_browser__new(hists); |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1136 | struct branch_info *bi; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1137 | struct pstack *fstack; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1138 | char *options[16]; |
| 1139 | int nr_options = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1140 | int key = -1; |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1141 | char buf[64]; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1142 | |
| 1143 | if (browser == NULL) |
| 1144 | return -1; |
| 1145 | |
| 1146 | fstack = pstack__new(2); |
| 1147 | if (fstack == NULL) |
| 1148 | goto out; |
| 1149 | |
| 1150 | ui_helpline__push(helpline); |
| 1151 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1152 | memset(options, 0, sizeof(options)); |
| 1153 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1154 | while (1) { |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1155 | const struct thread *thread = NULL; |
| 1156 | const struct dso *dso = NULL; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1157 | int choice = 0, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1158 | annotate = -2, zoom_dso = -2, zoom_thread = -2, |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1159 | annotate_f = -2, annotate_t = -2, browse_map = -2; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1160 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1161 | nr_options = 0; |
| 1162 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1163 | key = hist_browser__run(browser, ev_name, timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1164 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1165 | if (browser->he_selection != NULL) { |
| 1166 | thread = hist_browser__selected_thread(browser); |
| 1167 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
| 1168 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1169 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1170 | case K_TAB: |
| 1171 | case K_UNTAB: |
David Ahern | e4419b8 | 2011-10-19 11:37:47 -0600 | [diff] [blame] | 1172 | if (nr_events == 1) |
| 1173 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1174 | /* |
| 1175 | * Exit the browser, let hists__browser_tree |
| 1176 | * go to the next or previous |
| 1177 | */ |
| 1178 | goto out_free_stack; |
| 1179 | case 'a': |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 1180 | if (!browser->has_symbols) { |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1181 | ui_browser__warning(&browser->b, delay_secs * 2, |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 1182 | "Annotation is only available for symbolic views, " |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1183 | "include \"sym*\" in --sort to use it."); |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 1184 | continue; |
| 1185 | } |
| 1186 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1187 | if (browser->selection == NULL || |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 1188 | browser->selection->sym == NULL || |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1189 | browser->selection->map->dso->annotate_warned) |
| 1190 | continue; |
| 1191 | goto do_annotate; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1192 | case 'P': |
| 1193 | hist_browser__dump(browser); |
| 1194 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1195 | case 'd': |
| 1196 | goto zoom_dso; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 1197 | case 'V': |
| 1198 | browser->show_dso = !browser->show_dso; |
| 1199 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1200 | case 't': |
| 1201 | goto zoom_thread; |
Arnaldo Carvalho de Melo | 5a5626b | 2012-05-09 12:21:22 -0300 | [diff] [blame] | 1202 | case '/': |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1203 | if (ui_browser__input_window("Symbol to show", |
| 1204 | "Please enter the name of symbol you want to see", |
| 1205 | buf, "ENTER: OK, ESC: Cancel", |
| 1206 | delay_secs * 2) == K_ENTER) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1207 | hists->symbol_filter_str = *buf ? buf : NULL; |
| 1208 | hists__filter_by_symbol(hists); |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1209 | hist_browser__reset(browser); |
| 1210 | } |
| 1211 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1212 | case K_F1: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1213 | case 'h': |
| 1214 | case '?': |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1215 | ui_browser__help_window(&browser->b, |
| 1216 | "h/?/F1 Show this window\n" |
Arnaldo Carvalho de Melo | 2d5646c | 2011-10-18 13:02:52 -0200 | [diff] [blame] | 1217 | "UP/DOWN/PGUP\n" |
| 1218 | "PGDN/SPACE Navigate\n" |
| 1219 | "q/ESC/CTRL+C Exit browser\n\n" |
| 1220 | "For multiple event sessions:\n\n" |
| 1221 | "TAB/UNTAB Switch events\n\n" |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 1222 | "For symbolic views (--sort has sym):\n\n" |
Arnaldo Carvalho de Melo | 2d5646c | 2011-10-18 13:02:52 -0200 | [diff] [blame] | 1223 | "-> Zoom into DSO/Threads & Annotate current symbol\n" |
| 1224 | "<- Zoom out\n" |
| 1225 | "a Annotate current symbol\n" |
| 1226 | "C Collapse all callchains\n" |
| 1227 | "E Expand all callchains\n" |
| 1228 | "d Zoom into current DSO\n" |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 1229 | "t Zoom into current Thread\n" |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1230 | "P Print histograms to perf.hist.N\n" |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 1231 | "V Verbose (DSO names in callchains, etc)\n" |
Arnaldo Carvalho de Melo | 5a5626b | 2012-05-09 12:21:22 -0300 | [diff] [blame] | 1232 | "/ Filter symbol by name"); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1233 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1234 | case K_ENTER: |
| 1235 | case K_RIGHT: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1236 | /* menu */ |
| 1237 | break; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1238 | case K_LEFT: { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1239 | const void *top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1240 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1241 | if (pstack__empty(fstack)) { |
| 1242 | /* |
| 1243 | * Go back to the perf_evsel_menu__run or other user |
| 1244 | */ |
| 1245 | if (left_exits) |
| 1246 | goto out_free_stack; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1247 | continue; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1248 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1249 | top = pstack__pop(fstack); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1250 | if (top == &browser->hists->dso_filter) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1251 | goto zoom_out_dso; |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1252 | if (top == &browser->hists->thread_filter) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1253 | goto zoom_out_thread; |
| 1254 | continue; |
| 1255 | } |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1256 | case K_ESC: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1257 | if (!left_exits && |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1258 | !ui_browser__dialog_yesno(&browser->b, |
| 1259 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1260 | continue; |
| 1261 | /* Fall thru */ |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1262 | case 'q': |
| 1263 | case CTRL('c'): |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1264 | goto out_free_stack; |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1265 | default: |
| 1266 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1267 | } |
| 1268 | |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 1269 | if (!browser->has_symbols) |
| 1270 | goto add_exit_option; |
| 1271 | |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1272 | if (sort__branch_mode == 1) { |
| 1273 | bi = browser->he_selection->branch_info; |
| 1274 | if (browser->selection != NULL && |
| 1275 | bi && |
| 1276 | bi->from.sym != NULL && |
| 1277 | !bi->from.map->dso->annotate_warned && |
| 1278 | asprintf(&options[nr_options], "Annotate %s", |
| 1279 | bi->from.sym->name) > 0) |
| 1280 | annotate_f = nr_options++; |
| 1281 | |
| 1282 | if (browser->selection != NULL && |
| 1283 | bi && |
| 1284 | bi->to.sym != NULL && |
| 1285 | !bi->to.map->dso->annotate_warned && |
Stephane Eranian | 8bcd65f | 2012-03-12 16:13:29 +0100 | [diff] [blame] | 1286 | (bi->to.sym != bi->from.sym || |
| 1287 | bi->to.map->dso != bi->from.map->dso) && |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1288 | asprintf(&options[nr_options], "Annotate %s", |
| 1289 | bi->to.sym->name) > 0) |
| 1290 | annotate_t = nr_options++; |
| 1291 | } else { |
| 1292 | |
| 1293 | if (browser->selection != NULL && |
| 1294 | browser->selection->sym != NULL && |
| 1295 | !browser->selection->map->dso->annotate_warned && |
| 1296 | asprintf(&options[nr_options], "Annotate %s", |
| 1297 | browser->selection->sym->name) > 0) |
| 1298 | annotate = nr_options++; |
| 1299 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1300 | |
| 1301 | if (thread != NULL && |
| 1302 | asprintf(&options[nr_options], "Zoom %s %s(%d) thread", |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1303 | (browser->hists->thread_filter ? "out of" : "into"), |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1304 | (thread->comm_set ? thread->comm : ""), |
| 1305 | thread->pid) > 0) |
| 1306 | zoom_thread = nr_options++; |
| 1307 | |
| 1308 | if (dso != NULL && |
| 1309 | asprintf(&options[nr_options], "Zoom %s %s DSO", |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1310 | (browser->hists->dso_filter ? "out of" : "into"), |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1311 | (dso->kernel ? "the Kernel" : dso->short_name)) > 0) |
| 1312 | zoom_dso = nr_options++; |
| 1313 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1314 | if (browser->selection != NULL && |
| 1315 | browser->selection->map != NULL && |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1316 | asprintf(&options[nr_options], "Browse map details") > 0) |
| 1317 | browse_map = nr_options++; |
Arnaldo Carvalho de Melo | 724c9c9 | 2011-10-06 10:36:35 -0300 | [diff] [blame] | 1318 | add_exit_option: |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1319 | options[nr_options++] = (char *)"Exit"; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1320 | retry_popup_menu: |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 1321 | choice = ui__popup_menu(nr_options, options); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1322 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1323 | if (choice == nr_options - 1) |
| 1324 | break; |
| 1325 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1326 | if (choice == -1) { |
| 1327 | free_popup_options(options, nr_options - 1); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1328 | continue; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1329 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1330 | |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1331 | if (choice == annotate || choice == annotate_t || choice == annotate_f) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1332 | struct hist_entry *he; |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1333 | int err; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1334 | do_annotate: |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1335 | he = hist_browser__selected_entry(browser); |
| 1336 | if (he == NULL) |
| 1337 | continue; |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 1338 | |
| 1339 | /* |
| 1340 | * we stash the branch_info symbol + map into the |
| 1341 | * the ms so we don't have to rewrite all the annotation |
| 1342 | * code to use branch_info. |
| 1343 | * in branch mode, the ms struct is not used |
| 1344 | */ |
| 1345 | if (choice == annotate_f) { |
| 1346 | he->ms.sym = he->branch_info->from.sym; |
| 1347 | he->ms.map = he->branch_info->from.map; |
| 1348 | } else if (choice == annotate_t) { |
| 1349 | he->ms.sym = he->branch_info->to.sym; |
| 1350 | he->ms.map = he->branch_info->to.map; |
| 1351 | } |
| 1352 | |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 1353 | /* |
| 1354 | * Don't let this be freed, say, by hists__decay_entry. |
| 1355 | */ |
| 1356 | he->used = true; |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 1357 | err = hist_entry__tui_annotate(he, evsel->idx, |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1358 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 1359 | he->used = false; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1360 | /* |
| 1361 | * offer option to annotate the other branch source or target |
| 1362 | * (if they exists) when returning from annotate |
| 1363 | */ |
| 1364 | if ((err == 'q' || err == CTRL('c')) |
| 1365 | && annotate_t != -2 && annotate_f != -2) |
| 1366 | goto retry_popup_menu; |
| 1367 | |
Arnaldo Carvalho de Melo | 900e14a | 2011-10-11 16:15:39 -0300 | [diff] [blame] | 1368 | 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] | 1369 | if (err) |
| 1370 | ui_browser__handle_resize(&browser->b); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1371 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1372 | } else if (choice == browse_map) |
| 1373 | map__browse(browser->selection->map); |
| 1374 | else if (choice == zoom_dso) { |
| 1375 | zoom_dso: |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1376 | if (browser->hists->dso_filter) { |
| 1377 | pstack__remove(fstack, &browser->hists->dso_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1378 | zoom_out_dso: |
| 1379 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1380 | browser->hists->dso_filter = NULL; |
Arnaldo Carvalho de Melo | cc02c92 | 2011-10-20 08:02:30 -0200 | [diff] [blame] | 1381 | sort_dso.elide = false; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1382 | } else { |
| 1383 | if (dso == NULL) |
| 1384 | continue; |
| 1385 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", |
| 1386 | dso->kernel ? "the Kernel" : dso->short_name); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1387 | browser->hists->dso_filter = dso; |
Arnaldo Carvalho de Melo | cc02c92 | 2011-10-20 08:02:30 -0200 | [diff] [blame] | 1388 | sort_dso.elide = true; |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1389 | pstack__push(fstack, &browser->hists->dso_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1390 | } |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1391 | hists__filter_by_dso(hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1392 | hist_browser__reset(browser); |
| 1393 | } else if (choice == zoom_thread) { |
| 1394 | zoom_thread: |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1395 | if (browser->hists->thread_filter) { |
| 1396 | pstack__remove(fstack, &browser->hists->thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1397 | zoom_out_thread: |
| 1398 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1399 | browser->hists->thread_filter = NULL; |
Arnaldo Carvalho de Melo | cc02c92 | 2011-10-20 08:02:30 -0200 | [diff] [blame] | 1400 | sort_thread.elide = false; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1401 | } else { |
| 1402 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", |
| 1403 | thread->comm_set ? thread->comm : "", |
| 1404 | thread->pid); |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1405 | browser->hists->thread_filter = thread; |
Arnaldo Carvalho de Melo | cc02c92 | 2011-10-20 08:02:30 -0200 | [diff] [blame] | 1406 | sort_thread.elide = true; |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1407 | pstack__push(fstack, &browser->hists->thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1408 | } |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1409 | hists__filter_by_thread(hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1410 | hist_browser__reset(browser); |
| 1411 | } |
| 1412 | } |
| 1413 | out_free_stack: |
| 1414 | pstack__delete(fstack); |
| 1415 | out: |
| 1416 | hist_browser__delete(browser); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 1417 | free_popup_options(options, nr_options - 1); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1418 | return key; |
| 1419 | } |
| 1420 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1421 | struct perf_evsel_menu { |
| 1422 | struct ui_browser b; |
| 1423 | struct perf_evsel *selection; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1424 | bool lost_events, lost_events_warned; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1425 | }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1426 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1427 | static void perf_evsel_menu__write(struct ui_browser *browser, |
| 1428 | void *entry, int row) |
| 1429 | { |
| 1430 | struct perf_evsel_menu *menu = container_of(browser, |
| 1431 | struct perf_evsel_menu, b); |
| 1432 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); |
| 1433 | bool current_entry = ui_browser__is_current_entry(browser, row); |
| 1434 | unsigned long nr_events = evsel->hists.stats.nr_events[PERF_RECORD_SAMPLE]; |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1435 | const char *ev_name = perf_evsel__name(evsel); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1436 | char bf[256], unit; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1437 | const char *warn = " "; |
| 1438 | size_t printed; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1439 | |
| 1440 | ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : |
| 1441 | HE_COLORSET_NORMAL); |
| 1442 | |
| 1443 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1444 | 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] | 1445 | unit, unit == ' ' ? "" : " ", ev_name); |
| 1446 | slsmg_printf("%s", bf); |
| 1447 | |
| 1448 | nr_events = evsel->hists.stats.nr_events[PERF_RECORD_LOST]; |
| 1449 | if (nr_events != 0) { |
| 1450 | menu->lost_events = true; |
| 1451 | if (!current_entry) |
| 1452 | ui_browser__set_color(browser, HE_COLORSET_TOP); |
| 1453 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 1454 | printed += scnprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!", |
| 1455 | nr_events, unit, unit == ' ' ? "" : " "); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1456 | warn = bf; |
| 1457 | } |
| 1458 | |
| 1459 | slsmg_write_nstring(warn, browser->width - printed); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1460 | |
| 1461 | if (current_entry) |
| 1462 | menu->selection = evsel; |
| 1463 | } |
| 1464 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1465 | static int perf_evsel_menu__run(struct perf_evsel_menu *menu, |
| 1466 | int nr_events, const char *help, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1467 | void(*timer)(void *arg), void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1468 | { |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1469 | struct perf_evlist *evlist = menu->b.priv; |
| 1470 | struct perf_evsel *pos; |
| 1471 | const char *ev_name, *title = "Available samples"; |
| 1472 | int key; |
| 1473 | |
| 1474 | if (ui_browser__show(&menu->b, title, |
| 1475 | "ESC: exit, ENTER|->: Browse histograms") < 0) |
| 1476 | return -1; |
| 1477 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1478 | while (1) { |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 1479 | key = ui_browser__run(&menu->b, delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1480 | |
| 1481 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1482 | case K_TIMER: |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1483 | timer(arg); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1484 | |
| 1485 | if (!menu->lost_events_warned && menu->lost_events) { |
| 1486 | ui_browser__warn_lost_events(&menu->b); |
| 1487 | menu->lost_events_warned = true; |
| 1488 | } |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1489 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1490 | case K_RIGHT: |
| 1491 | case K_ENTER: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1492 | if (!menu->selection) |
| 1493 | continue; |
| 1494 | pos = menu->selection; |
| 1495 | browse_hists: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1496 | perf_evlist__set_selected(evlist, pos); |
| 1497 | /* |
| 1498 | * Give the calling tool a chance to populate the non |
| 1499 | * default evsel resorted hists tree. |
| 1500 | */ |
| 1501 | if (timer) |
| 1502 | timer(arg); |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1503 | ev_name = perf_evsel__name(pos); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1504 | key = perf_evsel__hists_browse(pos, nr_events, help, |
| 1505 | ev_name, true, timer, |
| 1506 | arg, delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1507 | ui_browser__show_title(&menu->b, title); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1508 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1509 | case K_TAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1510 | if (pos->node.next == &evlist->entries) |
| 1511 | pos = list_entry(evlist->entries.next, struct perf_evsel, node); |
| 1512 | else |
| 1513 | pos = list_entry(pos->node.next, struct perf_evsel, node); |
| 1514 | goto browse_hists; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1515 | case K_UNTAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1516 | if (pos->node.prev == &evlist->entries) |
| 1517 | pos = list_entry(evlist->entries.prev, struct perf_evsel, node); |
| 1518 | else |
| 1519 | pos = list_entry(pos->node.prev, struct perf_evsel, node); |
| 1520 | goto browse_hists; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1521 | case K_ESC: |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1522 | if (!ui_browser__dialog_yesno(&menu->b, |
| 1523 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1524 | continue; |
| 1525 | /* Fall thru */ |
| 1526 | case 'q': |
| 1527 | case CTRL('c'): |
| 1528 | goto out; |
| 1529 | default: |
| 1530 | continue; |
| 1531 | } |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1532 | case K_LEFT: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1533 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 1534 | case K_ESC: |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 1535 | if (!ui_browser__dialog_yesno(&menu->b, |
| 1536 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 1537 | continue; |
| 1538 | /* Fall thru */ |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1539 | case 'q': |
| 1540 | case CTRL('c'): |
| 1541 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1542 | default: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 1543 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1547 | out: |
| 1548 | ui_browser__hide(&menu->b); |
| 1549 | return key; |
| 1550 | } |
| 1551 | |
| 1552 | static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1553 | const char *help, |
| 1554 | void(*timer)(void *arg), void *arg, |
| 1555 | int delay_secs) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1556 | { |
| 1557 | struct perf_evsel *pos; |
| 1558 | struct perf_evsel_menu menu = { |
| 1559 | .b = { |
| 1560 | .entries = &evlist->entries, |
| 1561 | .refresh = ui_browser__list_head_refresh, |
| 1562 | .seek = ui_browser__list_head_seek, |
| 1563 | .write = perf_evsel_menu__write, |
| 1564 | .nr_entries = evlist->nr_entries, |
| 1565 | .priv = evlist, |
| 1566 | }, |
| 1567 | }; |
| 1568 | |
| 1569 | ui_helpline__push("Press ESC to exit"); |
| 1570 | |
| 1571 | list_for_each_entry(pos, &evlist->entries, node) { |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1572 | const char *ev_name = perf_evsel__name(pos); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1573 | size_t line_len = strlen(ev_name) + 7; |
| 1574 | |
| 1575 | if (menu.b.width < line_len) |
| 1576 | menu.b.width = line_len; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1577 | } |
| 1578 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1579 | return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer, |
| 1580 | arg, delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1581 | } |
| 1582 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1583 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, |
| 1584 | void(*timer)(void *arg), void *arg, |
| 1585 | int delay_secs) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1586 | { |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1587 | if (evlist->nr_entries == 1) { |
| 1588 | struct perf_evsel *first = list_entry(evlist->entries.next, |
| 1589 | struct perf_evsel, node); |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 1590 | const char *ev_name = perf_evsel__name(first); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 1591 | return perf_evsel__hists_browse(first, evlist->nr_entries, help, |
| 1592 | ev_name, false, timer, arg, |
| 1593 | delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 1594 | } |
| 1595 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 1596 | return __perf_evlist__tui_browse_hists(evlist, help, |
| 1597 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1598 | } |