builtin-report.c 17 KB

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