hists_output.c 18 KB

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