hist.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. #include "hist.h"
  2. #include "session.h"
  3. #include "sort.h"
  4. #include <math.h>
  5. struct callchain_param callchain_param = {
  6. .mode = CHAIN_GRAPH_REL,
  7. .min_percent = 0.5
  8. };
  9. void __perf_session__add_count(struct hist_entry *he,
  10. struct addr_location *al,
  11. u64 count)
  12. {
  13. he->count += count;
  14. switch (al->cpumode) {
  15. case PERF_RECORD_MISC_KERNEL:
  16. he->count_sys += count;
  17. break;
  18. case PERF_RECORD_MISC_USER:
  19. he->count_us += count;
  20. break;
  21. case PERF_RECORD_MISC_GUEST_KERNEL:
  22. he->count_guest_sys += count;
  23. break;
  24. case PERF_RECORD_MISC_GUEST_USER:
  25. he->count_guest_us += count;
  26. break;
  27. default:
  28. break;
  29. }
  30. }
  31. /*
  32. * histogram, sorted on item, collects counts
  33. */
  34. struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
  35. struct addr_location *al,
  36. struct symbol *sym_parent,
  37. u64 count, bool *hit)
  38. {
  39. struct rb_node **p = &hists->rb_node;
  40. struct rb_node *parent = NULL;
  41. struct hist_entry *he;
  42. struct hist_entry entry = {
  43. .thread = al->thread,
  44. .ms = {
  45. .map = al->map,
  46. .sym = al->sym,
  47. },
  48. .ip = al->addr,
  49. .level = al->level,
  50. .count = count,
  51. .parent = sym_parent,
  52. };
  53. int cmp;
  54. while (*p != NULL) {
  55. parent = *p;
  56. he = rb_entry(parent, struct hist_entry, rb_node);
  57. cmp = hist_entry__cmp(&entry, he);
  58. if (!cmp) {
  59. *hit = true;
  60. return he;
  61. }
  62. if (cmp < 0)
  63. p = &(*p)->rb_left;
  64. else
  65. p = &(*p)->rb_right;
  66. }
  67. he = malloc(sizeof(*he) + (symbol_conf.use_callchain ?
  68. sizeof(struct callchain_node) : 0));
  69. if (!he)
  70. return NULL;
  71. *he = entry;
  72. rb_link_node(&he->rb_node, parent, p);
  73. rb_insert_color(&he->rb_node, hists);
  74. *hit = false;
  75. return he;
  76. }
  77. int64_t
  78. hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
  79. {
  80. struct sort_entry *se;
  81. int64_t cmp = 0;
  82. list_for_each_entry(se, &hist_entry__sort_list, list) {
  83. cmp = se->se_cmp(left, right);
  84. if (cmp)
  85. break;
  86. }
  87. return cmp;
  88. }
  89. int64_t
  90. hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
  91. {
  92. struct sort_entry *se;
  93. int64_t cmp = 0;
  94. list_for_each_entry(se, &hist_entry__sort_list, list) {
  95. int64_t (*f)(struct hist_entry *, struct hist_entry *);
  96. f = se->se_collapse ?: se->se_cmp;
  97. cmp = f(left, right);
  98. if (cmp)
  99. break;
  100. }
  101. return cmp;
  102. }
  103. void hist_entry__free(struct hist_entry *he)
  104. {
  105. free(he);
  106. }
  107. /*
  108. * collapse the histogram
  109. */
  110. static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
  111. {
  112. struct rb_node **p = &root->rb_node;
  113. struct rb_node *parent = NULL;
  114. struct hist_entry *iter;
  115. int64_t cmp;
  116. while (*p != NULL) {
  117. parent = *p;
  118. iter = rb_entry(parent, struct hist_entry, rb_node);
  119. cmp = hist_entry__collapse(iter, he);
  120. if (!cmp) {
  121. iter->count += he->count;
  122. hist_entry__free(he);
  123. return;
  124. }
  125. if (cmp < 0)
  126. p = &(*p)->rb_left;
  127. else
  128. p = &(*p)->rb_right;
  129. }
  130. rb_link_node(&he->rb_node, parent, p);
  131. rb_insert_color(&he->rb_node, root);
  132. }
  133. void perf_session__collapse_resort(struct rb_root *hists)
  134. {
  135. struct rb_root tmp;
  136. struct rb_node *next;
  137. struct hist_entry *n;
  138. if (!sort__need_collapse)
  139. return;
  140. tmp = RB_ROOT;
  141. next = rb_first(hists);
  142. while (next) {
  143. n = rb_entry(next, struct hist_entry, rb_node);
  144. next = rb_next(&n->rb_node);
  145. rb_erase(&n->rb_node, hists);
  146. collapse__insert_entry(&tmp, n);
  147. }
  148. *hists = tmp;
  149. }
  150. /*
  151. * reverse the map, sort on count.
  152. */
  153. static void perf_session__insert_output_hist_entry(struct rb_root *root,
  154. struct hist_entry *he,
  155. u64 min_callchain_hits)
  156. {
  157. struct rb_node **p = &root->rb_node;
  158. struct rb_node *parent = NULL;
  159. struct hist_entry *iter;
  160. if (symbol_conf.use_callchain)
  161. callchain_param.sort(&he->sorted_chain, he->callchain,
  162. min_callchain_hits, &callchain_param);
  163. while (*p != NULL) {
  164. parent = *p;
  165. iter = rb_entry(parent, struct hist_entry, rb_node);
  166. if (he->count > iter->count)
  167. p = &(*p)->rb_left;
  168. else
  169. p = &(*p)->rb_right;
  170. }
  171. rb_link_node(&he->rb_node, parent, p);
  172. rb_insert_color(&he->rb_node, root);
  173. }
  174. u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples)
  175. {
  176. struct rb_root tmp;
  177. struct rb_node *next;
  178. struct hist_entry *n;
  179. u64 min_callchain_hits;
  180. u64 nr_hists = 0;
  181. min_callchain_hits =
  182. total_samples * (callchain_param.min_percent / 100);
  183. tmp = RB_ROOT;
  184. next = rb_first(hists);
  185. while (next) {
  186. n = rb_entry(next, struct hist_entry, rb_node);
  187. next = rb_next(&n->rb_node);
  188. rb_erase(&n->rb_node, hists);
  189. perf_session__insert_output_hist_entry(&tmp, n,
  190. min_callchain_hits);
  191. ++nr_hists;
  192. }
  193. *hists = tmp;
  194. return nr_hists;
  195. }
  196. static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
  197. {
  198. int i;
  199. int ret = fprintf(fp, " ");
  200. for (i = 0; i < left_margin; i++)
  201. ret += fprintf(fp, " ");
  202. return ret;
  203. }
  204. static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
  205. int left_margin)
  206. {
  207. int i;
  208. size_t ret = callchain__fprintf_left_margin(fp, left_margin);
  209. for (i = 0; i < depth; i++)
  210. if (depth_mask & (1 << i))
  211. ret += fprintf(fp, "| ");
  212. else
  213. ret += fprintf(fp, " ");
  214. ret += fprintf(fp, "\n");
  215. return ret;
  216. }
  217. static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
  218. int depth, int depth_mask, int count,
  219. u64 total_samples, int hits,
  220. int left_margin)
  221. {
  222. int i;
  223. size_t ret = 0;
  224. ret += callchain__fprintf_left_margin(fp, left_margin);
  225. for (i = 0; i < depth; i++) {
  226. if (depth_mask & (1 << i))
  227. ret += fprintf(fp, "|");
  228. else
  229. ret += fprintf(fp, " ");
  230. if (!count && i == depth - 1) {
  231. double percent;
  232. percent = hits * 100.0 / total_samples;
  233. ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
  234. } else
  235. ret += fprintf(fp, "%s", " ");
  236. }
  237. if (chain->ms.sym)
  238. ret += fprintf(fp, "%s\n", chain->ms.sym->name);
  239. else
  240. ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
  241. return ret;
  242. }
  243. static struct symbol *rem_sq_bracket;
  244. static struct callchain_list rem_hits;
  245. static void init_rem_hits(void)
  246. {
  247. rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
  248. if (!rem_sq_bracket) {
  249. fprintf(stderr, "Not enough memory to display remaining hits\n");
  250. return;
  251. }
  252. strcpy(rem_sq_bracket->name, "[...]");
  253. rem_hits.ms.sym = rem_sq_bracket;
  254. }
  255. static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
  256. u64 total_samples, int depth,
  257. int depth_mask, int left_margin)
  258. {
  259. struct rb_node *node, *next;
  260. struct callchain_node *child;
  261. struct callchain_list *chain;
  262. int new_depth_mask = depth_mask;
  263. u64 new_total;
  264. u64 remaining;
  265. size_t ret = 0;
  266. int i;
  267. if (callchain_param.mode == CHAIN_GRAPH_REL)
  268. new_total = self->children_hit;
  269. else
  270. new_total = total_samples;
  271. remaining = new_total;
  272. node = rb_first(&self->rb_root);
  273. while (node) {
  274. u64 cumul;
  275. child = rb_entry(node, struct callchain_node, rb_node);
  276. cumul = cumul_hits(child);
  277. remaining -= cumul;
  278. /*
  279. * The depth mask manages the output of pipes that show
  280. * the depth. We don't want to keep the pipes of the current
  281. * level for the last child of this depth.
  282. * Except if we have remaining filtered hits. They will
  283. * supersede the last child
  284. */
  285. next = rb_next(node);
  286. if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
  287. new_depth_mask &= ~(1 << (depth - 1));
  288. /*
  289. * But we keep the older depth mask for the line separator
  290. * to keep the level link until we reach the last child
  291. */
  292. ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
  293. left_margin);
  294. i = 0;
  295. list_for_each_entry(chain, &child->val, list) {
  296. ret += ipchain__fprintf_graph(fp, chain, depth,
  297. new_depth_mask, i++,
  298. new_total,
  299. cumul,
  300. left_margin);
  301. }
  302. ret += __callchain__fprintf_graph(fp, child, new_total,
  303. depth + 1,
  304. new_depth_mask | (1 << depth),
  305. left_margin);
  306. node = next;
  307. }
  308. if (callchain_param.mode == CHAIN_GRAPH_REL &&
  309. remaining && remaining != new_total) {
  310. if (!rem_sq_bracket)
  311. return ret;
  312. new_depth_mask &= ~(1 << (depth - 1));
  313. ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
  314. new_depth_mask, 0, new_total,
  315. remaining, left_margin);
  316. }
  317. return ret;
  318. }
  319. static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
  320. u64 total_samples, int left_margin)
  321. {
  322. struct callchain_list *chain;
  323. bool printed = false;
  324. int i = 0;
  325. int ret = 0;
  326. list_for_each_entry(chain, &self->val, list) {
  327. if (!i++ && sort__first_dimension == SORT_SYM)
  328. continue;
  329. if (!printed) {
  330. ret += callchain__fprintf_left_margin(fp, left_margin);
  331. ret += fprintf(fp, "|\n");
  332. ret += callchain__fprintf_left_margin(fp, left_margin);
  333. ret += fprintf(fp, "---");
  334. left_margin += 3;
  335. printed = true;
  336. } else
  337. ret += callchain__fprintf_left_margin(fp, left_margin);
  338. if (chain->ms.sym)
  339. ret += fprintf(fp, " %s\n", chain->ms.sym->name);
  340. else
  341. ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
  342. }
  343. ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
  344. return ret;
  345. }
  346. static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
  347. u64 total_samples)
  348. {
  349. struct callchain_list *chain;
  350. size_t ret = 0;
  351. if (!self)
  352. return 0;
  353. ret += callchain__fprintf_flat(fp, self->parent, total_samples);
  354. list_for_each_entry(chain, &self->val, list) {
  355. if (chain->ip >= PERF_CONTEXT_MAX)
  356. continue;
  357. if (chain->ms.sym)
  358. ret += fprintf(fp, " %s\n", chain->ms.sym->name);
  359. else
  360. ret += fprintf(fp, " %p\n",
  361. (void *)(long)chain->ip);
  362. }
  363. return ret;
  364. }
  365. static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
  366. u64 total_samples, int left_margin)
  367. {
  368. struct rb_node *rb_node;
  369. struct callchain_node *chain;
  370. size_t ret = 0;
  371. rb_node = rb_first(&self->sorted_chain);
  372. while (rb_node) {
  373. double percent;
  374. chain = rb_entry(rb_node, struct callchain_node, rb_node);
  375. percent = chain->hit * 100.0 / total_samples;
  376. switch (callchain_param.mode) {
  377. case CHAIN_FLAT:
  378. ret += percent_color_fprintf(fp, " %6.2f%%\n",
  379. percent);
  380. ret += callchain__fprintf_flat(fp, chain, total_samples);
  381. break;
  382. case CHAIN_GRAPH_ABS: /* Falldown */
  383. case CHAIN_GRAPH_REL:
  384. ret += callchain__fprintf_graph(fp, chain, total_samples,
  385. left_margin);
  386. case CHAIN_NONE:
  387. default:
  388. break;
  389. }
  390. ret += fprintf(fp, "\n");
  391. rb_node = rb_next(rb_node);
  392. }
  393. return ret;
  394. }
  395. int hist_entry__snprintf(struct hist_entry *self,
  396. char *s, size_t size,
  397. struct perf_session *pair_session,
  398. bool show_displacement,
  399. long displacement, bool color,
  400. u64 session_total)
  401. {
  402. struct sort_entry *se;
  403. u64 count, total, count_sys, count_us, count_guest_sys, count_guest_us;
  404. const char *sep = symbol_conf.field_sep;
  405. int ret;
  406. if (symbol_conf.exclude_other && !self->parent)
  407. return 0;
  408. if (pair_session) {
  409. count = self->pair ? self->pair->count : 0;
  410. total = pair_session->events_stats.total;
  411. count_sys = self->pair ? self->pair->count_sys : 0;
  412. count_us = self->pair ? self->pair->count_us : 0;
  413. count_guest_sys = self->pair ? self->pair->count_guest_sys : 0;
  414. count_guest_us = self->pair ? self->pair->count_guest_us : 0;
  415. } else {
  416. count = self->count;
  417. total = session_total;
  418. count_sys = self->count_sys;
  419. count_us = self->count_us;
  420. count_guest_sys = self->count_guest_sys;
  421. count_guest_us = self->count_guest_us;
  422. }
  423. if (total) {
  424. if (color)
  425. ret = percent_color_snprintf(s, size,
  426. sep ? "%.2f" : " %6.2f%%",
  427. (count * 100.0) / total);
  428. else
  429. ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
  430. (count * 100.0) / total);
  431. if (symbol_conf.show_cpu_utilization) {
  432. ret += percent_color_snprintf(s + ret, size - ret,
  433. sep ? "%.2f" : " %6.2f%%",
  434. (count_sys * 100.0) / total);
  435. ret += percent_color_snprintf(s + ret, size - ret,
  436. sep ? "%.2f" : " %6.2f%%",
  437. (count_us * 100.0) / total);
  438. if (perf_guest) {
  439. ret += percent_color_snprintf(s + ret,
  440. size - ret,
  441. sep ? "%.2f" : " %6.2f%%",
  442. (count_guest_sys * 100.0) /
  443. total);
  444. ret += percent_color_snprintf(s + ret,
  445. size - ret,
  446. sep ? "%.2f" : " %6.2f%%",
  447. (count_guest_us * 100.0) /
  448. total);
  449. }
  450. }
  451. } else
  452. ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count);
  453. if (symbol_conf.show_nr_samples) {
  454. if (sep)
  455. ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count);
  456. else
  457. ret += snprintf(s + ret, size - ret, "%11lld", count);
  458. }
  459. if (pair_session) {
  460. char bf[32];
  461. double old_percent = 0, new_percent = 0, diff;
  462. if (total > 0)
  463. old_percent = (count * 100.0) / total;
  464. if (session_total > 0)
  465. new_percent = (self->count * 100.0) / session_total;
  466. diff = new_percent - old_percent;
  467. if (fabs(diff) >= 0.01)
  468. snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
  469. else
  470. snprintf(bf, sizeof(bf), " ");
  471. if (sep)
  472. ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
  473. else
  474. ret += snprintf(s + ret, size - ret, "%11.11s", bf);
  475. if (show_displacement) {
  476. if (displacement)
  477. snprintf(bf, sizeof(bf), "%+4ld", displacement);
  478. else
  479. snprintf(bf, sizeof(bf), " ");
  480. if (sep)
  481. ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
  482. else
  483. ret += snprintf(s + ret, size - ret, "%6.6s", bf);
  484. }
  485. }
  486. list_for_each_entry(se, &hist_entry__sort_list, list) {
  487. if (se->elide)
  488. continue;
  489. ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
  490. ret += se->se_snprintf(self, s + ret, size - ret,
  491. se->se_width ? *se->se_width : 0);
  492. }
  493. return ret;
  494. }
  495. int hist_entry__fprintf(struct hist_entry *self,
  496. struct perf_session *pair_session,
  497. bool show_displacement,
  498. long displacement, FILE *fp,
  499. u64 session_total)
  500. {
  501. char bf[512];
  502. hist_entry__snprintf(self, bf, sizeof(bf), pair_session,
  503. show_displacement, displacement,
  504. true, session_total);
  505. return fprintf(fp, "%s\n", bf);
  506. }
  507. static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
  508. u64 session_total)
  509. {
  510. int left_margin = 0;
  511. if (sort__first_dimension == SORT_COMM) {
  512. struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
  513. typeof(*se), list);
  514. left_margin = se->se_width ? *se->se_width : 0;
  515. left_margin -= thread__comm_len(self->thread);
  516. }
  517. return hist_entry_callchain__fprintf(fp, self, session_total,
  518. left_margin);
  519. }
  520. size_t perf_session__fprintf_hists(struct rb_root *hists,
  521. struct perf_session *pair,
  522. bool show_displacement, FILE *fp,
  523. u64 session_total)
  524. {
  525. struct sort_entry *se;
  526. struct rb_node *nd;
  527. size_t ret = 0;
  528. unsigned long position = 1;
  529. long displacement = 0;
  530. unsigned int width;
  531. const char *sep = symbol_conf.field_sep;
  532. char *col_width = symbol_conf.col_width_list_str;
  533. init_rem_hits();
  534. fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
  535. if (symbol_conf.show_nr_samples) {
  536. if (sep)
  537. fprintf(fp, "%cSamples", *sep);
  538. else
  539. fputs(" Samples ", fp);
  540. }
  541. if (symbol_conf.show_cpu_utilization) {
  542. if (sep) {
  543. ret += fprintf(fp, "%csys", *sep);
  544. ret += fprintf(fp, "%cus", *sep);
  545. if (perf_guest) {
  546. ret += fprintf(fp, "%cguest sys", *sep);
  547. ret += fprintf(fp, "%cguest us", *sep);
  548. }
  549. } else {
  550. ret += fprintf(fp, " sys ");
  551. ret += fprintf(fp, " us ");
  552. if (perf_guest) {
  553. ret += fprintf(fp, " guest sys ");
  554. ret += fprintf(fp, " guest us ");
  555. }
  556. }
  557. }
  558. if (pair) {
  559. if (sep)
  560. ret += fprintf(fp, "%cDelta", *sep);
  561. else
  562. ret += fprintf(fp, " Delta ");
  563. if (show_displacement) {
  564. if (sep)
  565. ret += fprintf(fp, "%cDisplacement", *sep);
  566. else
  567. ret += fprintf(fp, " Displ");
  568. }
  569. }
  570. list_for_each_entry(se, &hist_entry__sort_list, list) {
  571. if (se->elide)
  572. continue;
  573. if (sep) {
  574. fprintf(fp, "%c%s", *sep, se->se_header);
  575. continue;
  576. }
  577. width = strlen(se->se_header);
  578. if (se->se_width) {
  579. if (symbol_conf.col_width_list_str) {
  580. if (col_width) {
  581. *se->se_width = atoi(col_width);
  582. col_width = strchr(col_width, ',');
  583. if (col_width)
  584. ++col_width;
  585. }
  586. }
  587. width = *se->se_width = max(*se->se_width, width);
  588. }
  589. fprintf(fp, " %*s", width, se->se_header);
  590. }
  591. fprintf(fp, "\n");
  592. if (sep)
  593. goto print_entries;
  594. fprintf(fp, "# ........");
  595. if (symbol_conf.show_nr_samples)
  596. fprintf(fp, " ..........");
  597. if (pair) {
  598. fprintf(fp, " ..........");
  599. if (show_displacement)
  600. fprintf(fp, " .....");
  601. }
  602. list_for_each_entry(se, &hist_entry__sort_list, list) {
  603. unsigned int i;
  604. if (se->elide)
  605. continue;
  606. fprintf(fp, " ");
  607. if (se->se_width)
  608. width = *se->se_width;
  609. else
  610. width = strlen(se->se_header);
  611. for (i = 0; i < width; i++)
  612. fprintf(fp, ".");
  613. }
  614. fprintf(fp, "\n#\n");
  615. print_entries:
  616. for (nd = rb_first(hists); nd; nd = rb_next(nd)) {
  617. struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
  618. if (show_displacement) {
  619. if (h->pair != NULL)
  620. displacement = ((long)h->pair->position -
  621. (long)position);
  622. else
  623. displacement = 0;
  624. ++position;
  625. }
  626. ret += hist_entry__fprintf(h, pair, show_displacement,
  627. displacement, fp, session_total);
  628. if (symbol_conf.use_callchain)
  629. ret += hist_entry__fprintf_callchain(h, fp, session_total);
  630. if (h->ms.map == NULL && verbose > 1) {
  631. __map_groups__fprintf_maps(&h->thread->mg,
  632. MAP__FUNCTION, verbose, fp);
  633. fprintf(fp, "%.10s end\n", graph_dotted_line);
  634. }
  635. }
  636. free(rem_sq_bracket);
  637. return ret;
  638. }