callchain.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * Copyright (C) 2009-2011, Frederic Weisbecker <fweisbec@gmail.com>
  3. *
  4. * Handle the callchains from the stream in an ad-hoc radix tree and then
  5. * sort them in an rbtree.
  6. *
  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. *
  10. */
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <stdbool.h>
  14. #include <errno.h>
  15. #include <math.h>
  16. #include "asm/bug.h"
  17. #include "hist.h"
  18. #include "util.h"
  19. #include "sort.h"
  20. #include "machine.h"
  21. #include "callchain.h"
  22. __thread struct callchain_cursor callchain_cursor;
  23. #ifdef HAVE_DWARF_UNWIND_SUPPORT
  24. static int get_stack_size(const char *str, unsigned long *_size)
  25. {
  26. char *endptr;
  27. unsigned long size;
  28. unsigned long max_size = round_down(USHRT_MAX, sizeof(u64));
  29. size = strtoul(str, &endptr, 0);
  30. do {
  31. if (*endptr)
  32. break;
  33. size = round_up(size, sizeof(u64));
  34. if (!size || size > max_size)
  35. break;
  36. *_size = size;
  37. return 0;
  38. } while (0);
  39. pr_err("callchain: Incorrect stack dump size (max %ld): %s\n",
  40. max_size, str);
  41. return -1;
  42. }
  43. #endif /* HAVE_DWARF_UNWIND_SUPPORT */
  44. int parse_callchain_record_opt(const char *arg)
  45. {
  46. char *tok, *name, *saveptr = NULL;
  47. char *buf;
  48. int ret = -1;
  49. /* We need buffer that we know we can write to. */
  50. buf = malloc(strlen(arg) + 1);
  51. if (!buf)
  52. return -ENOMEM;
  53. strcpy(buf, arg);
  54. tok = strtok_r((char *)buf, ",", &saveptr);
  55. name = tok ? : (char *)buf;
  56. do {
  57. /* Framepointer style */
  58. if (!strncmp(name, "fp", sizeof("fp"))) {
  59. if (!strtok_r(NULL, ",", &saveptr)) {
  60. callchain_param.record_mode = CALLCHAIN_FP;
  61. ret = 0;
  62. } else
  63. pr_err("callchain: No more arguments "
  64. "needed for -g fp\n");
  65. break;
  66. #ifdef HAVE_DWARF_UNWIND_SUPPORT
  67. /* Dwarf style */
  68. } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
  69. const unsigned long default_stack_dump_size = 8192;
  70. ret = 0;
  71. callchain_param.record_mode = CALLCHAIN_DWARF;
  72. callchain_param.dump_size = default_stack_dump_size;
  73. tok = strtok_r(NULL, ",", &saveptr);
  74. if (tok) {
  75. unsigned long size = 0;
  76. ret = get_stack_size(tok, &size);
  77. callchain_param.dump_size = size;
  78. }
  79. #endif /* HAVE_DWARF_UNWIND_SUPPORT */
  80. } else {
  81. pr_err("callchain: Unknown --call-graph option "
  82. "value: %s\n", arg);
  83. break;
  84. }
  85. } while (0);
  86. free(buf);
  87. return ret;
  88. }
  89. static int parse_callchain_mode(const char *value)
  90. {
  91. if (!strncmp(value, "graph", strlen(value))) {
  92. callchain_param.mode = CHAIN_GRAPH_ABS;
  93. return 0;
  94. }
  95. if (!strncmp(value, "flat", strlen(value))) {
  96. callchain_param.mode = CHAIN_FLAT;
  97. return 0;
  98. }
  99. if (!strncmp(value, "fractal", strlen(value))) {
  100. callchain_param.mode = CHAIN_GRAPH_REL;
  101. return 0;
  102. }
  103. return -1;
  104. }
  105. static int parse_callchain_order(const char *value)
  106. {
  107. if (!strncmp(value, "caller", strlen(value))) {
  108. callchain_param.order = ORDER_CALLER;
  109. return 0;
  110. }
  111. if (!strncmp(value, "callee", strlen(value))) {
  112. callchain_param.order = ORDER_CALLEE;
  113. return 0;
  114. }
  115. return -1;
  116. }
  117. static int parse_callchain_sort_key(const char *value)
  118. {
  119. if (!strncmp(value, "function", strlen(value))) {
  120. callchain_param.key = CCKEY_FUNCTION;
  121. return 0;
  122. }
  123. if (!strncmp(value, "address", strlen(value))) {
  124. callchain_param.key = CCKEY_ADDRESS;
  125. return 0;
  126. }
  127. return -1;
  128. }
  129. int
  130. parse_callchain_report_opt(const char *arg)
  131. {
  132. char *tok;
  133. char *endptr;
  134. bool minpcnt_set = false;
  135. symbol_conf.use_callchain = true;
  136. if (!arg)
  137. return 0;
  138. while ((tok = strtok((char *)arg, ",")) != NULL) {
  139. if (!strncmp(tok, "none", strlen(tok))) {
  140. callchain_param.mode = CHAIN_NONE;
  141. symbol_conf.use_callchain = false;
  142. return 0;
  143. }
  144. if (!parse_callchain_mode(tok) ||
  145. !parse_callchain_order(tok) ||
  146. !parse_callchain_sort_key(tok)) {
  147. /* parsing ok - move on to the next */
  148. } else if (!minpcnt_set) {
  149. /* try to get the min percent */
  150. callchain_param.min_percent = strtod(tok, &endptr);
  151. if (tok == endptr)
  152. return -1;
  153. minpcnt_set = true;
  154. } else {
  155. /* try print limit at last */
  156. callchain_param.print_limit = strtoul(tok, &endptr, 0);
  157. if (tok == endptr)
  158. return -1;
  159. }
  160. arg = NULL;
  161. }
  162. if (callchain_register_param(&callchain_param) < 0) {
  163. pr_err("Can't register callchain params\n");
  164. return -1;
  165. }
  166. return 0;
  167. }
  168. int perf_callchain_config(const char *var, const char *value)
  169. {
  170. char *endptr;
  171. if (prefixcmp(var, "call-graph."))
  172. return 0;
  173. var += sizeof("call-graph.") - 1;
  174. if (!strcmp(var, "record-mode"))
  175. return parse_callchain_record_opt(value);
  176. #ifdef HAVE_DWARF_UNWIND_SUPPORT
  177. if (!strcmp(var, "dump-size")) {
  178. unsigned long size = 0;
  179. int ret;
  180. ret = get_stack_size(value, &size);
  181. callchain_param.dump_size = size;
  182. return ret;
  183. }
  184. #endif
  185. if (!strcmp(var, "print-type"))
  186. return parse_callchain_mode(value);
  187. if (!strcmp(var, "order"))
  188. return parse_callchain_order(value);
  189. if (!strcmp(var, "sort-key"))
  190. return parse_callchain_sort_key(value);
  191. if (!strcmp(var, "threshold")) {
  192. callchain_param.min_percent = strtod(value, &endptr);
  193. if (value == endptr)
  194. return -1;
  195. }
  196. if (!strcmp(var, "print-limit")) {
  197. callchain_param.print_limit = strtod(value, &endptr);
  198. if (value == endptr)
  199. return -1;
  200. }
  201. return 0;
  202. }
  203. static void
  204. rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,
  205. enum chain_mode mode)
  206. {
  207. struct rb_node **p = &root->rb_node;
  208. struct rb_node *parent = NULL;
  209. struct callchain_node *rnode;
  210. u64 chain_cumul = callchain_cumul_hits(chain);
  211. while (*p) {
  212. u64 rnode_cumul;
  213. parent = *p;
  214. rnode = rb_entry(parent, struct callchain_node, rb_node);
  215. rnode_cumul = callchain_cumul_hits(rnode);
  216. switch (mode) {
  217. case CHAIN_FLAT:
  218. if (rnode->hit < chain->hit)
  219. p = &(*p)->rb_left;
  220. else
  221. p = &(*p)->rb_right;
  222. break;
  223. case CHAIN_GRAPH_ABS: /* Falldown */
  224. case CHAIN_GRAPH_REL:
  225. if (rnode_cumul < chain_cumul)
  226. p = &(*p)->rb_left;
  227. else
  228. p = &(*p)->rb_right;
  229. break;
  230. case CHAIN_NONE:
  231. default:
  232. break;
  233. }
  234. }
  235. rb_link_node(&chain->rb_node, parent, p);
  236. rb_insert_color(&chain->rb_node, root);
  237. }
  238. static void
  239. __sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node,
  240. u64 min_hit)
  241. {
  242. struct rb_node *n;
  243. struct callchain_node *child;
  244. n = rb_first(&node->rb_root_in);
  245. while (n) {
  246. child = rb_entry(n, struct callchain_node, rb_node_in);
  247. n = rb_next(n);
  248. __sort_chain_flat(rb_root, child, min_hit);
  249. }
  250. if (node->hit && node->hit >= min_hit)
  251. rb_insert_callchain(rb_root, node, CHAIN_FLAT);
  252. }
  253. /*
  254. * Once we get every callchains from the stream, we can now
  255. * sort them by hit
  256. */
  257. static void
  258. sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
  259. u64 min_hit, struct callchain_param *param __maybe_unused)
  260. {
  261. __sort_chain_flat(rb_root, &root->node, min_hit);
  262. }
  263. static void __sort_chain_graph_abs(struct callchain_node *node,
  264. u64 min_hit)
  265. {
  266. struct rb_node *n;
  267. struct callchain_node *child;
  268. node->rb_root = RB_ROOT;
  269. n = rb_first(&node->rb_root_in);
  270. while (n) {
  271. child = rb_entry(n, struct callchain_node, rb_node_in);
  272. n = rb_next(n);
  273. __sort_chain_graph_abs(child, min_hit);
  274. if (callchain_cumul_hits(child) >= min_hit)
  275. rb_insert_callchain(&node->rb_root, child,
  276. CHAIN_GRAPH_ABS);
  277. }
  278. }
  279. static void
  280. sort_chain_graph_abs(struct rb_root *rb_root, struct callchain_root *chain_root,
  281. u64 min_hit, struct callchain_param *param __maybe_unused)
  282. {
  283. __sort_chain_graph_abs(&chain_root->node, min_hit);
  284. rb_root->rb_node = chain_root->node.rb_root.rb_node;
  285. }
  286. static void __sort_chain_graph_rel(struct callchain_node *node,
  287. double min_percent)
  288. {
  289. struct rb_node *n;
  290. struct callchain_node *child;
  291. u64 min_hit;
  292. node->rb_root = RB_ROOT;
  293. min_hit = ceil(node->children_hit * min_percent);
  294. n = rb_first(&node->rb_root_in);
  295. while (n) {
  296. child = rb_entry(n, struct callchain_node, rb_node_in);
  297. n = rb_next(n);
  298. __sort_chain_graph_rel(child, min_percent);
  299. if (callchain_cumul_hits(child) >= min_hit)
  300. rb_insert_callchain(&node->rb_root, child,
  301. CHAIN_GRAPH_REL);
  302. }
  303. }
  304. static void
  305. sort_chain_graph_rel(struct rb_root *rb_root, struct callchain_root *chain_root,
  306. u64 min_hit __maybe_unused, struct callchain_param *param)
  307. {
  308. __sort_chain_graph_rel(&chain_root->node, param->min_percent / 100.0);
  309. rb_root->rb_node = chain_root->node.rb_root.rb_node;
  310. }
  311. int callchain_register_param(struct callchain_param *param)
  312. {
  313. switch (param->mode) {
  314. case CHAIN_GRAPH_ABS:
  315. param->sort = sort_chain_graph_abs;
  316. break;
  317. case CHAIN_GRAPH_REL:
  318. param->sort = sort_chain_graph_rel;
  319. break;
  320. case CHAIN_FLAT:
  321. param->sort = sort_chain_flat;
  322. break;
  323. case CHAIN_NONE:
  324. default:
  325. return -1;
  326. }
  327. return 0;
  328. }
  329. /*
  330. * Create a child for a parent. If inherit_children, then the new child
  331. * will become the new parent of it's parent children
  332. */
  333. static struct callchain_node *
  334. create_child(struct callchain_node *parent, bool inherit_children)
  335. {
  336. struct callchain_node *new;
  337. new = zalloc(sizeof(*new));
  338. if (!new) {
  339. perror("not enough memory to create child for code path tree");
  340. return NULL;
  341. }
  342. new->parent = parent;
  343. INIT_LIST_HEAD(&new->val);
  344. if (inherit_children) {
  345. struct rb_node *n;
  346. struct callchain_node *child;
  347. new->rb_root_in = parent->rb_root_in;
  348. parent->rb_root_in = RB_ROOT;
  349. n = rb_first(&new->rb_root_in);
  350. while (n) {
  351. child = rb_entry(n, struct callchain_node, rb_node_in);
  352. child->parent = new;
  353. n = rb_next(n);
  354. }
  355. /* make it the first child */
  356. rb_link_node(&new->rb_node_in, NULL, &parent->rb_root_in.rb_node);
  357. rb_insert_color(&new->rb_node_in, &parent->rb_root_in);
  358. }
  359. return new;
  360. }
  361. /*
  362. * Fill the node with callchain values
  363. */
  364. static void
  365. fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
  366. {
  367. struct callchain_cursor_node *cursor_node;
  368. node->val_nr = cursor->nr - cursor->pos;
  369. if (!node->val_nr)
  370. pr_warning("Warning: empty node in callchain tree\n");
  371. cursor_node = callchain_cursor_current(cursor);
  372. while (cursor_node) {
  373. struct callchain_list *call;
  374. call = zalloc(sizeof(*call));
  375. if (!call) {
  376. perror("not enough memory for the code path tree");
  377. return;
  378. }
  379. call->ip = cursor_node->ip;
  380. call->ms.sym = cursor_node->sym;
  381. call->ms.map = cursor_node->map;
  382. list_add_tail(&call->list, &node->val);
  383. callchain_cursor_advance(cursor);
  384. cursor_node = callchain_cursor_current(cursor);
  385. }
  386. }
  387. static struct callchain_node *
  388. add_child(struct callchain_node *parent,
  389. struct callchain_cursor *cursor,
  390. u64 period)
  391. {
  392. struct callchain_node *new;
  393. new = create_child(parent, false);
  394. fill_node(new, cursor);
  395. new->children_hit = 0;
  396. new->hit = period;
  397. return new;
  398. }
  399. static s64 match_chain(struct callchain_cursor_node *node,
  400. struct callchain_list *cnode)
  401. {
  402. struct symbol *sym = node->sym;
  403. if (cnode->ms.sym && sym &&
  404. callchain_param.key == CCKEY_FUNCTION)
  405. return cnode->ms.sym->start - sym->start;
  406. else
  407. return cnode->ip - node->ip;
  408. }
  409. /*
  410. * Split the parent in two parts (a new child is created) and
  411. * give a part of its callchain to the created child.
  412. * Then create another child to host the given callchain of new branch
  413. */
  414. static void
  415. split_add_child(struct callchain_node *parent,
  416. struct callchain_cursor *cursor,
  417. struct callchain_list *to_split,
  418. u64 idx_parents, u64 idx_local, u64 period)
  419. {
  420. struct callchain_node *new;
  421. struct list_head *old_tail;
  422. unsigned int idx_total = idx_parents + idx_local;
  423. /* split */
  424. new = create_child(parent, true);
  425. /* split the callchain and move a part to the new child */
  426. old_tail = parent->val.prev;
  427. list_del_range(&to_split->list, old_tail);
  428. new->val.next = &to_split->list;
  429. new->val.prev = old_tail;
  430. to_split->list.prev = &new->val;
  431. old_tail->next = &new->val;
  432. /* split the hits */
  433. new->hit = parent->hit;
  434. new->children_hit = parent->children_hit;
  435. parent->children_hit = callchain_cumul_hits(new);
  436. new->val_nr = parent->val_nr - idx_local;
  437. parent->val_nr = idx_local;
  438. /* create a new child for the new branch if any */
  439. if (idx_total < cursor->nr) {
  440. struct callchain_node *first;
  441. struct callchain_list *cnode;
  442. struct callchain_cursor_node *node;
  443. struct rb_node *p, **pp;
  444. parent->hit = 0;
  445. parent->children_hit += period;
  446. node = callchain_cursor_current(cursor);
  447. new = add_child(parent, cursor, period);
  448. /*
  449. * This is second child since we moved parent's children
  450. * to new (first) child above.
  451. */
  452. p = parent->rb_root_in.rb_node;
  453. first = rb_entry(p, struct callchain_node, rb_node_in);
  454. cnode = list_first_entry(&first->val, struct callchain_list,
  455. list);
  456. if (match_chain(node, cnode) < 0)
  457. pp = &p->rb_left;
  458. else
  459. pp = &p->rb_right;
  460. rb_link_node(&new->rb_node_in, p, pp);
  461. rb_insert_color(&new->rb_node_in, &parent->rb_root_in);
  462. } else {
  463. parent->hit = period;
  464. }
  465. }
  466. static int
  467. append_chain(struct callchain_node *root,
  468. struct callchain_cursor *cursor,
  469. u64 period);
  470. static void
  471. append_chain_children(struct callchain_node *root,
  472. struct callchain_cursor *cursor,
  473. u64 period)
  474. {
  475. struct callchain_node *rnode;
  476. struct callchain_cursor_node *node;
  477. struct rb_node **p = &root->rb_root_in.rb_node;
  478. struct rb_node *parent = NULL;
  479. node = callchain_cursor_current(cursor);
  480. if (!node)
  481. return;
  482. /* lookup in childrens */
  483. while (*p) {
  484. s64 ret;
  485. parent = *p;
  486. rnode = rb_entry(parent, struct callchain_node, rb_node_in);
  487. /* If at least first entry matches, rely to children */
  488. ret = append_chain(rnode, cursor, period);
  489. if (ret == 0)
  490. goto inc_children_hit;
  491. if (ret < 0)
  492. p = &parent->rb_left;
  493. else
  494. p = &parent->rb_right;
  495. }
  496. /* nothing in children, add to the current node */
  497. rnode = add_child(root, cursor, period);
  498. rb_link_node(&rnode->rb_node_in, parent, p);
  499. rb_insert_color(&rnode->rb_node_in, &root->rb_root_in);
  500. inc_children_hit:
  501. root->children_hit += period;
  502. }
  503. static int
  504. append_chain(struct callchain_node *root,
  505. struct callchain_cursor *cursor,
  506. u64 period)
  507. {
  508. struct callchain_list *cnode;
  509. u64 start = cursor->pos;
  510. bool found = false;
  511. u64 matches;
  512. int cmp = 0;
  513. /*
  514. * Lookup in the current node
  515. * If we have a symbol, then compare the start to match
  516. * anywhere inside a function, unless function
  517. * mode is disabled.
  518. */
  519. list_for_each_entry(cnode, &root->val, list) {
  520. struct callchain_cursor_node *node;
  521. node = callchain_cursor_current(cursor);
  522. if (!node)
  523. break;
  524. cmp = match_chain(node, cnode);
  525. if (cmp)
  526. break;
  527. found = true;
  528. callchain_cursor_advance(cursor);
  529. }
  530. /* matches not, relay no the parent */
  531. if (!found) {
  532. WARN_ONCE(!cmp, "Chain comparison error\n");
  533. return cmp;
  534. }
  535. matches = cursor->pos - start;
  536. /* we match only a part of the node. Split it and add the new chain */
  537. if (matches < root->val_nr) {
  538. split_add_child(root, cursor, cnode, start, matches, period);
  539. return 0;
  540. }
  541. /* we match 100% of the path, increment the hit */
  542. if (matches == root->val_nr && cursor->pos == cursor->nr) {
  543. root->hit += period;
  544. return 0;
  545. }
  546. /* We match the node and still have a part remaining */
  547. append_chain_children(root, cursor, period);
  548. return 0;
  549. }
  550. int callchain_append(struct callchain_root *root,
  551. struct callchain_cursor *cursor,
  552. u64 period)
  553. {
  554. if (!cursor->nr)
  555. return 0;
  556. callchain_cursor_commit(cursor);
  557. append_chain_children(&root->node, cursor, period);
  558. if (cursor->nr > root->max_depth)
  559. root->max_depth = cursor->nr;
  560. return 0;
  561. }
  562. static int
  563. merge_chain_branch(struct callchain_cursor *cursor,
  564. struct callchain_node *dst, struct callchain_node *src)
  565. {
  566. struct callchain_cursor_node **old_last = cursor->last;
  567. struct callchain_node *child;
  568. struct callchain_list *list, *next_list;
  569. struct rb_node *n;
  570. int old_pos = cursor->nr;
  571. int err = 0;
  572. list_for_each_entry_safe(list, next_list, &src->val, list) {
  573. callchain_cursor_append(cursor, list->ip,
  574. list->ms.map, list->ms.sym);
  575. list_del(&list->list);
  576. free(list);
  577. }
  578. if (src->hit) {
  579. callchain_cursor_commit(cursor);
  580. append_chain_children(dst, cursor, src->hit);
  581. }
  582. n = rb_first(&src->rb_root_in);
  583. while (n) {
  584. child = container_of(n, struct callchain_node, rb_node_in);
  585. n = rb_next(n);
  586. rb_erase(&child->rb_node_in, &src->rb_root_in);
  587. err = merge_chain_branch(cursor, dst, child);
  588. if (err)
  589. break;
  590. free(child);
  591. }
  592. cursor->nr = old_pos;
  593. cursor->last = old_last;
  594. return err;
  595. }
  596. int callchain_merge(struct callchain_cursor *cursor,
  597. struct callchain_root *dst, struct callchain_root *src)
  598. {
  599. return merge_chain_branch(cursor, &dst->node, &src->node);
  600. }
  601. int callchain_cursor_append(struct callchain_cursor *cursor,
  602. u64 ip, struct map *map, struct symbol *sym)
  603. {
  604. struct callchain_cursor_node *node = *cursor->last;
  605. if (!node) {
  606. node = calloc(1, sizeof(*node));
  607. if (!node)
  608. return -ENOMEM;
  609. *cursor->last = node;
  610. }
  611. node->ip = ip;
  612. node->map = map;
  613. node->sym = sym;
  614. cursor->nr++;
  615. cursor->last = &node->next;
  616. return 0;
  617. }
  618. int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
  619. struct perf_evsel *evsel, struct addr_location *al,
  620. int max_stack)
  621. {
  622. if (sample->callchain == NULL)
  623. return 0;
  624. if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain ||
  625. sort__has_parent) {
  626. return machine__resolve_callchain(al->machine, evsel, al->thread,
  627. sample, parent, al, max_stack);
  628. }
  629. return 0;
  630. }
  631. int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample)
  632. {
  633. if (!symbol_conf.use_callchain || sample->callchain == NULL)
  634. return 0;
  635. return callchain_append(he->callchain, &callchain_cursor, sample->period);
  636. }
  637. int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
  638. bool hide_unresolved)
  639. {
  640. al->map = node->map;
  641. al->sym = node->sym;
  642. if (node->map)
  643. al->addr = node->map->map_ip(node->map, node->ip);
  644. else
  645. al->addr = node->ip;
  646. if (al->sym == NULL) {
  647. if (hide_unresolved)
  648. return 0;
  649. if (al->map == NULL)
  650. goto out;
  651. }
  652. if (al->map->groups == &al->machine->kmaps) {
  653. if (machine__is_host(al->machine)) {
  654. al->cpumode = PERF_RECORD_MISC_KERNEL;
  655. al->level = 'k';
  656. } else {
  657. al->cpumode = PERF_RECORD_MISC_GUEST_KERNEL;
  658. al->level = 'g';
  659. }
  660. } else {
  661. if (machine__is_host(al->machine)) {
  662. al->cpumode = PERF_RECORD_MISC_USER;
  663. al->level = '.';
  664. } else if (perf_guest) {
  665. al->cpumode = PERF_RECORD_MISC_GUEST_USER;
  666. al->level = 'u';
  667. } else {
  668. al->cpumode = PERF_RECORD_MISC_HYPERVISOR;
  669. al->level = 'H';
  670. }
  671. }
  672. out:
  673. return 1;
  674. }