hists_output.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #include "perf.h"
  2. #include "util/debug.h"
  3. #include "util/symbol.h"
  4. #include "util/sort.h"
  5. #include "util/evsel.h"
  6. #include "util/evlist.h"
  7. #include "util/machine.h"
  8. #include "util/thread.h"
  9. #include "util/parse-events.h"
  10. #include "tests/tests.h"
  11. #include "tests/hists_common.h"
  12. struct sample {
  13. u32 cpu;
  14. u32 pid;
  15. u64 ip;
  16. struct thread *thread;
  17. struct map *map;
  18. struct symbol *sym;
  19. };
  20. /* For the numbers, see hists_common.c */
  21. static struct sample fake_samples[] = {
  22. /* perf [kernel] schedule() */
  23. { .cpu = 0, .pid = 100, .ip = 0xf0000 + 700, },
  24. /* perf [perf] main() */
  25. { .cpu = 1, .pid = 100, .ip = 0x40000 + 700, },
  26. /* perf [perf] cmd_record() */
  27. { .cpu = 1, .pid = 100, .ip = 0x40000 + 900, },
  28. /* perf [libc] malloc() */
  29. { .cpu = 1, .pid = 100, .ip = 0x50000 + 700, },
  30. /* perf [libc] free() */
  31. { .cpu = 2, .pid = 100, .ip = 0x50000 + 800, },
  32. /* perf [perf] main() */
  33. { .cpu = 2, .pid = 200, .ip = 0x40000 + 700, },
  34. /* perf [kernel] page_fault() */
  35. { .cpu = 2, .pid = 200, .ip = 0xf0000 + 800, },
  36. /* bash [bash] main() */
  37. { .cpu = 3, .pid = 300, .ip = 0x40000 + 700, },
  38. /* bash [bash] xmalloc() */
  39. { .cpu = 0, .pid = 300, .ip = 0x40000 + 800, },
  40. /* bash [kernel] page_fault() */
  41. { .cpu = 1, .pid = 300, .ip = 0xf0000 + 800, },
  42. };
  43. static int add_hist_entries(struct hists *hists, struct machine *machine)
  44. {
  45. struct addr_location al;
  46. struct hist_entry *he;
  47. struct perf_sample sample = { .period = 100, };
  48. size_t i;
  49. for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
  50. const union perf_event event = {
  51. .header = {
  52. .misc = PERF_RECORD_MISC_USER,
  53. },
  54. };
  55. sample.cpu = fake_samples[i].cpu;
  56. sample.pid = fake_samples[i].pid;
  57. sample.tid = fake_samples[i].pid;
  58. sample.ip = fake_samples[i].ip;
  59. if (perf_event__preprocess_sample(&event, machine, &al,
  60. &sample) < 0)
  61. goto out;
  62. he = __hists__add_entry(hists, &al, NULL, NULL, NULL,
  63. sample.period, 1, 0);
  64. if (he == NULL)
  65. goto out;
  66. fake_samples[i].thread = al.thread;
  67. fake_samples[i].map = al.map;
  68. fake_samples[i].sym = al.sym;
  69. }
  70. return TEST_OK;
  71. out:
  72. pr_debug("Not enough memory for adding a hist entry\n");
  73. return TEST_FAIL;
  74. }
  75. static void del_hist_entries(struct hists *hists)
  76. {
  77. struct hist_entry *he;
  78. struct rb_root *root_in;
  79. struct rb_root *root_out;
  80. struct rb_node *node;
  81. if (sort__need_collapse)
  82. root_in = &hists->entries_collapsed;
  83. else
  84. root_in = hists->entries_in;
  85. root_out = &hists->entries;
  86. while (!RB_EMPTY_ROOT(root_out)) {
  87. node = rb_first(root_out);
  88. he = rb_entry(node, struct hist_entry, rb_node);
  89. rb_erase(node, root_out);
  90. rb_erase(&he->rb_node_in, root_in);
  91. hist_entry__free(he);
  92. }
  93. }
  94. typedef int (*test_fn_t)(struct perf_evsel *, struct machine *);
  95. #define COMM(he) (thread__comm_str(he->thread))
  96. #define DSO(he) (he->ms.map->dso->short_name)
  97. #define SYM(he) (he->ms.sym->name)
  98. #define CPU(he) (he->cpu)
  99. #define PID(he) (he->thread->tid)
  100. /* default sort keys (no field) */
  101. static int test1(struct perf_evsel *evsel, struct machine *machine)
  102. {
  103. int err;
  104. struct hists *hists = &evsel->hists;
  105. struct hist_entry *he;
  106. struct rb_root *root;
  107. struct rb_node *node;
  108. field_order = NULL;
  109. sort_order = NULL; /* equivalent to sort_order = "comm,dso,sym" */
  110. setup_sorting();
  111. /*
  112. * expected output:
  113. *
  114. * Overhead Command Shared Object Symbol
  115. * ======== ======= ============= ==============
  116. * 20.00% perf perf [.] main
  117. * 10.00% bash [kernel] [k] page_fault
  118. * 10.00% bash bash [.] main
  119. * 10.00% bash bash [.] xmalloc
  120. * 10.00% perf [kernel] [k] page_fault
  121. * 10.00% perf [kernel] [k] schedule
  122. * 10.00% perf libc [.] free
  123. * 10.00% perf libc [.] malloc
  124. * 10.00% perf perf [.] cmd_record
  125. */
  126. err = add_hist_entries(hists, machine);
  127. if (err < 0)
  128. goto out;
  129. hists__collapse_resort(hists, NULL);
  130. hists__output_resort(hists);
  131. if (verbose > 2) {
  132. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  133. print_hists_out(hists);
  134. }
  135. root = &evsel->hists.entries;
  136. node = rb_first(root);
  137. he = rb_entry(node, struct hist_entry, rb_node);
  138. TEST_ASSERT_VAL("Invalid hist entry",
  139. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  140. !strcmp(SYM(he), "main") && he->stat.period == 200);
  141. node = rb_next(node);
  142. he = rb_entry(node, struct hist_entry, rb_node);
  143. TEST_ASSERT_VAL("Invalid hist entry",
  144. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
  145. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  146. node = rb_next(node);
  147. he = rb_entry(node, struct hist_entry, rb_node);
  148. TEST_ASSERT_VAL("Invalid hist entry",
  149. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  150. !strcmp(SYM(he), "main") && he->stat.period == 100);
  151. node = rb_next(node);
  152. he = rb_entry(node, struct hist_entry, rb_node);
  153. TEST_ASSERT_VAL("Invalid hist entry",
  154. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  155. !strcmp(SYM(he), "xmalloc") && he->stat.period == 100);
  156. node = rb_next(node);
  157. he = rb_entry(node, struct hist_entry, rb_node);
  158. TEST_ASSERT_VAL("Invalid hist entry",
  159. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  160. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  161. node = rb_next(node);
  162. he = rb_entry(node, struct hist_entry, rb_node);
  163. TEST_ASSERT_VAL("Invalid hist entry",
  164. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  165. !strcmp(SYM(he), "schedule") && he->stat.period == 100);
  166. node = rb_next(node);
  167. he = rb_entry(node, struct hist_entry, rb_node);
  168. TEST_ASSERT_VAL("Invalid hist entry",
  169. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  170. !strcmp(SYM(he), "free") && he->stat.period == 100);
  171. node = rb_next(node);
  172. he = rb_entry(node, struct hist_entry, rb_node);
  173. TEST_ASSERT_VAL("Invalid hist entry",
  174. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  175. !strcmp(SYM(he), "malloc") && he->stat.period == 100);
  176. node = rb_next(node);
  177. he = rb_entry(node, struct hist_entry, rb_node);
  178. TEST_ASSERT_VAL("Invalid hist entry",
  179. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  180. !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
  181. out:
  182. del_hist_entries(hists);
  183. reset_output_field();
  184. return err;
  185. }
  186. /* mixed fields and sort keys */
  187. static int test2(struct perf_evsel *evsel, struct machine *machine)
  188. {
  189. int err;
  190. struct hists *hists = &evsel->hists;
  191. struct hist_entry *he;
  192. struct rb_root *root;
  193. struct rb_node *node;
  194. field_order = "overhead,cpu";
  195. sort_order = "pid";
  196. setup_sorting();
  197. /*
  198. * expected output:
  199. *
  200. * Overhead CPU Command: Pid
  201. * ======== === =============
  202. * 30.00% 1 perf : 100
  203. * 10.00% 0 perf : 100
  204. * 10.00% 2 perf : 100
  205. * 20.00% 2 perf : 200
  206. * 10.00% 0 bash : 300
  207. * 10.00% 1 bash : 300
  208. * 10.00% 3 bash : 300
  209. */
  210. err = add_hist_entries(hists, machine);
  211. if (err < 0)
  212. goto out;
  213. hists__collapse_resort(hists, NULL);
  214. hists__output_resort(hists);
  215. if (verbose > 2) {
  216. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  217. print_hists_out(hists);
  218. }
  219. root = &evsel->hists.entries;
  220. node = rb_first(root);
  221. he = rb_entry(node, struct hist_entry, rb_node);
  222. TEST_ASSERT_VAL("Invalid hist entry",
  223. CPU(he) == 1 && PID(he) == 100 && he->stat.period == 300);
  224. node = rb_next(node);
  225. he = rb_entry(node, struct hist_entry, rb_node);
  226. TEST_ASSERT_VAL("Invalid hist entry",
  227. CPU(he) == 0 && PID(he) == 100 && he->stat.period == 100);
  228. out:
  229. del_hist_entries(hists);
  230. reset_output_field();
  231. return err;
  232. }
  233. /* fields only (no sort key) */
  234. static int test3(struct perf_evsel *evsel, struct machine *machine)
  235. {
  236. int err;
  237. struct hists *hists = &evsel->hists;
  238. struct hist_entry *he;
  239. struct rb_root *root;
  240. struct rb_node *node;
  241. field_order = "comm,overhead,dso";
  242. sort_order = NULL;
  243. setup_sorting();
  244. /*
  245. * expected output:
  246. *
  247. * Command Overhead Shared Object
  248. * ======= ======== =============
  249. * bash 20.00% bash
  250. * bash 10.00% [kernel]
  251. * perf 30.00% perf
  252. * perf 20.00% [kernel]
  253. * perf 20.00% libc
  254. */
  255. err = add_hist_entries(hists, machine);
  256. if (err < 0)
  257. goto out;
  258. hists__collapse_resort(hists, NULL);
  259. hists__output_resort(hists);
  260. if (verbose > 2) {
  261. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  262. print_hists_out(hists);
  263. }
  264. root = &evsel->hists.entries;
  265. node = rb_first(root);
  266. he = rb_entry(node, struct hist_entry, rb_node);
  267. TEST_ASSERT_VAL("Invalid hist entry",
  268. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  269. he->stat.period == 200);
  270. node = rb_next(node);
  271. he = rb_entry(node, struct hist_entry, rb_node);
  272. TEST_ASSERT_VAL("Invalid hist entry",
  273. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
  274. he->stat.period == 100);
  275. node = rb_next(node);
  276. he = rb_entry(node, struct hist_entry, rb_node);
  277. TEST_ASSERT_VAL("Invalid hist entry",
  278. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  279. he->stat.period == 300);
  280. node = rb_next(node);
  281. he = rb_entry(node, struct hist_entry, rb_node);
  282. TEST_ASSERT_VAL("Invalid hist entry",
  283. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  284. he->stat.period == 200);
  285. node = rb_next(node);
  286. he = rb_entry(node, struct hist_entry, rb_node);
  287. TEST_ASSERT_VAL("Invalid hist entry",
  288. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  289. he->stat.period == 200);
  290. out:
  291. del_hist_entries(hists);
  292. reset_output_field();
  293. return err;
  294. }
  295. /* handle duplicate 'dso' field */
  296. static int test4(struct perf_evsel *evsel, struct machine *machine)
  297. {
  298. int err;
  299. struct hists *hists = &evsel->hists;
  300. struct hist_entry *he;
  301. struct rb_root *root;
  302. struct rb_node *node;
  303. field_order = "dso,sym,comm,overhead,dso";
  304. sort_order = "sym";
  305. setup_sorting();
  306. /*
  307. * expected output:
  308. *
  309. * Shared Object Symbol Command Overhead
  310. * ============= ============== ======= ========
  311. * perf [.] cmd_record perf 10.00%
  312. * libc [.] free perf 10.00%
  313. * bash [.] main bash 10.00%
  314. * perf [.] main perf 20.00%
  315. * libc [.] malloc perf 10.00%
  316. * [kernel] [k] page_fault bash 10.00%
  317. * [kernel] [k] page_fault perf 10.00%
  318. * [kernel] [k] schedule perf 10.00%
  319. * bash [.] xmalloc bash 10.00%
  320. */
  321. err = add_hist_entries(hists, machine);
  322. if (err < 0)
  323. goto out;
  324. hists__collapse_resort(hists, NULL);
  325. hists__output_resort(hists);
  326. if (verbose > 2) {
  327. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  328. print_hists_out(hists);
  329. }
  330. root = &evsel->hists.entries;
  331. node = rb_first(root);
  332. he = rb_entry(node, struct hist_entry, rb_node);
  333. TEST_ASSERT_VAL("Invalid hist entry",
  334. !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") &&
  335. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  336. node = rb_next(node);
  337. he = rb_entry(node, struct hist_entry, rb_node);
  338. TEST_ASSERT_VAL("Invalid hist entry",
  339. !strcmp(DSO(he), "libc") && !strcmp(SYM(he), "free") &&
  340. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  341. node = rb_next(node);
  342. he = rb_entry(node, struct hist_entry, rb_node);
  343. TEST_ASSERT_VAL("Invalid hist entry",
  344. !strcmp(DSO(he), "bash") && !strcmp(SYM(he), "main") &&
  345. !strcmp(COMM(he), "bash") && he->stat.period == 100);
  346. node = rb_next(node);
  347. he = rb_entry(node, struct hist_entry, rb_node);
  348. TEST_ASSERT_VAL("Invalid hist entry",
  349. !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "main") &&
  350. !strcmp(COMM(he), "perf") && he->stat.period == 200);
  351. node = rb_next(node);
  352. he = rb_entry(node, struct hist_entry, rb_node);
  353. TEST_ASSERT_VAL("Invalid hist entry",
  354. !strcmp(DSO(he), "libc") && !strcmp(SYM(he), "malloc") &&
  355. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  356. node = rb_next(node);
  357. he = rb_entry(node, struct hist_entry, rb_node);
  358. TEST_ASSERT_VAL("Invalid hist entry",
  359. !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "page_fault") &&
  360. !strcmp(COMM(he), "bash") && he->stat.period == 100);
  361. node = rb_next(node);
  362. he = rb_entry(node, struct hist_entry, rb_node);
  363. TEST_ASSERT_VAL("Invalid hist entry",
  364. !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "page_fault") &&
  365. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  366. node = rb_next(node);
  367. he = rb_entry(node, struct hist_entry, rb_node);
  368. TEST_ASSERT_VAL("Invalid hist entry",
  369. !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "schedule") &&
  370. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  371. node = rb_next(node);
  372. he = rb_entry(node, struct hist_entry, rb_node);
  373. TEST_ASSERT_VAL("Invalid hist entry",
  374. !strcmp(DSO(he), "bash") && !strcmp(SYM(he), "xmalloc") &&
  375. !strcmp(COMM(he), "bash") && he->stat.period == 100);
  376. out:
  377. del_hist_entries(hists);
  378. reset_output_field();
  379. return err;
  380. }
  381. /* full sort keys w/o overhead field */
  382. static int test5(struct perf_evsel *evsel, struct machine *machine)
  383. {
  384. int err;
  385. struct hists *hists = &evsel->hists;
  386. struct hist_entry *he;
  387. struct rb_root *root;
  388. struct rb_node *node;
  389. field_order = "cpu,pid,comm,dso,sym";
  390. sort_order = "dso,pid";
  391. setup_sorting();
  392. /*
  393. * expected output:
  394. *
  395. * CPU Command: Pid Command Shared Object Symbol
  396. * === ============= ======= ============= ==============
  397. * 0 perf: 100 perf [kernel] [k] schedule
  398. * 2 perf: 200 perf [kernel] [k] page_fault
  399. * 1 bash: 300 bash [kernel] [k] page_fault
  400. * 0 bash: 300 bash bash [.] xmalloc
  401. * 3 bash: 300 bash bash [.] main
  402. * 1 perf: 100 perf libc [.] malloc
  403. * 2 perf: 100 perf libc [.] free
  404. * 1 perf: 100 perf perf [.] cmd_record
  405. * 1 perf: 100 perf perf [.] main
  406. * 2 perf: 200 perf perf [.] main
  407. */
  408. err = add_hist_entries(hists, machine);
  409. if (err < 0)
  410. goto out;
  411. hists__collapse_resort(hists, NULL);
  412. hists__output_resort(hists);
  413. if (verbose > 2) {
  414. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  415. print_hists_out(hists);
  416. }
  417. root = &evsel->hists.entries;
  418. node = rb_first(root);
  419. he = rb_entry(node, struct hist_entry, rb_node);
  420. TEST_ASSERT_VAL("Invalid hist entry",
  421. CPU(he) == 0 && PID(he) == 100 &&
  422. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  423. !strcmp(SYM(he), "schedule") && he->stat.period == 100);
  424. node = rb_next(node);
  425. he = rb_entry(node, struct hist_entry, rb_node);
  426. TEST_ASSERT_VAL("Invalid hist entry",
  427. CPU(he) == 2 && PID(he) == 200 &&
  428. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  429. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  430. node = rb_next(node);
  431. he = rb_entry(node, struct hist_entry, rb_node);
  432. TEST_ASSERT_VAL("Invalid hist entry",
  433. CPU(he) == 1 && PID(he) == 300 &&
  434. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
  435. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  436. node = rb_next(node);
  437. he = rb_entry(node, struct hist_entry, rb_node);
  438. TEST_ASSERT_VAL("Invalid hist entry",
  439. CPU(he) == 0 && PID(he) == 300 &&
  440. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  441. !strcmp(SYM(he), "xmalloc") && he->stat.period == 100);
  442. node = rb_next(node);
  443. he = rb_entry(node, struct hist_entry, rb_node);
  444. TEST_ASSERT_VAL("Invalid hist entry",
  445. CPU(he) == 3 && PID(he) == 300 &&
  446. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  447. !strcmp(SYM(he), "main") && he->stat.period == 100);
  448. node = rb_next(node);
  449. he = rb_entry(node, struct hist_entry, rb_node);
  450. TEST_ASSERT_VAL("Invalid hist entry",
  451. CPU(he) == 1 && PID(he) == 100 &&
  452. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  453. !strcmp(SYM(he), "malloc") && he->stat.period == 100);
  454. node = rb_next(node);
  455. he = rb_entry(node, struct hist_entry, rb_node);
  456. TEST_ASSERT_VAL("Invalid hist entry",
  457. CPU(he) == 2 && PID(he) == 100 &&
  458. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  459. !strcmp(SYM(he), "free") && he->stat.period == 100);
  460. node = rb_next(node);
  461. he = rb_entry(node, struct hist_entry, rb_node);
  462. TEST_ASSERT_VAL("Invalid hist entry",
  463. CPU(he) == 1 && PID(he) == 100 &&
  464. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  465. !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
  466. node = rb_next(node);
  467. he = rb_entry(node, struct hist_entry, rb_node);
  468. TEST_ASSERT_VAL("Invalid hist entry",
  469. CPU(he) == 1 && PID(he) == 100 &&
  470. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  471. !strcmp(SYM(he), "main") && he->stat.period == 100);
  472. node = rb_next(node);
  473. he = rb_entry(node, struct hist_entry, rb_node);
  474. TEST_ASSERT_VAL("Invalid hist entry",
  475. CPU(he) == 2 && PID(he) == 200 &&
  476. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  477. !strcmp(SYM(he), "main") && he->stat.period == 100);
  478. out:
  479. del_hist_entries(hists);
  480. reset_output_field();
  481. return err;
  482. }
  483. int test__hists_output(void)
  484. {
  485. int err = TEST_FAIL;
  486. struct machines machines;
  487. struct machine *machine;
  488. struct perf_evsel *evsel;
  489. struct perf_evlist *evlist = perf_evlist__new();
  490. size_t i;
  491. test_fn_t testcases[] = {
  492. test1,
  493. test2,
  494. test3,
  495. test4,
  496. test5,
  497. };
  498. TEST_ASSERT_VAL("No memory", evlist);
  499. err = parse_events(evlist, "cpu-clock");
  500. if (err)
  501. goto out;
  502. machines__init(&machines);
  503. /* setup threads/dso/map/symbols also */
  504. machine = setup_fake_machine(&machines);
  505. if (!machine)
  506. goto out;
  507. if (verbose > 1)
  508. machine__fprintf(machine, stderr);
  509. evsel = perf_evlist__first(evlist);
  510. for (i = 0; i < ARRAY_SIZE(testcases); i++) {
  511. err = testcases[i](evsel, machine);
  512. if (err < 0)
  513. break;
  514. }
  515. out:
  516. /* tear down everything */
  517. perf_evlist__delete(evlist);
  518. machines__exit(&machines);
  519. return err;
  520. }