hists_output.c 18 KB

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