Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 1 | /* |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 2 | * Copyright (C) 2009-2011, Frederic Weisbecker <fweisbec@gmail.com> |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 3 | * |
| 4 | * Handle the callchains from the stream in an ad-hoc radix tree and then |
| 5 | * sort them in an rbtree. |
| 6 | * |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 7 | * Using a radix for code path provides a fast retrieval and factorizes |
| 8 | * memory use. Also that lets us use the paths in a hierarchical graph view. |
| 9 | * |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdbool.h> |
| 15 | #include <errno.h> |
Frederic Weisbecker | c0a8865 | 2009-08-09 04:19:15 +0200 | [diff] [blame] | 16 | #include <math.h> |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 17 | |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 18 | #include "asm/bug.h" |
| 19 | |
Andi Kleen | 99571ab | 2013-07-18 15:33:57 -0700 | [diff] [blame] | 20 | #include "hist.h" |
Arnaldo Carvalho de Melo | b36f19d | 2010-05-20 12:15:33 -0300 | [diff] [blame] | 21 | #include "util.h" |
Namhyung Kim | 2dc9fb1 | 2014-01-14 14:25:35 +0900 | [diff] [blame] | 22 | #include "sort.h" |
| 23 | #include "machine.h" |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 24 | #include "callchain.h" |
| 25 | |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 26 | __thread struct callchain_cursor callchain_cursor; |
| 27 | |
Kan Liang | c3a6a8c | 2015-08-04 04:30:20 -0400 | [diff] [blame] | 28 | int parse_callchain_record_opt(const char *arg, struct callchain_param *param) |
Namhyung Kim | f7f084f | 2014-09-23 10:01:42 +0900 | [diff] [blame] | 29 | { |
Kan Liang | 076a30c | 2015-08-06 15:44:52 -0400 | [diff] [blame] | 30 | return parse_callchain_record(arg, param); |
Namhyung Kim | f7f084f | 2014-09-23 10:01:42 +0900 | [diff] [blame] | 31 | } |
| 32 | |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 33 | static int parse_callchain_mode(const char *value) |
| 34 | { |
| 35 | if (!strncmp(value, "graph", strlen(value))) { |
| 36 | callchain_param.mode = CHAIN_GRAPH_ABS; |
| 37 | return 0; |
| 38 | } |
| 39 | if (!strncmp(value, "flat", strlen(value))) { |
| 40 | callchain_param.mode = CHAIN_FLAT; |
| 41 | return 0; |
| 42 | } |
| 43 | if (!strncmp(value, "fractal", strlen(value))) { |
| 44 | callchain_param.mode = CHAIN_GRAPH_REL; |
| 45 | return 0; |
| 46 | } |
Namhyung Kim | 26e7792 | 2015-11-09 14:45:37 +0900 | [diff] [blame] | 47 | if (!strncmp(value, "folded", strlen(value))) { |
| 48 | callchain_param.mode = CHAIN_FOLDED; |
| 49 | return 0; |
| 50 | } |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | static int parse_callchain_order(const char *value) |
| 55 | { |
| 56 | if (!strncmp(value, "caller", strlen(value))) { |
| 57 | callchain_param.order = ORDER_CALLER; |
Namhyung Kim | 792aeaf | 2015-10-22 16:45:46 +0900 | [diff] [blame] | 58 | callchain_param.order_set = true; |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | if (!strncmp(value, "callee", strlen(value))) { |
| 62 | callchain_param.order = ORDER_CALLEE; |
Namhyung Kim | 792aeaf | 2015-10-22 16:45:46 +0900 | [diff] [blame] | 63 | callchain_param.order_set = true; |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | static int parse_callchain_sort_key(const char *value) |
| 70 | { |
| 71 | if (!strncmp(value, "function", strlen(value))) { |
| 72 | callchain_param.key = CCKEY_FUNCTION; |
| 73 | return 0; |
| 74 | } |
| 75 | if (!strncmp(value, "address", strlen(value))) { |
| 76 | callchain_param.key = CCKEY_ADDRESS; |
| 77 | return 0; |
| 78 | } |
Andi Kleen | 8b7bad5 | 2014-11-12 18:05:20 -0800 | [diff] [blame] | 79 | if (!strncmp(value, "branch", strlen(value))) { |
| 80 | callchain_param.branch_callstack = 1; |
| 81 | return 0; |
| 82 | } |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 86 | static int parse_callchain_value(const char *value) |
| 87 | { |
| 88 | if (!strncmp(value, "percent", strlen(value))) { |
| 89 | callchain_param.value = CCVAL_PERCENT; |
| 90 | return 0; |
| 91 | } |
| 92 | if (!strncmp(value, "period", strlen(value))) { |
| 93 | callchain_param.value = CCVAL_PERIOD; |
| 94 | return 0; |
| 95 | } |
| 96 | if (!strncmp(value, "count", strlen(value))) { |
| 97 | callchain_param.value = CCVAL_COUNT; |
| 98 | return 0; |
| 99 | } |
| 100 | return -1; |
| 101 | } |
| 102 | |
Namhyung Kim | a2c10d3 | 2015-10-22 15:28:49 +0900 | [diff] [blame] | 103 | static int |
| 104 | __parse_callchain_report_opt(const char *arg, bool allow_record_opt) |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 105 | { |
Namhyung Kim | e8232f1 | 2014-08-14 15:01:38 +0900 | [diff] [blame] | 106 | char *tok; |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 107 | char *endptr; |
Namhyung Kim | e8232f1 | 2014-08-14 15:01:38 +0900 | [diff] [blame] | 108 | bool minpcnt_set = false; |
Namhyung Kim | a2c10d3 | 2015-10-22 15:28:49 +0900 | [diff] [blame] | 109 | bool record_opt_set = false; |
| 110 | bool try_stack_size = false; |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 111 | |
| 112 | symbol_conf.use_callchain = true; |
| 113 | |
| 114 | if (!arg) |
| 115 | return 0; |
| 116 | |
Namhyung Kim | e8232f1 | 2014-08-14 15:01:38 +0900 | [diff] [blame] | 117 | while ((tok = strtok((char *)arg, ",")) != NULL) { |
| 118 | if (!strncmp(tok, "none", strlen(tok))) { |
| 119 | callchain_param.mode = CHAIN_NONE; |
| 120 | symbol_conf.use_callchain = false; |
| 121 | return 0; |
| 122 | } |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 123 | |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 124 | if (!parse_callchain_mode(tok) || |
| 125 | !parse_callchain_order(tok) || |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 126 | !parse_callchain_sort_key(tok) || |
| 127 | !parse_callchain_value(tok)) { |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 128 | /* parsing ok - move on to the next */ |
Namhyung Kim | a2c10d3 | 2015-10-22 15:28:49 +0900 | [diff] [blame] | 129 | try_stack_size = false; |
| 130 | goto next; |
| 131 | } else if (allow_record_opt && !record_opt_set) { |
| 132 | if (parse_callchain_record(tok, &callchain_param)) |
| 133 | goto try_numbers; |
| 134 | |
| 135 | /* assume that number followed by 'dwarf' is stack size */ |
| 136 | if (callchain_param.record_mode == CALLCHAIN_DWARF) |
| 137 | try_stack_size = true; |
| 138 | |
| 139 | record_opt_set = true; |
| 140 | goto next; |
| 141 | } |
| 142 | |
| 143 | try_numbers: |
| 144 | if (try_stack_size) { |
| 145 | unsigned long size = 0; |
| 146 | |
| 147 | if (get_stack_size(tok, &size) < 0) |
| 148 | return -1; |
| 149 | callchain_param.dump_size = size; |
| 150 | try_stack_size = false; |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 151 | } else if (!minpcnt_set) { |
| 152 | /* try to get the min percent */ |
Namhyung Kim | e8232f1 | 2014-08-14 15:01:38 +0900 | [diff] [blame] | 153 | callchain_param.min_percent = strtod(tok, &endptr); |
| 154 | if (tok == endptr) |
| 155 | return -1; |
| 156 | minpcnt_set = true; |
| 157 | } else { |
| 158 | /* try print limit at last */ |
| 159 | callchain_param.print_limit = strtoul(tok, &endptr, 0); |
| 160 | if (tok == endptr) |
| 161 | return -1; |
| 162 | } |
Namhyung Kim | a2c10d3 | 2015-10-22 15:28:49 +0900 | [diff] [blame] | 163 | next: |
Namhyung Kim | e8232f1 | 2014-08-14 15:01:38 +0900 | [diff] [blame] | 164 | arg = NULL; |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Don Zickus | cff6bb4 | 2014-04-07 14:55:24 -0400 | [diff] [blame] | 167 | if (callchain_register_param(&callchain_param) < 0) { |
| 168 | pr_err("Can't register callchain params\n"); |
| 169 | return -1; |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
Namhyung Kim | a2c10d3 | 2015-10-22 15:28:49 +0900 | [diff] [blame] | 174 | int parse_callchain_report_opt(const char *arg) |
| 175 | { |
| 176 | return __parse_callchain_report_opt(arg, false); |
| 177 | } |
| 178 | |
| 179 | int parse_callchain_top_opt(const char *arg) |
| 180 | { |
| 181 | return __parse_callchain_report_opt(arg, true); |
| 182 | } |
| 183 | |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 184 | int perf_callchain_config(const char *var, const char *value) |
| 185 | { |
| 186 | char *endptr; |
| 187 | |
| 188 | if (prefixcmp(var, "call-graph.")) |
| 189 | return 0; |
| 190 | var += sizeof("call-graph.") - 1; |
| 191 | |
| 192 | if (!strcmp(var, "record-mode")) |
Kan Liang | c3a6a8c | 2015-08-04 04:30:20 -0400 | [diff] [blame] | 193 | return parse_callchain_record_opt(value, &callchain_param); |
Namhyung Kim | 2b9240c | 2014-09-23 10:01:43 +0900 | [diff] [blame] | 194 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
| 195 | if (!strcmp(var, "dump-size")) { |
| 196 | unsigned long size = 0; |
| 197 | int ret; |
| 198 | |
| 199 | ret = get_stack_size(value, &size); |
| 200 | callchain_param.dump_size = size; |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | #endif |
| 205 | if (!strcmp(var, "print-type")) |
| 206 | return parse_callchain_mode(value); |
| 207 | if (!strcmp(var, "order")) |
| 208 | return parse_callchain_order(value); |
| 209 | if (!strcmp(var, "sort-key")) |
| 210 | return parse_callchain_sort_key(value); |
| 211 | if (!strcmp(var, "threshold")) { |
| 212 | callchain_param.min_percent = strtod(value, &endptr); |
| 213 | if (value == endptr) |
| 214 | return -1; |
| 215 | } |
| 216 | if (!strcmp(var, "print-limit")) { |
| 217 | callchain_param.print_limit = strtod(value, &endptr); |
| 218 | if (value == endptr) |
| 219 | return -1; |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 225 | static void |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 226 | rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, |
| 227 | enum chain_mode mode) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 228 | { |
| 229 | struct rb_node **p = &root->rb_node; |
| 230 | struct rb_node *parent = NULL; |
| 231 | struct callchain_node *rnode; |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 232 | u64 chain_cumul = callchain_cumul_hits(chain); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 233 | |
| 234 | while (*p) { |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 235 | u64 rnode_cumul; |
| 236 | |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 237 | parent = *p; |
| 238 | rnode = rb_entry(parent, struct callchain_node, rb_node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 239 | rnode_cumul = callchain_cumul_hits(rnode); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 240 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 241 | switch (mode) { |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 242 | case CHAIN_FLAT: |
Namhyung Kim | 26e7792 | 2015-11-09 14:45:37 +0900 | [diff] [blame] | 243 | case CHAIN_FOLDED: |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 244 | if (rnode->hit < chain->hit) |
| 245 | p = &(*p)->rb_left; |
| 246 | else |
| 247 | p = &(*p)->rb_right; |
| 248 | break; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 249 | case CHAIN_GRAPH_ABS: /* Falldown */ |
| 250 | case CHAIN_GRAPH_REL: |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 251 | if (rnode_cumul < chain_cumul) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 252 | p = &(*p)->rb_left; |
| 253 | else |
| 254 | p = &(*p)->rb_right; |
| 255 | break; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 256 | case CHAIN_NONE: |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 257 | default: |
| 258 | break; |
| 259 | } |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | rb_link_node(&chain->rb_node, parent, p); |
| 263 | rb_insert_color(&chain->rb_node, root); |
| 264 | } |
| 265 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 266 | static void |
| 267 | __sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node, |
| 268 | u64 min_hit) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 269 | { |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 270 | struct rb_node *n; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 271 | struct callchain_node *child; |
| 272 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 273 | n = rb_first(&node->rb_root_in); |
| 274 | while (n) { |
| 275 | child = rb_entry(n, struct callchain_node, rb_node_in); |
| 276 | n = rb_next(n); |
| 277 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 278 | __sort_chain_flat(rb_root, child, min_hit); |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 279 | } |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 280 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 281 | if (node->hit && node->hit >= min_hit) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 282 | rb_insert_callchain(rb_root, node, CHAIN_FLAT); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 285 | /* |
| 286 | * Once we get every callchains from the stream, we can now |
| 287 | * sort them by hit |
| 288 | */ |
| 289 | static void |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 290 | sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 291 | u64 min_hit, struct callchain_param *param __maybe_unused) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 292 | { |
Namhyung Kim | 0356218 | 2015-11-26 16:08:18 +0900 | [diff] [blame] | 293 | *rb_root = RB_ROOT; |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 294 | __sort_chain_flat(rb_root, &root->node, min_hit); |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void __sort_chain_graph_abs(struct callchain_node *node, |
| 298 | u64 min_hit) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 299 | { |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 300 | struct rb_node *n; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 301 | struct callchain_node *child; |
| 302 | |
| 303 | node->rb_root = RB_ROOT; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 304 | n = rb_first(&node->rb_root_in); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 305 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 306 | while (n) { |
| 307 | child = rb_entry(n, struct callchain_node, rb_node_in); |
| 308 | n = rb_next(n); |
| 309 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 310 | __sort_chain_graph_abs(child, min_hit); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 311 | if (callchain_cumul_hits(child) >= min_hit) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 312 | rb_insert_callchain(&node->rb_root, child, |
| 313 | CHAIN_GRAPH_ABS); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 317 | static void |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 318 | sort_chain_graph_abs(struct rb_root *rb_root, struct callchain_root *chain_root, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 319 | u64 min_hit, struct callchain_param *param __maybe_unused) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 320 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 321 | __sort_chain_graph_abs(&chain_root->node, min_hit); |
| 322 | rb_root->rb_node = chain_root->node.rb_root.rb_node; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 325 | static void __sort_chain_graph_rel(struct callchain_node *node, |
| 326 | double min_percent) |
| 327 | { |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 328 | struct rb_node *n; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 329 | struct callchain_node *child; |
| 330 | u64 min_hit; |
| 331 | |
| 332 | node->rb_root = RB_ROOT; |
Frederic Weisbecker | c0a8865 | 2009-08-09 04:19:15 +0200 | [diff] [blame] | 333 | min_hit = ceil(node->children_hit * min_percent); |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 334 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 335 | n = rb_first(&node->rb_root_in); |
| 336 | while (n) { |
| 337 | child = rb_entry(n, struct callchain_node, rb_node_in); |
| 338 | n = rb_next(n); |
| 339 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 340 | __sort_chain_graph_rel(child, min_percent); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 341 | if (callchain_cumul_hits(child) >= min_hit) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 342 | rb_insert_callchain(&node->rb_root, child, |
| 343 | CHAIN_GRAPH_REL); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static void |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 348 | sort_chain_graph_rel(struct rb_root *rb_root, struct callchain_root *chain_root, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 349 | u64 min_hit __maybe_unused, struct callchain_param *param) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 350 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 351 | __sort_chain_graph_rel(&chain_root->node, param->min_percent / 100.0); |
| 352 | rb_root->rb_node = chain_root->node.rb_root.rb_node; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Frederic Weisbecker | 16537f1 | 2011-01-14 04:52:00 +0100 | [diff] [blame] | 355 | int callchain_register_param(struct callchain_param *param) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 356 | { |
| 357 | switch (param->mode) { |
| 358 | case CHAIN_GRAPH_ABS: |
| 359 | param->sort = sort_chain_graph_abs; |
| 360 | break; |
| 361 | case CHAIN_GRAPH_REL: |
| 362 | param->sort = sort_chain_graph_rel; |
| 363 | break; |
| 364 | case CHAIN_FLAT: |
Namhyung Kim | 26e7792 | 2015-11-09 14:45:37 +0900 | [diff] [blame] | 365 | case CHAIN_FOLDED: |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 366 | param->sort = sort_chain_flat; |
| 367 | break; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 368 | case CHAIN_NONE: |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 369 | default: |
| 370 | return -1; |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 375 | /* |
| 376 | * Create a child for a parent. If inherit_children, then the new child |
| 377 | * will become the new parent of it's parent children |
| 378 | */ |
| 379 | static struct callchain_node * |
| 380 | create_child(struct callchain_node *parent, bool inherit_children) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 381 | { |
| 382 | struct callchain_node *new; |
| 383 | |
Arnaldo Carvalho de Melo | cdd5b75b | 2010-05-10 10:56:50 -0300 | [diff] [blame] | 384 | new = zalloc(sizeof(*new)); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 385 | if (!new) { |
| 386 | perror("not enough memory to create child for code path tree"); |
| 387 | return NULL; |
| 388 | } |
| 389 | new->parent = parent; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 390 | INIT_LIST_HEAD(&new->val); |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 391 | INIT_LIST_HEAD(&new->parent_val); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 392 | |
| 393 | if (inherit_children) { |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 394 | struct rb_node *n; |
| 395 | struct callchain_node *child; |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 396 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 397 | new->rb_root_in = parent->rb_root_in; |
| 398 | parent->rb_root_in = RB_ROOT; |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 399 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 400 | n = rb_first(&new->rb_root_in); |
| 401 | while (n) { |
| 402 | child = rb_entry(n, struct callchain_node, rb_node_in); |
| 403 | child->parent = new; |
| 404 | n = rb_next(n); |
| 405 | } |
| 406 | |
| 407 | /* make it the first child */ |
| 408 | rb_link_node(&new->rb_node_in, NULL, &parent->rb_root_in.rb_node); |
| 409 | rb_insert_color(&new->rb_node_in, &parent->rb_root_in); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 410 | } |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 411 | |
| 412 | return new; |
| 413 | } |
| 414 | |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 415 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 416 | /* |
| 417 | * Fill the node with callchain values |
| 418 | */ |
Namhyung Kim | 8451cbb | 2016-02-16 23:08:21 +0900 | [diff] [blame^] | 419 | static int |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 420 | fill_node(struct callchain_node *node, struct callchain_cursor *cursor) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 421 | { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 422 | struct callchain_cursor_node *cursor_node; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 423 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 424 | node->val_nr = cursor->nr - cursor->pos; |
| 425 | if (!node->val_nr) |
| 426 | pr_warning("Warning: empty node in callchain tree\n"); |
| 427 | |
| 428 | cursor_node = callchain_cursor_current(cursor); |
| 429 | |
| 430 | while (cursor_node) { |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 431 | struct callchain_list *call; |
| 432 | |
Arnaldo Carvalho de Melo | cdd5b75b | 2010-05-10 10:56:50 -0300 | [diff] [blame] | 433 | call = zalloc(sizeof(*call)); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 434 | if (!call) { |
| 435 | perror("not enough memory for the code path tree"); |
Namhyung Kim | 8451cbb | 2016-02-16 23:08:21 +0900 | [diff] [blame^] | 436 | return -1; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 437 | } |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 438 | call->ip = cursor_node->ip; |
| 439 | call->ms.sym = cursor_node->sym; |
| 440 | call->ms.map = cursor_node->map; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 441 | list_add_tail(&call->list, &node->val); |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 442 | |
| 443 | callchain_cursor_advance(cursor); |
| 444 | cursor_node = callchain_cursor_current(cursor); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 445 | } |
Namhyung Kim | 8451cbb | 2016-02-16 23:08:21 +0900 | [diff] [blame^] | 446 | return 0; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 447 | } |
| 448 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 449 | static struct callchain_node * |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 450 | add_child(struct callchain_node *parent, |
| 451 | struct callchain_cursor *cursor, |
| 452 | u64 period) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 453 | { |
| 454 | struct callchain_node *new; |
| 455 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 456 | new = create_child(parent, false); |
Namhyung Kim | 7565bd3 | 2016-02-16 23:08:20 +0900 | [diff] [blame] | 457 | if (new == NULL) |
| 458 | return NULL; |
| 459 | |
Namhyung Kim | 8451cbb | 2016-02-16 23:08:21 +0900 | [diff] [blame^] | 460 | if (fill_node(new, cursor) < 0) { |
| 461 | struct callchain_list *call, *tmp; |
| 462 | |
| 463 | list_for_each_entry_safe(call, tmp, &new->val, list) { |
| 464 | list_del(&call->list); |
| 465 | free(call); |
| 466 | } |
| 467 | free(new); |
| 468 | return NULL; |
| 469 | } |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 470 | |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 471 | new->children_hit = 0; |
Frederic Weisbecker | 108553e | 2010-07-08 03:41:46 +0200 | [diff] [blame] | 472 | new->hit = period; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 473 | new->children_count = 0; |
| 474 | new->count = 1; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 475 | return new; |
| 476 | } |
| 477 | |
| 478 | static s64 match_chain(struct callchain_cursor_node *node, |
| 479 | struct callchain_list *cnode) |
| 480 | { |
| 481 | struct symbol *sym = node->sym; |
| 482 | |
| 483 | if (cnode->ms.sym && sym && |
| 484 | callchain_param.key == CCKEY_FUNCTION) |
| 485 | return cnode->ms.sym->start - sym->start; |
| 486 | else |
| 487 | return cnode->ip - node->ip; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 488 | } |
| 489 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 490 | /* |
| 491 | * Split the parent in two parts (a new child is created) and |
| 492 | * give a part of its callchain to the created child. |
| 493 | * Then create another child to host the given callchain of new branch |
| 494 | */ |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 495 | static void |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 496 | split_add_child(struct callchain_node *parent, |
| 497 | struct callchain_cursor *cursor, |
| 498 | struct callchain_list *to_split, |
| 499 | u64 idx_parents, u64 idx_local, u64 period) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 500 | { |
| 501 | struct callchain_node *new; |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 502 | struct list_head *old_tail; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 503 | unsigned int idx_total = idx_parents + idx_local; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 504 | |
| 505 | /* split */ |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 506 | new = create_child(parent, true); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 507 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 508 | /* split the callchain and move a part to the new child */ |
| 509 | old_tail = parent->val.prev; |
| 510 | list_del_range(&to_split->list, old_tail); |
| 511 | new->val.next = &to_split->list; |
| 512 | new->val.prev = old_tail; |
| 513 | to_split->list.prev = &new->val; |
| 514 | old_tail->next = &new->val; |
| 515 | |
| 516 | /* split the hits */ |
| 517 | new->hit = parent->hit; |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 518 | new->children_hit = parent->children_hit; |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 519 | parent->children_hit = callchain_cumul_hits(new); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 520 | new->val_nr = parent->val_nr - idx_local; |
| 521 | parent->val_nr = idx_local; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 522 | new->count = parent->count; |
| 523 | new->children_count = parent->children_count; |
| 524 | parent->children_count = callchain_cumul_counts(new); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 525 | |
| 526 | /* create a new child for the new branch if any */ |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 527 | if (idx_total < cursor->nr) { |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 528 | struct callchain_node *first; |
| 529 | struct callchain_list *cnode; |
| 530 | struct callchain_cursor_node *node; |
| 531 | struct rb_node *p, **pp; |
| 532 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 533 | parent->hit = 0; |
Frederic Weisbecker | 108553e | 2010-07-08 03:41:46 +0200 | [diff] [blame] | 534 | parent->children_hit += period; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 535 | parent->count = 0; |
| 536 | parent->children_count += 1; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 537 | |
| 538 | node = callchain_cursor_current(cursor); |
| 539 | new = add_child(parent, cursor, period); |
Namhyung Kim | 7565bd3 | 2016-02-16 23:08:20 +0900 | [diff] [blame] | 540 | if (new == NULL) |
| 541 | return; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * This is second child since we moved parent's children |
| 545 | * to new (first) child above. |
| 546 | */ |
| 547 | p = parent->rb_root_in.rb_node; |
| 548 | first = rb_entry(p, struct callchain_node, rb_node_in); |
| 549 | cnode = list_first_entry(&first->val, struct callchain_list, |
| 550 | list); |
| 551 | |
| 552 | if (match_chain(node, cnode) < 0) |
| 553 | pp = &p->rb_left; |
| 554 | else |
| 555 | pp = &p->rb_right; |
| 556 | |
| 557 | rb_link_node(&new->rb_node_in, p, pp); |
| 558 | rb_insert_color(&new->rb_node_in, &parent->rb_root_in); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 559 | } else { |
Frederic Weisbecker | 108553e | 2010-07-08 03:41:46 +0200 | [diff] [blame] | 560 | parent->hit = period; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 561 | parent->count = 1; |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 562 | } |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static int |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 566 | append_chain(struct callchain_node *root, |
| 567 | struct callchain_cursor *cursor, |
| 568 | u64 period); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 569 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 570 | static void |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 571 | append_chain_children(struct callchain_node *root, |
| 572 | struct callchain_cursor *cursor, |
| 573 | u64 period) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 574 | { |
| 575 | struct callchain_node *rnode; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 576 | struct callchain_cursor_node *node; |
| 577 | struct rb_node **p = &root->rb_root_in.rb_node; |
| 578 | struct rb_node *parent = NULL; |
| 579 | |
| 580 | node = callchain_cursor_current(cursor); |
| 581 | if (!node) |
| 582 | return; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 583 | |
| 584 | /* lookup in childrens */ |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 585 | while (*p) { |
| 586 | s64 ret; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 587 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 588 | parent = *p; |
| 589 | rnode = rb_entry(parent, struct callchain_node, rb_node_in); |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 590 | |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 591 | /* If at least first entry matches, rely to children */ |
| 592 | ret = append_chain(rnode, cursor, period); |
| 593 | if (ret == 0) |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 594 | goto inc_children_hit; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 595 | |
| 596 | if (ret < 0) |
| 597 | p = &parent->rb_left; |
| 598 | else |
| 599 | p = &parent->rb_right; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 600 | } |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 601 | /* nothing in children, add to the current node */ |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 602 | rnode = add_child(root, cursor, period); |
Namhyung Kim | 7565bd3 | 2016-02-16 23:08:20 +0900 | [diff] [blame] | 603 | if (rnode == NULL) |
| 604 | return; |
| 605 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 606 | rb_link_node(&rnode->rb_node_in, parent, p); |
| 607 | rb_insert_color(&rnode->rb_node_in, &root->rb_root_in); |
Frederic Weisbecker | e05b876 | 2009-07-05 07:39:20 +0200 | [diff] [blame] | 608 | |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 609 | inc_children_hit: |
Frederic Weisbecker | 108553e | 2010-07-08 03:41:46 +0200 | [diff] [blame] | 610 | root->children_hit += period; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 611 | root->children_count++; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static int |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 615 | append_chain(struct callchain_node *root, |
| 616 | struct callchain_cursor *cursor, |
| 617 | u64 period) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 618 | { |
| 619 | struct callchain_list *cnode; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 620 | u64 start = cursor->pos; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 621 | bool found = false; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 622 | u64 matches; |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 623 | int cmp = 0; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 624 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 625 | /* |
| 626 | * Lookup in the current node |
| 627 | * If we have a symbol, then compare the start to match |
Andi Kleen | 99571ab | 2013-07-18 15:33:57 -0700 | [diff] [blame] | 628 | * anywhere inside a function, unless function |
| 629 | * mode is disabled. |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 630 | */ |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 631 | list_for_each_entry(cnode, &root->val, list) { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 632 | struct callchain_cursor_node *node; |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 633 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 634 | node = callchain_cursor_current(cursor); |
| 635 | if (!node) |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 636 | break; |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 637 | |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 638 | cmp = match_chain(node, cnode); |
| 639 | if (cmp) |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 640 | break; |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 641 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 642 | found = true; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 643 | |
| 644 | callchain_cursor_advance(cursor); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 647 | /* matches not, relay no the parent */ |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 648 | if (!found) { |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 649 | WARN_ONCE(!cmp, "Chain comparison error\n"); |
Frederic Weisbecker | b965bb4 | 2014-01-14 16:37:15 +0100 | [diff] [blame] | 650 | return cmp; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | matches = cursor->pos - start; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 654 | |
| 655 | /* we match only a part of the node. Split it and add the new chain */ |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 656 | if (matches < root->val_nr) { |
| 657 | split_add_child(root, cursor, cnode, start, matches, period); |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | /* we match 100% of the path, increment the hit */ |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 662 | if (matches == root->val_nr && cursor->pos == cursor->nr) { |
Frederic Weisbecker | 108553e | 2010-07-08 03:41:46 +0200 | [diff] [blame] | 663 | root->hit += period; |
Namhyung Kim | 5e47f8f | 2015-11-09 14:45:40 +0900 | [diff] [blame] | 664 | root->count++; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 665 | return 0; |
| 666 | } |
| 667 | |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 668 | /* We match the node and still have a part remaining */ |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 669 | append_chain_children(root, cursor, period); |
Frederic Weisbecker | deac911 | 2009-07-01 05:35:15 +0200 | [diff] [blame] | 670 | |
| 671 | return 0; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 674 | int callchain_append(struct callchain_root *root, |
| 675 | struct callchain_cursor *cursor, |
| 676 | u64 period) |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 677 | { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 678 | if (!cursor->nr) |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 679 | return 0; |
| 680 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 681 | callchain_cursor_commit(cursor); |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 682 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 683 | append_chain_children(&root->node, cursor, period); |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 684 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 685 | if (cursor->nr > root->max_depth) |
| 686 | root->max_depth = cursor->nr; |
Frederic Weisbecker | 301fde2 | 2010-03-22 13:09:33 -0300 | [diff] [blame] | 687 | |
| 688 | return 0; |
Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 689 | } |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 690 | |
| 691 | static int |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 692 | merge_chain_branch(struct callchain_cursor *cursor, |
| 693 | struct callchain_node *dst, struct callchain_node *src) |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 694 | { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 695 | struct callchain_cursor_node **old_last = cursor->last; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 696 | struct callchain_node *child; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 697 | struct callchain_list *list, *next_list; |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 698 | struct rb_node *n; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 699 | int old_pos = cursor->nr; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 700 | int err = 0; |
| 701 | |
| 702 | list_for_each_entry_safe(list, next_list, &src->val, list) { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 703 | callchain_cursor_append(cursor, list->ip, |
| 704 | list->ms.map, list->ms.sym); |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 705 | list_del(&list->list); |
| 706 | free(list); |
| 707 | } |
| 708 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 709 | if (src->hit) { |
| 710 | callchain_cursor_commit(cursor); |
| 711 | append_chain_children(dst, cursor, src->hit); |
| 712 | } |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 713 | |
Namhyung Kim | e369517 | 2013-10-11 14:15:36 +0900 | [diff] [blame] | 714 | n = rb_first(&src->rb_root_in); |
| 715 | while (n) { |
| 716 | child = container_of(n, struct callchain_node, rb_node_in); |
| 717 | n = rb_next(n); |
| 718 | rb_erase(&child->rb_node_in, &src->rb_root_in); |
| 719 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 720 | err = merge_chain_branch(cursor, dst, child); |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 721 | if (err) |
| 722 | break; |
| 723 | |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 724 | free(child); |
| 725 | } |
| 726 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 727 | cursor->nr = old_pos; |
| 728 | cursor->last = old_last; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 729 | |
| 730 | return err; |
| 731 | } |
| 732 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 733 | int callchain_merge(struct callchain_cursor *cursor, |
| 734 | struct callchain_root *dst, struct callchain_root *src) |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 735 | { |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 736 | return merge_chain_branch(cursor, &dst->node, &src->node); |
| 737 | } |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 738 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 739 | int callchain_cursor_append(struct callchain_cursor *cursor, |
| 740 | u64 ip, struct map *map, struct symbol *sym) |
| 741 | { |
| 742 | struct callchain_cursor_node *node = *cursor->last; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 743 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 744 | if (!node) { |
Paul Gortmaker | 91b9880 | 2013-01-30 20:05:49 -0500 | [diff] [blame] | 745 | node = calloc(1, sizeof(*node)); |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 746 | if (!node) |
| 747 | return -ENOMEM; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 748 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 749 | *cursor->last = node; |
| 750 | } |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 751 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 752 | node->ip = ip; |
| 753 | node->map = map; |
| 754 | node->sym = sym; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 755 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 756 | cursor->nr++; |
| 757 | |
| 758 | cursor->last = &node->next; |
| 759 | |
| 760 | return 0; |
Frederic Weisbecker | 612d4fd | 2010-08-22 21:10:35 +0200 | [diff] [blame] | 761 | } |
Namhyung Kim | 2dc9fb1 | 2014-01-14 14:25:35 +0900 | [diff] [blame] | 762 | |
| 763 | int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent, |
| 764 | struct perf_evsel *evsel, struct addr_location *al, |
| 765 | int max_stack) |
| 766 | { |
| 767 | if (sample->callchain == NULL) |
| 768 | return 0; |
| 769 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 770 | if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || |
| 771 | sort__has_parent) { |
Arnaldo Carvalho de Melo | cc8b7c2 | 2014-10-23 15:26:17 -0300 | [diff] [blame] | 772 | return thread__resolve_callchain(al->thread, evsel, sample, |
| 773 | parent, al, max_stack); |
Namhyung Kim | 2dc9fb1 | 2014-01-14 14:25:35 +0900 | [diff] [blame] | 774 | } |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample) |
| 779 | { |
Adrian Hunter | 4d40b05 | 2014-07-14 13:02:35 +0300 | [diff] [blame] | 780 | if (!symbol_conf.use_callchain || sample->callchain == NULL) |
Namhyung Kim | 2dc9fb1 | 2014-01-14 14:25:35 +0900 | [diff] [blame] | 781 | return 0; |
| 782 | return callchain_append(he->callchain, &callchain_cursor, sample->period); |
| 783 | } |
Namhyung Kim | c7405d8 | 2013-10-31 13:58:30 +0900 | [diff] [blame] | 784 | |
| 785 | int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, |
| 786 | bool hide_unresolved) |
| 787 | { |
| 788 | al->map = node->map; |
| 789 | al->sym = node->sym; |
| 790 | if (node->map) |
| 791 | al->addr = node->map->map_ip(node->map, node->ip); |
| 792 | else |
| 793 | al->addr = node->ip; |
| 794 | |
| 795 | if (al->sym == NULL) { |
| 796 | if (hide_unresolved) |
| 797 | return 0; |
| 798 | if (al->map == NULL) |
| 799 | goto out; |
| 800 | } |
| 801 | |
| 802 | if (al->map->groups == &al->machine->kmaps) { |
| 803 | if (machine__is_host(al->machine)) { |
| 804 | al->cpumode = PERF_RECORD_MISC_KERNEL; |
| 805 | al->level = 'k'; |
| 806 | } else { |
| 807 | al->cpumode = PERF_RECORD_MISC_GUEST_KERNEL; |
| 808 | al->level = 'g'; |
| 809 | } |
| 810 | } else { |
| 811 | if (machine__is_host(al->machine)) { |
| 812 | al->cpumode = PERF_RECORD_MISC_USER; |
| 813 | al->level = '.'; |
| 814 | } else if (perf_guest) { |
| 815 | al->cpumode = PERF_RECORD_MISC_GUEST_USER; |
| 816 | al->level = 'u'; |
| 817 | } else { |
| 818 | al->cpumode = PERF_RECORD_MISC_HYPERVISOR; |
| 819 | al->level = 'H'; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | out: |
| 824 | return 1; |
| 825 | } |
Andi Kleen | 2989cca | 2014-11-12 18:05:23 -0800 | [diff] [blame] | 826 | |
| 827 | char *callchain_list__sym_name(struct callchain_list *cl, |
| 828 | char *bf, size_t bfsize, bool show_dso) |
| 829 | { |
| 830 | int printed; |
| 831 | |
| 832 | if (cl->ms.sym) { |
Andi Kleen | 23f0981 | 2014-11-12 18:05:24 -0800 | [diff] [blame] | 833 | if (callchain_param.key == CCKEY_ADDRESS && |
| 834 | cl->ms.map && !cl->srcline) |
| 835 | cl->srcline = get_srcline(cl->ms.map->dso, |
| 836 | map__rip_2objdump(cl->ms.map, |
Andi Kleen | 85c116a | 2014-11-12 18:05:27 -0800 | [diff] [blame] | 837 | cl->ip), |
| 838 | cl->ms.sym, false); |
Andi Kleen | 23f0981 | 2014-11-12 18:05:24 -0800 | [diff] [blame] | 839 | if (cl->srcline) |
| 840 | printed = scnprintf(bf, bfsize, "%s %s", |
| 841 | cl->ms.sym->name, cl->srcline); |
| 842 | else |
| 843 | printed = scnprintf(bf, bfsize, "%s", cl->ms.sym->name); |
Andi Kleen | 2989cca | 2014-11-12 18:05:23 -0800 | [diff] [blame] | 844 | } else |
| 845 | printed = scnprintf(bf, bfsize, "%#" PRIx64, cl->ip); |
| 846 | |
| 847 | if (show_dso) |
| 848 | scnprintf(bf + printed, bfsize - printed, " %s", |
| 849 | cl->ms.map ? |
| 850 | cl->ms.map->dso->short_name : |
| 851 | "unknown"); |
| 852 | |
| 853 | return bf; |
| 854 | } |
Namhyung Kim | d114960 | 2014-12-30 14:38:13 +0900 | [diff] [blame] | 855 | |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 856 | char *callchain_node__scnprintf_value(struct callchain_node *node, |
| 857 | char *bf, size_t bfsize, u64 total) |
| 858 | { |
| 859 | double percent = 0.0; |
| 860 | u64 period = callchain_cumul_hits(node); |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 861 | unsigned count = callchain_cumul_counts(node); |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 862 | |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 863 | if (callchain_param.mode == CHAIN_FOLDED) { |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 864 | period = node->hit; |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 865 | count = node->count; |
| 866 | } |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 867 | |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 868 | switch (callchain_param.value) { |
| 869 | case CCVAL_PERIOD: |
| 870 | scnprintf(bf, bfsize, "%"PRIu64, period); |
| 871 | break; |
| 872 | case CCVAL_COUNT: |
| 873 | scnprintf(bf, bfsize, "%u", count); |
| 874 | break; |
| 875 | case CCVAL_PERCENT: |
| 876 | default: |
| 877 | if (total) |
| 878 | percent = period * 100.0 / total; |
| 879 | scnprintf(bf, bfsize, "%.2f%%", percent); |
| 880 | break; |
| 881 | } |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 882 | return bf; |
| 883 | } |
| 884 | |
| 885 | int callchain_node__fprintf_value(struct callchain_node *node, |
| 886 | FILE *fp, u64 total) |
| 887 | { |
| 888 | double percent = 0.0; |
| 889 | u64 period = callchain_cumul_hits(node); |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 890 | unsigned count = callchain_cumul_counts(node); |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 891 | |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 892 | if (callchain_param.mode == CHAIN_FOLDED) { |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 893 | period = node->hit; |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 894 | count = node->count; |
| 895 | } |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 896 | |
Namhyung Kim | f2af008 | 2015-11-09 14:45:41 +0900 | [diff] [blame] | 897 | switch (callchain_param.value) { |
| 898 | case CCVAL_PERIOD: |
| 899 | return fprintf(fp, "%"PRIu64, period); |
| 900 | case CCVAL_COUNT: |
| 901 | return fprintf(fp, "%u", count); |
| 902 | case CCVAL_PERCENT: |
| 903 | default: |
| 904 | if (total) |
| 905 | percent = period * 100.0 / total; |
| 906 | return percent_color_fprintf(fp, "%.2f%%", percent); |
| 907 | } |
| 908 | return 0; |
Namhyung Kim | 5ab250c | 2015-11-09 14:45:39 +0900 | [diff] [blame] | 909 | } |
| 910 | |
Namhyung Kim | d114960 | 2014-12-30 14:38:13 +0900 | [diff] [blame] | 911 | static void free_callchain_node(struct callchain_node *node) |
| 912 | { |
| 913 | struct callchain_list *list, *tmp; |
| 914 | struct callchain_node *child; |
| 915 | struct rb_node *n; |
| 916 | |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 917 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { |
| 918 | list_del(&list->list); |
| 919 | free(list); |
| 920 | } |
| 921 | |
Namhyung Kim | d114960 | 2014-12-30 14:38:13 +0900 | [diff] [blame] | 922 | list_for_each_entry_safe(list, tmp, &node->val, list) { |
| 923 | list_del(&list->list); |
| 924 | free(list); |
| 925 | } |
| 926 | |
| 927 | n = rb_first(&node->rb_root_in); |
| 928 | while (n) { |
| 929 | child = container_of(n, struct callchain_node, rb_node_in); |
| 930 | n = rb_next(n); |
| 931 | rb_erase(&child->rb_node_in, &node->rb_root_in); |
| 932 | |
| 933 | free_callchain_node(child); |
| 934 | free(child); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | void free_callchain(struct callchain_root *root) |
| 939 | { |
| 940 | if (!symbol_conf.use_callchain) |
| 941 | return; |
| 942 | |
| 943 | free_callchain_node(&root->node); |
| 944 | } |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 945 | |
Namhyung Kim | 42b276a | 2016-01-05 12:06:00 +0900 | [diff] [blame] | 946 | static u64 decay_callchain_node(struct callchain_node *node) |
| 947 | { |
| 948 | struct callchain_node *child; |
| 949 | struct rb_node *n; |
| 950 | u64 child_hits = 0; |
| 951 | |
| 952 | n = rb_first(&node->rb_root_in); |
| 953 | while (n) { |
| 954 | child = container_of(n, struct callchain_node, rb_node_in); |
| 955 | |
| 956 | child_hits += decay_callchain_node(child); |
| 957 | n = rb_next(n); |
| 958 | } |
| 959 | |
| 960 | node->hit = (node->hit * 7) / 8; |
| 961 | node->children_hit = child_hits; |
| 962 | |
| 963 | return node->hit; |
| 964 | } |
| 965 | |
| 966 | void decay_callchain(struct callchain_root *root) |
| 967 | { |
| 968 | if (!symbol_conf.use_callchain) |
| 969 | return; |
| 970 | |
| 971 | decay_callchain_node(&root->node); |
| 972 | } |
| 973 | |
Namhyung Kim | 4b3a321 | 2015-11-09 14:45:43 +0900 | [diff] [blame] | 974 | int callchain_node__make_parent_list(struct callchain_node *node) |
| 975 | { |
| 976 | struct callchain_node *parent = node->parent; |
| 977 | struct callchain_list *chain, *new; |
| 978 | LIST_HEAD(head); |
| 979 | |
| 980 | while (parent) { |
| 981 | list_for_each_entry_reverse(chain, &parent->val, list) { |
| 982 | new = malloc(sizeof(*new)); |
| 983 | if (new == NULL) |
| 984 | goto out; |
| 985 | *new = *chain; |
| 986 | new->has_children = false; |
| 987 | list_add_tail(&new->list, &head); |
| 988 | } |
| 989 | parent = parent->parent; |
| 990 | } |
| 991 | |
| 992 | list_for_each_entry_safe_reverse(chain, new, &head, list) |
| 993 | list_move_tail(&chain->list, &node->parent_val); |
| 994 | |
| 995 | if (!list_empty(&node->parent_val)) { |
| 996 | chain = list_first_entry(&node->parent_val, struct callchain_list, list); |
| 997 | chain->has_children = rb_prev(&node->rb_node) || rb_next(&node->rb_node); |
| 998 | |
| 999 | chain = list_first_entry(&node->val, struct callchain_list, list); |
| 1000 | chain->has_children = false; |
| 1001 | } |
| 1002 | return 0; |
| 1003 | |
| 1004 | out: |
| 1005 | list_for_each_entry_safe(chain, new, &head, list) { |
| 1006 | list_del(&chain->list); |
| 1007 | free(chain); |
| 1008 | } |
| 1009 | return -ENOMEM; |
| 1010 | } |