hist.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. #include <math.h>
  2. #include <linux/compiler.h>
  3. #include "../util/hist.h"
  4. #include "../util/util.h"
  5. #include "../util/sort.h"
  6. #include "../util/evsel.h"
  7. /* hist period print (hpp) functions */
  8. #define hpp__call_print_fn(hpp, fn, fmt, ...) \
  9. ({ \
  10. int __ret = fn(hpp, fmt, ##__VA_ARGS__); \
  11. advance_hpp(hpp, __ret); \
  12. __ret; \
  13. })
  14. static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
  15. hpp_field_fn get_field, const char *fmt, int len,
  16. hpp_snprint_fn print_fn, bool fmt_percent)
  17. {
  18. int ret;
  19. struct hists *hists = he->hists;
  20. struct perf_evsel *evsel = hists_to_evsel(hists);
  21. char *buf = hpp->buf;
  22. size_t size = hpp->size;
  23. if (fmt_percent) {
  24. double percent = 0.0;
  25. u64 total = hists__total_period(hists);
  26. if (total)
  27. percent = 100.0 * get_field(he) / total;
  28. ret = hpp__call_print_fn(hpp, print_fn, fmt, len, percent);
  29. } else
  30. ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he));
  31. if (perf_evsel__is_group_event(evsel)) {
  32. int prev_idx, idx_delta;
  33. struct hist_entry *pair;
  34. int nr_members = evsel->nr_members;
  35. prev_idx = perf_evsel__group_idx(evsel);
  36. list_for_each_entry(pair, &he->pairs.head, pairs.node) {
  37. u64 period = get_field(pair);
  38. u64 total = hists__total_period(pair->hists);
  39. if (!total)
  40. continue;
  41. evsel = hists_to_evsel(pair->hists);
  42. idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1;
  43. while (idx_delta--) {
  44. /*
  45. * zero-fill group members in the middle which
  46. * have no sample
  47. */
  48. if (fmt_percent) {
  49. ret += hpp__call_print_fn(hpp, print_fn,
  50. fmt, len, 0.0);
  51. } else {
  52. ret += hpp__call_print_fn(hpp, print_fn,
  53. fmt, len, 0ULL);
  54. }
  55. }
  56. if (fmt_percent) {
  57. ret += hpp__call_print_fn(hpp, print_fn, fmt, len,
  58. 100.0 * period / total);
  59. } else {
  60. ret += hpp__call_print_fn(hpp, print_fn, fmt,
  61. len, period);
  62. }
  63. prev_idx = perf_evsel__group_idx(evsel);
  64. }
  65. idx_delta = nr_members - prev_idx - 1;
  66. while (idx_delta--) {
  67. /*
  68. * zero-fill group members at last which have no sample
  69. */
  70. if (fmt_percent) {
  71. ret += hpp__call_print_fn(hpp, print_fn,
  72. fmt, len, 0.0);
  73. } else {
  74. ret += hpp__call_print_fn(hpp, print_fn,
  75. fmt, len, 0ULL);
  76. }
  77. }
  78. }
  79. /*
  80. * Restore original buf and size as it's where caller expects
  81. * the result will be saved.
  82. */
  83. hpp->buf = buf;
  84. hpp->size = size;
  85. return ret;
  86. }
  87. int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  88. struct hist_entry *he, hpp_field_fn get_field,
  89. const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent)
  90. {
  91. int len = fmt->user_len ?: fmt->len;
  92. if (symbol_conf.field_sep) {
  93. return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
  94. print_fn, fmt_percent);
  95. }
  96. if (fmt_percent)
  97. len -= 2; /* 2 for a space and a % sign */
  98. else
  99. len -= 1;
  100. return __hpp__fmt(hpp, he, get_field, fmtstr, len, print_fn, fmt_percent);
  101. }
  102. int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  103. struct hist_entry *he, hpp_field_fn get_field,
  104. const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent)
  105. {
  106. if (!symbol_conf.cumulate_callchain) {
  107. int len = fmt->user_len ?: fmt->len;
  108. return snprintf(hpp->buf, hpp->size, " %*s", len - 1, "N/A");
  109. }
  110. return hpp__fmt(fmt, hpp, he, get_field, fmtstr, print_fn, fmt_percent);
  111. }
  112. static int field_cmp(u64 field_a, u64 field_b)
  113. {
  114. if (field_a > field_b)
  115. return 1;
  116. if (field_a < field_b)
  117. return -1;
  118. return 0;
  119. }
  120. static int __hpp__sort(struct hist_entry *a, struct hist_entry *b,
  121. hpp_field_fn get_field)
  122. {
  123. s64 ret;
  124. int i, nr_members;
  125. struct perf_evsel *evsel;
  126. struct hist_entry *pair;
  127. u64 *fields_a, *fields_b;
  128. ret = field_cmp(get_field(a), get_field(b));
  129. if (ret || !symbol_conf.event_group)
  130. return ret;
  131. evsel = hists_to_evsel(a->hists);
  132. if (!perf_evsel__is_group_event(evsel))
  133. return ret;
  134. nr_members = evsel->nr_members;
  135. fields_a = calloc(sizeof(*fields_a), nr_members);
  136. fields_b = calloc(sizeof(*fields_b), nr_members);
  137. if (!fields_a || !fields_b)
  138. goto out;
  139. list_for_each_entry(pair, &a->pairs.head, pairs.node) {
  140. evsel = hists_to_evsel(pair->hists);
  141. fields_a[perf_evsel__group_idx(evsel)] = get_field(pair);
  142. }
  143. list_for_each_entry(pair, &b->pairs.head, pairs.node) {
  144. evsel = hists_to_evsel(pair->hists);
  145. fields_b[perf_evsel__group_idx(evsel)] = get_field(pair);
  146. }
  147. for (i = 1; i < nr_members; i++) {
  148. ret = field_cmp(fields_a[i], fields_b[i]);
  149. if (ret)
  150. break;
  151. }
  152. out:
  153. free(fields_a);
  154. free(fields_b);
  155. return ret;
  156. }
  157. static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
  158. hpp_field_fn get_field)
  159. {
  160. s64 ret = 0;
  161. if (symbol_conf.cumulate_callchain) {
  162. /*
  163. * Put caller above callee when they have equal period.
  164. */
  165. ret = field_cmp(get_field(a), get_field(b));
  166. if (ret)
  167. return ret;
  168. ret = b->callchain->max_depth - a->callchain->max_depth;
  169. }
  170. return ret;
  171. }
  172. static int hpp__width_fn(struct perf_hpp_fmt *fmt,
  173. struct perf_hpp *hpp __maybe_unused,
  174. struct perf_evsel *evsel)
  175. {
  176. int len = fmt->user_len ?: fmt->len;
  177. if (symbol_conf.event_group)
  178. len = max(len, evsel->nr_members * fmt->len);
  179. if (len < (int)strlen(fmt->name))
  180. len = strlen(fmt->name);
  181. return len;
  182. }
  183. static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  184. struct perf_evsel *evsel)
  185. {
  186. int len = hpp__width_fn(fmt, hpp, evsel);
  187. return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name);
  188. }
  189. static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
  190. {
  191. va_list args;
  192. ssize_t ssize = hpp->size;
  193. double percent;
  194. int ret, len;
  195. va_start(args, fmt);
  196. len = va_arg(args, int);
  197. percent = va_arg(args, double);
  198. ret = percent_color_len_snprintf(hpp->buf, hpp->size, fmt, len, percent);
  199. va_end(args);
  200. return (ret >= ssize) ? (ssize - 1) : ret;
  201. }
  202. static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
  203. {
  204. va_list args;
  205. ssize_t ssize = hpp->size;
  206. int ret;
  207. va_start(args, fmt);
  208. ret = vsnprintf(hpp->buf, hpp->size, fmt, args);
  209. va_end(args);
  210. return (ret >= ssize) ? (ssize - 1) : ret;
  211. }
  212. #define __HPP_COLOR_PERCENT_FN(_type, _field) \
  213. static u64 he_get_##_field(struct hist_entry *he) \
  214. { \
  215. return he->stat._field; \
  216. } \
  217. \
  218. static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
  219. struct perf_hpp *hpp, struct hist_entry *he) \
  220. { \
  221. return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
  222. hpp_color_scnprintf, true); \
  223. }
  224. #define __HPP_ENTRY_PERCENT_FN(_type, _field) \
  225. static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
  226. struct perf_hpp *hpp, struct hist_entry *he) \
  227. { \
  228. return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
  229. hpp_entry_scnprintf, true); \
  230. }
  231. #define __HPP_SORT_FN(_type, _field) \
  232. static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
  233. { \
  234. return __hpp__sort(a, b, he_get_##_field); \
  235. }
  236. #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
  237. static u64 he_get_acc_##_field(struct hist_entry *he) \
  238. { \
  239. return he->stat_acc->_field; \
  240. } \
  241. \
  242. static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
  243. struct perf_hpp *hpp, struct hist_entry *he) \
  244. { \
  245. return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \
  246. hpp_color_scnprintf, true); \
  247. }
  248. #define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
  249. static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
  250. struct perf_hpp *hpp, struct hist_entry *he) \
  251. { \
  252. return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \
  253. hpp_entry_scnprintf, true); \
  254. }
  255. #define __HPP_SORT_ACC_FN(_type, _field) \
  256. static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
  257. { \
  258. return __hpp__sort_acc(a, b, he_get_acc_##_field); \
  259. }
  260. #define __HPP_ENTRY_RAW_FN(_type, _field) \
  261. static u64 he_get_raw_##_field(struct hist_entry *he) \
  262. { \
  263. return he->stat._field; \
  264. } \
  265. \
  266. static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
  267. struct perf_hpp *hpp, struct hist_entry *he) \
  268. { \
  269. return hpp__fmt(fmt, hpp, he, he_get_raw_##_field, " %*"PRIu64, \
  270. hpp_entry_scnprintf, false); \
  271. }
  272. #define __HPP_SORT_RAW_FN(_type, _field) \
  273. static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
  274. { \
  275. return __hpp__sort(a, b, he_get_raw_##_field); \
  276. }
  277. #define HPP_PERCENT_FNS(_type, _field) \
  278. __HPP_COLOR_PERCENT_FN(_type, _field) \
  279. __HPP_ENTRY_PERCENT_FN(_type, _field) \
  280. __HPP_SORT_FN(_type, _field)
  281. #define HPP_PERCENT_ACC_FNS(_type, _field) \
  282. __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
  283. __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
  284. __HPP_SORT_ACC_FN(_type, _field)
  285. #define HPP_RAW_FNS(_type, _field) \
  286. __HPP_ENTRY_RAW_FN(_type, _field) \
  287. __HPP_SORT_RAW_FN(_type, _field)
  288. HPP_PERCENT_FNS(overhead, period)
  289. HPP_PERCENT_FNS(overhead_sys, period_sys)
  290. HPP_PERCENT_FNS(overhead_us, period_us)
  291. HPP_PERCENT_FNS(overhead_guest_sys, period_guest_sys)
  292. HPP_PERCENT_FNS(overhead_guest_us, period_guest_us)
  293. HPP_PERCENT_ACC_FNS(overhead_acc, period)
  294. HPP_RAW_FNS(samples, nr_events)
  295. HPP_RAW_FNS(period, period)
  296. static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
  297. struct hist_entry *b __maybe_unused)
  298. {
  299. return 0;
  300. }
  301. #define HPP__COLOR_PRINT_FNS(_name, _fn) \
  302. { \
  303. .name = _name, \
  304. .header = hpp__header_fn, \
  305. .width = hpp__width_fn, \
  306. .color = hpp__color_ ## _fn, \
  307. .entry = hpp__entry_ ## _fn, \
  308. .cmp = hpp__nop_cmp, \
  309. .collapse = hpp__nop_cmp, \
  310. .sort = hpp__sort_ ## _fn, \
  311. }
  312. #define HPP__COLOR_ACC_PRINT_FNS(_name, _fn) \
  313. { \
  314. .name = _name, \
  315. .header = hpp__header_fn, \
  316. .width = hpp__width_fn, \
  317. .color = hpp__color_ ## _fn, \
  318. .entry = hpp__entry_ ## _fn, \
  319. .cmp = hpp__nop_cmp, \
  320. .collapse = hpp__nop_cmp, \
  321. .sort = hpp__sort_ ## _fn, \
  322. }
  323. #define HPP__PRINT_FNS(_name, _fn) \
  324. { \
  325. .name = _name, \
  326. .header = hpp__header_fn, \
  327. .width = hpp__width_fn, \
  328. .entry = hpp__entry_ ## _fn, \
  329. .cmp = hpp__nop_cmp, \
  330. .collapse = hpp__nop_cmp, \
  331. .sort = hpp__sort_ ## _fn, \
  332. }
  333. struct perf_hpp_fmt perf_hpp__format[] = {
  334. HPP__COLOR_PRINT_FNS("Overhead", overhead),
  335. HPP__COLOR_PRINT_FNS("sys", overhead_sys),
  336. HPP__COLOR_PRINT_FNS("usr", overhead_us),
  337. HPP__COLOR_PRINT_FNS("guest sys", overhead_guest_sys),
  338. HPP__COLOR_PRINT_FNS("guest usr", overhead_guest_us),
  339. HPP__COLOR_ACC_PRINT_FNS("Children", overhead_acc),
  340. HPP__PRINT_FNS("Samples", samples),
  341. HPP__PRINT_FNS("Period", period)
  342. };
  343. LIST_HEAD(perf_hpp__list);
  344. LIST_HEAD(perf_hpp__sort_list);
  345. #undef HPP__COLOR_PRINT_FNS
  346. #undef HPP__COLOR_ACC_PRINT_FNS
  347. #undef HPP__PRINT_FNS
  348. #undef HPP_PERCENT_FNS
  349. #undef HPP_PERCENT_ACC_FNS
  350. #undef HPP_RAW_FNS
  351. #undef __HPP_HEADER_FN
  352. #undef __HPP_WIDTH_FN
  353. #undef __HPP_COLOR_PERCENT_FN
  354. #undef __HPP_ENTRY_PERCENT_FN
  355. #undef __HPP_COLOR_ACC_PERCENT_FN
  356. #undef __HPP_ENTRY_ACC_PERCENT_FN
  357. #undef __HPP_ENTRY_RAW_FN
  358. #undef __HPP_SORT_FN
  359. #undef __HPP_SORT_ACC_FN
  360. #undef __HPP_SORT_RAW_FN
  361. void perf_hpp__init(void)
  362. {
  363. struct list_head *list;
  364. int i;
  365. for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
  366. struct perf_hpp_fmt *fmt = &perf_hpp__format[i];
  367. INIT_LIST_HEAD(&fmt->list);
  368. /* sort_list may be linked by setup_sorting() */
  369. if (fmt->sort_list.next == NULL)
  370. INIT_LIST_HEAD(&fmt->sort_list);
  371. }
  372. /*
  373. * If user specified field order, no need to setup default fields.
  374. */
  375. if (is_strict_order(field_order))
  376. return;
  377. if (symbol_conf.cumulate_callchain) {
  378. perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);
  379. perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
  380. }
  381. perf_hpp__column_enable(PERF_HPP__OVERHEAD);
  382. if (symbol_conf.show_cpu_utilization) {
  383. perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
  384. perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
  385. if (perf_guest) {
  386. perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
  387. perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
  388. }
  389. }
  390. if (symbol_conf.show_nr_samples)
  391. perf_hpp__column_enable(PERF_HPP__SAMPLES);
  392. if (symbol_conf.show_total_period)
  393. perf_hpp__column_enable(PERF_HPP__PERIOD);
  394. /* prepend overhead field for backward compatiblity. */
  395. list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
  396. if (list_empty(list))
  397. list_add(list, &perf_hpp__sort_list);
  398. if (symbol_conf.cumulate_callchain) {
  399. list = &perf_hpp__format[PERF_HPP__OVERHEAD_ACC].sort_list;
  400. if (list_empty(list))
  401. list_add(list, &perf_hpp__sort_list);
  402. }
  403. }
  404. void perf_hpp__column_register(struct perf_hpp_fmt *format)
  405. {
  406. list_add_tail(&format->list, &perf_hpp__list);
  407. }
  408. void perf_hpp__column_unregister(struct perf_hpp_fmt *format)
  409. {
  410. list_del(&format->list);
  411. }
  412. void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)
  413. {
  414. list_add_tail(&format->sort_list, &perf_hpp__sort_list);
  415. }
  416. void perf_hpp__column_enable(unsigned col)
  417. {
  418. BUG_ON(col >= PERF_HPP__MAX_INDEX);
  419. perf_hpp__column_register(&perf_hpp__format[col]);
  420. }
  421. void perf_hpp__column_disable(unsigned col)
  422. {
  423. BUG_ON(col >= PERF_HPP__MAX_INDEX);
  424. perf_hpp__column_unregister(&perf_hpp__format[col]);
  425. }
  426. void perf_hpp__cancel_cumulate(void)
  427. {
  428. if (is_strict_order(field_order))
  429. return;
  430. perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
  431. perf_hpp__format[PERF_HPP__OVERHEAD].name = "Overhead";
  432. }
  433. void perf_hpp__setup_output_field(void)
  434. {
  435. struct perf_hpp_fmt *fmt;
  436. /* append sort keys to output field */
  437. perf_hpp__for_each_sort_list(fmt) {
  438. if (!list_empty(&fmt->list))
  439. continue;
  440. /*
  441. * sort entry fields are dynamically created,
  442. * so they can share a same sort key even though
  443. * the list is empty.
  444. */
  445. if (perf_hpp__is_sort_entry(fmt)) {
  446. struct perf_hpp_fmt *pos;
  447. perf_hpp__for_each_format(pos) {
  448. if (perf_hpp__same_sort_entry(pos, fmt))
  449. goto next;
  450. }
  451. }
  452. perf_hpp__column_register(fmt);
  453. next:
  454. continue;
  455. }
  456. }
  457. void perf_hpp__append_sort_keys(void)
  458. {
  459. struct perf_hpp_fmt *fmt;
  460. /* append output fields to sort keys */
  461. perf_hpp__for_each_format(fmt) {
  462. if (!list_empty(&fmt->sort_list))
  463. continue;
  464. /*
  465. * sort entry fields are dynamically created,
  466. * so they can share a same sort key even though
  467. * the list is empty.
  468. */
  469. if (perf_hpp__is_sort_entry(fmt)) {
  470. struct perf_hpp_fmt *pos;
  471. perf_hpp__for_each_sort_list(pos) {
  472. if (perf_hpp__same_sort_entry(pos, fmt))
  473. goto next;
  474. }
  475. }
  476. perf_hpp__register_sort_field(fmt);
  477. next:
  478. continue;
  479. }
  480. }
  481. void perf_hpp__reset_output_field(void)
  482. {
  483. struct perf_hpp_fmt *fmt, *tmp;
  484. /* reset output fields */
  485. perf_hpp__for_each_format_safe(fmt, tmp) {
  486. list_del_init(&fmt->list);
  487. list_del_init(&fmt->sort_list);
  488. }
  489. /* reset sort keys */
  490. perf_hpp__for_each_sort_list_safe(fmt, tmp) {
  491. list_del_init(&fmt->list);
  492. list_del_init(&fmt->sort_list);
  493. }
  494. }
  495. /*
  496. * See hists__fprintf to match the column widths
  497. */
  498. unsigned int hists__sort_list_width(struct hists *hists)
  499. {
  500. struct perf_hpp_fmt *fmt;
  501. int ret = 0;
  502. bool first = true;
  503. struct perf_hpp dummy_hpp;
  504. perf_hpp__for_each_format(fmt) {
  505. if (perf_hpp__should_skip(fmt))
  506. continue;
  507. if (first)
  508. first = false;
  509. else
  510. ret += 2;
  511. ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
  512. }
  513. if (verbose && sort__has_sym) /* Addr + origin */
  514. ret += 3 + BITS_PER_LONG / 4;
  515. return ret;
  516. }
  517. void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
  518. {
  519. int idx;
  520. if (perf_hpp__is_sort_entry(fmt))
  521. return perf_hpp__reset_sort_width(fmt, hists);
  522. for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) {
  523. if (fmt == &perf_hpp__format[idx])
  524. break;
  525. }
  526. if (idx == PERF_HPP__MAX_INDEX)
  527. return;
  528. switch (idx) {
  529. case PERF_HPP__OVERHEAD:
  530. case PERF_HPP__OVERHEAD_SYS:
  531. case PERF_HPP__OVERHEAD_US:
  532. case PERF_HPP__OVERHEAD_ACC:
  533. fmt->len = 8;
  534. break;
  535. case PERF_HPP__OVERHEAD_GUEST_SYS:
  536. case PERF_HPP__OVERHEAD_GUEST_US:
  537. fmt->len = 9;
  538. break;
  539. case PERF_HPP__SAMPLES:
  540. case PERF_HPP__PERIOD:
  541. fmt->len = 12;
  542. break;
  543. default:
  544. break;
  545. }
  546. }
  547. void perf_hpp__set_user_width(const char *width_list_str)
  548. {
  549. struct perf_hpp_fmt *fmt;
  550. const char *ptr = width_list_str;
  551. perf_hpp__for_each_format(fmt) {
  552. char *p;
  553. int len = strtol(ptr, &p, 10);
  554. fmt->user_len = len;
  555. if (*p == ',')
  556. ptr = p + 1;
  557. else
  558. break;
  559. }
  560. }