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