callchain.c 18 KB

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