Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1 | #define _GNU_SOURCE |
| 2 | #include <stdio.h> |
| 3 | #undef _GNU_SOURCE |
| 4 | #include "../libslang.h" |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <newt.h> |
| 8 | #include <linux/rbtree.h> |
| 9 | |
| 10 | #include "../../hist.h" |
| 11 | #include "../../pstack.h" |
| 12 | #include "../../sort.h" |
| 13 | #include "../../util.h" |
| 14 | |
| 15 | #include "../browser.h" |
| 16 | #include "../helpline.h" |
| 17 | #include "../util.h" |
| 18 | #include "map.h" |
| 19 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 20 | struct hist_browser { |
| 21 | struct ui_browser b; |
| 22 | struct hists *hists; |
| 23 | struct hist_entry *he_selection; |
| 24 | struct map_symbol *selection; |
| 25 | }; |
| 26 | |
| 27 | static void hist_browser__refresh_dimensions(struct hist_browser *self) |
| 28 | { |
| 29 | /* 3 == +/- toggle symbol before actual hist_entry rendering */ |
| 30 | self->b.width = 3 + (hists__sort_list_width(self->hists) + |
| 31 | sizeof("[k]")); |
| 32 | } |
| 33 | |
| 34 | static void hist_browser__reset(struct hist_browser *self) |
| 35 | { |
| 36 | self->b.nr_entries = self->hists->nr_entries; |
| 37 | hist_browser__refresh_dimensions(self); |
| 38 | ui_browser__reset_index(&self->b); |
| 39 | } |
| 40 | |
| 41 | static char tree__folded_sign(bool unfolded) |
| 42 | { |
| 43 | return unfolded ? '-' : '+'; |
| 44 | } |
| 45 | |
| 46 | static char map_symbol__folded(const struct map_symbol *self) |
| 47 | { |
| 48 | return self->has_children ? tree__folded_sign(self->unfolded) : ' '; |
| 49 | } |
| 50 | |
| 51 | static char hist_entry__folded(const struct hist_entry *self) |
| 52 | { |
| 53 | return map_symbol__folded(&self->ms); |
| 54 | } |
| 55 | |
| 56 | static char callchain_list__folded(const struct callchain_list *self) |
| 57 | { |
| 58 | return map_symbol__folded(&self->ms); |
| 59 | } |
| 60 | |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 61 | static void map_symbol__set_folding(struct map_symbol *self, bool unfold) |
| 62 | { |
| 63 | self->unfolded = unfold ? self->has_children : false; |
| 64 | } |
| 65 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 66 | static int callchain_node__count_rows_rb_tree(struct callchain_node *self) |
| 67 | { |
| 68 | int n = 0; |
| 69 | struct rb_node *nd; |
| 70 | |
| 71 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { |
| 72 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 73 | struct callchain_list *chain; |
| 74 | char folded_sign = ' '; /* No children */ |
| 75 | |
| 76 | list_for_each_entry(chain, &child->val, list) { |
| 77 | ++n; |
| 78 | /* We need this because we may not have children */ |
| 79 | folded_sign = callchain_list__folded(chain); |
| 80 | if (folded_sign == '+') |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | if (folded_sign == '-') /* Have children and they're unfolded */ |
| 85 | n += callchain_node__count_rows_rb_tree(child); |
| 86 | } |
| 87 | |
| 88 | return n; |
| 89 | } |
| 90 | |
| 91 | static int callchain_node__count_rows(struct callchain_node *node) |
| 92 | { |
| 93 | struct callchain_list *chain; |
| 94 | bool unfolded = false; |
| 95 | int n = 0; |
| 96 | |
| 97 | list_for_each_entry(chain, &node->val, list) { |
| 98 | ++n; |
| 99 | unfolded = chain->ms.unfolded; |
| 100 | } |
| 101 | |
| 102 | if (unfolded) |
| 103 | n += callchain_node__count_rows_rb_tree(node); |
| 104 | |
| 105 | return n; |
| 106 | } |
| 107 | |
| 108 | static int callchain__count_rows(struct rb_root *chain) |
| 109 | { |
| 110 | struct rb_node *nd; |
| 111 | int n = 0; |
| 112 | |
| 113 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 114 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 115 | n += callchain_node__count_rows(node); |
| 116 | } |
| 117 | |
| 118 | return n; |
| 119 | } |
| 120 | |
| 121 | static bool map_symbol__toggle_fold(struct map_symbol *self) |
| 122 | { |
| 123 | if (!self->has_children) |
| 124 | return false; |
| 125 | |
| 126 | self->unfolded = !self->unfolded; |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | static void callchain_node__init_have_children_rb_tree(struct callchain_node *self) |
| 131 | { |
| 132 | struct rb_node *nd = rb_first(&self->rb_root); |
| 133 | |
| 134 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { |
| 135 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 136 | struct callchain_list *chain; |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 137 | bool first = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 138 | |
| 139 | list_for_each_entry(chain, &child->val, list) { |
| 140 | if (first) { |
| 141 | first = false; |
| 142 | chain->ms.has_children = chain->list.next != &child->val || |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 143 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 144 | } else |
| 145 | chain->ms.has_children = chain->list.next == &child->val && |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 146 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | callchain_node__init_have_children_rb_tree(child); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | static void callchain_node__init_have_children(struct callchain_node *self) |
| 154 | { |
| 155 | struct callchain_list *chain; |
| 156 | |
| 157 | list_for_each_entry(chain, &self->val, list) |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 158 | chain->ms.has_children = !RB_EMPTY_ROOT(&self->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 159 | |
| 160 | callchain_node__init_have_children_rb_tree(self); |
| 161 | } |
| 162 | |
| 163 | static void callchain__init_have_children(struct rb_root *self) |
| 164 | { |
| 165 | struct rb_node *nd; |
| 166 | |
| 167 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
| 168 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 169 | callchain_node__init_have_children(node); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static void hist_entry__init_have_children(struct hist_entry *self) |
| 174 | { |
| 175 | if (!self->init_have_children) { |
Arnaldo Carvalho de Melo | 18b308d | 2010-08-25 12:47:44 -0300 | [diff] [blame] | 176 | self->ms.has_children = !RB_EMPTY_ROOT(&self->sorted_chain); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 177 | callchain__init_have_children(&self->sorted_chain); |
| 178 | self->init_have_children = true; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static bool hist_browser__toggle_fold(struct hist_browser *self) |
| 183 | { |
| 184 | if (map_symbol__toggle_fold(self->selection)) { |
| 185 | struct hist_entry *he = self->he_selection; |
| 186 | |
| 187 | hist_entry__init_have_children(he); |
| 188 | self->hists->nr_entries -= he->nr_rows; |
| 189 | |
| 190 | if (he->ms.unfolded) |
| 191 | he->nr_rows = callchain__count_rows(&he->sorted_chain); |
| 192 | else |
| 193 | he->nr_rows = 0; |
| 194 | self->hists->nr_entries += he->nr_rows; |
| 195 | self->b.nr_entries = self->hists->nr_entries; |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | /* If it doesn't have children, no toggling performed */ |
| 201 | return false; |
| 202 | } |
| 203 | |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 204 | static int callchain_node__set_folding_rb_tree(struct callchain_node *self, bool unfold) |
| 205 | { |
| 206 | int n = 0; |
| 207 | struct rb_node *nd; |
| 208 | |
| 209 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { |
| 210 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 211 | struct callchain_list *chain; |
| 212 | bool has_children = false; |
| 213 | |
| 214 | list_for_each_entry(chain, &child->val, list) { |
| 215 | ++n; |
| 216 | map_symbol__set_folding(&chain->ms, unfold); |
| 217 | has_children = chain->ms.has_children; |
| 218 | } |
| 219 | |
| 220 | if (has_children) |
| 221 | n += callchain_node__set_folding_rb_tree(child, unfold); |
| 222 | } |
| 223 | |
| 224 | return n; |
| 225 | } |
| 226 | |
| 227 | static int callchain_node__set_folding(struct callchain_node *node, bool unfold) |
| 228 | { |
| 229 | struct callchain_list *chain; |
| 230 | bool has_children = false; |
| 231 | int n = 0; |
| 232 | |
| 233 | list_for_each_entry(chain, &node->val, list) { |
| 234 | ++n; |
| 235 | map_symbol__set_folding(&chain->ms, unfold); |
| 236 | has_children = chain->ms.has_children; |
| 237 | } |
| 238 | |
| 239 | if (has_children) |
| 240 | n += callchain_node__set_folding_rb_tree(node, unfold); |
| 241 | |
| 242 | return n; |
| 243 | } |
| 244 | |
| 245 | static int callchain__set_folding(struct rb_root *chain, bool unfold) |
| 246 | { |
| 247 | struct rb_node *nd; |
| 248 | int n = 0; |
| 249 | |
| 250 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 251 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 252 | n += callchain_node__set_folding(node, unfold); |
| 253 | } |
| 254 | |
| 255 | return n; |
| 256 | } |
| 257 | |
| 258 | static void hist_entry__set_folding(struct hist_entry *self, bool unfold) |
| 259 | { |
| 260 | hist_entry__init_have_children(self); |
| 261 | map_symbol__set_folding(&self->ms, unfold); |
| 262 | |
| 263 | if (self->ms.has_children) { |
| 264 | int n = callchain__set_folding(&self->sorted_chain, unfold); |
| 265 | self->nr_rows = unfold ? n : 0; |
| 266 | } else |
| 267 | self->nr_rows = 0; |
| 268 | } |
| 269 | |
| 270 | static void hists__set_folding(struct hists *self, bool unfold) |
| 271 | { |
| 272 | struct rb_node *nd; |
| 273 | |
| 274 | self->nr_entries = 0; |
| 275 | |
| 276 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
| 277 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 278 | hist_entry__set_folding(he, unfold); |
| 279 | self->nr_entries += 1 + he->nr_rows; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static void hist_browser__set_folding(struct hist_browser *self, bool unfold) |
| 284 | { |
| 285 | hists__set_folding(self->hists, unfold); |
| 286 | self->b.nr_entries = self->hists->nr_entries; |
| 287 | /* Go to the start, we may be way after valid entries after a collapse */ |
| 288 | ui_browser__reset_index(&self->b); |
| 289 | } |
| 290 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 291 | static int hist_browser__run(struct hist_browser *self, const char *title) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 292 | { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 293 | int key; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 294 | int exit_keys[] = { 'a', '?', 'h', 'C', 'd', 'D', 'E', 't', |
| 295 | NEWT_KEY_ENTER, NEWT_KEY_RIGHT, NEWT_KEY_LEFT, 0, }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 296 | |
| 297 | self->b.entries = &self->hists->entries; |
| 298 | self->b.nr_entries = self->hists->nr_entries; |
| 299 | |
| 300 | hist_browser__refresh_dimensions(self); |
| 301 | |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 302 | if (ui_browser__show(&self->b, title, |
| 303 | "Press '?' for help on key bindings") < 0) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 304 | return -1; |
| 305 | |
Arnaldo Carvalho de Melo | 4c1c952 | 2010-08-12 12:37:51 -0300 | [diff] [blame] | 306 | ui_browser__add_exit_keys(&self->b, exit_keys); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 307 | |
| 308 | while (1) { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 309 | key = ui_browser__run(&self->b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 310 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 311 | switch (key) { |
Arnaldo Carvalho de Melo | 4694153 | 2010-08-10 15:50:07 -0300 | [diff] [blame] | 312 | case 'D': { /* Debug */ |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 313 | static int seq; |
| 314 | struct hist_entry *h = rb_entry(self->b.top, |
| 315 | struct hist_entry, rb_node); |
| 316 | ui_helpline__pop(); |
| 317 | ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d", |
| 318 | seq++, self->b.nr_entries, |
| 319 | self->hists->nr_entries, |
| 320 | self->b.height, |
| 321 | self->b.index, |
| 322 | self->b.top_idx, |
| 323 | h->row_offset, h->nr_rows); |
| 324 | } |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 325 | break; |
| 326 | case 'C': |
| 327 | /* Collapse the whole world. */ |
| 328 | hist_browser__set_folding(self, false); |
| 329 | break; |
| 330 | case 'E': |
| 331 | /* Expand the whole world. */ |
| 332 | hist_browser__set_folding(self, true); |
| 333 | break; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 334 | case NEWT_KEY_ENTER: |
| 335 | if (hist_browser__toggle_fold(self)) |
| 336 | break; |
| 337 | /* fall thru */ |
| 338 | default: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 339 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 340 | } |
| 341 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 342 | out: |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 343 | ui_browser__hide(&self->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 344 | return key; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static char *callchain_list__sym_name(struct callchain_list *self, |
| 348 | char *bf, size_t bfsize) |
| 349 | { |
| 350 | if (self->ms.sym) |
| 351 | return self->ms.sym->name; |
| 352 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 353 | snprintf(bf, bfsize, "%#" PRIx64, self->ip); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 354 | return bf; |
| 355 | } |
| 356 | |
| 357 | #define LEVEL_OFFSET_STEP 3 |
| 358 | |
| 359 | static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self, |
| 360 | struct callchain_node *chain_node, |
| 361 | u64 total, int level, |
| 362 | unsigned short row, |
| 363 | off_t *row_offset, |
| 364 | bool *is_current_entry) |
| 365 | { |
| 366 | struct rb_node *node; |
| 367 | int first_row = row, width, offset = level * LEVEL_OFFSET_STEP; |
| 368 | u64 new_total, remaining; |
| 369 | |
| 370 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 371 | new_total = chain_node->children_hit; |
| 372 | else |
| 373 | new_total = total; |
| 374 | |
| 375 | remaining = new_total; |
| 376 | node = rb_first(&chain_node->rb_root); |
| 377 | while (node) { |
| 378 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 379 | struct rb_node *next = rb_next(node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 380 | u64 cumul = callchain_cumul_hits(child); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 381 | struct callchain_list *chain; |
| 382 | char folded_sign = ' '; |
| 383 | int first = true; |
| 384 | int extra_offset = 0; |
| 385 | |
| 386 | remaining -= cumul; |
| 387 | |
| 388 | list_for_each_entry(chain, &child->val, list) { |
| 389 | char ipstr[BITS_PER_LONG / 4 + 1], *alloc_str; |
| 390 | const char *str; |
| 391 | int color; |
| 392 | bool was_first = first; |
| 393 | |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 394 | if (first) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 395 | first = false; |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 396 | else |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 397 | extra_offset = LEVEL_OFFSET_STEP; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 398 | |
| 399 | folded_sign = callchain_list__folded(chain); |
| 400 | if (*row_offset != 0) { |
| 401 | --*row_offset; |
| 402 | goto do_next; |
| 403 | } |
| 404 | |
| 405 | alloc_str = NULL; |
| 406 | str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); |
| 407 | if (was_first) { |
| 408 | double percent = cumul * 100.0 / new_total; |
| 409 | |
| 410 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) |
| 411 | str = "Not enough memory!"; |
| 412 | else |
| 413 | str = alloc_str; |
| 414 | } |
| 415 | |
| 416 | color = HE_COLORSET_NORMAL; |
| 417 | width = self->b.width - (offset + extra_offset + 2); |
| 418 | if (ui_browser__is_current_entry(&self->b, row)) { |
| 419 | self->selection = &chain->ms; |
| 420 | color = HE_COLORSET_SELECTED; |
| 421 | *is_current_entry = true; |
| 422 | } |
| 423 | |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 424 | ui_browser__set_color(&self->b, color); |
| 425 | ui_browser__gotorc(&self->b, row, 0); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 426 | slsmg_write_nstring(" ", offset + extra_offset); |
| 427 | slsmg_printf("%c ", folded_sign); |
| 428 | slsmg_write_nstring(str, width); |
| 429 | free(alloc_str); |
| 430 | |
| 431 | if (++row == self->b.height) |
| 432 | goto out; |
| 433 | do_next: |
| 434 | if (folded_sign == '+') |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | if (folded_sign == '-') { |
| 439 | const int new_level = level + (extra_offset ? 2 : 1); |
| 440 | row += hist_browser__show_callchain_node_rb_tree(self, child, new_total, |
| 441 | new_level, row, row_offset, |
| 442 | is_current_entry); |
| 443 | } |
| 444 | if (row == self->b.height) |
| 445 | goto out; |
| 446 | node = next; |
| 447 | } |
| 448 | out: |
| 449 | return row - first_row; |
| 450 | } |
| 451 | |
| 452 | static int hist_browser__show_callchain_node(struct hist_browser *self, |
| 453 | struct callchain_node *node, |
| 454 | int level, unsigned short row, |
| 455 | off_t *row_offset, |
| 456 | bool *is_current_entry) |
| 457 | { |
| 458 | struct callchain_list *chain; |
| 459 | int first_row = row, |
| 460 | offset = level * LEVEL_OFFSET_STEP, |
| 461 | width = self->b.width - offset; |
| 462 | char folded_sign = ' '; |
| 463 | |
| 464 | list_for_each_entry(chain, &node->val, list) { |
| 465 | char ipstr[BITS_PER_LONG / 4 + 1], *s; |
| 466 | int color; |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 467 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 468 | folded_sign = callchain_list__folded(chain); |
| 469 | |
| 470 | if (*row_offset != 0) { |
| 471 | --*row_offset; |
| 472 | continue; |
| 473 | } |
| 474 | |
| 475 | color = HE_COLORSET_NORMAL; |
| 476 | if (ui_browser__is_current_entry(&self->b, row)) { |
| 477 | self->selection = &chain->ms; |
| 478 | color = HE_COLORSET_SELECTED; |
| 479 | *is_current_entry = true; |
| 480 | } |
| 481 | |
| 482 | s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 483 | ui_browser__gotorc(&self->b, row, 0); |
| 484 | ui_browser__set_color(&self->b, color); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 485 | slsmg_write_nstring(" ", offset); |
| 486 | slsmg_printf("%c ", folded_sign); |
| 487 | slsmg_write_nstring(s, width - 2); |
| 488 | |
| 489 | if (++row == self->b.height) |
| 490 | goto out; |
| 491 | } |
| 492 | |
| 493 | if (folded_sign == '-') |
| 494 | row += hist_browser__show_callchain_node_rb_tree(self, node, |
| 495 | self->hists->stats.total_period, |
| 496 | level + 1, row, |
| 497 | row_offset, |
| 498 | is_current_entry); |
| 499 | out: |
| 500 | return row - first_row; |
| 501 | } |
| 502 | |
| 503 | static int hist_browser__show_callchain(struct hist_browser *self, |
| 504 | struct rb_root *chain, |
| 505 | int level, unsigned short row, |
| 506 | off_t *row_offset, |
| 507 | bool *is_current_entry) |
| 508 | { |
| 509 | struct rb_node *nd; |
| 510 | int first_row = row; |
| 511 | |
| 512 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 513 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 514 | |
| 515 | row += hist_browser__show_callchain_node(self, node, level, |
| 516 | row, row_offset, |
| 517 | is_current_entry); |
| 518 | if (row == self->b.height) |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | return row - first_row; |
| 523 | } |
| 524 | |
| 525 | static int hist_browser__show_entry(struct hist_browser *self, |
| 526 | struct hist_entry *entry, |
| 527 | unsigned short row) |
| 528 | { |
| 529 | char s[256]; |
| 530 | double percent; |
| 531 | int printed = 0; |
| 532 | int color, width = self->b.width; |
| 533 | char folded_sign = ' '; |
| 534 | bool current_entry = ui_browser__is_current_entry(&self->b, row); |
| 535 | off_t row_offset = entry->row_offset; |
| 536 | |
| 537 | if (current_entry) { |
| 538 | self->he_selection = entry; |
| 539 | self->selection = &entry->ms; |
| 540 | } |
| 541 | |
| 542 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 543 | hist_entry__init_have_children(entry); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 544 | folded_sign = hist_entry__folded(entry); |
| 545 | } |
| 546 | |
| 547 | if (row_offset == 0) { |
| 548 | hist_entry__snprintf(entry, s, sizeof(s), self->hists, NULL, false, |
| 549 | 0, false, self->hists->stats.total_period); |
| 550 | percent = (entry->period * 100.0) / self->hists->stats.total_period; |
| 551 | |
| 552 | color = HE_COLORSET_SELECTED; |
| 553 | if (!current_entry) { |
| 554 | if (percent >= MIN_RED) |
| 555 | color = HE_COLORSET_TOP; |
| 556 | else if (percent >= MIN_GREEN) |
| 557 | color = HE_COLORSET_MEDIUM; |
| 558 | else |
| 559 | color = HE_COLORSET_NORMAL; |
| 560 | } |
| 561 | |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 562 | ui_browser__set_color(&self->b, color); |
| 563 | ui_browser__gotorc(&self->b, row, 0); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 564 | if (symbol_conf.use_callchain) { |
| 565 | slsmg_printf("%c ", folded_sign); |
| 566 | width -= 2; |
| 567 | } |
| 568 | slsmg_write_nstring(s, width); |
| 569 | ++row; |
| 570 | ++printed; |
| 571 | } else |
| 572 | --row_offset; |
| 573 | |
| 574 | if (folded_sign == '-' && row != self->b.height) { |
| 575 | printed += hist_browser__show_callchain(self, &entry->sorted_chain, |
| 576 | 1, row, &row_offset, |
| 577 | ¤t_entry); |
| 578 | if (current_entry) |
| 579 | self->he_selection = entry; |
| 580 | } |
| 581 | |
| 582 | return printed; |
| 583 | } |
| 584 | |
| 585 | static unsigned int hist_browser__refresh(struct ui_browser *self) |
| 586 | { |
| 587 | unsigned row = 0; |
| 588 | struct rb_node *nd; |
| 589 | struct hist_browser *hb = container_of(self, struct hist_browser, b); |
| 590 | |
| 591 | if (self->top == NULL) |
| 592 | self->top = rb_first(&hb->hists->entries); |
| 593 | |
| 594 | for (nd = self->top; nd; nd = rb_next(nd)) { |
| 595 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 596 | |
| 597 | if (h->filtered) |
| 598 | continue; |
| 599 | |
| 600 | row += hist_browser__show_entry(hb, h, row); |
| 601 | if (row == self->height) |
| 602 | break; |
| 603 | } |
| 604 | |
| 605 | return row; |
| 606 | } |
| 607 | |
| 608 | static struct rb_node *hists__filter_entries(struct rb_node *nd) |
| 609 | { |
| 610 | while (nd != NULL) { |
| 611 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 612 | if (!h->filtered) |
| 613 | return nd; |
| 614 | |
| 615 | nd = rb_next(nd); |
| 616 | } |
| 617 | |
| 618 | return NULL; |
| 619 | } |
| 620 | |
| 621 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd) |
| 622 | { |
| 623 | while (nd != NULL) { |
| 624 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 625 | if (!h->filtered) |
| 626 | return nd; |
| 627 | |
| 628 | nd = rb_prev(nd); |
| 629 | } |
| 630 | |
| 631 | return NULL; |
| 632 | } |
| 633 | |
| 634 | static void ui_browser__hists_seek(struct ui_browser *self, |
| 635 | off_t offset, int whence) |
| 636 | { |
| 637 | struct hist_entry *h; |
| 638 | struct rb_node *nd; |
| 639 | bool first = true; |
| 640 | |
| 641 | switch (whence) { |
| 642 | case SEEK_SET: |
| 643 | nd = hists__filter_entries(rb_first(self->entries)); |
| 644 | break; |
| 645 | case SEEK_CUR: |
| 646 | nd = self->top; |
| 647 | goto do_offset; |
| 648 | case SEEK_END: |
| 649 | nd = hists__filter_prev_entries(rb_last(self->entries)); |
| 650 | first = false; |
| 651 | break; |
| 652 | default: |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Moves not relative to the first visible entry invalidates its |
| 658 | * row_offset: |
| 659 | */ |
| 660 | h = rb_entry(self->top, struct hist_entry, rb_node); |
| 661 | h->row_offset = 0; |
| 662 | |
| 663 | /* |
| 664 | * Here we have to check if nd is expanded (+), if it is we can't go |
| 665 | * the next top level hist_entry, instead we must compute an offset of |
| 666 | * what _not_ to show and not change the first visible entry. |
| 667 | * |
| 668 | * This offset increments when we are going from top to bottom and |
| 669 | * decreases when we're going from bottom to top. |
| 670 | * |
| 671 | * As we don't have backpointers to the top level in the callchains |
| 672 | * structure, we need to always print the whole hist_entry callchain, |
| 673 | * skipping the first ones that are before the first visible entry |
| 674 | * and stop when we printed enough lines to fill the screen. |
| 675 | */ |
| 676 | do_offset: |
| 677 | if (offset > 0) { |
| 678 | do { |
| 679 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 680 | if (h->ms.unfolded) { |
| 681 | u16 remaining = h->nr_rows - h->row_offset; |
| 682 | if (offset > remaining) { |
| 683 | offset -= remaining; |
| 684 | h->row_offset = 0; |
| 685 | } else { |
| 686 | h->row_offset += offset; |
| 687 | offset = 0; |
| 688 | self->top = nd; |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | nd = hists__filter_entries(rb_next(nd)); |
| 693 | if (nd == NULL) |
| 694 | break; |
| 695 | --offset; |
| 696 | self->top = nd; |
| 697 | } while (offset != 0); |
| 698 | } else if (offset < 0) { |
| 699 | while (1) { |
| 700 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 701 | if (h->ms.unfolded) { |
| 702 | if (first) { |
| 703 | if (-offset > h->row_offset) { |
| 704 | offset += h->row_offset; |
| 705 | h->row_offset = 0; |
| 706 | } else { |
| 707 | h->row_offset += offset; |
| 708 | offset = 0; |
| 709 | self->top = nd; |
| 710 | break; |
| 711 | } |
| 712 | } else { |
| 713 | if (-offset > h->nr_rows) { |
| 714 | offset += h->nr_rows; |
| 715 | h->row_offset = 0; |
| 716 | } else { |
| 717 | h->row_offset = h->nr_rows + offset; |
| 718 | offset = 0; |
| 719 | self->top = nd; |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | nd = hists__filter_prev_entries(rb_prev(nd)); |
| 726 | if (nd == NULL) |
| 727 | break; |
| 728 | ++offset; |
| 729 | self->top = nd; |
| 730 | if (offset == 0) { |
| 731 | /* |
| 732 | * Last unfiltered hist_entry, check if it is |
| 733 | * unfolded, if it is then we should have |
| 734 | * row_offset at its last entry. |
| 735 | */ |
| 736 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 737 | if (h->ms.unfolded) |
| 738 | h->row_offset = h->nr_rows; |
| 739 | break; |
| 740 | } |
| 741 | first = false; |
| 742 | } |
| 743 | } else { |
| 744 | self->top = nd; |
| 745 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 746 | h->row_offset = 0; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | static struct hist_browser *hist_browser__new(struct hists *hists) |
| 751 | { |
| 752 | struct hist_browser *self = zalloc(sizeof(*self)); |
| 753 | |
| 754 | if (self) { |
| 755 | self->hists = hists; |
| 756 | self->b.refresh = hist_browser__refresh; |
| 757 | self->b.seek = ui_browser__hists_seek; |
| 758 | } |
| 759 | |
| 760 | return self; |
| 761 | } |
| 762 | |
| 763 | static void hist_browser__delete(struct hist_browser *self) |
| 764 | { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 765 | free(self); |
| 766 | } |
| 767 | |
| 768 | static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self) |
| 769 | { |
| 770 | return self->he_selection; |
| 771 | } |
| 772 | |
| 773 | static struct thread *hist_browser__selected_thread(struct hist_browser *self) |
| 774 | { |
| 775 | return self->he_selection->thread; |
| 776 | } |
| 777 | |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 778 | static int hists__browser_title(struct hists *self, char *bf, size_t size, |
| 779 | const char *ev_name, const struct dso *dso, |
| 780 | const struct thread *thread) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 781 | { |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 782 | char unit; |
| 783 | int printed; |
| 784 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 785 | |
| 786 | nr_events = convert_unit(nr_events, &unit); |
| 787 | printed = snprintf(bf, size, "Events: %lu%c %s", nr_events, unit, ev_name); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 788 | |
| 789 | if (thread) |
| 790 | printed += snprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 791 | ", Thread: %s(%d)", |
| 792 | (thread->comm_set ? thread->comm : ""), |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 793 | thread->pid); |
| 794 | if (dso) |
| 795 | printed += snprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 796 | ", DSO: %s", dso->short_name); |
| 797 | return printed; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 798 | } |
| 799 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 800 | int hists__browse(struct hists *self, const char *helpline, |
| 801 | const char *ev_name, int evidx) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 802 | { |
| 803 | struct hist_browser *browser = hist_browser__new(self); |
| 804 | struct pstack *fstack; |
| 805 | const struct thread *thread_filter = NULL; |
| 806 | const struct dso *dso_filter = NULL; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 807 | char msg[160]; |
| 808 | int key = -1; |
| 809 | |
| 810 | if (browser == NULL) |
| 811 | return -1; |
| 812 | |
| 813 | fstack = pstack__new(2); |
| 814 | if (fstack == NULL) |
| 815 | goto out; |
| 816 | |
| 817 | ui_helpline__push(helpline); |
| 818 | |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 819 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
| 820 | dso_filter, thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 821 | while (1) { |
| 822 | const struct thread *thread; |
| 823 | const struct dso *dso; |
| 824 | char *options[16]; |
| 825 | int nr_options = 0, choice = 0, i, |
| 826 | annotate = -2, zoom_dso = -2, zoom_thread = -2, |
| 827 | browse_map = -2; |
| 828 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 829 | key = hist_browser__run(browser, msg); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 830 | |
| 831 | thread = hist_browser__selected_thread(browser); |
| 832 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
| 833 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 834 | switch (key) { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 835 | case NEWT_KEY_TAB: |
| 836 | case NEWT_KEY_UNTAB: |
| 837 | /* |
| 838 | * Exit the browser, let hists__browser_tree |
| 839 | * go to the next or previous |
| 840 | */ |
| 841 | goto out_free_stack; |
| 842 | case 'a': |
| 843 | if (browser->selection->map == NULL && |
| 844 | browser->selection->map->dso->annotate_warned) |
| 845 | continue; |
| 846 | goto do_annotate; |
| 847 | case 'd': |
| 848 | goto zoom_dso; |
| 849 | case 't': |
| 850 | goto zoom_thread; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 851 | case NEWT_KEY_F1: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 852 | case 'h': |
| 853 | case '?': |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 854 | ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n" |
| 855 | "<- Zoom out\n" |
| 856 | "a Annotate current symbol\n" |
| 857 | "h/?/F1 Show this window\n" |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 858 | "C Collapse all callchains\n" |
| 859 | "E Expand all callchains\n" |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 860 | "d Zoom into current DSO\n" |
| 861 | "t Zoom into current Thread\n" |
| 862 | "q/CTRL+C Exit browser"); |
| 863 | continue; |
| 864 | case NEWT_KEY_ENTER: |
| 865 | case NEWT_KEY_RIGHT: |
| 866 | /* menu */ |
| 867 | break; |
| 868 | case NEWT_KEY_LEFT: { |
| 869 | const void *top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 870 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 871 | if (pstack__empty(fstack)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 872 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 873 | top = pstack__pop(fstack); |
| 874 | if (top == &dso_filter) |
| 875 | goto zoom_out_dso; |
| 876 | if (top == &thread_filter) |
| 877 | goto zoom_out_thread; |
| 878 | continue; |
| 879 | } |
| 880 | case NEWT_KEY_ESCAPE: |
| 881 | if (!ui__dialog_yesno("Do you really want to exit?")) |
| 882 | continue; |
| 883 | /* Fall thru */ |
| 884 | default: |
| 885 | goto out_free_stack; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | if (browser->selection->sym != NULL && |
| 889 | !browser->selection->map->dso->annotate_warned && |
| 890 | asprintf(&options[nr_options], "Annotate %s", |
| 891 | browser->selection->sym->name) > 0) |
| 892 | annotate = nr_options++; |
| 893 | |
| 894 | if (thread != NULL && |
| 895 | asprintf(&options[nr_options], "Zoom %s %s(%d) thread", |
| 896 | (thread_filter ? "out of" : "into"), |
| 897 | (thread->comm_set ? thread->comm : ""), |
| 898 | thread->pid) > 0) |
| 899 | zoom_thread = nr_options++; |
| 900 | |
| 901 | if (dso != NULL && |
| 902 | asprintf(&options[nr_options], "Zoom %s %s DSO", |
| 903 | (dso_filter ? "out of" : "into"), |
| 904 | (dso->kernel ? "the Kernel" : dso->short_name)) > 0) |
| 905 | zoom_dso = nr_options++; |
| 906 | |
| 907 | if (browser->selection->map != NULL && |
| 908 | asprintf(&options[nr_options], "Browse map details") > 0) |
| 909 | browse_map = nr_options++; |
| 910 | |
| 911 | options[nr_options++] = (char *)"Exit"; |
| 912 | |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 913 | choice = ui__popup_menu(nr_options, options); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 914 | |
| 915 | for (i = 0; i < nr_options - 1; ++i) |
| 916 | free(options[i]); |
| 917 | |
| 918 | if (choice == nr_options - 1) |
| 919 | break; |
| 920 | |
| 921 | if (choice == -1) |
| 922 | continue; |
| 923 | |
| 924 | if (choice == annotate) { |
| 925 | struct hist_entry *he; |
| 926 | do_annotate: |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 927 | he = hist_browser__selected_entry(browser); |
| 928 | if (he == NULL) |
| 929 | continue; |
| 930 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 931 | hist_entry__tui_annotate(he, evidx); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 932 | } else if (choice == browse_map) |
| 933 | map__browse(browser->selection->map); |
| 934 | else if (choice == zoom_dso) { |
| 935 | zoom_dso: |
| 936 | if (dso_filter) { |
| 937 | pstack__remove(fstack, &dso_filter); |
| 938 | zoom_out_dso: |
| 939 | ui_helpline__pop(); |
| 940 | dso_filter = NULL; |
| 941 | } else { |
| 942 | if (dso == NULL) |
| 943 | continue; |
| 944 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", |
| 945 | dso->kernel ? "the Kernel" : dso->short_name); |
| 946 | dso_filter = dso; |
| 947 | pstack__push(fstack, &dso_filter); |
| 948 | } |
| 949 | hists__filter_by_dso(self, dso_filter); |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 950 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
| 951 | dso_filter, thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 952 | hist_browser__reset(browser); |
| 953 | } else if (choice == zoom_thread) { |
| 954 | zoom_thread: |
| 955 | if (thread_filter) { |
| 956 | pstack__remove(fstack, &thread_filter); |
| 957 | zoom_out_thread: |
| 958 | ui_helpline__pop(); |
| 959 | thread_filter = NULL; |
| 960 | } else { |
| 961 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", |
| 962 | thread->comm_set ? thread->comm : "", |
| 963 | thread->pid); |
| 964 | thread_filter = thread; |
| 965 | pstack__push(fstack, &thread_filter); |
| 966 | } |
| 967 | hists__filter_by_thread(self, thread_filter); |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 968 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
| 969 | dso_filter, thread_filter); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 970 | hist_browser__reset(browser); |
| 971 | } |
| 972 | } |
| 973 | out_free_stack: |
| 974 | pstack__delete(fstack); |
| 975 | out: |
| 976 | hist_browser__delete(browser); |
| 977 | return key; |
| 978 | } |
| 979 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 980 | int hists__tui_browse_tree(struct rb_root *self, const char *help, int evidx) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 981 | { |
| 982 | struct rb_node *first = rb_first(self), *nd = first, *next; |
| 983 | int key = 0; |
| 984 | |
| 985 | while (nd) { |
| 986 | struct hists *hists = rb_entry(nd, struct hists, rb_node); |
| 987 | const char *ev_name = __event_name(hists->type, hists->config); |
| 988 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 989 | key = hists__browse(hists, help, ev_name, evidx); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 990 | switch (key) { |
| 991 | case NEWT_KEY_TAB: |
| 992 | next = rb_next(nd); |
| 993 | if (next) |
| 994 | nd = next; |
| 995 | break; |
| 996 | case NEWT_KEY_UNTAB: |
| 997 | if (nd == first) |
| 998 | continue; |
| 999 | nd = rb_prev(nd); |
| 1000 | default: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 1001 | return key; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | return key; |
| 1006 | } |