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