Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 2 | #include <dirent.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 3 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 4 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 5 | #include <stdio.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 8 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | b0742e9 | 2017-04-18 11:08:10 -0300 | [diff] [blame] | 9 | #include <sys/ttydefaults.h> |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 10 | |
Namhyung Kim | aca7a94 | 2012-04-04 00:14:26 -0700 | [diff] [blame] | 11 | #include "../../util/evsel.h" |
| 12 | #include "../../util/evlist.h" |
| 13 | #include "../../util/hist.h" |
| 14 | #include "../../util/pstack.h" |
| 15 | #include "../../util/sort.h" |
| 16 | #include "../../util/util.h" |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 17 | #include "../../util/top.h" |
Arnaldo Carvalho de Melo | e7ff892 | 2017-04-19 21:34:35 -0300 | [diff] [blame] | 18 | #include "../../util/thread.h" |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 19 | #include "../../arch/common.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 20 | |
Jiri Olsa | f758990 | 2016-06-20 23:58:13 +0200 | [diff] [blame] | 21 | #include "../browsers/hists.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 22 | #include "../helpline.h" |
| 23 | #include "../util.h" |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 24 | #include "../ui.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 25 | #include "map.h" |
Jiri Olsa | d755330 | 2014-06-15 10:22:15 +0200 | [diff] [blame] | 26 | #include "annotate.h" |
Arnaldo Carvalho de Melo | 632a5ca | 2017-04-17 16:30:49 -0300 | [diff] [blame] | 27 | #include "srcline.h" |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 28 | #include "string2.h" |
Arnaldo Carvalho de Melo | 58db1d6 | 2017-04-19 16:05:56 -0300 | [diff] [blame] | 29 | #include "units.h" |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 30 | |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 31 | #include "sane_ctype.h" |
| 32 | |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 33 | extern void hist_browser__init_hpp(void); |
| 34 | |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 35 | static int perf_evsel_browser_title(struct hist_browser *browser, |
| 36 | char *bf, size_t size); |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 37 | 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] | 38 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 39 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 40 | float min_pcnt); |
| 41 | |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 42 | static bool hist_browser__has_filter(struct hist_browser *hb) |
| 43 | { |
Jiri Olsa | 5a1a99c | 2016-01-06 16:59:02 +0100 | [diff] [blame] | 44 | return hists__has_filter(hb->hists) || hb->min_pcnt || symbol_conf.has_filter || hb->c2c_filter; |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 45 | } |
| 46 | |
He Kuang | 4fabf3d | 2015-03-12 15:21:49 +0800 | [diff] [blame] | 47 | static int hist_browser__get_folding(struct hist_browser *browser) |
| 48 | { |
| 49 | struct rb_node *nd; |
| 50 | struct hists *hists = browser->hists; |
| 51 | int unfolded_rows = 0; |
| 52 | |
| 53 | for (nd = rb_first(&hists->entries); |
| 54 | (nd = hists__filter_entries(nd, browser->min_pcnt)) != NULL; |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 55 | nd = rb_hierarchy_next(nd)) { |
He Kuang | 4fabf3d | 2015-03-12 15:21:49 +0800 | [diff] [blame] | 56 | struct hist_entry *he = |
| 57 | rb_entry(nd, struct hist_entry, rb_node); |
| 58 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 59 | if (he->leaf && he->unfolded) |
He Kuang | 4fabf3d | 2015-03-12 15:21:49 +0800 | [diff] [blame] | 60 | unfolded_rows += he->nr_rows; |
| 61 | } |
| 62 | return unfolded_rows; |
| 63 | } |
| 64 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 65 | static u32 hist_browser__nr_entries(struct hist_browser *hb) |
| 66 | { |
| 67 | u32 nr_entries; |
| 68 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 69 | if (symbol_conf.report_hierarchy) |
| 70 | nr_entries = hb->nr_hierarchy_entries; |
| 71 | else if (hist_browser__has_filter(hb)) |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 72 | nr_entries = hb->nr_non_filtered_entries; |
| 73 | else |
| 74 | nr_entries = hb->hists->nr_entries; |
| 75 | |
He Kuang | 4fabf3d | 2015-03-12 15:21:49 +0800 | [diff] [blame] | 76 | hb->nr_callchain_rows = hist_browser__get_folding(hb); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 77 | return nr_entries + hb->nr_callchain_rows; |
| 78 | } |
| 79 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 80 | static void hist_browser__update_rows(struct hist_browser *hb) |
| 81 | { |
| 82 | struct ui_browser *browser = &hb->b; |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 83 | struct hists *hists = hb->hists; |
| 84 | struct perf_hpp_list *hpp_list = hists->hpp_list; |
| 85 | u16 header_offset, index_row; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 86 | |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 87 | header_offset = hb->show_headers ? hpp_list->nr_header_lines : 0; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 88 | browser->rows = browser->height - header_offset; |
| 89 | /* |
| 90 | * Verify if we were at the last line and that line isn't |
| 91 | * visibe because we now show the header line(s). |
| 92 | */ |
| 93 | index_row = browser->index - browser->top_idx; |
| 94 | if (index_row >= browser->rows) |
| 95 | browser->index -= index_row - browser->rows + 1; |
| 96 | } |
| 97 | |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 98 | static void hist_browser__refresh_dimensions(struct ui_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 99 | { |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 100 | struct hist_browser *hb = container_of(browser, struct hist_browser, b); |
| 101 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 102 | /* 3 == +/- toggle symbol before actual hist_entry rendering */ |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 103 | browser->width = 3 + (hists__sort_list_width(hb->hists) + sizeof("[k]")); |
| 104 | /* |
| 105 | * FIXME: Just keeping existing behaviour, but this really should be |
| 106 | * before updating browser->width, as it will invalidate the |
| 107 | * calculation above. Fix this and the fallout in another |
| 108 | * changeset. |
| 109 | */ |
| 110 | ui_browser__refresh_dimensions(browser); |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 111 | hist_browser__update_rows(hb); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 112 | } |
| 113 | |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 114 | static void hist_browser__gotorc(struct hist_browser *browser, int row, int column) |
| 115 | { |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 116 | struct hists *hists = browser->hists; |
| 117 | struct perf_hpp_list *hpp_list = hists->hpp_list; |
| 118 | u16 header_offset; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 119 | |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 120 | header_offset = browser->show_headers ? hpp_list->nr_header_lines : 0; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 121 | ui_browser__gotorc(&browser->b, row + header_offset, column); |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 122 | } |
| 123 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 124 | static void hist_browser__reset(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 125 | { |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 126 | /* |
| 127 | * The hists__remove_entry_filter() already folds non-filtered |
| 128 | * entries so we can assume it has 0 callchain rows. |
| 129 | */ |
| 130 | browser->nr_callchain_rows = 0; |
| 131 | |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 132 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 133 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | 357cfff | 2014-07-01 17:01:01 -0300 | [diff] [blame] | 134 | hist_browser__refresh_dimensions(&browser->b); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 135 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static char tree__folded_sign(bool unfolded) |
| 139 | { |
| 140 | return unfolded ? '-' : '+'; |
| 141 | } |
| 142 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 143 | static char hist_entry__folded(const struct hist_entry *he) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 144 | { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 145 | return he->has_children ? tree__folded_sign(he->unfolded) : ' '; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 146 | } |
| 147 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 148 | static char callchain_list__folded(const struct callchain_list *cl) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 149 | { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 150 | return cl->has_children ? tree__folded_sign(cl->unfolded) : ' '; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 151 | } |
| 152 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 153 | 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] | 154 | { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 155 | cl->unfolded = unfold ? cl->has_children : false; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 156 | } |
| 157 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 158 | 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] | 159 | { |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 160 | int n = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 161 | struct rb_node *nd; |
| 162 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 163 | 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] | 164 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 165 | struct callchain_list *chain; |
| 166 | char folded_sign = ' '; /* No children */ |
| 167 | |
| 168 | list_for_each_entry(chain, &child->val, list) { |
| 169 | ++n; |
Jin Yao | 0d3eb0b | 2017-03-26 04:34:29 +0800 | [diff] [blame] | 170 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 171 | /* We need this because we may not have children */ |
| 172 | folded_sign = callchain_list__folded(chain); |
| 173 | if (folded_sign == '+') |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | if (folded_sign == '-') /* Have children and they're unfolded */ |
| 178 | n += callchain_node__count_rows_rb_tree(child); |
| 179 | } |
| 180 | |
| 181 | return n; |
| 182 | } |
| 183 | |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 184 | static int callchain_node__count_flat_rows(struct callchain_node *node) |
| 185 | { |
| 186 | struct callchain_list *chain; |
| 187 | char folded_sign = 0; |
| 188 | int n = 0; |
| 189 | |
| 190 | list_for_each_entry(chain, &node->parent_val, list) { |
| 191 | if (!folded_sign) { |
| 192 | /* only check first chain list entry */ |
| 193 | folded_sign = callchain_list__folded(chain); |
| 194 | if (folded_sign == '+') |
| 195 | return 1; |
| 196 | } |
| 197 | n++; |
| 198 | } |
| 199 | |
| 200 | list_for_each_entry(chain, &node->val, list) { |
| 201 | if (!folded_sign) { |
| 202 | /* node->parent_val list might be empty */ |
| 203 | folded_sign = callchain_list__folded(chain); |
| 204 | if (folded_sign == '+') |
| 205 | return 1; |
| 206 | } |
| 207 | n++; |
| 208 | } |
| 209 | |
| 210 | return n; |
| 211 | } |
| 212 | |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 213 | static int callchain_node__count_folded_rows(struct callchain_node *node __maybe_unused) |
| 214 | { |
| 215 | return 1; |
| 216 | } |
| 217 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 218 | static int callchain_node__count_rows(struct callchain_node *node) |
| 219 | { |
| 220 | struct callchain_list *chain; |
| 221 | bool unfolded = false; |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 222 | int n = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 223 | |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 224 | if (callchain_param.mode == CHAIN_FLAT) |
| 225 | return callchain_node__count_flat_rows(node); |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 226 | else if (callchain_param.mode == CHAIN_FOLDED) |
| 227 | return callchain_node__count_folded_rows(node); |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 228 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 229 | list_for_each_entry(chain, &node->val, list) { |
| 230 | ++n; |
Jin Yao | 0d3eb0b | 2017-03-26 04:34:29 +0800 | [diff] [blame] | 231 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 232 | unfolded = chain->unfolded; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | if (unfolded) |
| 236 | n += callchain_node__count_rows_rb_tree(node); |
| 237 | |
| 238 | return n; |
| 239 | } |
| 240 | |
| 241 | static int callchain__count_rows(struct rb_root *chain) |
| 242 | { |
| 243 | struct rb_node *nd; |
| 244 | int n = 0; |
| 245 | |
| 246 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 247 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 248 | n += callchain_node__count_rows(node); |
| 249 | } |
| 250 | |
| 251 | return n; |
| 252 | } |
| 253 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 254 | static int hierarchy_count_rows(struct hist_browser *hb, struct hist_entry *he, |
| 255 | bool include_children) |
| 256 | { |
| 257 | int count = 0; |
| 258 | struct rb_node *node; |
| 259 | struct hist_entry *child; |
| 260 | |
| 261 | if (he->leaf) |
| 262 | return callchain__count_rows(&he->sorted_chain); |
| 263 | |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 264 | if (he->has_no_entry) |
| 265 | return 1; |
| 266 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 267 | node = rb_first(&he->hroot_out); |
| 268 | while (node) { |
| 269 | float percent; |
| 270 | |
| 271 | child = rb_entry(node, struct hist_entry, rb_node); |
| 272 | percent = hist_entry__get_percent_limit(child); |
| 273 | |
| 274 | if (!child->filtered && percent >= hb->min_pcnt) { |
| 275 | count++; |
| 276 | |
| 277 | if (include_children && child->unfolded) |
| 278 | count += hierarchy_count_rows(hb, child, true); |
| 279 | } |
| 280 | |
| 281 | node = rb_next(node); |
| 282 | } |
| 283 | return count; |
| 284 | } |
| 285 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 286 | static bool hist_entry__toggle_fold(struct hist_entry *he) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 287 | { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 288 | if (!he) |
Jiri Olsa | 8493fe1 | 2012-04-04 22:21:31 +0200 | [diff] [blame] | 289 | return false; |
| 290 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 291 | if (!he->has_children) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 292 | return false; |
| 293 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 294 | he->unfolded = !he->unfolded; |
| 295 | return true; |
| 296 | } |
| 297 | |
| 298 | static bool callchain_list__toggle_fold(struct callchain_list *cl) |
| 299 | { |
| 300 | if (!cl) |
| 301 | return false; |
| 302 | |
| 303 | if (!cl->has_children) |
| 304 | return false; |
| 305 | |
| 306 | cl->unfolded = !cl->unfolded; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 307 | return true; |
| 308 | } |
| 309 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 310 | 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] | 311 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 312 | struct rb_node *nd = rb_first(&node->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 313 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 314 | 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] | 315 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 316 | struct callchain_list *chain; |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 317 | bool first = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 318 | |
| 319 | list_for_each_entry(chain, &child->val, list) { |
| 320 | if (first) { |
| 321 | first = false; |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 322 | chain->has_children = chain->list.next != &child->val || |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 323 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 324 | } else |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 325 | chain->has_children = chain->list.next == &child->val && |
Arnaldo Carvalho de Melo | 293db47 | 2010-08-25 16:05:36 -0300 | [diff] [blame] | 326 | !RB_EMPTY_ROOT(&child->rb_root); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | callchain_node__init_have_children_rb_tree(child); |
| 330 | } |
| 331 | } |
| 332 | |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 333 | static void callchain_node__init_have_children(struct callchain_node *node, |
| 334 | bool has_sibling) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 335 | { |
| 336 | struct callchain_list *chain; |
| 337 | |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 338 | chain = list_entry(node->val.next, struct callchain_list, list); |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 339 | chain->has_children = has_sibling; |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 340 | |
Andres Freund | 9098903 | 2016-03-30 21:02:45 +0200 | [diff] [blame] | 341 | if (!list_empty(&node->val)) { |
Namhyung Kim | 82162b5 | 2014-08-13 15:02:41 +0900 | [diff] [blame] | 342 | chain = list_entry(node->val.prev, struct callchain_list, list); |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 343 | chain->has_children = !RB_EMPTY_ROOT(&node->rb_root); |
Namhyung Kim | 82162b5 | 2014-08-13 15:02:41 +0900 | [diff] [blame] | 344 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 345 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 346 | callchain_node__init_have_children_rb_tree(node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 347 | } |
| 348 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 349 | static void callchain__init_have_children(struct rb_root *root) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 350 | { |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 351 | struct rb_node *nd = rb_first(root); |
| 352 | bool has_sibling = nd && rb_next(nd); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 353 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 354 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 355 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
Namhyung Kim | a7444af | 2014-11-24 17:13:27 +0900 | [diff] [blame] | 356 | callchain_node__init_have_children(node, has_sibling); |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 357 | if (callchain_param.mode == CHAIN_FLAT || |
| 358 | callchain_param.mode == CHAIN_FOLDED) |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 359 | callchain_node__make_parent_list(node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 363 | 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] | 364 | { |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 365 | if (he->init_have_children) |
| 366 | return; |
| 367 | |
| 368 | if (he->leaf) { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 369 | he->has_children = !RB_EMPTY_ROOT(&he->sorted_chain); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 370 | callchain__init_have_children(&he->sorted_chain); |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 371 | } else { |
| 372 | he->has_children = !RB_EMPTY_ROOT(&he->hroot_out); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 373 | } |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 374 | |
| 375 | he->init_have_children = true; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 376 | } |
| 377 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 378 | static bool hist_browser__toggle_fold(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 379 | { |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 380 | struct hist_entry *he = browser->he_selection; |
| 381 | struct map_symbol *ms = browser->selection; |
| 382 | struct callchain_list *cl = container_of(ms, struct callchain_list, ms); |
| 383 | bool has_children; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 384 | |
Wang Nan | 4938cf0 | 2015-12-07 02:35:44 +0000 | [diff] [blame] | 385 | if (!he || !ms) |
| 386 | return false; |
| 387 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 388 | if (ms == &he->ms) |
| 389 | has_children = hist_entry__toggle_fold(he); |
| 390 | else |
| 391 | has_children = callchain_list__toggle_fold(cl); |
| 392 | |
| 393 | if (has_children) { |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 394 | int child_rows = 0; |
| 395 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 396 | hist_entry__init_have_children(he); |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 397 | browser->b.nr_entries -= he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 398 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 399 | if (he->leaf) |
| 400 | browser->nr_callchain_rows -= he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 401 | else |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 402 | browser->nr_hierarchy_entries -= he->nr_rows; |
| 403 | |
| 404 | if (symbol_conf.report_hierarchy) |
| 405 | child_rows = hierarchy_count_rows(browser, he, true); |
| 406 | |
| 407 | if (he->unfolded) { |
| 408 | if (he->leaf) |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 409 | he->nr_rows = callchain__count_rows( |
| 410 | &he->sorted_chain); |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 411 | else |
| 412 | he->nr_rows = hierarchy_count_rows(browser, he, false); |
| 413 | |
| 414 | /* account grand children */ |
| 415 | if (symbol_conf.report_hierarchy) |
| 416 | browser->b.nr_entries += child_rows - he->nr_rows; |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 417 | |
| 418 | if (!he->leaf && he->nr_rows == 0) { |
| 419 | he->has_no_entry = true; |
| 420 | he->nr_rows = 1; |
| 421 | } |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 422 | } else { |
| 423 | if (symbol_conf.report_hierarchy) |
| 424 | browser->b.nr_entries -= child_rows - he->nr_rows; |
| 425 | |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 426 | if (he->has_no_entry) |
| 427 | he->has_no_entry = false; |
| 428 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 429 | he->nr_rows = 0; |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 430 | } |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 431 | |
| 432 | browser->b.nr_entries += he->nr_rows; |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 433 | |
| 434 | if (he->leaf) |
| 435 | browser->nr_callchain_rows += he->nr_rows; |
| 436 | else |
| 437 | browser->nr_hierarchy_entries += he->nr_rows; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | /* If it doesn't have children, no toggling performed */ |
| 443 | return false; |
| 444 | } |
| 445 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 446 | 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] | 447 | { |
| 448 | int n = 0; |
| 449 | struct rb_node *nd; |
| 450 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 451 | 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] | 452 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
| 453 | struct callchain_list *chain; |
| 454 | bool has_children = false; |
| 455 | |
| 456 | list_for_each_entry(chain, &child->val, list) { |
| 457 | ++n; |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 458 | callchain_list__set_folding(chain, unfold); |
| 459 | has_children = chain->has_children; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | if (has_children) |
| 463 | n += callchain_node__set_folding_rb_tree(child, unfold); |
| 464 | } |
| 465 | |
| 466 | return n; |
| 467 | } |
| 468 | |
| 469 | static int callchain_node__set_folding(struct callchain_node *node, bool unfold) |
| 470 | { |
| 471 | struct callchain_list *chain; |
| 472 | bool has_children = false; |
| 473 | int n = 0; |
| 474 | |
| 475 | list_for_each_entry(chain, &node->val, list) { |
| 476 | ++n; |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 477 | callchain_list__set_folding(chain, unfold); |
| 478 | has_children = chain->has_children; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | if (has_children) |
| 482 | n += callchain_node__set_folding_rb_tree(node, unfold); |
| 483 | |
| 484 | return n; |
| 485 | } |
| 486 | |
| 487 | static int callchain__set_folding(struct rb_root *chain, bool unfold) |
| 488 | { |
| 489 | struct rb_node *nd; |
| 490 | int n = 0; |
| 491 | |
| 492 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { |
| 493 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 494 | n += callchain_node__set_folding(node, unfold); |
| 495 | } |
| 496 | |
| 497 | return n; |
| 498 | } |
| 499 | |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 500 | static int hierarchy_set_folding(struct hist_browser *hb, struct hist_entry *he, |
| 501 | bool unfold __maybe_unused) |
| 502 | { |
| 503 | float percent; |
| 504 | struct rb_node *nd; |
| 505 | struct hist_entry *child; |
| 506 | int n = 0; |
| 507 | |
| 508 | for (nd = rb_first(&he->hroot_out); nd; nd = rb_next(nd)) { |
| 509 | child = rb_entry(nd, struct hist_entry, rb_node); |
| 510 | percent = hist_entry__get_percent_limit(child); |
| 511 | if (!child->filtered && percent >= hb->min_pcnt) |
| 512 | n++; |
| 513 | } |
| 514 | |
| 515 | return n; |
| 516 | } |
| 517 | |
Jiri Olsa | b33f922 | 2017-01-20 10:20:29 +0100 | [diff] [blame] | 518 | static void __hist_entry__set_folding(struct hist_entry *he, |
| 519 | struct hist_browser *hb, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 520 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 521 | hist_entry__init_have_children(he); |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 522 | he->unfolded = unfold ? he->has_children : false; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 523 | |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 524 | if (he->has_children) { |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 525 | int n; |
| 526 | |
| 527 | if (he->leaf) |
| 528 | n = callchain__set_folding(&he->sorted_chain, unfold); |
| 529 | else |
| 530 | n = hierarchy_set_folding(hb, he, unfold); |
| 531 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 532 | he->nr_rows = unfold ? n : 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 533 | } else |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 534 | he->nr_rows = 0; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 535 | } |
| 536 | |
Jiri Olsa | b33f922 | 2017-01-20 10:20:29 +0100 | [diff] [blame] | 537 | static void hist_entry__set_folding(struct hist_entry *he, |
| 538 | struct hist_browser *browser, bool unfold) |
| 539 | { |
| 540 | double percent; |
| 541 | |
| 542 | percent = hist_entry__get_percent_limit(he); |
| 543 | if (he->filtered || percent < browser->min_pcnt) |
| 544 | return; |
| 545 | |
| 546 | __hist_entry__set_folding(he, browser, unfold); |
| 547 | |
| 548 | if (!he->depth || unfold) |
| 549 | browser->nr_hierarchy_entries++; |
| 550 | if (he->leaf) |
| 551 | browser->nr_callchain_rows += he->nr_rows; |
| 552 | else if (unfold && !hist_entry__has_hierarchy_children(he, browser->min_pcnt)) { |
| 553 | browser->nr_hierarchy_entries++; |
| 554 | he->has_no_entry = true; |
| 555 | he->nr_rows = 1; |
| 556 | } else |
| 557 | he->has_no_entry = false; |
| 558 | } |
| 559 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 560 | static void |
| 561 | __hist_browser__set_folding(struct hist_browser *browser, bool unfold) |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 562 | { |
| 563 | struct rb_node *nd; |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 564 | struct hist_entry *he; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 565 | |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 566 | nd = rb_first(&browser->hists->entries); |
| 567 | while (nd) { |
| 568 | he = rb_entry(nd, struct hist_entry, rb_node); |
| 569 | |
| 570 | /* set folding state even if it's currently folded */ |
| 571 | nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD); |
| 572 | |
| 573 | hist_entry__set_folding(he, browser, unfold); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 577 | 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] | 578 | { |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 579 | browser->nr_hierarchy_entries = 0; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 580 | browser->nr_callchain_rows = 0; |
| 581 | __hist_browser__set_folding(browser, unfold); |
| 582 | |
| 583 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 584 | /* 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] | 585 | ui_browser__reset_index(&browser->b); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 586 | } |
| 587 | |
Jiri Olsa | 0e3fa7a | 2017-01-20 10:20:30 +0100 | [diff] [blame] | 588 | static void hist_browser__set_folding_selected(struct hist_browser *browser, bool unfold) |
| 589 | { |
| 590 | if (!browser->he_selection) |
| 591 | return; |
| 592 | |
| 593 | hist_entry__set_folding(browser->he_selection, browser, unfold); |
| 594 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
| 595 | } |
| 596 | |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 597 | static void ui_browser__warn_lost_events(struct ui_browser *browser) |
| 598 | { |
| 599 | ui_browser__warning(browser, 4, |
| 600 | "Events are being lost, check IO/CPU overload!\n\n" |
| 601 | "You may want to run 'perf' using a RT scheduler policy:\n\n" |
| 602 | " perf top -r 80\n\n" |
| 603 | "Or reduce the sampling frequency."); |
| 604 | } |
| 605 | |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 606 | static int hist_browser__title(struct hist_browser *browser, char *bf, size_t size) |
| 607 | { |
| 608 | return browser->title ? browser->title(browser, bf, size) : 0; |
| 609 | } |
| 610 | |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 611 | int hist_browser__run(struct hist_browser *browser, const char *help, |
| 612 | bool warn_lost_event) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 613 | { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 614 | int key; |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 615 | char title[160]; |
Namhyung Kim | c2a51ab | 2015-04-22 16:18:15 +0900 | [diff] [blame] | 616 | struct hist_browser_timer *hbt = browser->hbt; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 617 | int delay_secs = hbt ? hbt->refresh : 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 618 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 619 | browser->b.entries = &browser->hists->entries; |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 620 | browser->b.nr_entries = hist_browser__nr_entries(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 621 | |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 622 | hist_browser__title(browser, title, sizeof(title)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 623 | |
Namhyung Kim | 090cff3 | 2016-01-11 19:53:14 +0900 | [diff] [blame] | 624 | if (ui_browser__show(&browser->b, title, "%s", help) < 0) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 625 | return -1; |
| 626 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 627 | while (1) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 628 | key = ui_browser__run(&browser->b, delay_secs); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 629 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 630 | switch (key) { |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 631 | case K_TIMER: { |
| 632 | u64 nr_entries; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 633 | hbt->timer(hbt->arg); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 634 | |
Namhyung Kim | c611152 | 2016-10-07 14:04:12 +0900 | [diff] [blame] | 635 | if (hist_browser__has_filter(browser) || |
| 636 | symbol_conf.report_hierarchy) |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 637 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 638 | |
Namhyung Kim | c3b7895 | 2014-04-22 15:56:17 +0900 | [diff] [blame] | 639 | nr_entries = hist_browser__nr_entries(browser); |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 640 | ui_browser__update_nr_entries(&browser->b, nr_entries); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 641 | |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 642 | if (warn_lost_event && |
| 643 | (browser->hists->stats.nr_lost_warned != |
| 644 | browser->hists->stats.nr_events[PERF_RECORD_LOST])) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 645 | browser->hists->stats.nr_lost_warned = |
| 646 | browser->hists->stats.nr_events[PERF_RECORD_LOST]; |
| 647 | ui_browser__warn_lost_events(&browser->b); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 648 | } |
| 649 | |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 650 | hist_browser__title(browser, title, sizeof(title)); |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 651 | ui_browser__show_title(&browser->b, title); |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 652 | continue; |
Namhyung Kim | fa5df94 | 2013-05-14 11:09:05 +0900 | [diff] [blame] | 653 | } |
Arnaldo Carvalho de Melo | 4694153 | 2010-08-10 15:50:07 -0300 | [diff] [blame] | 654 | case 'D': { /* Debug */ |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 655 | static int seq; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 656 | struct hist_entry *h = rb_entry(browser->b.top, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 657 | struct hist_entry, rb_node); |
| 658 | ui_helpline__pop(); |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 659 | 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] | 660 | seq++, browser->b.nr_entries, |
| 661 | browser->hists->nr_entries, |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 662 | browser->b.rows, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 663 | browser->b.index, |
| 664 | browser->b.top_idx, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 665 | h->row_offset, h->nr_rows); |
| 666 | } |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 667 | break; |
| 668 | case 'C': |
| 669 | /* Collapse the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 670 | hist_browser__set_folding(browser, false); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 671 | break; |
Jiri Olsa | 0e3fa7a | 2017-01-20 10:20:30 +0100 | [diff] [blame] | 672 | case 'c': |
| 673 | /* Collapse the selected entry. */ |
| 674 | hist_browser__set_folding_selected(browser, false); |
| 675 | break; |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 676 | case 'E': |
| 677 | /* Expand the whole world. */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 678 | hist_browser__set_folding(browser, true); |
Arnaldo Carvalho de Melo | 3c916cc | 2010-08-25 17:18:35 -0300 | [diff] [blame] | 679 | break; |
Jiri Olsa | 0e3fa7a | 2017-01-20 10:20:30 +0100 | [diff] [blame] | 680 | case 'e': |
| 681 | /* Expand the selected entry. */ |
| 682 | hist_browser__set_folding_selected(browser, true); |
| 683 | break; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 684 | case 'H': |
| 685 | browser->show_headers = !browser->show_headers; |
| 686 | hist_browser__update_rows(browser); |
| 687 | break; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 688 | case K_ENTER: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 689 | if (hist_browser__toggle_fold(browser)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 690 | break; |
| 691 | /* fall thru */ |
| 692 | default: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 693 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 694 | } |
| 695 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 696 | out: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 697 | ui_browser__hide(&browser->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 698 | return key; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 699 | } |
| 700 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 701 | struct callchain_print_arg { |
| 702 | /* for hists browser */ |
| 703 | off_t row_offset; |
| 704 | bool is_current_entry; |
| 705 | |
| 706 | /* for file dump */ |
| 707 | FILE *fp; |
| 708 | int printed; |
| 709 | }; |
| 710 | |
| 711 | typedef void (*print_callchain_entry_fn)(struct hist_browser *browser, |
| 712 | struct callchain_list *chain, |
| 713 | const char *str, int offset, |
| 714 | unsigned short row, |
| 715 | struct callchain_print_arg *arg); |
| 716 | |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 717 | static void hist_browser__show_callchain_entry(struct hist_browser *browser, |
| 718 | struct callchain_list *chain, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 719 | const char *str, int offset, |
| 720 | unsigned short row, |
| 721 | struct callchain_print_arg *arg) |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 722 | { |
| 723 | int color, width; |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 724 | char folded_sign = callchain_list__folded(chain); |
Arnaldo Carvalho de Melo | 70e9727 | 2015-03-19 16:07:21 -0300 | [diff] [blame] | 725 | 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] | 726 | |
| 727 | color = HE_COLORSET_NORMAL; |
| 728 | width = browser->b.width - (offset + 2); |
| 729 | if (ui_browser__is_current_entry(&browser->b, row)) { |
| 730 | browser->selection = &chain->ms; |
| 731 | color = HE_COLORSET_SELECTED; |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 732 | arg->is_current_entry = true; |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | ui_browser__set_color(&browser->b, color); |
| 736 | hist_browser__gotorc(browser, row, 0); |
Arnaldo Carvalho de Melo | 26270a0 | 2015-08-11 12:24:27 -0300 | [diff] [blame] | 737 | ui_browser__write_nstring(&browser->b, " ", offset); |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 738 | ui_browser__printf(&browser->b, "%c", folded_sign); |
Arnaldo Carvalho de Melo | 70e9727 | 2015-03-19 16:07:21 -0300 | [diff] [blame] | 739 | ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' '); |
Arnaldo Carvalho de Melo | 26270a0 | 2015-08-11 12:24:27 -0300 | [diff] [blame] | 740 | ui_browser__write_nstring(&browser->b, str, width); |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 741 | } |
| 742 | |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 743 | static void hist_browser__fprintf_callchain_entry(struct hist_browser *b __maybe_unused, |
| 744 | struct callchain_list *chain, |
| 745 | const char *str, int offset, |
| 746 | unsigned short row __maybe_unused, |
| 747 | struct callchain_print_arg *arg) |
| 748 | { |
| 749 | char folded_sign = callchain_list__folded(chain); |
| 750 | |
| 751 | arg->printed += fprintf(arg->fp, "%*s%c %s\n", offset, " ", |
| 752 | folded_sign, str); |
| 753 | } |
| 754 | |
| 755 | typedef bool (*check_output_full_fn)(struct hist_browser *browser, |
| 756 | unsigned short row); |
| 757 | |
| 758 | static bool hist_browser__check_output_full(struct hist_browser *browser, |
| 759 | unsigned short row) |
| 760 | { |
| 761 | return browser->b.rows == row; |
| 762 | } |
| 763 | |
| 764 | static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_unused, |
| 765 | unsigned short row __maybe_unused) |
| 766 | { |
| 767 | return false; |
| 768 | } |
| 769 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 770 | #define LEVEL_OFFSET_STEP 3 |
| 771 | |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 772 | static int hist_browser__show_callchain_list(struct hist_browser *browser, |
| 773 | struct callchain_node *node, |
| 774 | struct callchain_list *chain, |
| 775 | unsigned short row, u64 total, |
| 776 | bool need_percent, int offset, |
| 777 | print_callchain_entry_fn print, |
| 778 | struct callchain_print_arg *arg) |
| 779 | { |
| 780 | char bf[1024], *alloc_str; |
Jin Yao | fef51ec | 2016-10-31 09:19:53 +0800 | [diff] [blame] | 781 | char buf[64], *alloc_str2; |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 782 | const char *str; |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 783 | int ret = 1; |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 784 | |
| 785 | if (arg->row_offset != 0) { |
| 786 | arg->row_offset--; |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | alloc_str = NULL; |
Jin Yao | fef51ec | 2016-10-31 09:19:53 +0800 | [diff] [blame] | 791 | alloc_str2 = NULL; |
| 792 | |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 793 | str = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 794 | browser->show_dso); |
| 795 | |
Jin Yao | fef51ec | 2016-10-31 09:19:53 +0800 | [diff] [blame] | 796 | if (symbol_conf.show_branchflag_count) { |
Jin Yao | c4ee062 | 2017-08-07 21:05:15 +0800 | [diff] [blame] | 797 | callchain_list_counts__printf_value(chain, NULL, |
| 798 | buf, sizeof(buf)); |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 799 | |
Jin Yao | fef51ec | 2016-10-31 09:19:53 +0800 | [diff] [blame] | 800 | if (asprintf(&alloc_str2, "%s%s", str, buf) < 0) |
| 801 | str = "Not enough memory!"; |
| 802 | else |
| 803 | str = alloc_str2; |
| 804 | } |
| 805 | |
| 806 | if (need_percent) { |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 807 | callchain_node__scnprintf_value(node, buf, sizeof(buf), |
| 808 | total); |
| 809 | |
| 810 | if (asprintf(&alloc_str, "%s %s", buf, str) < 0) |
| 811 | str = "Not enough memory!"; |
| 812 | else |
| 813 | str = alloc_str; |
| 814 | } |
| 815 | |
| 816 | print(browser, chain, str, offset, row, arg); |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 817 | free(alloc_str); |
Jin Yao | fef51ec | 2016-10-31 09:19:53 +0800 | [diff] [blame] | 818 | free(alloc_str2); |
Jin Yao | 0d3eb0b | 2017-03-26 04:34:29 +0800 | [diff] [blame] | 819 | |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 820 | return ret; |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 821 | } |
| 822 | |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 823 | static bool check_percent_display(struct rb_node *node, u64 parent_total) |
| 824 | { |
| 825 | struct callchain_node *child; |
| 826 | |
| 827 | if (node == NULL) |
| 828 | return false; |
| 829 | |
| 830 | if (rb_next(node)) |
| 831 | return true; |
| 832 | |
| 833 | child = rb_entry(node, struct callchain_node, rb_node); |
| 834 | return callchain_cumul_hits(child) != parent_total; |
| 835 | } |
| 836 | |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 837 | static int hist_browser__show_callchain_flat(struct hist_browser *browser, |
| 838 | struct rb_root *root, |
| 839 | unsigned short row, u64 total, |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 840 | u64 parent_total, |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 841 | print_callchain_entry_fn print, |
| 842 | struct callchain_print_arg *arg, |
| 843 | check_output_full_fn is_output_full) |
| 844 | { |
| 845 | struct rb_node *node; |
| 846 | int first_row = row, offset = LEVEL_OFFSET_STEP; |
| 847 | bool need_percent; |
| 848 | |
| 849 | node = rb_first(root); |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 850 | need_percent = check_percent_display(node, parent_total); |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 851 | |
| 852 | while (node) { |
| 853 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 854 | struct rb_node *next = rb_next(node); |
| 855 | struct callchain_list *chain; |
| 856 | char folded_sign = ' '; |
| 857 | int first = true; |
| 858 | int extra_offset = 0; |
| 859 | |
| 860 | list_for_each_entry(chain, &child->parent_val, list) { |
| 861 | bool was_first = first; |
| 862 | |
| 863 | if (first) |
| 864 | first = false; |
| 865 | else if (need_percent) |
| 866 | extra_offset = LEVEL_OFFSET_STEP; |
| 867 | |
| 868 | folded_sign = callchain_list__folded(chain); |
| 869 | |
| 870 | row += hist_browser__show_callchain_list(browser, child, |
| 871 | chain, row, total, |
| 872 | was_first && need_percent, |
| 873 | offset + extra_offset, |
| 874 | print, arg); |
| 875 | |
| 876 | if (is_output_full(browser, row)) |
| 877 | goto out; |
| 878 | |
| 879 | if (folded_sign == '+') |
| 880 | goto next; |
| 881 | } |
| 882 | |
| 883 | list_for_each_entry(chain, &child->val, list) { |
| 884 | bool was_first = first; |
| 885 | |
| 886 | if (first) |
| 887 | first = false; |
| 888 | else if (need_percent) |
| 889 | extra_offset = LEVEL_OFFSET_STEP; |
| 890 | |
| 891 | folded_sign = callchain_list__folded(chain); |
| 892 | |
| 893 | row += hist_browser__show_callchain_list(browser, child, |
| 894 | chain, row, total, |
| 895 | was_first && need_percent, |
| 896 | offset + extra_offset, |
| 897 | print, arg); |
| 898 | |
| 899 | if (is_output_full(browser, row)) |
| 900 | goto out; |
| 901 | |
| 902 | if (folded_sign == '+') |
| 903 | break; |
| 904 | } |
| 905 | |
| 906 | next: |
| 907 | if (is_output_full(browser, row)) |
| 908 | break; |
| 909 | node = next; |
| 910 | } |
| 911 | out: |
| 912 | return row - first_row; |
| 913 | } |
| 914 | |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 915 | static char *hist_browser__folded_callchain_str(struct hist_browser *browser, |
| 916 | struct callchain_list *chain, |
| 917 | char *value_str, char *old_str) |
| 918 | { |
| 919 | char bf[1024]; |
| 920 | const char *str; |
| 921 | char *new; |
| 922 | |
| 923 | str = callchain_list__sym_name(chain, bf, sizeof(bf), |
| 924 | browser->show_dso); |
| 925 | if (old_str) { |
| 926 | if (asprintf(&new, "%s%s%s", old_str, |
| 927 | symbol_conf.field_sep ?: ";", str) < 0) |
| 928 | new = NULL; |
| 929 | } else { |
| 930 | if (value_str) { |
| 931 | if (asprintf(&new, "%s %s", value_str, str) < 0) |
| 932 | new = NULL; |
| 933 | } else { |
| 934 | if (asprintf(&new, "%s", str) < 0) |
| 935 | new = NULL; |
| 936 | } |
| 937 | } |
| 938 | return new; |
| 939 | } |
| 940 | |
| 941 | static int hist_browser__show_callchain_folded(struct hist_browser *browser, |
| 942 | struct rb_root *root, |
| 943 | unsigned short row, u64 total, |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 944 | u64 parent_total, |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 945 | print_callchain_entry_fn print, |
| 946 | struct callchain_print_arg *arg, |
| 947 | check_output_full_fn is_output_full) |
| 948 | { |
| 949 | struct rb_node *node; |
| 950 | int first_row = row, offset = LEVEL_OFFSET_STEP; |
| 951 | bool need_percent; |
| 952 | |
| 953 | node = rb_first(root); |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 954 | need_percent = check_percent_display(node, parent_total); |
Namhyung Kim | 8c430a3 | 2015-11-09 14:45:44 +0900 | [diff] [blame] | 955 | |
| 956 | while (node) { |
| 957 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 958 | struct rb_node *next = rb_next(node); |
| 959 | struct callchain_list *chain, *first_chain = NULL; |
| 960 | int first = true; |
| 961 | char *value_str = NULL, *value_str_alloc = NULL; |
| 962 | char *chain_str = NULL, *chain_str_alloc = NULL; |
| 963 | |
| 964 | if (arg->row_offset != 0) { |
| 965 | arg->row_offset--; |
| 966 | goto next; |
| 967 | } |
| 968 | |
| 969 | if (need_percent) { |
| 970 | char buf[64]; |
| 971 | |
| 972 | callchain_node__scnprintf_value(child, buf, sizeof(buf), total); |
| 973 | if (asprintf(&value_str, "%s", buf) < 0) { |
| 974 | value_str = (char *)"<...>"; |
| 975 | goto do_print; |
| 976 | } |
| 977 | value_str_alloc = value_str; |
| 978 | } |
| 979 | |
| 980 | list_for_each_entry(chain, &child->parent_val, list) { |
| 981 | chain_str = hist_browser__folded_callchain_str(browser, |
| 982 | chain, value_str, chain_str); |
| 983 | if (first) { |
| 984 | first = false; |
| 985 | first_chain = chain; |
| 986 | } |
| 987 | |
| 988 | if (chain_str == NULL) { |
| 989 | chain_str = (char *)"Not enough memory!"; |
| 990 | goto do_print; |
| 991 | } |
| 992 | |
| 993 | chain_str_alloc = chain_str; |
| 994 | } |
| 995 | |
| 996 | list_for_each_entry(chain, &child->val, list) { |
| 997 | chain_str = hist_browser__folded_callchain_str(browser, |
| 998 | chain, value_str, chain_str); |
| 999 | if (first) { |
| 1000 | first = false; |
| 1001 | first_chain = chain; |
| 1002 | } |
| 1003 | |
| 1004 | if (chain_str == NULL) { |
| 1005 | chain_str = (char *)"Not enough memory!"; |
| 1006 | goto do_print; |
| 1007 | } |
| 1008 | |
| 1009 | chain_str_alloc = chain_str; |
| 1010 | } |
| 1011 | |
| 1012 | do_print: |
| 1013 | print(browser, first_chain, chain_str, offset, row++, arg); |
| 1014 | free(value_str_alloc); |
| 1015 | free(chain_str_alloc); |
| 1016 | |
| 1017 | next: |
| 1018 | if (is_output_full(browser, row)) |
| 1019 | break; |
| 1020 | node = next; |
| 1021 | } |
| 1022 | |
| 1023 | return row - first_row; |
| 1024 | } |
| 1025 | |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1026 | static int hist_browser__show_callchain_graph(struct hist_browser *browser, |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1027 | struct rb_root *root, int level, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1028 | unsigned short row, u64 total, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1029 | u64 parent_total, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1030 | print_callchain_entry_fn print, |
| 1031 | struct callchain_print_arg *arg, |
| 1032 | check_output_full_fn is_output_full) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1033 | { |
| 1034 | struct rb_node *node; |
Namhyung Kim | f4536dd | 2014-08-20 17:07:57 +0900 | [diff] [blame] | 1035 | int first_row = row, offset = level * LEVEL_OFFSET_STEP; |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 1036 | bool need_percent; |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1037 | u64 percent_total = total; |
| 1038 | |
| 1039 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 1040 | percent_total = parent_total; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1041 | |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1042 | node = rb_first(root); |
Namhyung Kim | 59c624e | 2016-01-28 00:40:56 +0900 | [diff] [blame] | 1043 | need_percent = check_percent_display(node, parent_total); |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 1044 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1045 | while (node) { |
| 1046 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 1047 | struct rb_node *next = rb_next(node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1048 | struct callchain_list *chain; |
| 1049 | char folded_sign = ' '; |
| 1050 | int first = true; |
| 1051 | int extra_offset = 0; |
| 1052 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1053 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1054 | bool was_first = first; |
| 1055 | |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 1056 | if (first) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1057 | first = false; |
Namhyung Kim | 4087d11 | 2014-11-24 17:13:26 +0900 | [diff] [blame] | 1058 | else if (need_percent) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1059 | extra_offset = LEVEL_OFFSET_STEP; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1060 | |
| 1061 | folded_sign = callchain_list__folded(chain); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1062 | |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 1063 | row += hist_browser__show_callchain_list(browser, child, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1064 | chain, row, percent_total, |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 1065 | was_first && need_percent, |
| 1066 | offset + extra_offset, |
| 1067 | print, arg); |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1068 | |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 1069 | if (is_output_full(browser, row)) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1070 | goto out; |
Namhyung Kim | 18bb838 | 2015-11-09 14:45:42 +0900 | [diff] [blame] | 1071 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1072 | if (folded_sign == '+') |
| 1073 | break; |
| 1074 | } |
| 1075 | |
| 1076 | if (folded_sign == '-') { |
| 1077 | const int new_level = level + (extra_offset ? 2 : 1); |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1078 | |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1079 | row += hist_browser__show_callchain_graph(browser, &child->rb_root, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1080 | new_level, row, total, |
| 1081 | child->children_hit, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1082 | print, arg, is_output_full); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1083 | } |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1084 | if (is_output_full(browser, row)) |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1085 | break; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1086 | node = next; |
| 1087 | } |
| 1088 | out: |
| 1089 | return row - first_row; |
| 1090 | } |
| 1091 | |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1092 | static int hist_browser__show_callchain(struct hist_browser *browser, |
| 1093 | struct hist_entry *entry, int level, |
| 1094 | unsigned short row, |
| 1095 | print_callchain_entry_fn print, |
| 1096 | struct callchain_print_arg *arg, |
| 1097 | check_output_full_fn is_output_full) |
| 1098 | { |
| 1099 | u64 total = hists__total_period(entry->hists); |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1100 | u64 parent_total; |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1101 | int printed; |
| 1102 | |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1103 | if (symbol_conf.cumulate_callchain) |
| 1104 | parent_total = entry->stat_acc->period; |
| 1105 | else |
| 1106 | parent_total = entry->stat.period; |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1107 | |
| 1108 | if (callchain_param.mode == CHAIN_FLAT) { |
| 1109 | printed = hist_browser__show_callchain_flat(browser, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1110 | &entry->sorted_chain, row, |
| 1111 | total, parent_total, print, arg, |
| 1112 | is_output_full); |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1113 | } else if (callchain_param.mode == CHAIN_FOLDED) { |
| 1114 | printed = hist_browser__show_callchain_folded(browser, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1115 | &entry->sorted_chain, row, |
| 1116 | total, parent_total, print, arg, |
| 1117 | is_output_full); |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1118 | } else { |
| 1119 | printed = hist_browser__show_callchain_graph(browser, |
Namhyung Kim | 5eca104 | 2016-01-28 00:40:55 +0900 | [diff] [blame] | 1120 | &entry->sorted_chain, level, row, |
| 1121 | total, parent_total, print, arg, |
| 1122 | is_output_full); |
Namhyung Kim | 0c841c6 | 2016-01-28 00:40:54 +0900 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | if (arg->is_current_entry) |
| 1126 | browser->he_selection = entry; |
| 1127 | |
| 1128 | return printed; |
| 1129 | } |
| 1130 | |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 1131 | struct hpp_arg { |
| 1132 | struct ui_browser *b; |
| 1133 | char folded_sign; |
| 1134 | bool current_entry; |
| 1135 | }; |
| 1136 | |
Jiri Olsa | 98ba160 | 2016-09-22 17:36:35 +0200 | [diff] [blame] | 1137 | int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...) |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 1138 | { |
| 1139 | struct hpp_arg *arg = hpp->ptr; |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 1140 | int ret, len; |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 1141 | va_list args; |
| 1142 | double percent; |
| 1143 | |
| 1144 | va_start(args, fmt); |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 1145 | len = va_arg(args, int); |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 1146 | percent = va_arg(args, double); |
| 1147 | va_end(args); |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1148 | |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 1149 | ui_browser__set_percent_color(arg->b, percent, arg->current_entry); |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1150 | |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 1151 | ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent); |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1152 | ui_browser__printf(arg->b, "%s", hpp->buf); |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 1153 | |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1154 | return ret; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1155 | } |
| 1156 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 1157 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1158 | static u64 __hpp_get_##_field(struct hist_entry *he) \ |
| 1159 | { \ |
| 1160 | return he->stat._field; \ |
| 1161 | } \ |
| 1162 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 1163 | static int \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1164 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 1165 | struct perf_hpp *hpp, \ |
| 1166 | struct hist_entry *he) \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1167 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1168 | return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \ |
| 1169 | __hpp__slsmg_color_printf, true); \ |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1170 | } |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1171 | |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1172 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
| 1173 | static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ |
| 1174 | { \ |
| 1175 | return he->stat_acc->_field; \ |
| 1176 | } \ |
| 1177 | \ |
| 1178 | static int \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1179 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1180 | struct perf_hpp *hpp, \ |
| 1181 | struct hist_entry *he) \ |
| 1182 | { \ |
| 1183 | if (!symbol_conf.cumulate_callchain) { \ |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1184 | struct hpp_arg *arg = hpp->ptr; \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1185 | int len = fmt->user_len ?: fmt->len; \ |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 1186 | int ret = scnprintf(hpp->buf, hpp->size, \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1187 | "%*s", len, "N/A"); \ |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1188 | ui_browser__printf(arg->b, "%s", hpp->buf); \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1189 | \ |
| 1190 | return ret; \ |
| 1191 | } \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1192 | return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \ |
| 1193 | " %*.2f%%", __hpp__slsmg_color_printf, true); \ |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1194 | } |
| 1195 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 1196 | __HPP_COLOR_PERCENT_FN(overhead, period) |
| 1197 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) |
| 1198 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) |
| 1199 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) |
| 1200 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1201 | __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period) |
Namhyung Kim | 5aed9d2 | 2013-01-22 18:09:35 +0900 | [diff] [blame] | 1202 | |
| 1203 | #undef __HPP_COLOR_PERCENT_FN |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1204 | #undef __HPP_COLOR_ACC_PERCENT_FN |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1205 | |
| 1206 | void hist_browser__init_hpp(void) |
| 1207 | { |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1208 | perf_hpp__format[PERF_HPP__OVERHEAD].color = |
| 1209 | hist_browser__hpp_color_overhead; |
| 1210 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color = |
| 1211 | hist_browser__hpp_color_overhead_sys; |
| 1212 | perf_hpp__format[PERF_HPP__OVERHEAD_US].color = |
| 1213 | hist_browser__hpp_color_overhead_us; |
| 1214 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color = |
| 1215 | hist_browser__hpp_color_overhead_guest_sys; |
| 1216 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = |
| 1217 | hist_browser__hpp_color_overhead_guest_us; |
Namhyung Kim | 0434ddd | 2013-10-30 16:12:59 +0900 | [diff] [blame] | 1218 | perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color = |
| 1219 | hist_browser__hpp_color_overhead_acc; |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1220 | } |
| 1221 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1222 | static int hist_browser__show_entry(struct hist_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1223 | struct hist_entry *entry, |
| 1224 | unsigned short row) |
| 1225 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 1226 | int printed = 0; |
Namhyung Kim | 67d2591 | 2012-09-12 15:35:06 +0900 | [diff] [blame] | 1227 | int width = browser->b.width; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1228 | char folded_sign = ' '; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1229 | 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] | 1230 | off_t row_offset = entry->row_offset; |
Namhyung Kim | 63a1a3d | 2012-10-15 18:14:35 -0300 | [diff] [blame] | 1231 | bool first = true; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 1232 | struct perf_hpp_fmt *fmt; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1233 | |
| 1234 | if (current_entry) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1235 | browser->he_selection = entry; |
| 1236 | browser->selection = &entry->ms; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 163caed | 2010-08-25 16:30:03 -0300 | [diff] [blame] | 1240 | hist_entry__init_have_children(entry); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1241 | folded_sign = hist_entry__folded(entry); |
| 1242 | } |
| 1243 | |
| 1244 | if (row_offset == 0) { |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 1245 | struct hpp_arg arg = { |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 1246 | .b = &browser->b, |
Namhyung Kim | 8970146 | 2013-01-22 18:09:38 +0900 | [diff] [blame] | 1247 | .folded_sign = folded_sign, |
| 1248 | .current_entry = current_entry, |
| 1249 | }; |
Arnaldo Carvalho de Melo | c6c3c02 | 2015-08-11 17:22:43 -0300 | [diff] [blame] | 1250 | int column = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1251 | |
Arnaldo Carvalho de Melo | ca3ff33 | 2014-07-01 16:42:24 -0300 | [diff] [blame] | 1252 | hist_browser__gotorc(browser, row, 0); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1253 | |
Jiri Olsa | f0786af | 2016-01-18 10:24:23 +0100 | [diff] [blame] | 1254 | hists__for_each_format(browser->hists, fmt) { |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1255 | char s[2048]; |
| 1256 | struct perf_hpp hpp = { |
| 1257 | .buf = s, |
| 1258 | .size = sizeof(s), |
| 1259 | .ptr = &arg, |
| 1260 | }; |
| 1261 | |
Namhyung Kim | 361459f | 2015-12-23 02:07:08 +0900 | [diff] [blame] | 1262 | if (perf_hpp__should_skip(fmt, entry->hists) || |
| 1263 | column++ < browser->b.horiz_scroll) |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1264 | continue; |
| 1265 | |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 1266 | if (current_entry && browser->b.navkeypressed) { |
| 1267 | ui_browser__set_color(&browser->b, |
| 1268 | HE_COLORSET_SELECTED); |
| 1269 | } else { |
| 1270 | ui_browser__set_color(&browser->b, |
| 1271 | HE_COLORSET_NORMAL); |
| 1272 | } |
| 1273 | |
| 1274 | if (first) { |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 1275 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1276 | ui_browser__printf(&browser->b, "%c ", folded_sign); |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 1277 | width -= 2; |
| 1278 | } |
| 1279 | first = false; |
| 1280 | } else { |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1281 | ui_browser__printf(&browser->b, " "); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1282 | width -= 2; |
| 1283 | } |
| 1284 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 1285 | if (fmt->color) { |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1286 | int ret = fmt->color(fmt, &hpp, entry); |
| 1287 | hist_entry__snprintf_alignment(entry, &hpp, fmt, ret); |
| 1288 | /* |
| 1289 | * fmt->color() already used ui_browser to |
| 1290 | * print the non alignment bits, skip it (+ret): |
| 1291 | */ |
| 1292 | ui_browser__printf(&browser->b, "%s", s + ret); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1293 | } else { |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1294 | hist_entry__snprintf_alignment(entry, &hpp, fmt, fmt->entry(fmt, &hpp, entry)); |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 1295 | ui_browser__printf(&browser->b, "%s", s); |
Namhyung Kim | f5951d5 | 2012-09-03 11:53:09 +0900 | [diff] [blame] | 1296 | } |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1297 | width -= hpp.buf - s; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1298 | } |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 1299 | |
| 1300 | /* The scroll bar isn't being used */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1301 | if (!browser->b.navkeypressed) |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 1302 | width += 1; |
| 1303 | |
Arnaldo Carvalho de Melo | 26270a0 | 2015-08-11 12:24:27 -0300 | [diff] [blame] | 1304 | ui_browser__write_nstring(&browser->b, "", width); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1305 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1306 | ++row; |
| 1307 | ++printed; |
| 1308 | } else |
| 1309 | --row_offset; |
| 1310 | |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 1311 | if (folded_sign == '-' && row != browser->b.rows) { |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1312 | struct callchain_print_arg arg = { |
| 1313 | .row_offset = row_offset, |
| 1314 | .is_current_entry = current_entry, |
| 1315 | }; |
Namhyung Kim | c09a7e7 | 2014-08-21 10:15:45 +0900 | [diff] [blame] | 1316 | |
Milian Wolff | 2a704fc | 2017-10-09 22:32:55 +0200 | [diff] [blame] | 1317 | printed += hist_browser__show_callchain(browser, |
| 1318 | entry, 1, row, |
| 1319 | hist_browser__show_callchain_entry, |
| 1320 | &arg, |
| 1321 | hist_browser__check_output_full); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | return printed; |
| 1325 | } |
| 1326 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1327 | static int hist_browser__show_hierarchy_entry(struct hist_browser *browser, |
| 1328 | struct hist_entry *entry, |
| 1329 | unsigned short row, |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1330 | int level) |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1331 | { |
| 1332 | int printed = 0; |
| 1333 | int width = browser->b.width; |
| 1334 | char folded_sign = ' '; |
| 1335 | bool current_entry = ui_browser__is_current_entry(&browser->b, row); |
| 1336 | off_t row_offset = entry->row_offset; |
| 1337 | bool first = true; |
| 1338 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1339 | struct perf_hpp_list_node *fmt_node; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1340 | struct hpp_arg arg = { |
| 1341 | .b = &browser->b, |
| 1342 | .current_entry = current_entry, |
| 1343 | }; |
| 1344 | int column = 0; |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1345 | int hierarchy_indent = (entry->hists->nr_hpp_node - 2) * HIERARCHY_INDENT; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1346 | |
| 1347 | if (current_entry) { |
| 1348 | browser->he_selection = entry; |
| 1349 | browser->selection = &entry->ms; |
| 1350 | } |
| 1351 | |
| 1352 | hist_entry__init_have_children(entry); |
| 1353 | folded_sign = hist_entry__folded(entry); |
| 1354 | arg.folded_sign = folded_sign; |
| 1355 | |
| 1356 | if (entry->leaf && row_offset) { |
| 1357 | row_offset--; |
| 1358 | goto show_callchain; |
| 1359 | } |
| 1360 | |
| 1361 | hist_browser__gotorc(browser, row, 0); |
| 1362 | |
| 1363 | if (current_entry && browser->b.navkeypressed) |
| 1364 | ui_browser__set_color(&browser->b, HE_COLORSET_SELECTED); |
| 1365 | else |
| 1366 | ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); |
| 1367 | |
| 1368 | ui_browser__write_nstring(&browser->b, "", level * HIERARCHY_INDENT); |
| 1369 | width -= level * HIERARCHY_INDENT; |
| 1370 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1371 | /* the first hpp_list_node is for overhead columns */ |
| 1372 | fmt_node = list_first_entry(&entry->hists->hpp_formats, |
| 1373 | struct perf_hpp_list_node, list); |
| 1374 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1375 | char s[2048]; |
| 1376 | struct perf_hpp hpp = { |
| 1377 | .buf = s, |
| 1378 | .size = sizeof(s), |
| 1379 | .ptr = &arg, |
| 1380 | }; |
| 1381 | |
| 1382 | if (perf_hpp__should_skip(fmt, entry->hists) || |
| 1383 | column++ < browser->b.horiz_scroll) |
| 1384 | continue; |
| 1385 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1386 | if (current_entry && browser->b.navkeypressed) { |
| 1387 | ui_browser__set_color(&browser->b, |
| 1388 | HE_COLORSET_SELECTED); |
| 1389 | } else { |
| 1390 | ui_browser__set_color(&browser->b, |
| 1391 | HE_COLORSET_NORMAL); |
| 1392 | } |
| 1393 | |
| 1394 | if (first) { |
Namhyung Kim | 3d9f468 | 2016-11-08 22:08:30 +0900 | [diff] [blame] | 1395 | ui_browser__printf(&browser->b, "%c ", folded_sign); |
| 1396 | width -= 2; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1397 | first = false; |
| 1398 | } else { |
| 1399 | ui_browser__printf(&browser->b, " "); |
| 1400 | width -= 2; |
| 1401 | } |
| 1402 | |
| 1403 | if (fmt->color) { |
| 1404 | int ret = fmt->color(fmt, &hpp, entry); |
| 1405 | hist_entry__snprintf_alignment(entry, &hpp, fmt, ret); |
| 1406 | /* |
| 1407 | * fmt->color() already used ui_browser to |
| 1408 | * print the non alignment bits, skip it (+ret): |
| 1409 | */ |
| 1410 | ui_browser__printf(&browser->b, "%s", s + ret); |
| 1411 | } else { |
| 1412 | int ret = fmt->entry(fmt, &hpp, entry); |
| 1413 | hist_entry__snprintf_alignment(entry, &hpp, fmt, ret); |
| 1414 | ui_browser__printf(&browser->b, "%s", s); |
| 1415 | } |
| 1416 | width -= hpp.buf - s; |
| 1417 | } |
| 1418 | |
Namhyung Kim | b9bf911 | 2016-11-08 22:08:32 +0900 | [diff] [blame] | 1419 | if (!first) { |
| 1420 | ui_browser__write_nstring(&browser->b, "", hierarchy_indent); |
| 1421 | width -= hierarchy_indent; |
| 1422 | } |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1423 | |
| 1424 | if (column >= browser->b.horiz_scroll) { |
| 1425 | char s[2048]; |
| 1426 | struct perf_hpp hpp = { |
| 1427 | .buf = s, |
| 1428 | .size = sizeof(s), |
| 1429 | .ptr = &arg, |
| 1430 | }; |
| 1431 | |
| 1432 | if (current_entry && browser->b.navkeypressed) { |
| 1433 | ui_browser__set_color(&browser->b, |
| 1434 | HE_COLORSET_SELECTED); |
| 1435 | } else { |
| 1436 | ui_browser__set_color(&browser->b, |
| 1437 | HE_COLORSET_NORMAL); |
| 1438 | } |
| 1439 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1440 | perf_hpp_list__for_each_format(entry->hpp_list, fmt) { |
Namhyung Kim | 131d51e | 2016-11-08 22:08:31 +0900 | [diff] [blame] | 1441 | if (first) { |
| 1442 | ui_browser__printf(&browser->b, "%c ", folded_sign); |
| 1443 | first = false; |
| 1444 | } else { |
| 1445 | ui_browser__write_nstring(&browser->b, "", 2); |
| 1446 | } |
| 1447 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1448 | width -= 2; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1449 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1450 | /* |
| 1451 | * No need to call hist_entry__snprintf_alignment() |
| 1452 | * since this fmt is always the last column in the |
| 1453 | * hierarchy mode. |
| 1454 | */ |
| 1455 | if (fmt->color) { |
| 1456 | width -= fmt->color(fmt, &hpp, entry); |
| 1457 | } else { |
| 1458 | int i = 0; |
Namhyung Kim | cb1fab9 | 2016-02-27 03:52:45 +0900 | [diff] [blame] | 1459 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1460 | width -= fmt->entry(fmt, &hpp, entry); |
| 1461 | ui_browser__printf(&browser->b, "%s", ltrim(s)); |
Namhyung Kim | cb1fab9 | 2016-02-27 03:52:45 +0900 | [diff] [blame] | 1462 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1463 | while (isspace(s[i++])) |
| 1464 | width++; |
| 1465 | } |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | /* The scroll bar isn't being used */ |
| 1470 | if (!browser->b.navkeypressed) |
| 1471 | width += 1; |
| 1472 | |
| 1473 | ui_browser__write_nstring(&browser->b, "", width); |
| 1474 | |
| 1475 | ++row; |
| 1476 | ++printed; |
| 1477 | |
| 1478 | show_callchain: |
| 1479 | if (entry->leaf && folded_sign == '-' && row != browser->b.rows) { |
| 1480 | struct callchain_print_arg carg = { |
| 1481 | .row_offset = row_offset, |
| 1482 | }; |
| 1483 | |
| 1484 | printed += hist_browser__show_callchain(browser, entry, |
| 1485 | level + 1, row, |
| 1486 | hist_browser__show_callchain_entry, &carg, |
| 1487 | hist_browser__check_output_full); |
| 1488 | } |
| 1489 | |
| 1490 | return printed; |
| 1491 | } |
| 1492 | |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1493 | static int hist_browser__show_no_entry(struct hist_browser *browser, |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1494 | unsigned short row, int level) |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1495 | { |
| 1496 | int width = browser->b.width; |
| 1497 | bool current_entry = ui_browser__is_current_entry(&browser->b, row); |
| 1498 | bool first = true; |
| 1499 | int column = 0; |
| 1500 | int ret; |
| 1501 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1502 | struct perf_hpp_list_node *fmt_node; |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1503 | int indent = browser->hists->nr_hpp_node - 2; |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1504 | |
| 1505 | if (current_entry) { |
| 1506 | browser->he_selection = NULL; |
| 1507 | browser->selection = NULL; |
| 1508 | } |
| 1509 | |
| 1510 | hist_browser__gotorc(browser, row, 0); |
| 1511 | |
| 1512 | if (current_entry && browser->b.navkeypressed) |
| 1513 | ui_browser__set_color(&browser->b, HE_COLORSET_SELECTED); |
| 1514 | else |
| 1515 | ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); |
| 1516 | |
| 1517 | ui_browser__write_nstring(&browser->b, "", level * HIERARCHY_INDENT); |
| 1518 | width -= level * HIERARCHY_INDENT; |
| 1519 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1520 | /* the first hpp_list_node is for overhead columns */ |
| 1521 | fmt_node = list_first_entry(&browser->hists->hpp_formats, |
| 1522 | struct perf_hpp_list_node, list); |
| 1523 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1524 | if (perf_hpp__should_skip(fmt, browser->hists) || |
| 1525 | column++ < browser->b.horiz_scroll) |
| 1526 | continue; |
| 1527 | |
Jiri Olsa | da1b040 | 2016-06-14 20:19:20 +0200 | [diff] [blame] | 1528 | ret = fmt->width(fmt, NULL, browser->hists); |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1529 | |
| 1530 | if (first) { |
| 1531 | /* for folded sign */ |
| 1532 | first = false; |
| 1533 | ret++; |
| 1534 | } else { |
| 1535 | /* space between columns */ |
| 1536 | ret += 2; |
| 1537 | } |
| 1538 | |
| 1539 | ui_browser__write_nstring(&browser->b, "", ret); |
| 1540 | width -= ret; |
| 1541 | } |
| 1542 | |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1543 | ui_browser__write_nstring(&browser->b, "", indent * HIERARCHY_INDENT); |
| 1544 | width -= indent * HIERARCHY_INDENT; |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1545 | |
| 1546 | if (column >= browser->b.horiz_scroll) { |
| 1547 | char buf[32]; |
| 1548 | |
| 1549 | ret = snprintf(buf, sizeof(buf), "no entry >= %.2f%%", browser->min_pcnt); |
| 1550 | ui_browser__printf(&browser->b, " %s", buf); |
| 1551 | width -= ret + 2; |
| 1552 | } |
| 1553 | |
| 1554 | /* The scroll bar isn't being used */ |
| 1555 | if (!browser->b.navkeypressed) |
| 1556 | width += 1; |
| 1557 | |
| 1558 | ui_browser__write_nstring(&browser->b, "", width); |
| 1559 | return 1; |
| 1560 | } |
| 1561 | |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1562 | static int advance_hpp_check(struct perf_hpp *hpp, int inc) |
| 1563 | { |
| 1564 | advance_hpp(hpp, inc); |
| 1565 | return hpp->size <= 0; |
| 1566 | } |
| 1567 | |
Jiri Olsa | 69705b3 | 2016-08-07 17:28:28 +0200 | [diff] [blame] | 1568 | static int |
| 1569 | hists_browser__scnprintf_headers(struct hist_browser *browser, char *buf, |
| 1570 | size_t size, int line) |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1571 | { |
Arnaldo Carvalho de Melo | c6c3c02 | 2015-08-11 17:22:43 -0300 | [diff] [blame] | 1572 | struct hists *hists = browser->hists; |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1573 | struct perf_hpp dummy_hpp = { |
| 1574 | .buf = buf, |
| 1575 | .size = size, |
| 1576 | }; |
| 1577 | struct perf_hpp_fmt *fmt; |
| 1578 | size_t ret = 0; |
Arnaldo Carvalho de Melo | c6c3c02 | 2015-08-11 17:22:43 -0300 | [diff] [blame] | 1579 | int column = 0; |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1580 | int span = 0; |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1581 | |
| 1582 | if (symbol_conf.use_callchain) { |
| 1583 | ret = scnprintf(buf, size, " "); |
| 1584 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1585 | return ret; |
| 1586 | } |
| 1587 | |
Jiri Olsa | f0786af | 2016-01-18 10:24:23 +0100 | [diff] [blame] | 1588 | hists__for_each_format(browser->hists, fmt) { |
Namhyung Kim | 361459f | 2015-12-23 02:07:08 +0900 | [diff] [blame] | 1589 | if (perf_hpp__should_skip(fmt, hists) || column++ < browser->b.horiz_scroll) |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1590 | continue; |
| 1591 | |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1592 | ret = fmt->header(fmt, &dummy_hpp, hists, line, &span); |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1593 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1594 | break; |
| 1595 | |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1596 | if (span) |
| 1597 | continue; |
| 1598 | |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1599 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " "); |
| 1600 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1601 | break; |
| 1602 | } |
| 1603 | |
| 1604 | return ret; |
| 1605 | } |
| 1606 | |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1607 | static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *browser, char *buf, size_t size) |
| 1608 | { |
| 1609 | struct hists *hists = browser->hists; |
| 1610 | struct perf_hpp dummy_hpp = { |
| 1611 | .buf = buf, |
| 1612 | .size = size, |
| 1613 | }; |
| 1614 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1615 | struct perf_hpp_list_node *fmt_node; |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1616 | size_t ret = 0; |
| 1617 | int column = 0; |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1618 | int indent = hists->nr_hpp_node - 2; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1619 | bool first_node, first_col; |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1620 | |
Namhyung Kim | 3d9f468 | 2016-11-08 22:08:30 +0900 | [diff] [blame] | 1621 | ret = scnprintf(buf, size, " "); |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1622 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1623 | return ret; |
| 1624 | |
Namhyung Kim | b9bf911 | 2016-11-08 22:08:32 +0900 | [diff] [blame] | 1625 | first_node = true; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1626 | /* the first hpp_list_node is for overhead columns */ |
| 1627 | fmt_node = list_first_entry(&hists->hpp_formats, |
| 1628 | struct perf_hpp_list_node, list); |
| 1629 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1630 | if (column++ < browser->b.horiz_scroll) |
| 1631 | continue; |
| 1632 | |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1633 | ret = fmt->header(fmt, &dummy_hpp, hists, 0, NULL); |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1634 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1635 | break; |
| 1636 | |
| 1637 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " "); |
| 1638 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1639 | break; |
Namhyung Kim | b9bf911 | 2016-11-08 22:08:32 +0900 | [diff] [blame] | 1640 | |
| 1641 | first_node = false; |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1642 | } |
| 1643 | |
Namhyung Kim | b9bf911 | 2016-11-08 22:08:32 +0900 | [diff] [blame] | 1644 | if (!first_node) { |
| 1645 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "%*s", |
| 1646 | indent * HIERARCHY_INDENT, ""); |
| 1647 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1648 | return ret; |
| 1649 | } |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1650 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1651 | first_node = true; |
| 1652 | list_for_each_entry_continue(fmt_node, &hists->hpp_formats, list) { |
| 1653 | if (!first_node) { |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1654 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, " / "); |
| 1655 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1656 | break; |
| 1657 | } |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1658 | first_node = false; |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1659 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1660 | first_col = true; |
| 1661 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { |
| 1662 | char *start; |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1663 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1664 | if (perf_hpp__should_skip(fmt, hists)) |
| 1665 | continue; |
Namhyung Kim | cb1fab9 | 2016-02-27 03:52:45 +0900 | [diff] [blame] | 1666 | |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1667 | if (!first_col) { |
| 1668 | ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "+"); |
| 1669 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1670 | break; |
| 1671 | } |
| 1672 | first_col = false; |
Namhyung Kim | cb1fab9 | 2016-02-27 03:52:45 +0900 | [diff] [blame] | 1673 | |
Jiri Olsa | 29659ab | 2016-08-07 17:28:30 +0200 | [diff] [blame] | 1674 | ret = fmt->header(fmt, &dummy_hpp, hists, 0, NULL); |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1675 | dummy_hpp.buf[ret] = '\0'; |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1676 | |
Jiri Olsa | 7d6a7e7 | 2016-04-07 09:11:11 +0200 | [diff] [blame] | 1677 | start = trim(dummy_hpp.buf); |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1678 | ret = strlen(start); |
| 1679 | |
| 1680 | if (start != dummy_hpp.buf) |
| 1681 | memmove(dummy_hpp.buf, start, ret + 1); |
| 1682 | |
| 1683 | if (advance_hpp_check(&dummy_hpp, ret)) |
| 1684 | break; |
| 1685 | } |
Namhyung Kim | d8b9240 | 2016-02-25 00:13:46 +0900 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | return ret; |
| 1689 | } |
| 1690 | |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1691 | static void hists_browser__hierarchy_headers(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1692 | { |
Jiri Olsa | 81a888f | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1693 | char headers[1024]; |
| 1694 | |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1695 | hists_browser__scnprintf_hierarchy_headers(browser, headers, |
| 1696 | sizeof(headers)); |
| 1697 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1698 | ui_browser__gotorc(&browser->b, 0, 0); |
| 1699 | ui_browser__set_color(&browser->b, HE_COLORSET_ROOT); |
Arnaldo Carvalho de Melo | 26270a0 | 2015-08-11 12:24:27 -0300 | [diff] [blame] | 1700 | ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1); |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1701 | } |
| 1702 | |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1703 | static void hists_browser__headers(struct hist_browser *browser) |
| 1704 | { |
Jiri Olsa | 69705b3 | 2016-08-07 17:28:28 +0200 | [diff] [blame] | 1705 | struct hists *hists = browser->hists; |
| 1706 | struct perf_hpp_list *hpp_list = hists->hpp_list; |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1707 | |
Jiri Olsa | 69705b3 | 2016-08-07 17:28:28 +0200 | [diff] [blame] | 1708 | int line; |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1709 | |
Jiri Olsa | 69705b3 | 2016-08-07 17:28:28 +0200 | [diff] [blame] | 1710 | for (line = 0; line < hpp_list->nr_header_lines; line++) { |
| 1711 | char headers[1024]; |
| 1712 | |
| 1713 | hists_browser__scnprintf_headers(browser, headers, |
| 1714 | sizeof(headers), line); |
| 1715 | |
| 1716 | ui_browser__gotorc(&browser->b, line, 0); |
| 1717 | ui_browser__set_color(&browser->b, HE_COLORSET_ROOT); |
| 1718 | ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1); |
| 1719 | } |
Jiri Olsa | 01b4770 | 2016-06-14 20:19:13 +0200 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static void hist_browser__show_headers(struct hist_browser *browser) |
| 1723 | { |
| 1724 | if (symbol_conf.report_hierarchy) |
| 1725 | hists_browser__hierarchy_headers(browser); |
| 1726 | else |
| 1727 | hists_browser__headers(browser); |
| 1728 | } |
| 1729 | |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 1730 | static void ui_browser__hists_init_top(struct ui_browser *browser) |
| 1731 | { |
| 1732 | if (browser->top == NULL) { |
| 1733 | struct hist_browser *hb; |
| 1734 | |
| 1735 | hb = container_of(browser, struct hist_browser, b); |
| 1736 | browser->top = rb_first(&hb->hists->entries); |
| 1737 | } |
| 1738 | } |
| 1739 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1740 | static unsigned int hist_browser__refresh(struct ui_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1741 | { |
| 1742 | unsigned row = 0; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1743 | u16 header_offset = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1744 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1745 | struct hist_browser *hb = container_of(browser, struct hist_browser, b); |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 1746 | struct hists *hists = hb->hists; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1747 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1748 | if (hb->show_headers) { |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 1749 | struct perf_hpp_list *hpp_list = hists->hpp_list; |
| 1750 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1751 | hist_browser__show_headers(hb); |
Jiri Olsa | f8e6710 | 2016-08-07 17:28:26 +0200 | [diff] [blame] | 1752 | header_offset = hpp_list->nr_header_lines; |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1755 | ui_browser__hists_init_top(browser); |
Wang Nan | 979d2ca | 2015-12-07 02:35:46 +0000 | [diff] [blame] | 1756 | hb->he_selection = NULL; |
| 1757 | hb->selection = NULL; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1758 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1759 | for (nd = browser->top; nd; nd = rb_hierarchy_next(nd)) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1760 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1761 | float percent; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1762 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1763 | if (h->filtered) { |
| 1764 | /* let it move to sibling */ |
| 1765 | h->unfolded = false; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1766 | continue; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1767 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1768 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1769 | percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1770 | if (percent < hb->min_pcnt) |
| 1771 | continue; |
| 1772 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1773 | if (symbol_conf.report_hierarchy) { |
| 1774 | row += hist_browser__show_hierarchy_entry(hb, h, row, |
Namhyung Kim | 2dbbe9f | 2016-03-07 16:44:48 -0300 | [diff] [blame] | 1775 | h->depth); |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1776 | if (row == browser->rows) |
| 1777 | break; |
| 1778 | |
| 1779 | if (h->has_no_entry) { |
Namhyung Kim | a61a22f | 2016-03-07 16:44:50 -0300 | [diff] [blame] | 1780 | hist_browser__show_no_entry(hb, row, h->depth + 1); |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1781 | row++; |
| 1782 | } |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1783 | } else { |
| 1784 | row += hist_browser__show_entry(hb, h, row); |
| 1785 | } |
| 1786 | |
Arnaldo Carvalho de Melo | 62c95ae | 2014-07-01 11:07:54 -0300 | [diff] [blame] | 1787 | if (row == browser->rows) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1788 | break; |
| 1789 | } |
| 1790 | |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 1791 | return row + header_offset; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1792 | } |
| 1793 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1794 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1795 | float min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1796 | { |
| 1797 | while (nd != NULL) { |
| 1798 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1799 | float percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1800 | |
Namhyung Kim | c0f1527 | 2014-04-16 11:16:33 +0900 | [diff] [blame] | 1801 | if (!h->filtered && percent >= min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1802 | return nd; |
| 1803 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1804 | /* |
| 1805 | * If it's filtered, its all children also were filtered. |
| 1806 | * So move to sibling node. |
| 1807 | */ |
| 1808 | if (rb_next(nd)) |
| 1809 | nd = rb_next(nd); |
| 1810 | else |
| 1811 | nd = rb_hierarchy_next(nd); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | return NULL; |
| 1815 | } |
| 1816 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1817 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1818 | float min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1819 | { |
| 1820 | while (nd != NULL) { |
| 1821 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1822 | float percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1823 | |
| 1824 | if (!h->filtered && percent >= min_pcnt) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1825 | return nd; |
| 1826 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1827 | nd = rb_hierarchy_prev(nd); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | return NULL; |
| 1831 | } |
| 1832 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1833 | static void ui_browser__hists_seek(struct ui_browser *browser, |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1834 | off_t offset, int whence) |
| 1835 | { |
| 1836 | struct hist_entry *h; |
| 1837 | struct rb_node *nd; |
| 1838 | bool first = true; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1839 | struct hist_browser *hb; |
| 1840 | |
| 1841 | hb = container_of(browser, struct hist_browser, b); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1842 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1843 | if (browser->nr_entries == 0) |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 1844 | return; |
| 1845 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1846 | ui_browser__hists_init_top(browser); |
Arnaldo Carvalho de Melo | 437cfe7 | 2011-10-14 09:31:53 -0300 | [diff] [blame] | 1847 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1848 | switch (whence) { |
| 1849 | case SEEK_SET: |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1850 | nd = hists__filter_entries(rb_first(browser->entries), |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 1851 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1852 | break; |
| 1853 | case SEEK_CUR: |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1854 | nd = browser->top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1855 | goto do_offset; |
| 1856 | case SEEK_END: |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1857 | nd = rb_hierarchy_last(rb_last(browser->entries)); |
| 1858 | nd = hists__filter_prev_entries(nd, hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1859 | first = false; |
| 1860 | break; |
| 1861 | default: |
| 1862 | return; |
| 1863 | } |
| 1864 | |
| 1865 | /* |
| 1866 | * Moves not relative to the first visible entry invalidates its |
| 1867 | * row_offset: |
| 1868 | */ |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1869 | h = rb_entry(browser->top, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1870 | h->row_offset = 0; |
| 1871 | |
| 1872 | /* |
| 1873 | * Here we have to check if nd is expanded (+), if it is we can't go |
| 1874 | * the next top level hist_entry, instead we must compute an offset of |
| 1875 | * what _not_ to show and not change the first visible entry. |
| 1876 | * |
| 1877 | * This offset increments when we are going from top to bottom and |
| 1878 | * decreases when we're going from bottom to top. |
| 1879 | * |
| 1880 | * As we don't have backpointers to the top level in the callchains |
| 1881 | * structure, we need to always print the whole hist_entry callchain, |
| 1882 | * skipping the first ones that are before the first visible entry |
| 1883 | * and stop when we printed enough lines to fill the screen. |
| 1884 | */ |
| 1885 | do_offset: |
Wang Nan | 837eeb7 | 2015-12-07 02:35:45 +0000 | [diff] [blame] | 1886 | if (!nd) |
| 1887 | return; |
| 1888 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1889 | if (offset > 0) { |
| 1890 | do { |
| 1891 | h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1892 | if (h->unfolded && h->leaf) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1893 | u16 remaining = h->nr_rows - h->row_offset; |
| 1894 | if (offset > remaining) { |
| 1895 | offset -= remaining; |
| 1896 | h->row_offset = 0; |
| 1897 | } else { |
| 1898 | h->row_offset += offset; |
| 1899 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1900 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1901 | break; |
| 1902 | } |
| 1903 | } |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1904 | nd = hists__filter_entries(rb_hierarchy_next(nd), |
| 1905 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1906 | if (nd == NULL) |
| 1907 | break; |
| 1908 | --offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1909 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1910 | } while (offset != 0); |
| 1911 | } else if (offset < 0) { |
| 1912 | while (1) { |
| 1913 | h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1914 | if (h->unfolded && h->leaf) { |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1915 | if (first) { |
| 1916 | if (-offset > h->row_offset) { |
| 1917 | offset += h->row_offset; |
| 1918 | h->row_offset = 0; |
| 1919 | } else { |
| 1920 | h->row_offset += offset; |
| 1921 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1922 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1923 | break; |
| 1924 | } |
| 1925 | } else { |
| 1926 | if (-offset > h->nr_rows) { |
| 1927 | offset += h->nr_rows; |
| 1928 | h->row_offset = 0; |
| 1929 | } else { |
| 1930 | h->row_offset = h->nr_rows + offset; |
| 1931 | offset = 0; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1932 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1933 | break; |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1938 | nd = hists__filter_prev_entries(rb_hierarchy_prev(nd), |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 1939 | hb->min_pcnt); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1940 | if (nd == NULL) |
| 1941 | break; |
| 1942 | ++offset; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1943 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1944 | if (offset == 0) { |
| 1945 | /* |
| 1946 | * Last unfiltered hist_entry, check if it is |
| 1947 | * unfolded, if it is then we should have |
| 1948 | * row_offset at its last entry. |
| 1949 | */ |
| 1950 | h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1951 | if (h->unfolded && h->leaf) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1952 | h->row_offset = h->nr_rows; |
| 1953 | break; |
| 1954 | } |
| 1955 | first = false; |
| 1956 | } |
| 1957 | } else { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 1958 | browser->top = nd; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 1959 | h = rb_entry(nd, struct hist_entry, rb_node); |
| 1960 | h->row_offset = 0; |
| 1961 | } |
| 1962 | } |
| 1963 | |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1964 | static int hist_browser__fprintf_callchain(struct hist_browser *browser, |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1965 | struct hist_entry *he, FILE *fp, |
| 1966 | int level) |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1967 | { |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1968 | struct callchain_print_arg arg = { |
| 1969 | .fp = fp, |
| 1970 | }; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1971 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 1972 | hist_browser__show_callchain(browser, he, level, 0, |
Namhyung Kim | 39ee533 | 2014-08-22 09:13:21 +0900 | [diff] [blame] | 1973 | hist_browser__fprintf_callchain_entry, &arg, |
| 1974 | hist_browser__check_dump_full); |
| 1975 | return arg.printed; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | static int hist_browser__fprintf_entry(struct hist_browser *browser, |
| 1979 | struct hist_entry *he, FILE *fp) |
| 1980 | { |
| 1981 | char s[8192]; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1982 | int printed = 0; |
| 1983 | char folded_sign = ' '; |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1984 | struct perf_hpp hpp = { |
| 1985 | .buf = s, |
| 1986 | .size = sizeof(s), |
| 1987 | }; |
| 1988 | struct perf_hpp_fmt *fmt; |
| 1989 | bool first = true; |
| 1990 | int ret; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1991 | |
Arnaldo Carvalho de Melo | 1b6b678 | 2016-04-18 12:24:41 -0300 | [diff] [blame] | 1992 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1993 | folded_sign = hist_entry__folded(he); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1994 | printed += fprintf(fp, "%c ", folded_sign); |
Arnaldo Carvalho de Melo | 1b6b678 | 2016-04-18 12:24:41 -0300 | [diff] [blame] | 1995 | } |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 1996 | |
Jiri Olsa | f0786af | 2016-01-18 10:24:23 +0100 | [diff] [blame] | 1997 | hists__for_each_format(browser->hists, fmt) { |
Namhyung Kim | 361459f | 2015-12-23 02:07:08 +0900 | [diff] [blame] | 1998 | if (perf_hpp__should_skip(fmt, he->hists)) |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1999 | continue; |
| 2000 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 2001 | if (!first) { |
| 2002 | ret = scnprintf(hpp.buf, hpp.size, " "); |
| 2003 | advance_hpp(&hpp, ret); |
| 2004 | } else |
| 2005 | first = false; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2006 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 2007 | ret = fmt->entry(fmt, &hpp, he); |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 2008 | ret = hist_entry__snprintf_alignment(he, &hpp, fmt, ret); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 2009 | advance_hpp(&hpp, ret); |
| 2010 | } |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 2011 | printed += fprintf(fp, "%s\n", s); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2012 | |
| 2013 | if (folded_sign == '-') |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2014 | printed += hist_browser__fprintf_callchain(browser, he, fp, 1); |
| 2015 | |
| 2016 | return printed; |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | static int hist_browser__fprintf_hierarchy_entry(struct hist_browser *browser, |
| 2021 | struct hist_entry *he, |
Namhyung Kim | 325a628 | 2016-03-09 22:47:00 +0900 | [diff] [blame] | 2022 | FILE *fp, int level) |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2023 | { |
| 2024 | char s[8192]; |
| 2025 | int printed = 0; |
| 2026 | char folded_sign = ' '; |
| 2027 | struct perf_hpp hpp = { |
| 2028 | .buf = s, |
| 2029 | .size = sizeof(s), |
| 2030 | }; |
| 2031 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 325a628 | 2016-03-09 22:47:00 +0900 | [diff] [blame] | 2032 | struct perf_hpp_list_node *fmt_node; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2033 | bool first = true; |
| 2034 | int ret; |
Namhyung Kim | 325a628 | 2016-03-09 22:47:00 +0900 | [diff] [blame] | 2035 | int hierarchy_indent = (he->hists->nr_hpp_node - 2) * HIERARCHY_INDENT; |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2036 | |
| 2037 | printed = fprintf(fp, "%*s", level * HIERARCHY_INDENT, ""); |
| 2038 | |
| 2039 | folded_sign = hist_entry__folded(he); |
| 2040 | printed += fprintf(fp, "%c", folded_sign); |
| 2041 | |
Namhyung Kim | 325a628 | 2016-03-09 22:47:00 +0900 | [diff] [blame] | 2042 | /* the first hpp_list_node is for overhead columns */ |
| 2043 | fmt_node = list_first_entry(&he->hists->hpp_formats, |
| 2044 | struct perf_hpp_list_node, list); |
| 2045 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) { |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2046 | if (!first) { |
| 2047 | ret = scnprintf(hpp.buf, hpp.size, " "); |
| 2048 | advance_hpp(&hpp, ret); |
| 2049 | } else |
| 2050 | first = false; |
| 2051 | |
| 2052 | ret = fmt->entry(fmt, &hpp, he); |
| 2053 | advance_hpp(&hpp, ret); |
| 2054 | } |
| 2055 | |
| 2056 | ret = scnprintf(hpp.buf, hpp.size, "%*s", hierarchy_indent, ""); |
| 2057 | advance_hpp(&hpp, ret); |
| 2058 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 2059 | perf_hpp_list__for_each_format(he->hpp_list, fmt) { |
| 2060 | ret = scnprintf(hpp.buf, hpp.size, " "); |
| 2061 | advance_hpp(&hpp, ret); |
| 2062 | |
| 2063 | ret = fmt->entry(fmt, &hpp, he); |
| 2064 | advance_hpp(&hpp, ret); |
| 2065 | } |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2066 | |
| 2067 | printed += fprintf(fp, "%s\n", rtrim(s)); |
| 2068 | |
| 2069 | if (he->leaf && folded_sign == '-') { |
| 2070 | printed += hist_browser__fprintf_callchain(browser, he, fp, |
| 2071 | he->depth + 1); |
| 2072 | } |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2073 | |
| 2074 | return printed; |
| 2075 | } |
| 2076 | |
| 2077 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) |
| 2078 | { |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2079 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries), |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2080 | browser->min_pcnt); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2081 | int printed = 0; |
| 2082 | |
| 2083 | while (nd) { |
| 2084 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 2085 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2086 | if (symbol_conf.report_hierarchy) { |
| 2087 | printed += hist_browser__fprintf_hierarchy_entry(browser, |
| 2088 | h, fp, |
Namhyung Kim | 325a628 | 2016-03-09 22:47:00 +0900 | [diff] [blame] | 2089 | h->depth); |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2090 | } else { |
| 2091 | printed += hist_browser__fprintf_entry(browser, h, fp); |
| 2092 | } |
| 2093 | |
| 2094 | nd = hists__filter_entries(rb_hierarchy_next(nd), |
| 2095 | browser->min_pcnt); |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | return printed; |
| 2099 | } |
| 2100 | |
| 2101 | static int hist_browser__dump(struct hist_browser *browser) |
| 2102 | { |
| 2103 | char filename[64]; |
| 2104 | FILE *fp; |
| 2105 | |
| 2106 | while (1) { |
| 2107 | scnprintf(filename, sizeof(filename), "perf.hist.%d", browser->print_seq); |
| 2108 | if (access(filename, F_OK)) |
| 2109 | break; |
| 2110 | /* |
| 2111 | * XXX: Just an arbitrary lazy upper limit |
| 2112 | */ |
| 2113 | if (++browser->print_seq == 8192) { |
| 2114 | ui_helpline__fpush("Too many perf.hist.N files, nothing written!"); |
| 2115 | return -1; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | fp = fopen(filename, "w"); |
| 2120 | if (fp == NULL) { |
| 2121 | char bf[64]; |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 2122 | const char *err = str_error_r(errno, bf, sizeof(bf)); |
Kirill A. Shutemov | 4cc49d4 | 2012-07-24 00:06:54 +0300 | [diff] [blame] | 2123 | 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] | 2124 | return -1; |
| 2125 | } |
| 2126 | |
| 2127 | ++browser->print_seq; |
| 2128 | hist_browser__fprintf(browser, fp); |
| 2129 | fclose(fp); |
| 2130 | ui_helpline__fpush("%s written!", filename); |
| 2131 | |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
Jiri Olsa | fcd8642 | 2016-06-20 23:58:18 +0200 | [diff] [blame] | 2135 | void hist_browser__init(struct hist_browser *browser, |
| 2136 | struct hists *hists) |
| 2137 | { |
| 2138 | struct perf_hpp_fmt *fmt; |
| 2139 | |
| 2140 | browser->hists = hists; |
| 2141 | browser->b.refresh = hist_browser__refresh; |
| 2142 | browser->b.refresh_dimensions = hist_browser__refresh_dimensions; |
| 2143 | browser->b.seek = ui_browser__hists_seek; |
| 2144 | browser->b.use_navkeypressed = true; |
| 2145 | browser->show_headers = symbol_conf.show_hist_headers; |
| 2146 | |
Namhyung Kim | 8a06b0b | 2016-10-25 01:21:10 +0900 | [diff] [blame] | 2147 | if (symbol_conf.report_hierarchy) { |
| 2148 | struct perf_hpp_list_node *fmt_node; |
| 2149 | |
| 2150 | /* count overhead columns (in the first node) */ |
| 2151 | fmt_node = list_first_entry(&hists->hpp_formats, |
| 2152 | struct perf_hpp_list_node, list); |
| 2153 | perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) |
| 2154 | ++browser->b.columns; |
| 2155 | |
| 2156 | /* add a single column for whole hierarchy sort keys*/ |
Jiri Olsa | fcd8642 | 2016-06-20 23:58:18 +0200 | [diff] [blame] | 2157 | ++browser->b.columns; |
Namhyung Kim | 8a06b0b | 2016-10-25 01:21:10 +0900 | [diff] [blame] | 2158 | } else { |
| 2159 | hists__for_each_format(hists, fmt) |
| 2160 | ++browser->b.columns; |
| 2161 | } |
Namhyung Kim | e3b60bc | 2016-09-20 14:30:24 +0900 | [diff] [blame] | 2162 | |
| 2163 | hists__reset_column_width(hists); |
Jiri Olsa | fcd8642 | 2016-06-20 23:58:18 +0200 | [diff] [blame] | 2164 | } |
| 2165 | |
Jiri Olsa | a6ec894 | 2016-06-20 23:58:17 +0200 | [diff] [blame] | 2166 | struct hist_browser *hist_browser__new(struct hists *hists) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2167 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2168 | struct hist_browser *browser = zalloc(sizeof(*browser)); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2169 | |
Jiri Olsa | fcd8642 | 2016-06-20 23:58:18 +0200 | [diff] [blame] | 2170 | if (browser) |
| 2171 | hist_browser__init(browser, hists); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2172 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2173 | return browser; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2174 | } |
| 2175 | |
Jiri Olsa | a6ec894 | 2016-06-20 23:58:17 +0200 | [diff] [blame] | 2176 | static struct hist_browser * |
| 2177 | perf_evsel_browser__new(struct perf_evsel *evsel, |
| 2178 | struct hist_browser_timer *hbt, |
| 2179 | struct perf_env *env) |
| 2180 | { |
| 2181 | struct hist_browser *browser = hist_browser__new(evsel__hists(evsel)); |
| 2182 | |
| 2183 | if (browser) { |
| 2184 | browser->hbt = hbt; |
| 2185 | browser->env = env; |
| 2186 | browser->title = perf_evsel_browser_title; |
| 2187 | } |
| 2188 | return browser; |
| 2189 | } |
| 2190 | |
Jiri Olsa | dabd201 | 2016-06-20 23:58:14 +0200 | [diff] [blame] | 2191 | void hist_browser__delete(struct hist_browser *browser) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2192 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2193 | free(browser); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2194 | } |
| 2195 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2196 | 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] | 2197 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2198 | return browser->he_selection; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2199 | } |
| 2200 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2201 | 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] | 2202 | { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2203 | return browser->he_selection->thread; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2204 | } |
| 2205 | |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 2206 | /* Check whether the browser is for 'top' or 'report' */ |
| 2207 | static inline bool is_report_browser(void *timer) |
| 2208 | { |
| 2209 | return timer == NULL; |
| 2210 | } |
| 2211 | |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 2212 | static int perf_evsel_browser_title(struct hist_browser *browser, |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 2213 | char *bf, size_t size) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2214 | { |
Jiri Olsa | 5b91a86 | 2016-06-20 23:58:15 +0200 | [diff] [blame] | 2215 | struct hist_browser_timer *hbt = browser->hbt; |
| 2216 | struct hists *hists = browser->hists; |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 2217 | char unit; |
| 2218 | int printed; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2219 | const struct dso *dso = hists->dso_filter; |
| 2220 | const struct thread *thread = hists->thread_filter; |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2221 | int socket_id = hists->socket_filter; |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2222 | unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 2223 | u64 nr_events = hists->stats.total_period; |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 2224 | struct perf_evsel *evsel = hists_to_evsel(hists); |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 2225 | const char *ev_name = perf_evsel__name(evsel); |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 2226 | char buf[512]; |
| 2227 | size_t buflen = sizeof(buf); |
Kan Liang | 9e207dd | 2015-08-11 06:30:49 -0400 | [diff] [blame] | 2228 | char ref[30] = " show reference callgraph, "; |
| 2229 | bool enable_ref = false; |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 2230 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2231 | if (symbol_conf.filter_relative) { |
| 2232 | nr_samples = hists->stats.nr_non_filtered_samples; |
| 2233 | nr_events = hists->stats.total_non_filtered_period; |
| 2234 | } |
| 2235 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 2236 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 2237 | struct perf_evsel *pos; |
| 2238 | |
| 2239 | perf_evsel__group_desc(evsel, buf, buflen); |
| 2240 | ev_name = buf; |
| 2241 | |
| 2242 | for_each_group_member(pos, evsel) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 2243 | struct hists *pos_hists = evsel__hists(pos); |
| 2244 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2245 | if (symbol_conf.filter_relative) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 2246 | nr_samples += pos_hists->stats.nr_non_filtered_samples; |
| 2247 | nr_events += pos_hists->stats.total_non_filtered_period; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2248 | } else { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 2249 | nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
| 2250 | nr_events += pos_hists->stats.total_period; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2251 | } |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 2252 | } |
| 2253 | } |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 2254 | |
Kan Liang | 9e207dd | 2015-08-11 06:30:49 -0400 | [diff] [blame] | 2255 | if (symbol_conf.show_ref_callgraph && |
| 2256 | strstr(ev_name, "call-graph=no")) |
| 2257 | enable_ref = true; |
Ashay Rane | cc686280 | 2012-04-05 21:01:01 -0500 | [diff] [blame] | 2258 | nr_samples = convert_unit(nr_samples, &unit); |
| 2259 | printed = scnprintf(bf, size, |
Kan Liang | 9e207dd | 2015-08-11 06:30:49 -0400 | [diff] [blame] | 2260 | "Samples: %lu%c of event '%s',%sEvent count (approx.): %" PRIu64, |
| 2261 | nr_samples, unit, ev_name, enable_ref ? ref : " ", nr_events); |
Ashay Rane | cc686280 | 2012-04-05 21:01:01 -0500 | [diff] [blame] | 2262 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2263 | |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2264 | if (hists->uid_filter_str) |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 2265 | printed += snprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2266 | ", UID: %s", hists->uid_filter_str); |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2267 | if (thread) { |
Jiri Olsa | fa82911 | 2016-05-03 13:54:47 +0200 | [diff] [blame] | 2268 | if (hists__has(hists, thread)) { |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2269 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 2270 | ", Thread: %s(%d)", |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 2271 | (thread->comm_set ? thread__comm_str(thread) : ""), |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 2272 | thread->tid); |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2273 | } else { |
| 2274 | printed += scnprintf(bf + printed, size - printed, |
| 2275 | ", Thread: %s", |
| 2276 | (thread->comm_set ? thread__comm_str(thread) : "")); |
| 2277 | } |
| 2278 | } |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2279 | if (dso) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 2280 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 2281 | ", DSO: %s", dso->short_name); |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2282 | if (socket_id > -1) |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 2283 | printed += scnprintf(bf + printed, size - printed, |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2284 | ", Processor Socket: %d", socket_id); |
Taeung Song | 1e378eb | 2014-10-07 16:13:15 +0900 | [diff] [blame] | 2285 | if (!is_report_browser(hbt)) { |
| 2286 | struct perf_top *top = hbt->arg; |
| 2287 | |
| 2288 | if (top->zero) |
| 2289 | printed += scnprintf(bf + printed, size - printed, " [z]"); |
| 2290 | } |
| 2291 | |
Arnaldo Carvalho de Melo | 469917c | 2010-09-13 10:25:04 -0300 | [diff] [blame] | 2292 | return printed; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2293 | } |
| 2294 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2295 | static inline void free_popup_options(char **options, int n) |
| 2296 | { |
| 2297 | int i; |
| 2298 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 2299 | for (i = 0; i < n; ++i) |
| 2300 | zfree(&options[i]); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2303 | /* |
| 2304 | * Only runtime switching of perf data file will make "input_name" point |
| 2305 | * to a malloced buffer. So add "is_input_name_malloced" flag to decide |
| 2306 | * whether we need to call free() for current "input_name" during the switch. |
| 2307 | */ |
| 2308 | static bool is_input_name_malloced = false; |
| 2309 | |
| 2310 | static int switch_data_file(void) |
| 2311 | { |
| 2312 | char *pwd, *options[32], *abs_path[32], *tmp; |
| 2313 | DIR *pwd_dir; |
| 2314 | int nr_options = 0, choice = -1, ret = -1; |
| 2315 | struct dirent *dent; |
| 2316 | |
| 2317 | pwd = getenv("PWD"); |
| 2318 | if (!pwd) |
| 2319 | return ret; |
| 2320 | |
| 2321 | pwd_dir = opendir(pwd); |
| 2322 | if (!pwd_dir) |
| 2323 | return ret; |
| 2324 | |
| 2325 | memset(options, 0, sizeof(options)); |
Changbin Du | 3ef5b40 | 2017-03-13 19:46:52 +0800 | [diff] [blame] | 2326 | memset(abs_path, 0, sizeof(abs_path)); |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2327 | |
| 2328 | while ((dent = readdir(pwd_dir))) { |
| 2329 | char path[PATH_MAX]; |
| 2330 | u64 magic; |
| 2331 | char *name = dent->d_name; |
| 2332 | FILE *file; |
| 2333 | |
| 2334 | if (!(dent->d_type == DT_REG)) |
| 2335 | continue; |
| 2336 | |
| 2337 | snprintf(path, sizeof(path), "%s/%s", pwd, name); |
| 2338 | |
| 2339 | file = fopen(path, "r"); |
| 2340 | if (!file) |
| 2341 | continue; |
| 2342 | |
| 2343 | if (fread(&magic, 1, 8, file) < 8) |
| 2344 | goto close_file_and_continue; |
| 2345 | |
| 2346 | if (is_perf_magic(magic)) { |
| 2347 | options[nr_options] = strdup(name); |
| 2348 | if (!options[nr_options]) |
| 2349 | goto close_file_and_continue; |
| 2350 | |
| 2351 | abs_path[nr_options] = strdup(path); |
| 2352 | if (!abs_path[nr_options]) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 2353 | zfree(&options[nr_options]); |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2354 | ui__warning("Can't search all data files due to memory shortage.\n"); |
| 2355 | fclose(file); |
| 2356 | break; |
| 2357 | } |
| 2358 | |
| 2359 | nr_options++; |
| 2360 | } |
| 2361 | |
| 2362 | close_file_and_continue: |
| 2363 | fclose(file); |
| 2364 | if (nr_options >= 32) { |
| 2365 | ui__warning("Too many perf data files in PWD!\n" |
| 2366 | "Only the first 32 files will be listed.\n"); |
| 2367 | break; |
| 2368 | } |
| 2369 | } |
| 2370 | closedir(pwd_dir); |
| 2371 | |
| 2372 | if (nr_options) { |
| 2373 | choice = ui__popup_menu(nr_options, options); |
| 2374 | if (choice < nr_options && choice >= 0) { |
| 2375 | tmp = strdup(abs_path[choice]); |
| 2376 | if (tmp) { |
| 2377 | if (is_input_name_malloced) |
| 2378 | free((void *)input_name); |
| 2379 | input_name = tmp; |
| 2380 | is_input_name_malloced = true; |
| 2381 | ret = 0; |
| 2382 | } else |
| 2383 | ui__warning("Data switch failed due to memory shortage!\n"); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | free_popup_options(options, nr_options); |
| 2388 | free_popup_options(abs_path, nr_options); |
| 2389 | return ret; |
| 2390 | } |
| 2391 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2392 | struct popup_action { |
| 2393 | struct thread *thread; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2394 | struct map_symbol ms; |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2395 | int socket; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2396 | |
| 2397 | int (*fn)(struct hist_browser *browser, struct popup_action *act); |
| 2398 | }; |
| 2399 | |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2400 | static int |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2401 | do_annotate(struct hist_browser *browser, struct popup_action *act) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2402 | { |
| 2403 | struct perf_evsel *evsel; |
| 2404 | struct annotation *notes; |
| 2405 | struct hist_entry *he; |
| 2406 | int err; |
| 2407 | |
Arnaldo Carvalho de Melo | eebd0bf | 2015-09-08 15:52:20 -0300 | [diff] [blame] | 2408 | if (!objdump_path && perf_env__lookup_objdump(browser->env)) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2409 | return 0; |
| 2410 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2411 | notes = symbol__annotation(act->ms.sym); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2412 | if (!notes->src) |
| 2413 | return 0; |
| 2414 | |
| 2415 | evsel = hists_to_evsel(browser->hists); |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2416 | err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2417 | he = hist_browser__selected_entry(browser); |
| 2418 | /* |
| 2419 | * offer option to annotate the other branch source or target |
| 2420 | * (if they exists) when returning from annotate |
| 2421 | */ |
| 2422 | if ((err == 'q' || err == CTRL('c')) && he->branch_info) |
| 2423 | return 1; |
| 2424 | |
| 2425 | ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); |
| 2426 | if (err) |
| 2427 | ui_browser__handle_resize(&browser->b); |
| 2428 | return 0; |
| 2429 | } |
| 2430 | |
| 2431 | static int |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2432 | add_annotate_opt(struct hist_browser *browser __maybe_unused, |
| 2433 | struct popup_action *act, char **optstr, |
| 2434 | struct map *map, struct symbol *sym) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2435 | { |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2436 | if (sym == NULL || map->dso->annotate_warned) |
| 2437 | return 0; |
| 2438 | |
| 2439 | if (asprintf(optstr, "Annotate %s", sym->name) < 0) |
| 2440 | return 0; |
| 2441 | |
| 2442 | act->ms.map = map; |
| 2443 | act->ms.sym = sym; |
| 2444 | act->fn = do_annotate; |
| 2445 | return 1; |
| 2446 | } |
| 2447 | |
| 2448 | static int |
| 2449 | do_zoom_thread(struct hist_browser *browser, struct popup_action *act) |
| 2450 | { |
| 2451 | struct thread *thread = act->thread; |
| 2452 | |
Jiri Olsa | 7cecb7f | 2016-05-03 13:54:48 +0200 | [diff] [blame] | 2453 | if ((!hists__has(browser->hists, thread) && |
| 2454 | !hists__has(browser->hists, comm)) || thread == NULL) |
Namhyung Kim | 599a2f3 | 2016-03-09 23:20:53 +0900 | [diff] [blame] | 2455 | return 0; |
| 2456 | |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2457 | if (browser->hists->thread_filter) { |
| 2458 | pstack__remove(browser->pstack, &browser->hists->thread_filter); |
| 2459 | perf_hpp__set_elide(HISTC_THREAD, false); |
| 2460 | thread__zput(browser->hists->thread_filter); |
| 2461 | ui_helpline__pop(); |
| 2462 | } else { |
Jiri Olsa | fa82911 | 2016-05-03 13:54:47 +0200 | [diff] [blame] | 2463 | if (hists__has(browser->hists, thread)) { |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2464 | ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"", |
| 2465 | thread->comm_set ? thread__comm_str(thread) : "", |
| 2466 | thread->tid); |
| 2467 | } else { |
| 2468 | ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"", |
| 2469 | thread->comm_set ? thread__comm_str(thread) : ""); |
| 2470 | } |
| 2471 | |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2472 | browser->hists->thread_filter = thread__get(thread); |
| 2473 | perf_hpp__set_elide(HISTC_THREAD, false); |
| 2474 | pstack__push(browser->pstack, &browser->hists->thread_filter); |
| 2475 | } |
| 2476 | |
| 2477 | hists__filter_by_thread(browser->hists); |
| 2478 | hist_browser__reset(browser); |
| 2479 | return 0; |
| 2480 | } |
| 2481 | |
| 2482 | static int |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2483 | add_thread_opt(struct hist_browser *browser, struct popup_action *act, |
| 2484 | char **optstr, struct thread *thread) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2485 | { |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2486 | int ret; |
| 2487 | |
Jiri Olsa | 7cecb7f | 2016-05-03 13:54:48 +0200 | [diff] [blame] | 2488 | if ((!hists__has(browser->hists, thread) && |
| 2489 | !hists__has(browser->hists, comm)) || thread == NULL) |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2490 | return 0; |
| 2491 | |
Jiri Olsa | fa82911 | 2016-05-03 13:54:47 +0200 | [diff] [blame] | 2492 | if (hists__has(browser->hists, thread)) { |
Namhyung Kim | 6962ccb | 2016-03-10 00:14:50 +0900 | [diff] [blame] | 2493 | ret = asprintf(optstr, "Zoom %s %s(%d) thread", |
| 2494 | browser->hists->thread_filter ? "out of" : "into", |
| 2495 | thread->comm_set ? thread__comm_str(thread) : "", |
| 2496 | thread->tid); |
| 2497 | } else { |
| 2498 | ret = asprintf(optstr, "Zoom %s %s thread", |
| 2499 | browser->hists->thread_filter ? "out of" : "into", |
| 2500 | thread->comm_set ? thread__comm_str(thread) : ""); |
| 2501 | } |
| 2502 | if (ret < 0) |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2503 | return 0; |
| 2504 | |
| 2505 | act->thread = thread; |
| 2506 | act->fn = do_zoom_thread; |
| 2507 | return 1; |
| 2508 | } |
| 2509 | |
| 2510 | static int |
| 2511 | do_zoom_dso(struct hist_browser *browser, struct popup_action *act) |
| 2512 | { |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2513 | struct map *map = act->ms.map; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2514 | |
Jiri Olsa | 69849fc | 2016-05-03 13:54:45 +0200 | [diff] [blame] | 2515 | if (!hists__has(browser->hists, dso) || map == NULL) |
Namhyung Kim | 599a2f3 | 2016-03-09 23:20:53 +0900 | [diff] [blame] | 2516 | return 0; |
| 2517 | |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2518 | if (browser->hists->dso_filter) { |
| 2519 | pstack__remove(browser->pstack, &browser->hists->dso_filter); |
| 2520 | perf_hpp__set_elide(HISTC_DSO, false); |
| 2521 | browser->hists->dso_filter = NULL; |
| 2522 | ui_helpline__pop(); |
| 2523 | } else { |
Arnaldo Carvalho de Melo | 7727a92 | 2015-10-12 13:56:50 -0300 | [diff] [blame] | 2524 | ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"", |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2525 | __map__is_kernel(map) ? "the Kernel" : map->dso->short_name); |
| 2526 | browser->hists->dso_filter = map->dso; |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2527 | perf_hpp__set_elide(HISTC_DSO, true); |
| 2528 | pstack__push(browser->pstack, &browser->hists->dso_filter); |
| 2529 | } |
| 2530 | |
| 2531 | hists__filter_by_dso(browser->hists); |
| 2532 | hist_browser__reset(browser); |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
| 2536 | static int |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2537 | add_dso_opt(struct hist_browser *browser, struct popup_action *act, |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2538 | char **optstr, struct map *map) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2539 | { |
Jiri Olsa | 69849fc | 2016-05-03 13:54:45 +0200 | [diff] [blame] | 2540 | if (!hists__has(browser->hists, dso) || map == NULL) |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2541 | return 0; |
| 2542 | |
| 2543 | if (asprintf(optstr, "Zoom %s %s DSO", |
| 2544 | browser->hists->dso_filter ? "out of" : "into", |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2545 | __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0) |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2546 | return 0; |
| 2547 | |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2548 | act->ms.map = map; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2549 | act->fn = do_zoom_dso; |
| 2550 | return 1; |
| 2551 | } |
| 2552 | |
| 2553 | static int |
| 2554 | do_browse_map(struct hist_browser *browser __maybe_unused, |
| 2555 | struct popup_action *act) |
| 2556 | { |
| 2557 | map__browse(act->ms.map); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2558 | return 0; |
| 2559 | } |
| 2560 | |
| 2561 | static int |
Jiri Olsa | 69849fc | 2016-05-03 13:54:45 +0200 | [diff] [blame] | 2562 | add_map_opt(struct hist_browser *browser, |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2563 | struct popup_action *act, char **optstr, struct map *map) |
| 2564 | { |
Jiri Olsa | 69849fc | 2016-05-03 13:54:45 +0200 | [diff] [blame] | 2565 | if (!hists__has(browser->hists, dso) || map == NULL) |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2566 | return 0; |
| 2567 | |
| 2568 | if (asprintf(optstr, "Browse map details") < 0) |
| 2569 | return 0; |
| 2570 | |
| 2571 | act->ms.map = map; |
| 2572 | act->fn = do_browse_map; |
| 2573 | return 1; |
| 2574 | } |
| 2575 | |
| 2576 | static int |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2577 | do_run_script(struct hist_browser *browser __maybe_unused, |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2578 | struct popup_action *act) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2579 | { |
| 2580 | char script_opt[64]; |
| 2581 | memset(script_opt, 0, sizeof(script_opt)); |
| 2582 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2583 | if (act->thread) { |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2584 | scnprintf(script_opt, sizeof(script_opt), " -c %s ", |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2585 | thread__comm_str(act->thread)); |
| 2586 | } else if (act->ms.sym) { |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2587 | scnprintf(script_opt, sizeof(script_opt), " -S %s ", |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2588 | act->ms.sym->name); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | script_browse(script_opt); |
| 2592 | return 0; |
| 2593 | } |
| 2594 | |
| 2595 | static int |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2596 | add_script_opt(struct hist_browser *browser __maybe_unused, |
| 2597 | struct popup_action *act, char **optstr, |
| 2598 | struct thread *thread, struct symbol *sym) |
| 2599 | { |
| 2600 | if (thread) { |
| 2601 | if (asprintf(optstr, "Run scripts for samples of thread [%s]", |
| 2602 | thread__comm_str(thread)) < 0) |
| 2603 | return 0; |
| 2604 | } else if (sym) { |
| 2605 | if (asprintf(optstr, "Run scripts for samples of symbol [%s]", |
| 2606 | sym->name) < 0) |
| 2607 | return 0; |
| 2608 | } else { |
| 2609 | if (asprintf(optstr, "Run scripts for all samples") < 0) |
| 2610 | return 0; |
| 2611 | } |
| 2612 | |
| 2613 | act->thread = thread; |
| 2614 | act->ms.sym = sym; |
| 2615 | act->fn = do_run_script; |
| 2616 | return 1; |
| 2617 | } |
| 2618 | |
| 2619 | static int |
| 2620 | do_switch_data(struct hist_browser *browser __maybe_unused, |
| 2621 | struct popup_action *act __maybe_unused) |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2622 | { |
| 2623 | if (switch_data_file()) { |
| 2624 | ui__warning("Won't switch the data files due to\n" |
| 2625 | "no valid data file get selected!\n"); |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2626 | return 0; |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | return K_SWITCH_INPUT_DATA; |
| 2630 | } |
| 2631 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2632 | static int |
| 2633 | add_switch_opt(struct hist_browser *browser, |
| 2634 | struct popup_action *act, char **optstr) |
| 2635 | { |
| 2636 | if (!is_report_browser(browser->hbt)) |
| 2637 | return 0; |
| 2638 | |
| 2639 | if (asprintf(optstr, "Switch to another data file in PWD") < 0) |
| 2640 | return 0; |
| 2641 | |
| 2642 | act->fn = do_switch_data; |
| 2643 | return 1; |
| 2644 | } |
| 2645 | |
| 2646 | static int |
| 2647 | do_exit_browser(struct hist_browser *browser __maybe_unused, |
| 2648 | struct popup_action *act __maybe_unused) |
| 2649 | { |
| 2650 | return 0; |
| 2651 | } |
| 2652 | |
| 2653 | static int |
| 2654 | add_exit_opt(struct hist_browser *browser __maybe_unused, |
| 2655 | struct popup_action *act, char **optstr) |
| 2656 | { |
| 2657 | if (asprintf(optstr, "Exit") < 0) |
| 2658 | return 0; |
| 2659 | |
| 2660 | act->fn = do_exit_browser; |
| 2661 | return 1; |
| 2662 | } |
| 2663 | |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2664 | static int |
| 2665 | do_zoom_socket(struct hist_browser *browser, struct popup_action *act) |
| 2666 | { |
Jiri Olsa | 35a634f | 2016-05-03 13:54:46 +0200 | [diff] [blame] | 2667 | if (!hists__has(browser->hists, socket) || act->socket < 0) |
Namhyung Kim | 599a2f3 | 2016-03-09 23:20:53 +0900 | [diff] [blame] | 2668 | return 0; |
| 2669 | |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2670 | if (browser->hists->socket_filter > -1) { |
| 2671 | pstack__remove(browser->pstack, &browser->hists->socket_filter); |
| 2672 | browser->hists->socket_filter = -1; |
| 2673 | perf_hpp__set_elide(HISTC_SOCKET, false); |
| 2674 | } else { |
| 2675 | browser->hists->socket_filter = act->socket; |
| 2676 | perf_hpp__set_elide(HISTC_SOCKET, true); |
| 2677 | pstack__push(browser->pstack, &browser->hists->socket_filter); |
| 2678 | } |
| 2679 | |
| 2680 | hists__filter_by_socket(browser->hists); |
| 2681 | hist_browser__reset(browser); |
| 2682 | return 0; |
| 2683 | } |
| 2684 | |
| 2685 | static int |
| 2686 | add_socket_opt(struct hist_browser *browser, struct popup_action *act, |
| 2687 | char **optstr, int socket_id) |
| 2688 | { |
Jiri Olsa | 35a634f | 2016-05-03 13:54:46 +0200 | [diff] [blame] | 2689 | if (!hists__has(browser->hists, socket) || socket_id < 0) |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2690 | return 0; |
| 2691 | |
| 2692 | if (asprintf(optstr, "Zoom %s Processor Socket %d", |
| 2693 | (browser->hists->socket_filter > -1) ? "out of" : "into", |
| 2694 | socket_id) < 0) |
| 2695 | return 0; |
| 2696 | |
| 2697 | act->socket = socket_id; |
| 2698 | act->fn = do_zoom_socket; |
| 2699 | return 1; |
| 2700 | } |
| 2701 | |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 2702 | static void hist_browser__update_nr_entries(struct hist_browser *hb) |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2703 | { |
| 2704 | u64 nr_entries = 0; |
| 2705 | struct rb_node *nd = rb_first(&hb->hists->entries); |
| 2706 | |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 2707 | if (hb->min_pcnt == 0 && !symbol_conf.report_hierarchy) { |
Namhyung Kim | 268397c | 2014-04-22 14:49:31 +0900 | [diff] [blame] | 2708 | hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries; |
| 2709 | return; |
| 2710 | } |
| 2711 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 2712 | while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) { |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2713 | nr_entries++; |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 2714 | nd = rb_hierarchy_next(nd); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2715 | } |
| 2716 | |
Namhyung Kim | 112f761 | 2014-04-22 14:05:35 +0900 | [diff] [blame] | 2717 | hb->nr_non_filtered_entries = nr_entries; |
Namhyung Kim | f5b763f | 2016-02-25 00:13:43 +0900 | [diff] [blame] | 2718 | hb->nr_hierarchy_entries = nr_entries; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2719 | } |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2720 | |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2721 | static void hist_browser__update_percent_limit(struct hist_browser *hb, |
| 2722 | double percent) |
| 2723 | { |
| 2724 | struct hist_entry *he; |
| 2725 | struct rb_node *nd = rb_first(&hb->hists->entries); |
| 2726 | u64 total = hists__total_period(hb->hists); |
| 2727 | u64 min_callchain_hits = total * (percent / 100); |
| 2728 | |
| 2729 | hb->min_pcnt = callchain_param.min_percent = percent; |
| 2730 | |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2731 | while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) { |
| 2732 | he = rb_entry(nd, struct hist_entry, rb_node); |
| 2733 | |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 2734 | if (he->has_no_entry) { |
| 2735 | he->has_no_entry = false; |
| 2736 | he->nr_rows = 0; |
| 2737 | } |
| 2738 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2739 | if (!he->leaf || !symbol_conf.use_callchain) |
| 2740 | goto next; |
| 2741 | |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2742 | if (callchain_param.mode == CHAIN_GRAPH_REL) { |
| 2743 | total = he->stat.period; |
| 2744 | |
| 2745 | if (symbol_conf.cumulate_callchain) |
| 2746 | total = he->stat_acc->period; |
| 2747 | |
| 2748 | min_callchain_hits = total * (percent / 100); |
| 2749 | } |
| 2750 | |
| 2751 | callchain_param.sort(&he->sorted_chain, he->callchain, |
| 2752 | min_callchain_hits, &callchain_param); |
| 2753 | |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2754 | next: |
Namhyung Kim | 201fde7 | 2016-02-26 21:13:18 +0900 | [diff] [blame] | 2755 | nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD); |
Namhyung Kim | d0506ed | 2016-02-25 00:13:45 +0900 | [diff] [blame] | 2756 | |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2757 | /* force to re-evaluate folding state of callchains */ |
| 2758 | he->init_have_children = false; |
Namhyung Kim | 492b101 | 2016-02-25 00:13:44 +0900 | [diff] [blame] | 2759 | hist_entry__set_folding(he, hb, false); |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2760 | } |
| 2761 | } |
| 2762 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 2763 | 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] | 2764 | const char *helpline, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 2765 | bool left_exits, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 2766 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2767 | float min_pcnt, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 2768 | struct perf_env *env, |
| 2769 | bool warn_lost_event) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2770 | { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 2771 | struct hists *hists = evsel__hists(evsel); |
Jiri Olsa | a6ec894 | 2016-06-20 23:58:17 +0200 | [diff] [blame] | 2772 | struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env); |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 2773 | struct branch_info *bi; |
Namhyung Kim | f2b487d | 2015-04-22 16:18:14 +0900 | [diff] [blame] | 2774 | #define MAX_OPTIONS 16 |
| 2775 | char *options[MAX_OPTIONS]; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2776 | struct popup_action actions[MAX_OPTIONS]; |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2777 | int nr_options = 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2778 | int key = -1; |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 2779 | char buf[64]; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 2780 | int delay_secs = hbt ? hbt->refresh : 0; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2781 | |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2782 | #define HIST_BROWSER_HELP_COMMON \ |
| 2783 | "h/?/F1 Show this window\n" \ |
| 2784 | "UP/DOWN/PGUP\n" \ |
| 2785 | "PGDN/SPACE Navigate\n" \ |
| 2786 | "q/ESC/CTRL+C Exit browser\n\n" \ |
| 2787 | "For multiple event sessions:\n\n" \ |
| 2788 | "TAB/UNTAB Switch events\n\n" \ |
| 2789 | "For symbolic views (--sort has sym):\n\n" \ |
Arnaldo Carvalho de Melo | 7727a92 | 2015-10-12 13:56:50 -0300 | [diff] [blame] | 2790 | "ENTER Zoom into DSO/Threads & Annotate current symbol\n" \ |
| 2791 | "ESC Zoom out\n" \ |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2792 | "a Annotate current symbol\n" \ |
| 2793 | "C Collapse all callchains\n" \ |
| 2794 | "d Zoom into current DSO\n" \ |
| 2795 | "E Expand all callchains\n" \ |
Namhyung Kim | 105eb30 | 2014-02-10 11:20:10 +0900 | [diff] [blame] | 2796 | "F Toggle percentage of filtered entries\n" \ |
Arnaldo Carvalho de Melo | 025bf7e | 2014-06-14 15:44:52 +0200 | [diff] [blame] | 2797 | "H Display column headers\n" \ |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2798 | "L Change percent limit\n" \ |
Namhyung Kim | 31eb436 | 2015-10-13 09:02:01 +0900 | [diff] [blame] | 2799 | "m Display context menu\n" \ |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2800 | "S Zoom into current Processor Socket\n" \ |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2801 | |
| 2802 | /* help messages are sorted by lexical order of the hotkey */ |
| 2803 | const char report_help[] = HIST_BROWSER_HELP_COMMON |
Namhyung Kim | 6dd6013 | 2013-12-26 14:37:59 +0900 | [diff] [blame] | 2804 | "i Show header information\n" |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2805 | "P Print histograms to perf.hist.N\n" |
| 2806 | "r Run available scripts\n" |
| 2807 | "s Switch to another data file in PWD\n" |
| 2808 | "t Zoom into current Thread\n" |
| 2809 | "V Verbose (DSO names in callchains, etc)\n" |
| 2810 | "/ Filter symbol by name"; |
| 2811 | const char top_help[] = HIST_BROWSER_HELP_COMMON |
| 2812 | "P Print histograms to perf.hist.N\n" |
| 2813 | "t Zoom into current Thread\n" |
| 2814 | "V Verbose (DSO names in callchains, etc)\n" |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 2815 | "z Toggle zeroing of samples\n" |
Arnaldo Carvalho de Melo | fbb7997 | 2015-06-19 16:56:04 -0300 | [diff] [blame] | 2816 | "f Enable/Disable events\n" |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2817 | "/ Filter symbol by name"; |
| 2818 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2819 | if (browser == NULL) |
| 2820 | return -1; |
| 2821 | |
Namhyung Kim | ed42691 | 2015-05-29 21:53:44 +0900 | [diff] [blame] | 2822 | /* reset abort key so that it can get Ctrl-C as a key */ |
| 2823 | SLang_reset_tty(); |
| 2824 | SLang_init_tty(0, 0, 0); |
| 2825 | |
Namhyung Kim | 0390504 | 2015-11-28 02:32:39 +0900 | [diff] [blame] | 2826 | if (min_pcnt) |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2827 | browser->min_pcnt = min_pcnt; |
Namhyung Kim | 0390504 | 2015-11-28 02:32:39 +0900 | [diff] [blame] | 2828 | hist_browser__update_nr_entries(browser); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 2829 | |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2830 | browser->pstack = pstack__new(3); |
Namhyung Kim | 01f00a1 | 2015-04-22 16:18:16 +0900 | [diff] [blame] | 2831 | if (browser->pstack == NULL) |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2832 | goto out; |
| 2833 | |
| 2834 | ui_helpline__push(helpline); |
| 2835 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2836 | memset(options, 0, sizeof(options)); |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2837 | memset(actions, 0, sizeof(actions)); |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2838 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 2839 | if (symbol_conf.col_width_list_str) |
| 2840 | perf_hpp__set_user_width(symbol_conf.col_width_list_str); |
| 2841 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2842 | while (1) { |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 2843 | struct thread *thread = NULL; |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2844 | struct map *map = NULL; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2845 | int choice = 0; |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2846 | int socked_id = -1; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2847 | |
Stephane Eranian | 24bff2d | 2012-03-12 16:13:30 +0100 | [diff] [blame] | 2848 | nr_options = 0; |
| 2849 | |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 2850 | key = hist_browser__run(browser, helpline, |
| 2851 | warn_lost_event); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2852 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 2853 | if (browser->he_selection != NULL) { |
| 2854 | thread = hist_browser__selected_thread(browser); |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 2855 | map = browser->selection->map; |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2856 | socked_id = browser->he_selection->socket; |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 2857 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2858 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 2859 | case K_TAB: |
| 2860 | case K_UNTAB: |
David Ahern | e4419b8 | 2011-10-19 11:37:47 -0600 | [diff] [blame] | 2861 | if (nr_events == 1) |
| 2862 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2863 | /* |
| 2864 | * Exit the browser, let hists__browser_tree |
| 2865 | * go to the next or previous |
| 2866 | */ |
| 2867 | goto out_free_stack; |
| 2868 | case 'a': |
Jiri Olsa | 2e0453a | 2016-05-03 13:54:44 +0200 | [diff] [blame] | 2869 | if (!hists__has(hists, sym)) { |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 2870 | ui_browser__warning(&browser->b, delay_secs * 2, |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 2871 | "Annotation is only available for symbolic views, " |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 2872 | "include \"sym*\" in --sort to use it."); |
Arnaldo Carvalho de Melo | a6e51f9 | 2011-10-21 10:58:24 -0200 | [diff] [blame] | 2873 | continue; |
| 2874 | } |
| 2875 | |
Arnaldo Carvalho de Melo | 6009891 | 2011-03-04 21:19:21 -0300 | [diff] [blame] | 2876 | if (browser->selection == NULL || |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 2877 | browser->selection->sym == NULL || |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2878 | browser->selection->map->dso->annotate_warned) |
| 2879 | continue; |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2880 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2881 | actions->ms.map = browser->selection->map; |
| 2882 | actions->ms.sym = browser->selection->sym; |
| 2883 | do_annotate(browser, actions); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2884 | continue; |
Arnaldo Carvalho de Melo | aff3f3f | 2012-06-07 19:31:28 -0300 | [diff] [blame] | 2885 | case 'P': |
| 2886 | hist_browser__dump(browser); |
| 2887 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2888 | case 'd': |
Arnaldo Carvalho de Melo | fae0065 | 2015-11-12 15:59:26 -0300 | [diff] [blame] | 2889 | actions->ms.map = map; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2890 | do_zoom_dso(browser, actions); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2891 | continue; |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 2892 | case 'V': |
Alexis Berlemont | 21e8c81 | 2016-10-12 23:48:23 +0200 | [diff] [blame] | 2893 | verbose = (verbose + 1) % 4; |
| 2894 | browser->show_dso = verbose > 0; |
| 2895 | ui_helpline__fpush("Verbosity level set to %d\n", |
| 2896 | verbose); |
Arnaldo Carvalho de Melo | a7cb886 | 2012-08-03 13:53:40 -0300 | [diff] [blame] | 2897 | continue; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2898 | case 't': |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2899 | actions->thread = thread; |
| 2900 | do_zoom_thread(browser, actions); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2901 | continue; |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 2902 | case 'S': |
| 2903 | actions->socket = socked_id; |
| 2904 | do_zoom_socket(browser, actions); |
| 2905 | continue; |
Arnaldo Carvalho de Melo | 5a5626b | 2012-05-09 12:21:22 -0300 | [diff] [blame] | 2906 | case '/': |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 2907 | if (ui_browser__input_window("Symbol to show", |
Arnaldo Carvalho de Melo | 4aa8e454 | 2015-10-12 14:02:29 -0300 | [diff] [blame] | 2908 | "Please enter the name of symbol you want to see.\n" |
| 2909 | "To remove the filter later, press / + ENTER.", |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 2910 | buf, "ENTER: OK, ESC: Cancel", |
| 2911 | delay_secs * 2) == K_ENTER) { |
Arnaldo Carvalho de Melo | 05e8b08 | 2012-05-29 22:42:18 -0300 | [diff] [blame] | 2912 | hists->symbol_filter_str = *buf ? buf : NULL; |
| 2913 | hists__filter_by_symbol(hists); |
Namhyung Kim | 938a23a | 2012-03-16 17:50:53 +0900 | [diff] [blame] | 2914 | hist_browser__reset(browser); |
| 2915 | } |
| 2916 | continue; |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 2917 | case 'r': |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2918 | if (is_report_browser(hbt)) { |
| 2919 | actions->thread = NULL; |
| 2920 | actions->ms.sym = NULL; |
| 2921 | do_run_script(browser, actions); |
| 2922 | } |
Feng Tang | c77d8d7 | 2012-11-01 00:00:55 +0800 | [diff] [blame] | 2923 | continue; |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2924 | case 's': |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2925 | if (is_report_browser(hbt)) { |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 2926 | key = do_switch_data(browser, actions); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2927 | if (key == K_SWITCH_INPUT_DATA) |
| 2928 | goto out_free_stack; |
| 2929 | } |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 2930 | continue; |
Namhyung Kim | 6dd6013 | 2013-12-26 14:37:59 +0900 | [diff] [blame] | 2931 | case 'i': |
| 2932 | /* env->arch is NULL for live-mode (i.e. perf top) */ |
| 2933 | if (env->arch) |
| 2934 | tui__header_window(env); |
| 2935 | continue; |
Namhyung Kim | 105eb30 | 2014-02-10 11:20:10 +0900 | [diff] [blame] | 2936 | case 'F': |
| 2937 | symbol_conf.filter_relative ^= 1; |
| 2938 | continue; |
Namhyung Kim | 42337a2 | 2014-08-12 17:16:06 +0900 | [diff] [blame] | 2939 | case 'z': |
| 2940 | if (!is_report_browser(hbt)) { |
| 2941 | struct perf_top *top = hbt->arg; |
| 2942 | |
| 2943 | top->zero = !top->zero; |
| 2944 | } |
| 2945 | continue; |
Namhyung Kim | b62e8df | 2016-02-03 23:11:23 +0900 | [diff] [blame] | 2946 | case 'L': |
| 2947 | if (ui_browser__input_window("Percent Limit", |
| 2948 | "Please enter the value you want to hide entries under that percent.", |
| 2949 | buf, "ENTER: OK, ESC: Cancel", |
| 2950 | delay_secs * 2) == K_ENTER) { |
| 2951 | char *end; |
| 2952 | double new_percent = strtod(buf, &end); |
| 2953 | |
| 2954 | if (new_percent < 0 || new_percent > 100) { |
| 2955 | ui_browser__warning(&browser->b, delay_secs * 2, |
| 2956 | "Invalid percent: %.2f", new_percent); |
| 2957 | continue; |
| 2958 | } |
| 2959 | |
| 2960 | hist_browser__update_percent_limit(browser, new_percent); |
| 2961 | hist_browser__reset(browser); |
| 2962 | } |
| 2963 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 2964 | case K_F1: |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2965 | case 'h': |
| 2966 | case '?': |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 2967 | ui_browser__help_window(&browser->b, |
Namhyung Kim | e8e684a | 2013-12-26 14:37:58 +0900 | [diff] [blame] | 2968 | is_report_browser(hbt) ? report_help : top_help); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2969 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 2970 | case K_ENTER: |
| 2971 | case K_RIGHT: |
Namhyung Kim | 31eb436 | 2015-10-13 09:02:01 +0900 | [diff] [blame] | 2972 | case 'm': |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2973 | /* menu */ |
| 2974 | break; |
Arnaldo Carvalho de Melo | 63ab174 | 2015-08-12 12:42:58 -0300 | [diff] [blame] | 2975 | case K_ESC: |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 2976 | case K_LEFT: { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 2977 | const void *top; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2978 | |
Namhyung Kim | 01f00a1 | 2015-04-22 16:18:16 +0900 | [diff] [blame] | 2979 | if (pstack__empty(browser->pstack)) { |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 2980 | /* |
| 2981 | * Go back to the perf_evsel_menu__run or other user |
| 2982 | */ |
| 2983 | if (left_exits) |
| 2984 | goto out_free_stack; |
Arnaldo Carvalho de Melo | 63ab174 | 2015-08-12 12:42:58 -0300 | [diff] [blame] | 2985 | |
| 2986 | if (key == K_ESC && |
| 2987 | ui_browser__dialog_yesno(&browser->b, |
| 2988 | "Do you really want to exit?")) |
| 2989 | goto out_free_stack; |
| 2990 | |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 2991 | continue; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 2992 | } |
Namhyung Kim | 6422184 | 2015-04-24 10:15:33 +0900 | [diff] [blame] | 2993 | top = pstack__peek(browser->pstack); |
Namhyung Kim | bc7cad4 | 2015-04-22 16:18:18 +0900 | [diff] [blame] | 2994 | if (top == &browser->hists->dso_filter) { |
Namhyung Kim | 6422184 | 2015-04-24 10:15:33 +0900 | [diff] [blame] | 2995 | /* |
| 2996 | * No need to set actions->dso here since |
| 2997 | * it's just to remove the current filter. |
| 2998 | * Ditto for thread below. |
| 2999 | */ |
| 3000 | do_zoom_dso(browser, actions); |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 3001 | } else if (top == &browser->hists->thread_filter) { |
Namhyung Kim | 6422184 | 2015-04-24 10:15:33 +0900 | [diff] [blame] | 3002 | do_zoom_thread(browser, actions); |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 3003 | } else if (top == &browser->hists->socket_filter) { |
| 3004 | do_zoom_socket(browser, actions); |
| 3005 | } |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 3006 | continue; |
| 3007 | } |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 3008 | case 'q': |
| 3009 | case CTRL('c'): |
Arnaldo Carvalho de Melo | 516e536 | 2015-06-19 16:59:43 -0300 | [diff] [blame] | 3010 | goto out_free_stack; |
Arnaldo Carvalho de Melo | fbb7997 | 2015-06-19 16:56:04 -0300 | [diff] [blame] | 3011 | case 'f': |
Namhyung Kim | 13d1e53 | 2015-06-21 12:41:16 +0900 | [diff] [blame] | 3012 | if (!is_report_browser(hbt)) { |
| 3013 | struct perf_top *top = hbt->arg; |
| 3014 | |
| 3015 | perf_evlist__toggle_enable(top->evlist); |
| 3016 | /* |
| 3017 | * No need to refresh, resort/decay histogram |
| 3018 | * entries if we are not collecting samples: |
| 3019 | */ |
| 3020 | if (top->evlist->enabled) { |
| 3021 | helpline = "Press 'f' to disable the events or 'h' to see other hotkeys"; |
| 3022 | hbt->refresh = delay_secs; |
| 3023 | } else { |
| 3024 | helpline = "Press 'f' again to re-enable the events"; |
| 3025 | hbt->refresh = 0; |
| 3026 | } |
| 3027 | continue; |
| 3028 | } |
Arnaldo Carvalho de Melo | 3e323dc | 2015-06-19 17:49:29 -0300 | [diff] [blame] | 3029 | /* Fall thru */ |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 3030 | default: |
Arnaldo Carvalho de Melo | 3e323dc | 2015-06-19 17:49:29 -0300 | [diff] [blame] | 3031 | helpline = "Press '?' for help on key bindings"; |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 3032 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3033 | } |
| 3034 | |
Jiri Olsa | 2e0453a | 2016-05-03 13:54:44 +0200 | [diff] [blame] | 3035 | if (!hists__has(hists, sym) || browser->selection == NULL) |
Arnaldo Carvalho de Melo | 0ba332f | 2015-03-16 17:41:52 -0300 | [diff] [blame] | 3036 | goto skip_annotation; |
| 3037 | |
Namhyung Kim | 55369fc | 2013-04-01 20:35:20 +0900 | [diff] [blame] | 3038 | if (sort__mode == SORT_MODE__BRANCH) { |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 3039 | bi = browser->he_selection->branch_info; |
Arnaldo Carvalho de Melo | 0ba332f | 2015-03-16 17:41:52 -0300 | [diff] [blame] | 3040 | |
| 3041 | if (bi == NULL) |
| 3042 | goto skip_annotation; |
| 3043 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3044 | nr_options += add_annotate_opt(browser, |
| 3045 | &actions[nr_options], |
| 3046 | &options[nr_options], |
| 3047 | bi->from.map, |
| 3048 | bi->from.sym); |
| 3049 | if (bi->to.sym != bi->from.sym) |
| 3050 | nr_options += add_annotate_opt(browser, |
| 3051 | &actions[nr_options], |
| 3052 | &options[nr_options], |
| 3053 | bi->to.map, |
| 3054 | bi->to.sym); |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 3055 | } else { |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3056 | nr_options += add_annotate_opt(browser, |
| 3057 | &actions[nr_options], |
| 3058 | &options[nr_options], |
| 3059 | browser->selection->map, |
| 3060 | browser->selection->sym); |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 3061 | } |
Arnaldo Carvalho de Melo | 0ba332f | 2015-03-16 17:41:52 -0300 | [diff] [blame] | 3062 | skip_annotation: |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3063 | nr_options += add_thread_opt(browser, &actions[nr_options], |
| 3064 | &options[nr_options], thread); |
| 3065 | nr_options += add_dso_opt(browser, &actions[nr_options], |
Arnaldo Carvalho de Melo | 045b80d | 2015-09-23 15:38:55 -0300 | [diff] [blame] | 3066 | &options[nr_options], map); |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3067 | nr_options += add_map_opt(browser, &actions[nr_options], |
| 3068 | &options[nr_options], |
Wang Nan | bd315aa | 2015-09-14 10:23:55 +0000 | [diff] [blame] | 3069 | browser->selection ? |
| 3070 | browser->selection->map : NULL); |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 3071 | nr_options += add_socket_opt(browser, &actions[nr_options], |
| 3072 | &options[nr_options], |
| 3073 | socked_id); |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 3074 | /* perf script support */ |
Namhyung Kim | b1baae8 | 2016-01-26 15:37:30 -0300 | [diff] [blame] | 3075 | if (!is_report_browser(hbt)) |
| 3076 | goto skip_scripting; |
| 3077 | |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 3078 | if (browser->he_selection) { |
Jiri Olsa | fa82911 | 2016-05-03 13:54:47 +0200 | [diff] [blame] | 3079 | if (hists__has(hists, thread) && thread) { |
Namhyung Kim | 2eafd41 | 2016-01-21 19:13:24 -0300 | [diff] [blame] | 3080 | nr_options += add_script_opt(browser, |
| 3081 | &actions[nr_options], |
| 3082 | &options[nr_options], |
| 3083 | thread, NULL); |
| 3084 | } |
Wang Nan | bd315aa | 2015-09-14 10:23:55 +0000 | [diff] [blame] | 3085 | /* |
| 3086 | * Note that browser->selection != NULL |
| 3087 | * when browser->he_selection is not NULL, |
| 3088 | * so we don't need to check browser->selection |
| 3089 | * before fetching browser->selection->sym like what |
| 3090 | * we do before fetching browser->selection->map. |
| 3091 | * |
| 3092 | * See hist_browser__show_entry. |
| 3093 | */ |
Jiri Olsa | 2e0453a | 2016-05-03 13:54:44 +0200 | [diff] [blame] | 3094 | if (hists__has(hists, sym) && browser->selection->sym) { |
Namhyung Kim | c221acb | 2016-01-21 19:50:09 -0300 | [diff] [blame] | 3095 | nr_options += add_script_opt(browser, |
| 3096 | &actions[nr_options], |
| 3097 | &options[nr_options], |
| 3098 | NULL, browser->selection->sym); |
| 3099 | } |
Feng Tang | cdbab7c | 2012-10-30 11:56:06 +0800 | [diff] [blame] | 3100 | } |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3101 | nr_options += add_script_opt(browser, &actions[nr_options], |
| 3102 | &options[nr_options], NULL, NULL); |
| 3103 | nr_options += add_switch_opt(browser, &actions[nr_options], |
| 3104 | &options[nr_options]); |
Namhyung Kim | b1baae8 | 2016-01-26 15:37:30 -0300 | [diff] [blame] | 3105 | skip_scripting: |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3106 | nr_options += add_exit_opt(browser, &actions[nr_options], |
| 3107 | &options[nr_options]); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3108 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3109 | do { |
| 3110 | struct popup_action *act; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3111 | |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3112 | choice = ui__popup_menu(nr_options, options); |
| 3113 | if (choice == -1 || choice >= nr_options) |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 3114 | break; |
Namhyung Kim | ea7cd59 | 2015-04-22 16:18:19 +0900 | [diff] [blame] | 3115 | |
| 3116 | act = &actions[choice]; |
| 3117 | key = act->fn(browser, act); |
| 3118 | } while (key == 1); |
| 3119 | |
| 3120 | if (key == K_SWITCH_INPUT_DATA) |
| 3121 | break; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3122 | } |
| 3123 | out_free_stack: |
Namhyung Kim | 01f00a1 | 2015-04-22 16:18:16 +0900 | [diff] [blame] | 3124 | pstack__delete(browser->pstack); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3125 | out: |
| 3126 | hist_browser__delete(browser); |
Namhyung Kim | f2b487d | 2015-04-22 16:18:14 +0900 | [diff] [blame] | 3127 | free_popup_options(options, MAX_OPTIONS); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3128 | return key; |
| 3129 | } |
| 3130 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3131 | struct perf_evsel_menu { |
| 3132 | struct ui_browser b; |
| 3133 | struct perf_evsel *selection; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3134 | bool lost_events, lost_events_warned; |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 3135 | float min_pcnt; |
Kan Liang | ce80d3b | 2015-08-28 05:48:04 -0400 | [diff] [blame] | 3136 | struct perf_env *env; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3137 | }; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3138 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3139 | static void perf_evsel_menu__write(struct ui_browser *browser, |
| 3140 | void *entry, int row) |
| 3141 | { |
| 3142 | struct perf_evsel_menu *menu = container_of(browser, |
| 3143 | struct perf_evsel_menu, b); |
| 3144 | 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] | 3145 | struct hists *hists = evsel__hists(evsel); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3146 | bool current_entry = ui_browser__is_current_entry(browser, row); |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 3147 | 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] | 3148 | const char *ev_name = perf_evsel__name(evsel); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3149 | char bf[256], unit; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3150 | const char *warn = " "; |
| 3151 | size_t printed; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3152 | |
| 3153 | ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : |
| 3154 | HE_COLORSET_NORMAL); |
| 3155 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 3156 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 3157 | struct perf_evsel *pos; |
| 3158 | |
| 3159 | ev_name = perf_evsel__group_name(evsel); |
| 3160 | |
| 3161 | for_each_group_member(pos, evsel) { |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 3162 | struct hists *pos_hists = evsel__hists(pos); |
| 3163 | nr_events += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE]; |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3167 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 3168 | 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] | 3169 | unit, unit == ' ' ? "" : " ", ev_name); |
Arnaldo Carvalho de Melo | 517dfdb | 2015-08-11 12:50:55 -0300 | [diff] [blame] | 3170 | ui_browser__printf(browser, "%s", bf); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3171 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 3172 | nr_events = hists->stats.nr_events[PERF_RECORD_LOST]; |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3173 | if (nr_events != 0) { |
| 3174 | menu->lost_events = true; |
| 3175 | if (!current_entry) |
| 3176 | ui_browser__set_color(browser, HE_COLORSET_TOP); |
| 3177 | nr_events = convert_unit(nr_events, &unit); |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 3178 | printed += scnprintf(bf, sizeof(bf), ": %ld%c%schunks LOST!", |
| 3179 | nr_events, unit, unit == ' ' ? "" : " "); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3180 | warn = bf; |
| 3181 | } |
| 3182 | |
Arnaldo Carvalho de Melo | 26270a0 | 2015-08-11 12:24:27 -0300 | [diff] [blame] | 3183 | ui_browser__write_nstring(browser, warn, browser->width - printed); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3184 | |
| 3185 | if (current_entry) |
| 3186 | menu->selection = evsel; |
| 3187 | } |
| 3188 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 3189 | static int perf_evsel_menu__run(struct perf_evsel_menu *menu, |
| 3190 | int nr_events, const char *help, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3191 | struct hist_browser_timer *hbt, |
| 3192 | bool warn_lost_event) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3193 | { |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3194 | struct perf_evlist *evlist = menu->b.priv; |
| 3195 | struct perf_evsel *pos; |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 3196 | const char *title = "Available samples"; |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 3197 | int delay_secs = hbt ? hbt->refresh : 0; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3198 | int key; |
| 3199 | |
| 3200 | if (ui_browser__show(&menu->b, title, |
| 3201 | "ESC: exit, ENTER|->: Browse histograms") < 0) |
| 3202 | return -1; |
| 3203 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3204 | while (1) { |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 3205 | key = ui_browser__run(&menu->b, delay_secs); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3206 | |
| 3207 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3208 | case K_TIMER: |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 3209 | hbt->timer(hbt->arg); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3210 | |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3211 | if (!menu->lost_events_warned && |
| 3212 | menu->lost_events && |
| 3213 | warn_lost_event) { |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 3214 | ui_browser__warn_lost_events(&menu->b); |
| 3215 | menu->lost_events_warned = true; |
| 3216 | } |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 3217 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3218 | case K_RIGHT: |
| 3219 | case K_ENTER: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3220 | if (!menu->selection) |
| 3221 | continue; |
| 3222 | pos = menu->selection; |
| 3223 | browse_hists: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3224 | perf_evlist__set_selected(evlist, pos); |
| 3225 | /* |
| 3226 | * Give the calling tool a chance to populate the non |
| 3227 | * default evsel resorted hists tree. |
| 3228 | */ |
Namhyung Kim | 9783adf | 2012-11-02 14:50:05 +0900 | [diff] [blame] | 3229 | if (hbt) |
| 3230 | hbt->timer(hbt->arg); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 3231 | key = perf_evsel__hists_browse(pos, nr_events, help, |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 3232 | true, hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 3233 | menu->min_pcnt, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3234 | menu->env, |
| 3235 | warn_lost_event); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3236 | ui_browser__show_title(&menu->b, title); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3237 | switch (key) { |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3238 | case K_TAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3239 | if (pos->node.next == &evlist->entries) |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 3240 | pos = perf_evlist__first(evlist); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3241 | else |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 3242 | pos = perf_evsel__next(pos); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3243 | goto browse_hists; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3244 | case K_UNTAB: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3245 | if (pos->node.prev == &evlist->entries) |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 3246 | pos = perf_evlist__last(evlist); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3247 | else |
Arnaldo Carvalho de Melo | d87fcb4 | 2013-11-13 15:56:40 -0300 | [diff] [blame] | 3248 | pos = perf_evsel__prev(pos); |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3249 | goto browse_hists; |
Feng Tang | 341487ab | 2013-02-03 14:38:20 +0800 | [diff] [blame] | 3250 | case K_SWITCH_INPUT_DATA: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3251 | case 'q': |
| 3252 | case CTRL('c'): |
| 3253 | goto out; |
Arnaldo Carvalho de Melo | 63ab174 | 2015-08-12 12:42:58 -0300 | [diff] [blame] | 3254 | case K_ESC: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3255 | default: |
| 3256 | continue; |
| 3257 | } |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3258 | case K_LEFT: |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3259 | continue; |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 3260 | case K_ESC: |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 3261 | if (!ui_browser__dialog_yesno(&menu->b, |
| 3262 | "Do you really want to exit?")) |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 3263 | continue; |
| 3264 | /* Fall thru */ |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3265 | case 'q': |
| 3266 | case CTRL('c'): |
| 3267 | goto out; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3268 | default: |
Arnaldo Carvalho de Melo | 18eaf0b | 2011-10-13 12:22:28 -0300 | [diff] [blame] | 3269 | continue; |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3273 | out: |
| 3274 | ui_browser__hide(&menu->b); |
| 3275 | return key; |
| 3276 | } |
| 3277 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 3278 | static bool filter_group_entries(struct ui_browser *browser __maybe_unused, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3279 | void *entry) |
| 3280 | { |
| 3281 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); |
| 3282 | |
| 3283 | if (symbol_conf.event_group && !perf_evsel__is_group_leader(evsel)) |
| 3284 | return true; |
| 3285 | |
| 3286 | return false; |
| 3287 | } |
| 3288 | |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3289 | static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3290 | int nr_entries, const char *help, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 3291 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 3292 | float min_pcnt, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3293 | struct perf_env *env, |
| 3294 | bool warn_lost_event) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3295 | { |
| 3296 | struct perf_evsel *pos; |
| 3297 | struct perf_evsel_menu menu = { |
| 3298 | .b = { |
| 3299 | .entries = &evlist->entries, |
| 3300 | .refresh = ui_browser__list_head_refresh, |
| 3301 | .seek = ui_browser__list_head_seek, |
| 3302 | .write = perf_evsel_menu__write, |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3303 | .filter = filter_group_entries, |
| 3304 | .nr_entries = nr_entries, |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3305 | .priv = evlist, |
| 3306 | }, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 3307 | .min_pcnt = min_pcnt, |
Namhyung Kim | 68d8075 | 2012-11-02 14:50:06 +0900 | [diff] [blame] | 3308 | .env = env, |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3309 | }; |
| 3310 | |
| 3311 | ui_helpline__push("Press ESC to exit"); |
| 3312 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3313 | evlist__for_each_entry(evlist, pos) { |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 3314 | const char *ev_name = perf_evsel__name(pos); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3315 | size_t line_len = strlen(ev_name) + 7; |
| 3316 | |
| 3317 | if (menu.b.width < line_len) |
| 3318 | menu.b.width = line_len; |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3319 | } |
| 3320 | |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3321 | return perf_evsel_menu__run(&menu, nr_entries, help, |
| 3322 | hbt, warn_lost_event); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3323 | } |
| 3324 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 3325 | 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] | 3326 | struct hist_browser_timer *hbt, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 3327 | float min_pcnt, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3328 | struct perf_env *env, |
| 3329 | bool warn_lost_event) |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3330 | { |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3331 | int nr_entries = evlist->nr_entries; |
| 3332 | |
| 3333 | single_entry: |
| 3334 | if (nr_entries == 1) { |
Arnaldo Carvalho de Melo | 9a354cd | 2013-11-13 15:54:30 -0300 | [diff] [blame] | 3335 | struct perf_evsel *first = perf_evlist__first(evlist); |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3336 | |
| 3337 | return perf_evsel__hists_browse(first, nr_entries, help, |
Jiri Olsa | dd00d48 | 2014-06-19 13:41:13 +0200 | [diff] [blame] | 3338 | false, hbt, min_pcnt, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3339 | env, warn_lost_event); |
Arnaldo Carvalho de Melo | 7f0030b | 2011-03-06 13:07:30 -0300 | [diff] [blame] | 3340 | } |
| 3341 | |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3342 | if (symbol_conf.event_group) { |
| 3343 | struct perf_evsel *pos; |
| 3344 | |
| 3345 | nr_entries = 0; |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3346 | evlist__for_each_entry(evlist, pos) { |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3347 | if (perf_evsel__is_group_leader(pos)) |
| 3348 | nr_entries++; |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 3349 | } |
Namhyung Kim | fc24d7c | 2013-01-22 18:09:43 +0900 | [diff] [blame] | 3350 | |
| 3351 | if (nr_entries == 1) |
| 3352 | goto single_entry; |
| 3353 | } |
| 3354 | |
| 3355 | return __perf_evlist__tui_browse_hists(evlist, nr_entries, help, |
Kan Liang | 06cc1a4 | 2018-01-18 13:26:29 -0800 | [diff] [blame^] | 3356 | hbt, min_pcnt, env, |
| 3357 | warn_lost_event); |
Arnaldo Carvalho de Melo | d1b4f24 | 2010-08-10 15:49:07 -0300 | [diff] [blame] | 3358 | } |