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