builtin-report.c 17 KB

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