builtin-report.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /*
  2. * builtin-report.c
  3. *
  4. * Builtin report command: Analyze the perf.data input file,
  5. * look up and read DSOs and symbol information and display
  6. * a histogram of results, along various sorting keys.
  7. */
  8. #include "builtin.h"
  9. #include "util/util.h"
  10. #include "util/list.h"
  11. #include "util/cache.h"
  12. #include "util/rbtree.h"
  13. #include "util/symbol.h"
  14. #include "util/string.h"
  15. #include "perf.h"
  16. #include "util/parse-options.h"
  17. #include "util/parse-events.h"
  18. #define SHOW_KERNEL 1
  19. #define SHOW_USER 2
  20. #define SHOW_HV 4
  21. static char const *input_name = "perf.data";
  22. static char *vmlinux = NULL;
  23. static char *sort_order = "comm,dso";
  24. static int input;
  25. static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
  26. static int dump_trace = 0;
  27. #define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
  28. static int verbose;
  29. static int full_paths;
  30. static unsigned long page_size;
  31. static unsigned long mmap_window = 32;
  32. const char *perf_event_names[] = {
  33. [PERF_EVENT_MMAP] = " PERF_EVENT_MMAP",
  34. [PERF_EVENT_MUNMAP] = " PERF_EVENT_MUNMAP",
  35. [PERF_EVENT_COMM] = " PERF_EVENT_COMM",
  36. };
  37. struct ip_event {
  38. struct perf_event_header header;
  39. __u64 ip;
  40. __u32 pid, tid;
  41. };
  42. struct mmap_event {
  43. struct perf_event_header header;
  44. __u32 pid, tid;
  45. __u64 start;
  46. __u64 len;
  47. __u64 pgoff;
  48. char filename[PATH_MAX];
  49. };
  50. struct comm_event {
  51. struct perf_event_header header;
  52. __u32 pid,tid;
  53. char comm[16];
  54. };
  55. typedef union event_union {
  56. struct perf_event_header header;
  57. struct ip_event ip;
  58. struct mmap_event mmap;
  59. struct comm_event comm;
  60. } event_t;
  61. static LIST_HEAD(dsos);
  62. static struct dso *kernel_dso;
  63. static void dsos__add(struct dso *dso)
  64. {
  65. list_add_tail(&dso->node, &dsos);
  66. }
  67. static struct dso *dsos__find(const char *name)
  68. {
  69. struct dso *pos;
  70. list_for_each_entry(pos, &dsos, node)
  71. if (strcmp(pos->name, name) == 0)
  72. return pos;
  73. return NULL;
  74. }
  75. static struct dso *dsos__findnew(const char *name)
  76. {
  77. struct dso *dso = dsos__find(name);
  78. int nr;
  79. if (dso)
  80. return dso;
  81. dso = dso__new(name, 0);
  82. if (!dso)
  83. goto out_delete_dso;
  84. nr = dso__load(dso, NULL);
  85. if (nr < 0) {
  86. fprintf(stderr, "Failed to open: %s\n", name);
  87. goto out_delete_dso;
  88. }
  89. if (!nr && verbose) {
  90. fprintf(stderr,
  91. "No symbols found in: %s, maybe install a debug package?\n",
  92. name);
  93. }
  94. dsos__add(dso);
  95. return dso;
  96. out_delete_dso:
  97. dso__delete(dso);
  98. return NULL;
  99. }
  100. static void dsos__fprintf(FILE *fp)
  101. {
  102. struct dso *pos;
  103. list_for_each_entry(pos, &dsos, node)
  104. dso__fprintf(pos, fp);
  105. }
  106. static int load_kernel(void)
  107. {
  108. int err;
  109. kernel_dso = dso__new("[kernel]", 0);
  110. if (!kernel_dso)
  111. return -1;
  112. err = dso__load_kernel(kernel_dso, vmlinux, NULL);
  113. if (err) {
  114. dso__delete(kernel_dso);
  115. kernel_dso = NULL;
  116. } else
  117. dsos__add(kernel_dso);
  118. return err;
  119. }
  120. static int strcommon(const char *pathname, const char *cwd, int cwdlen)
  121. {
  122. int n = 0;
  123. while (pathname[n] == cwd[n] && n < cwdlen)
  124. ++n;
  125. return n;
  126. }
  127. struct map {
  128. struct list_head node;
  129. uint64_t start;
  130. uint64_t end;
  131. uint64_t pgoff;
  132. struct dso *dso;
  133. };
  134. static struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
  135. {
  136. struct map *self = malloc(sizeof(*self));
  137. if (self != NULL) {
  138. const char *filename = event->filename;
  139. char newfilename[PATH_MAX];
  140. if (cwd) {
  141. int n = strcommon(filename, cwd, cwdlen);
  142. if (n == cwdlen) {
  143. snprintf(newfilename, sizeof(newfilename),
  144. ".%s", filename + n);
  145. filename = newfilename;
  146. }
  147. }
  148. self->start = event->start;
  149. self->end = event->start + event->len;
  150. self->pgoff = event->pgoff;
  151. self->dso = dsos__findnew(filename);
  152. if (self->dso == NULL)
  153. goto out_delete;
  154. }
  155. return self;
  156. out_delete:
  157. free(self);
  158. return NULL;
  159. }
  160. struct thread;
  161. struct thread {
  162. struct rb_node rb_node;
  163. struct list_head maps;
  164. pid_t pid;
  165. char *comm;
  166. };
  167. static struct thread *thread__new(pid_t pid)
  168. {
  169. struct thread *self = malloc(sizeof(*self));
  170. if (self != NULL) {
  171. self->pid = pid;
  172. self->comm = malloc(30);
  173. if (self->comm)
  174. sprintf(self->comm, ":%d", pid);
  175. INIT_LIST_HEAD(&self->maps);
  176. }
  177. return self;
  178. }
  179. static int thread__set_comm(struct thread *self, const char *comm)
  180. {
  181. self->comm = strdup(comm);
  182. return self->comm ? 0 : -ENOMEM;
  183. }
  184. static struct rb_root threads;
  185. static struct thread *threads__findnew(pid_t pid)
  186. {
  187. struct rb_node **p = &threads.rb_node;
  188. struct rb_node *parent = NULL;
  189. struct thread *th;
  190. while (*p != NULL) {
  191. parent = *p;
  192. th = rb_entry(parent, struct thread, rb_node);
  193. if (th->pid == pid)
  194. return th;
  195. if (pid < th->pid)
  196. p = &(*p)->rb_left;
  197. else
  198. p = &(*p)->rb_right;
  199. }
  200. th = thread__new(pid);
  201. if (th != NULL) {
  202. rb_link_node(&th->rb_node, parent, p);
  203. rb_insert_color(&th->rb_node, &threads);
  204. }
  205. return th;
  206. }
  207. static void thread__insert_map(struct thread *self, struct map *map)
  208. {
  209. list_add_tail(&map->node, &self->maps);
  210. }
  211. static struct map *thread__find_map(struct thread *self, uint64_t ip)
  212. {
  213. struct map *pos;
  214. if (self == NULL)
  215. return NULL;
  216. list_for_each_entry(pos, &self->maps, node)
  217. if (ip >= pos->start && ip <= pos->end)
  218. return pos;
  219. return NULL;
  220. }
  221. /*
  222. * histogram, sorted on item, collects counts
  223. */
  224. static struct rb_root hist;
  225. struct hist_entry {
  226. struct rb_node rb_node;
  227. struct thread *thread;
  228. struct map *map;
  229. struct dso *dso;
  230. struct symbol *sym;
  231. uint64_t ip;
  232. char level;
  233. uint32_t count;
  234. };
  235. /*
  236. * configurable sorting bits
  237. */
  238. struct sort_entry {
  239. struct list_head list;
  240. char *header;
  241. int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
  242. size_t (*print)(FILE *fp, struct hist_entry *);
  243. };
  244. static int64_t
  245. sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
  246. {
  247. return right->thread->pid - left->thread->pid;
  248. }
  249. static size_t
  250. sort__thread_print(FILE *fp, struct hist_entry *self)
  251. {
  252. return fprintf(fp, " %16s:%5d", self->thread->comm ?: "", self->thread->pid);
  253. }
  254. static struct sort_entry sort_thread = {
  255. .header = " Command: Pid ",
  256. .cmp = sort__thread_cmp,
  257. .print = sort__thread_print,
  258. };
  259. static int64_t
  260. sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
  261. {
  262. char *comm_l = left->thread->comm;
  263. char *comm_r = right->thread->comm;
  264. if (!comm_l || !comm_r) {
  265. if (!comm_l && !comm_r)
  266. return 0;
  267. else if (!comm_l)
  268. return -1;
  269. else
  270. return 1;
  271. }
  272. return strcmp(comm_l, comm_r);
  273. }
  274. static size_t
  275. sort__comm_print(FILE *fp, struct hist_entry *self)
  276. {
  277. return fprintf(fp, " %16s", self->thread->comm);
  278. }
  279. static struct sort_entry sort_comm = {
  280. .header = " Command",
  281. .cmp = sort__comm_cmp,
  282. .print = sort__comm_print,
  283. };
  284. static int64_t
  285. sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
  286. {
  287. struct dso *dso_l = left->dso;
  288. struct dso *dso_r = right->dso;
  289. if (!dso_l || !dso_r) {
  290. if (!dso_l && !dso_r)
  291. return 0;
  292. else if (!dso_l)
  293. return -1;
  294. else
  295. return 1;
  296. }
  297. return strcmp(dso_l->name, dso_r->name);
  298. }
  299. static size_t
  300. sort__dso_print(FILE *fp, struct hist_entry *self)
  301. {
  302. if (self->dso)
  303. return fprintf(fp, " %-25s", self->dso->name);
  304. return fprintf(fp, " %016llx", (__u64)self->ip);
  305. }
  306. static struct sort_entry sort_dso = {
  307. .header = " Shared Object ",
  308. .cmp = sort__dso_cmp,
  309. .print = sort__dso_print,
  310. };
  311. static int64_t
  312. sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
  313. {
  314. uint64_t ip_l, ip_r;
  315. if (left->sym == right->sym)
  316. return 0;
  317. ip_l = left->sym ? left->sym->start : left->ip;
  318. ip_r = right->sym ? right->sym->start : right->ip;
  319. return (int64_t)(ip_r - ip_l);
  320. }
  321. static size_t
  322. sort__sym_print(FILE *fp, struct hist_entry *self)
  323. {
  324. size_t ret = 0;
  325. if (verbose)
  326. ret += fprintf(fp, " %#018llx", (__u64)self->ip);
  327. if (self->dso)
  328. ret += fprintf(fp, " %s: ", self->dso->name);
  329. else
  330. ret += fprintf(fp, " %#016llx: ", (__u64)self->ip);
  331. if (self->sym)
  332. ret += fprintf(fp, "%s", self->sym->name);
  333. else
  334. ret += fprintf(fp, "%#016llx", (__u64)self->ip);
  335. return ret;
  336. }
  337. static struct sort_entry sort_sym = {
  338. .header = " Shared Object: Symbol",
  339. .cmp = sort__sym_cmp,
  340. .print = sort__sym_print,
  341. };
  342. struct sort_dimension {
  343. char *name;
  344. struct sort_entry *entry;
  345. int taken;
  346. };
  347. static struct sort_dimension sort_dimensions[] = {
  348. { .name = "pid", .entry = &sort_thread, },
  349. { .name = "comm", .entry = &sort_comm, },
  350. { .name = "dso", .entry = &sort_dso, },
  351. { .name = "symbol", .entry = &sort_sym, },
  352. };
  353. static LIST_HEAD(hist_entry__sort_list);
  354. static int sort_dimension__add(char *tok)
  355. {
  356. int i;
  357. for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
  358. struct sort_dimension *sd = &sort_dimensions[i];
  359. if (sd->taken)
  360. continue;
  361. if (strncasecmp(tok, sd->name, strlen(tok)))
  362. continue;
  363. list_add_tail(&sd->entry->list, &hist_entry__sort_list);
  364. sd->taken = 1;
  365. return 0;
  366. }
  367. return -ESRCH;
  368. }
  369. static int64_t
  370. hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
  371. {
  372. struct sort_entry *se;
  373. int64_t cmp = 0;
  374. list_for_each_entry(se, &hist_entry__sort_list, list) {
  375. cmp = se->cmp(left, right);
  376. if (cmp)
  377. break;
  378. }
  379. return cmp;
  380. }
  381. static size_t
  382. hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples)
  383. {
  384. struct sort_entry *se;
  385. size_t ret;
  386. if (total_samples) {
  387. ret = fprintf(fp, " %5.2f%%",
  388. (self->count * 100.0) / total_samples);
  389. } else
  390. ret = fprintf(fp, "%12d ", self->count);
  391. list_for_each_entry(se, &hist_entry__sort_list, list)
  392. ret += se->print(fp, self);
  393. ret += fprintf(fp, "\n");
  394. return ret;
  395. }
  396. /*
  397. * collect histogram counts
  398. */
  399. static int
  400. hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
  401. struct symbol *sym, uint64_t ip, char level)
  402. {
  403. struct rb_node **p = &hist.rb_node;
  404. struct rb_node *parent = NULL;
  405. struct hist_entry *he;
  406. struct hist_entry entry = {
  407. .thread = thread,
  408. .map = map,
  409. .dso = dso,
  410. .sym = sym,
  411. .ip = ip,
  412. .level = level,
  413. .count = 1,
  414. };
  415. int cmp;
  416. while (*p != NULL) {
  417. parent = *p;
  418. he = rb_entry(parent, struct hist_entry, rb_node);
  419. cmp = hist_entry__cmp(&entry, he);
  420. if (!cmp) {
  421. he->count++;
  422. return 0;
  423. }
  424. if (cmp < 0)
  425. p = &(*p)->rb_left;
  426. else
  427. p = &(*p)->rb_right;
  428. }
  429. he = malloc(sizeof(*he));
  430. if (!he)
  431. return -ENOMEM;
  432. *he = entry;
  433. rb_link_node(&he->rb_node, parent, p);
  434. rb_insert_color(&he->rb_node, &hist);
  435. return 0;
  436. }
  437. /*
  438. * reverse the map, sort on count.
  439. */
  440. static struct rb_root output_hists;
  441. static void output__insert_entry(struct hist_entry *he)
  442. {
  443. struct rb_node **p = &output_hists.rb_node;
  444. struct rb_node *parent = NULL;
  445. struct hist_entry *iter;
  446. while (*p != NULL) {
  447. parent = *p;
  448. iter = rb_entry(parent, struct hist_entry, rb_node);
  449. if (he->count > iter->count)
  450. p = &(*p)->rb_left;
  451. else
  452. p = &(*p)->rb_right;
  453. }
  454. rb_link_node(&he->rb_node, parent, p);
  455. rb_insert_color(&he->rb_node, &output_hists);
  456. }
  457. static void output__resort(void)
  458. {
  459. struct rb_node *next = rb_first(&hist);
  460. struct hist_entry *n;
  461. while (next) {
  462. n = rb_entry(next, struct hist_entry, rb_node);
  463. next = rb_next(&n->rb_node);
  464. rb_erase(&n->rb_node, &hist);
  465. output__insert_entry(n);
  466. }
  467. }
  468. static size_t output__fprintf(FILE *fp, uint64_t total_samples)
  469. {
  470. struct hist_entry *pos;
  471. struct sort_entry *se;
  472. struct rb_node *nd;
  473. size_t ret = 0;
  474. fprintf(fp, "#\n");
  475. fprintf(fp, "# Overhead");
  476. list_for_each_entry(se, &hist_entry__sort_list, list)
  477. fprintf(fp, " %s", se->header);
  478. fprintf(fp, "\n");
  479. fprintf(fp, "# ........");
  480. list_for_each_entry(se, &hist_entry__sort_list, list) {
  481. int i;
  482. fprintf(fp, " ");
  483. for (i = 0; i < strlen(se->header)-1; i++)
  484. fprintf(fp, ".");
  485. }
  486. fprintf(fp, "\n");
  487. fprintf(fp, "#\n");
  488. for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) {
  489. pos = rb_entry(nd, struct hist_entry, rb_node);
  490. ret += hist_entry__fprintf(fp, pos, total_samples);
  491. }
  492. return ret;
  493. }
  494. static void register_idle_thread(void)
  495. {
  496. struct thread *thread = threads__findnew(0);
  497. if (thread == NULL ||
  498. thread__set_comm(thread, "[idle]")) {
  499. fprintf(stderr, "problem inserting idle task.\n");
  500. exit(-1);
  501. }
  502. }
  503. static int __cmd_report(void)
  504. {
  505. unsigned long offset = 0;
  506. unsigned long head = 0;
  507. struct stat stat;
  508. char *buf;
  509. event_t *event;
  510. int ret, rc = EXIT_FAILURE;
  511. uint32_t size;
  512. unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
  513. char cwd[PATH_MAX], *cwdp = cwd;
  514. int cwdlen;
  515. register_idle_thread();
  516. input = open(input_name, O_RDONLY);
  517. if (input < 0) {
  518. perror("failed to open file");
  519. exit(-1);
  520. }
  521. ret = fstat(input, &stat);
  522. if (ret < 0) {
  523. perror("failed to stat file");
  524. exit(-1);
  525. }
  526. if (!stat.st_size) {
  527. fprintf(stderr, "zero-sized file, nothing to do!\n");
  528. exit(0);
  529. }
  530. if (load_kernel() < 0) {
  531. perror("failed to load kernel symbols");
  532. return EXIT_FAILURE;
  533. }
  534. if (!full_paths) {
  535. if (getcwd(cwd, sizeof(cwd)) == NULL) {
  536. perror("failed to get the current directory");
  537. return EXIT_FAILURE;
  538. }
  539. cwdlen = strlen(cwd);
  540. } else {
  541. cwdp = NULL;
  542. cwdlen = 0;
  543. }
  544. remap:
  545. buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
  546. MAP_SHARED, input, offset);
  547. if (buf == MAP_FAILED) {
  548. perror("failed to mmap file");
  549. exit(-1);
  550. }
  551. more:
  552. event = (event_t *)(buf + head);
  553. size = event->header.size;
  554. if (!size)
  555. size = 8;
  556. if (head + event->header.size >= page_size * mmap_window) {
  557. unsigned long shift = page_size * (head / page_size);
  558. int ret;
  559. ret = munmap(buf, page_size * mmap_window);
  560. assert(ret == 0);
  561. offset += shift;
  562. head -= shift;
  563. goto remap;
  564. }
  565. size = event->header.size;
  566. if (!size)
  567. goto broken_event;
  568. if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) {
  569. char level;
  570. int show = 0;
  571. struct dso *dso = NULL;
  572. struct thread *thread = threads__findnew(event->ip.pid);
  573. uint64_t ip = event->ip.ip;
  574. struct map *map = NULL;
  575. dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
  576. (void *)(offset + head),
  577. (void *)(long)(event->header.size),
  578. event->header.misc,
  579. event->ip.pid,
  580. (void *)(long)ip);
  581. if (thread == NULL) {
  582. fprintf(stderr, "problem processing %d event, skipping it.\n",
  583. event->header.type);
  584. goto broken_event;
  585. }
  586. if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
  587. show = SHOW_KERNEL;
  588. level = 'k';
  589. dso = kernel_dso;
  590. } else if (event->header.misc & PERF_EVENT_MISC_USER) {
  591. show = SHOW_USER;
  592. level = '.';
  593. map = thread__find_map(thread, ip);
  594. if (map != NULL) {
  595. dso = map->dso;
  596. ip -= map->start + map->pgoff;
  597. }
  598. } else {
  599. show = SHOW_HV;
  600. level = 'H';
  601. }
  602. if (show & show_mask) {
  603. struct symbol *sym = dso__find_symbol(dso, ip);
  604. if (hist_entry__add(thread, map, dso, sym, ip, level)) {
  605. fprintf(stderr,
  606. "problem incrementing symbol count, skipping event\n");
  607. goto broken_event;
  608. }
  609. }
  610. total++;
  611. } else switch (event->header.type) {
  612. case PERF_EVENT_MMAP: {
  613. struct thread *thread = threads__findnew(event->mmap.pid);
  614. struct map *map = map__new(&event->mmap, cwdp, cwdlen);
  615. dprintf("%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
  616. (void *)(offset + head),
  617. (void *)(long)(event->header.size),
  618. (void *)(long)event->mmap.start,
  619. (void *)(long)event->mmap.len,
  620. (void *)(long)event->mmap.pgoff,
  621. event->mmap.filename);
  622. if (thread == NULL || map == NULL) {
  623. if (verbose)
  624. fprintf(stderr, "problem processing PERF_EVENT_MMAP, skipping event.\n");
  625. goto broken_event;
  626. }
  627. thread__insert_map(thread, map);
  628. total_mmap++;
  629. break;
  630. }
  631. case PERF_EVENT_COMM: {
  632. struct thread *thread = threads__findnew(event->comm.pid);
  633. dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
  634. (void *)(offset + head),
  635. (void *)(long)(event->header.size),
  636. event->comm.comm, event->comm.pid);
  637. if (thread == NULL ||
  638. thread__set_comm(thread, event->comm.comm)) {
  639. fprintf(stderr, "problem processing PERF_EVENT_COMM, skipping event.\n");
  640. goto broken_event;
  641. }
  642. total_comm++;
  643. break;
  644. }
  645. default: {
  646. broken_event:
  647. dprintf("%p [%p]: skipping unknown header type: %d\n",
  648. (void *)(offset + head),
  649. (void *)(long)(event->header.size),
  650. event->header.type);
  651. total_unknown++;
  652. /*
  653. * assume we lost track of the stream, check alignment, and
  654. * increment a single u64 in the hope to catch on again 'soon'.
  655. */
  656. if (unlikely(head & 7))
  657. head &= ~7ULL;
  658. size = 8;
  659. }
  660. }
  661. head += size;
  662. if (offset + head < stat.st_size)
  663. goto more;
  664. rc = EXIT_SUCCESS;
  665. close(input);
  666. dprintf(" IP events: %10ld\n", total);
  667. dprintf(" mmap events: %10ld\n", total_mmap);
  668. dprintf(" comm events: %10ld\n", total_comm);
  669. dprintf(" unknown events: %10ld\n", total_unknown);
  670. if (dump_trace)
  671. return 0;
  672. if (verbose >= 2)
  673. dsos__fprintf(stdout);
  674. output__resort();
  675. output__fprintf(stdout, total);
  676. return rc;
  677. }
  678. static const char * const report_usage[] = {
  679. "perf report [<options>] <command>",
  680. NULL
  681. };
  682. static const struct option options[] = {
  683. OPT_STRING('i', "input", &input_name, "file",
  684. "input file name"),
  685. OPT_BOOLEAN('v', "verbose", &verbose,
  686. "be more verbose (show symbol address, etc)"),
  687. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  688. "dump raw trace in ASCII"),
  689. OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
  690. OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
  691. "sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"),
  692. OPT_BOOLEAN('P', "full-paths", &full_paths,
  693. "Don't shorten the pathnames taking into account the cwd"),
  694. OPT_END()
  695. };
  696. static void setup_sorting(void)
  697. {
  698. char *tmp, *tok, *str = strdup(sort_order);
  699. for (tok = strtok_r(str, ", ", &tmp);
  700. tok; tok = strtok_r(NULL, ", ", &tmp)) {
  701. if (sort_dimension__add(tok) < 0) {
  702. error("Unknown --sort key: `%s'", tok);
  703. usage_with_options(report_usage, options);
  704. }
  705. }
  706. free(str);
  707. }
  708. int cmd_report(int argc, const char **argv, const char *prefix)
  709. {
  710. symbol__init();
  711. page_size = getpagesize();
  712. parse_options(argc, argv, options, report_usage, 0);
  713. setup_sorting();
  714. setup_pager();
  715. return __cmd_report();
  716. }