hists_output.c 18 KB

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