hists_output.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. const union perf_event event = {
  51. .header = {
  52. .misc = PERF_RECORD_MISC_USER,
  53. },
  54. };
  55. struct hist_entry_iter iter = {
  56. .evsel = evsel,
  57. .sample = &sample,
  58. .ops = &hist_iter_normal,
  59. .hide_unresolved = false,
  60. };
  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 (perf_event__preprocess_sample(&event, machine, &al,
  66. &sample) < 0)
  67. goto out;
  68. if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
  69. NULL) < 0) {
  70. addr_location__put(&al);
  71. goto out;
  72. }
  73. fake_samples[i].thread = al.thread;
  74. fake_samples[i].map = al.map;
  75. fake_samples[i].sym = al.sym;
  76. }
  77. return TEST_OK;
  78. out:
  79. pr_debug("Not enough memory for adding a hist entry\n");
  80. return TEST_FAIL;
  81. }
  82. static void del_hist_entries(struct hists *hists)
  83. {
  84. struct hist_entry *he;
  85. struct rb_root *root_in;
  86. struct rb_root *root_out;
  87. struct rb_node *node;
  88. if (sort__need_collapse)
  89. root_in = &hists->entries_collapsed;
  90. else
  91. root_in = hists->entries_in;
  92. root_out = &hists->entries;
  93. while (!RB_EMPTY_ROOT(root_out)) {
  94. node = rb_first(root_out);
  95. he = rb_entry(node, struct hist_entry, rb_node);
  96. rb_erase(node, root_out);
  97. rb_erase(&he->rb_node_in, root_in);
  98. hist_entry__delete(he);
  99. }
  100. }
  101. typedef int (*test_fn_t)(struct perf_evsel *, struct machine *);
  102. #define COMM(he) (thread__comm_str(he->thread))
  103. #define DSO(he) (he->ms.map->dso->short_name)
  104. #define SYM(he) (he->ms.sym->name)
  105. #define CPU(he) (he->cpu)
  106. #define PID(he) (he->thread->tid)
  107. /* default sort keys (no field) */
  108. static int test1(struct perf_evsel *evsel, struct machine *machine)
  109. {
  110. int err;
  111. struct hists *hists = evsel__hists(evsel);
  112. struct hist_entry *he;
  113. struct rb_root *root;
  114. struct rb_node *node;
  115. field_order = NULL;
  116. sort_order = NULL; /* equivalent to sort_order = "comm,dso,sym" */
  117. setup_sorting();
  118. /*
  119. * expected output:
  120. *
  121. * Overhead Command Shared Object Symbol
  122. * ======== ======= ============= ==============
  123. * 20.00% perf perf [.] main
  124. * 10.00% bash [kernel] [k] page_fault
  125. * 10.00% bash bash [.] main
  126. * 10.00% bash bash [.] xmalloc
  127. * 10.00% perf [kernel] [k] page_fault
  128. * 10.00% perf [kernel] [k] schedule
  129. * 10.00% perf libc [.] free
  130. * 10.00% perf libc [.] malloc
  131. * 10.00% perf perf [.] cmd_record
  132. */
  133. err = add_hist_entries(hists, machine);
  134. if (err < 0)
  135. goto out;
  136. hists__collapse_resort(hists, NULL);
  137. hists__output_resort(hists, NULL);
  138. if (verbose > 2) {
  139. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  140. print_hists_out(hists);
  141. }
  142. root = &hists->entries;
  143. node = rb_first(root);
  144. he = rb_entry(node, struct hist_entry, rb_node);
  145. TEST_ASSERT_VAL("Invalid hist entry",
  146. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  147. !strcmp(SYM(he), "main") && he->stat.period == 200);
  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), "[kernel]") &&
  152. !strcmp(SYM(he), "page_fault") && 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), "main") && 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), "bash") && !strcmp(DSO(he), "bash") &&
  162. !strcmp(SYM(he), "xmalloc") && 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), "page_fault") && 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), "[kernel]") &&
  172. !strcmp(SYM(he), "schedule") && 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), "free") && 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), "libc") &&
  182. !strcmp(SYM(he), "malloc") && he->stat.period == 100);
  183. node = rb_next(node);
  184. he = rb_entry(node, struct hist_entry, rb_node);
  185. TEST_ASSERT_VAL("Invalid hist entry",
  186. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  187. !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
  188. out:
  189. del_hist_entries(hists);
  190. reset_output_field();
  191. return err;
  192. }
  193. /* mixed fields and sort keys */
  194. static int test2(struct perf_evsel *evsel, struct machine *machine)
  195. {
  196. int err;
  197. struct hists *hists = evsel__hists(evsel);
  198. struct hist_entry *he;
  199. struct rb_root *root;
  200. struct rb_node *node;
  201. field_order = "overhead,cpu";
  202. sort_order = "pid";
  203. setup_sorting();
  204. /*
  205. * expected output:
  206. *
  207. * Overhead CPU Command: Pid
  208. * ======== === =============
  209. * 30.00% 1 perf : 100
  210. * 10.00% 0 perf : 100
  211. * 10.00% 2 perf : 100
  212. * 20.00% 2 perf : 200
  213. * 10.00% 0 bash : 300
  214. * 10.00% 1 bash : 300
  215. * 10.00% 3 bash : 300
  216. */
  217. err = add_hist_entries(hists, machine);
  218. if (err < 0)
  219. goto out;
  220. hists__collapse_resort(hists, NULL);
  221. hists__output_resort(hists, NULL);
  222. if (verbose > 2) {
  223. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  224. print_hists_out(hists);
  225. }
  226. root = &hists->entries;
  227. node = rb_first(root);
  228. he = rb_entry(node, struct hist_entry, rb_node);
  229. TEST_ASSERT_VAL("Invalid hist entry",
  230. CPU(he) == 1 && PID(he) == 100 && he->stat.period == 300);
  231. node = rb_next(node);
  232. he = rb_entry(node, struct hist_entry, rb_node);
  233. TEST_ASSERT_VAL("Invalid hist entry",
  234. CPU(he) == 0 && PID(he) == 100 && he->stat.period == 100);
  235. out:
  236. del_hist_entries(hists);
  237. reset_output_field();
  238. return err;
  239. }
  240. /* fields only (no sort key) */
  241. static int test3(struct perf_evsel *evsel, struct machine *machine)
  242. {
  243. int err;
  244. struct hists *hists = evsel__hists(evsel);
  245. struct hist_entry *he;
  246. struct rb_root *root;
  247. struct rb_node *node;
  248. field_order = "comm,overhead,dso";
  249. sort_order = NULL;
  250. setup_sorting();
  251. /*
  252. * expected output:
  253. *
  254. * Command Overhead Shared Object
  255. * ======= ======== =============
  256. * bash 20.00% bash
  257. * bash 10.00% [kernel]
  258. * perf 30.00% perf
  259. * perf 20.00% [kernel]
  260. * perf 20.00% libc
  261. */
  262. err = add_hist_entries(hists, machine);
  263. if (err < 0)
  264. goto out;
  265. hists__collapse_resort(hists, NULL);
  266. hists__output_resort(hists, NULL);
  267. if (verbose > 2) {
  268. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  269. print_hists_out(hists);
  270. }
  271. root = &hists->entries;
  272. node = rb_first(root);
  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), "bash") &&
  276. he->stat.period == 200);
  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), "bash") && !strcmp(DSO(he), "[kernel]") &&
  281. he->stat.period == 100);
  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), "perf") &&
  286. he->stat.period == 300);
  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), "[kernel]") &&
  291. he->stat.period == 200);
  292. node = rb_next(node);
  293. he = rb_entry(node, struct hist_entry, rb_node);
  294. TEST_ASSERT_VAL("Invalid hist entry",
  295. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  296. he->stat.period == 200);
  297. out:
  298. del_hist_entries(hists);
  299. reset_output_field();
  300. return err;
  301. }
  302. /* handle duplicate 'dso' field */
  303. static int test4(struct perf_evsel *evsel, struct machine *machine)
  304. {
  305. int err;
  306. struct hists *hists = evsel__hists(evsel);
  307. struct hist_entry *he;
  308. struct rb_root *root;
  309. struct rb_node *node;
  310. field_order = "dso,sym,comm,overhead,dso";
  311. sort_order = "sym";
  312. setup_sorting();
  313. /*
  314. * expected output:
  315. *
  316. * Shared Object Symbol Command Overhead
  317. * ============= ============== ======= ========
  318. * perf [.] cmd_record perf 10.00%
  319. * libc [.] free perf 10.00%
  320. * bash [.] main bash 10.00%
  321. * perf [.] main perf 20.00%
  322. * libc [.] malloc perf 10.00%
  323. * [kernel] [k] page_fault bash 10.00%
  324. * [kernel] [k] page_fault perf 10.00%
  325. * [kernel] [k] schedule perf 10.00%
  326. * bash [.] xmalloc bash 10.00%
  327. */
  328. err = add_hist_entries(hists, machine);
  329. if (err < 0)
  330. goto out;
  331. hists__collapse_resort(hists, NULL);
  332. hists__output_resort(hists, NULL);
  333. if (verbose > 2) {
  334. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  335. print_hists_out(hists);
  336. }
  337. root = &hists->entries;
  338. node = rb_first(root);
  339. he = rb_entry(node, struct hist_entry, rb_node);
  340. TEST_ASSERT_VAL("Invalid hist entry",
  341. !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") &&
  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), "libc") && !strcmp(SYM(he), "free") &&
  347. !strcmp(COMM(he), "perf") && 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), "bash") && !strcmp(SYM(he), "main") &&
  352. !strcmp(COMM(he), "bash") && he->stat.period == 100);
  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), "perf") && !strcmp(SYM(he), "main") &&
  357. !strcmp(COMM(he), "perf") && he->stat.period == 200);
  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), "libc") && !strcmp(SYM(he), "malloc") &&
  362. !strcmp(COMM(he), "perf") && 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), "bash") && 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), "page_fault") &&
  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), "[kernel]") && !strcmp(SYM(he), "schedule") &&
  377. !strcmp(COMM(he), "perf") && he->stat.period == 100);
  378. node = rb_next(node);
  379. he = rb_entry(node, struct hist_entry, rb_node);
  380. TEST_ASSERT_VAL("Invalid hist entry",
  381. !strcmp(DSO(he), "bash") && !strcmp(SYM(he), "xmalloc") &&
  382. !strcmp(COMM(he), "bash") && he->stat.period == 100);
  383. out:
  384. del_hist_entries(hists);
  385. reset_output_field();
  386. return err;
  387. }
  388. /* full sort keys w/o overhead field */
  389. static int test5(struct perf_evsel *evsel, struct machine *machine)
  390. {
  391. int err;
  392. struct hists *hists = evsel__hists(evsel);
  393. struct hist_entry *he;
  394. struct rb_root *root;
  395. struct rb_node *node;
  396. field_order = "cpu,pid,comm,dso,sym";
  397. sort_order = "dso,pid";
  398. setup_sorting();
  399. /*
  400. * expected output:
  401. *
  402. * CPU Command: Pid Command Shared Object Symbol
  403. * === ============= ======= ============= ==============
  404. * 0 perf: 100 perf [kernel] [k] schedule
  405. * 2 perf: 200 perf [kernel] [k] page_fault
  406. * 1 bash: 300 bash [kernel] [k] page_fault
  407. * 0 bash: 300 bash bash [.] xmalloc
  408. * 3 bash: 300 bash bash [.] main
  409. * 1 perf: 100 perf libc [.] malloc
  410. * 2 perf: 100 perf libc [.] free
  411. * 1 perf: 100 perf perf [.] cmd_record
  412. * 1 perf: 100 perf perf [.] main
  413. * 2 perf: 200 perf perf [.] main
  414. */
  415. err = add_hist_entries(hists, machine);
  416. if (err < 0)
  417. goto out;
  418. hists__collapse_resort(hists, NULL);
  419. hists__output_resort(hists, NULL);
  420. if (verbose > 2) {
  421. pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
  422. print_hists_out(hists);
  423. }
  424. root = &hists->entries;
  425. node = rb_first(root);
  426. he = rb_entry(node, struct hist_entry, rb_node);
  427. TEST_ASSERT_VAL("Invalid hist entry",
  428. CPU(he) == 0 && PID(he) == 100 &&
  429. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  430. !strcmp(SYM(he), "schedule") && he->stat.period == 100);
  431. node = rb_next(node);
  432. he = rb_entry(node, struct hist_entry, rb_node);
  433. TEST_ASSERT_VAL("Invalid hist entry",
  434. CPU(he) == 2 && PID(he) == 200 &&
  435. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
  436. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  437. node = rb_next(node);
  438. he = rb_entry(node, struct hist_entry, rb_node);
  439. TEST_ASSERT_VAL("Invalid hist entry",
  440. CPU(he) == 1 && PID(he) == 300 &&
  441. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
  442. !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
  443. node = rb_next(node);
  444. he = rb_entry(node, struct hist_entry, rb_node);
  445. TEST_ASSERT_VAL("Invalid hist entry",
  446. CPU(he) == 0 && PID(he) == 300 &&
  447. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  448. !strcmp(SYM(he), "xmalloc") && he->stat.period == 100);
  449. node = rb_next(node);
  450. he = rb_entry(node, struct hist_entry, rb_node);
  451. TEST_ASSERT_VAL("Invalid hist entry",
  452. CPU(he) == 3 && PID(he) == 300 &&
  453. !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
  454. !strcmp(SYM(he), "main") && he->stat.period == 100);
  455. node = rb_next(node);
  456. he = rb_entry(node, struct hist_entry, rb_node);
  457. TEST_ASSERT_VAL("Invalid hist entry",
  458. CPU(he) == 1 && PID(he) == 100 &&
  459. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  460. !strcmp(SYM(he), "malloc") && he->stat.period == 100);
  461. node = rb_next(node);
  462. he = rb_entry(node, struct hist_entry, rb_node);
  463. TEST_ASSERT_VAL("Invalid hist entry",
  464. CPU(he) == 2 && PID(he) == 100 &&
  465. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
  466. !strcmp(SYM(he), "free") && he->stat.period == 100);
  467. node = rb_next(node);
  468. he = rb_entry(node, struct hist_entry, rb_node);
  469. TEST_ASSERT_VAL("Invalid hist entry",
  470. CPU(he) == 1 && PID(he) == 100 &&
  471. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  472. !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
  473. node = rb_next(node);
  474. he = rb_entry(node, struct hist_entry, rb_node);
  475. TEST_ASSERT_VAL("Invalid hist entry",
  476. CPU(he) == 1 && PID(he) == 100 &&
  477. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  478. !strcmp(SYM(he), "main") && he->stat.period == 100);
  479. node = rb_next(node);
  480. he = rb_entry(node, struct hist_entry, rb_node);
  481. TEST_ASSERT_VAL("Invalid hist entry",
  482. CPU(he) == 2 && PID(he) == 200 &&
  483. !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
  484. !strcmp(SYM(he), "main") && he->stat.period == 100);
  485. out:
  486. del_hist_entries(hists);
  487. reset_output_field();
  488. return err;
  489. }
  490. int test__hists_output(void)
  491. {
  492. int err = TEST_FAIL;
  493. struct machines machines;
  494. struct machine *machine;
  495. struct perf_evsel *evsel;
  496. struct perf_evlist *evlist = perf_evlist__new();
  497. size_t i;
  498. test_fn_t testcases[] = {
  499. test1,
  500. test2,
  501. test3,
  502. test4,
  503. test5,
  504. };
  505. TEST_ASSERT_VAL("No memory", evlist);
  506. err = parse_events(evlist, "cpu-clock", NULL);
  507. if (err)
  508. goto out;
  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 = perf_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. perf_evlist__delete(evlist);
  525. machines__exit(&machines);
  526. return err;
  527. }