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