hist.c 17 KB

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