hists_output.c 18 KB

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