hists_output.c 18 KB

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