builtin-report.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  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/color.h"
  11. #include "util/list.h"
  12. #include "util/cache.h"
  13. #include "util/rbtree.h"
  14. #include "util/symbol.h"
  15. #include "util/string.h"
  16. #include "perf.h"
  17. #include "util/header.h"
  18. #include "util/parse-options.h"
  19. #include "util/parse-events.h"
  20. #define SHOW_KERNEL 1
  21. #define SHOW_USER 2
  22. #define SHOW_HV 4
  23. static char const *input_name = "perf.data";
  24. static char *vmlinux = NULL;
  25. static char default_sort_order[] = "comm,dso";
  26. static char *sort_order = default_sort_order;
  27. static int input;
  28. static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
  29. static int dump_trace = 0;
  30. #define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
  31. #define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0)
  32. static int verbose;
  33. #define eprintf(x...) do { if (verbose) fprintf(stderr, x); } while (0)
  34. static int full_paths;
  35. static unsigned long page_size;
  36. static unsigned long mmap_window = 32;
  37. static char default_parent_pattern[] = "^sys_|^do_page_fault";
  38. static char *parent_pattern = default_parent_pattern;
  39. static regex_t parent_regex;
  40. static int exclude_other = 1;
  41. struct ip_event {
  42. struct perf_event_header header;
  43. u64 ip;
  44. u32 pid, tid;
  45. unsigned char __more_data[];
  46. };
  47. struct ip_callchain {
  48. u64 nr;
  49. u64 ips[0];
  50. };
  51. struct mmap_event {
  52. struct perf_event_header header;
  53. u32 pid, tid;
  54. u64 start;
  55. u64 len;
  56. u64 pgoff;
  57. char filename[PATH_MAX];
  58. };
  59. struct comm_event {
  60. struct perf_event_header header;
  61. u32 pid, tid;
  62. char comm[16];
  63. };
  64. struct fork_event {
  65. struct perf_event_header header;
  66. u32 pid, ppid;
  67. };
  68. struct period_event {
  69. struct perf_event_header header;
  70. u64 time;
  71. u64 id;
  72. u64 sample_period;
  73. };
  74. struct lost_event {
  75. struct perf_event_header header;
  76. u64 id;
  77. u64 lost;
  78. };
  79. typedef union event_union {
  80. struct perf_event_header header;
  81. struct ip_event ip;
  82. struct mmap_event mmap;
  83. struct comm_event comm;
  84. struct fork_event fork;
  85. struct period_event period;
  86. struct lost_event lost;
  87. } event_t;
  88. static LIST_HEAD(dsos);
  89. static struct dso *kernel_dso;
  90. static struct dso *vdso;
  91. static void dsos__add(struct dso *dso)
  92. {
  93. list_add_tail(&dso->node, &dsos);
  94. }
  95. static struct dso *dsos__find(const char *name)
  96. {
  97. struct dso *pos;
  98. list_for_each_entry(pos, &dsos, node)
  99. if (strcmp(pos->name, name) == 0)
  100. return pos;
  101. return NULL;
  102. }
  103. static struct dso *dsos__findnew(const char *name)
  104. {
  105. struct dso *dso = dsos__find(name);
  106. int nr;
  107. if (dso)
  108. return dso;
  109. dso = dso__new(name, 0);
  110. if (!dso)
  111. goto out_delete_dso;
  112. nr = dso__load(dso, NULL, verbose);
  113. if (nr < 0) {
  114. eprintf("Failed to open: %s\n", name);
  115. goto out_delete_dso;
  116. }
  117. if (!nr)
  118. eprintf("No symbols found in: %s, maybe install a debug package?\n", name);
  119. dsos__add(dso);
  120. return dso;
  121. out_delete_dso:
  122. dso__delete(dso);
  123. return NULL;
  124. }
  125. static void dsos__fprintf(FILE *fp)
  126. {
  127. struct dso *pos;
  128. list_for_each_entry(pos, &dsos, node)
  129. dso__fprintf(pos, fp);
  130. }
  131. static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
  132. {
  133. return dso__find_symbol(kernel_dso, ip);
  134. }
  135. static int load_kernel(void)
  136. {
  137. int err;
  138. kernel_dso = dso__new("[kernel]", 0);
  139. if (!kernel_dso)
  140. return -1;
  141. err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose);
  142. if (err) {
  143. dso__delete(kernel_dso);
  144. kernel_dso = NULL;
  145. } else
  146. dsos__add(kernel_dso);
  147. vdso = dso__new("[vdso]", 0);
  148. if (!vdso)
  149. return -1;
  150. vdso->find_symbol = vdso__find_symbol;
  151. dsos__add(vdso);
  152. return err;
  153. }
  154. static char __cwd[PATH_MAX];
  155. static char *cwd = __cwd;
  156. static int cwdlen;
  157. static int strcommon(const char *pathname)
  158. {
  159. int n = 0;
  160. while (pathname[n] == cwd[n] && n < cwdlen)
  161. ++n;
  162. return n;
  163. }
  164. struct map {
  165. struct list_head node;
  166. u64 start;
  167. u64 end;
  168. u64 pgoff;
  169. u64 (*map_ip)(struct map *, u64);
  170. struct dso *dso;
  171. };
  172. static u64 map__map_ip(struct map *map, u64 ip)
  173. {
  174. return ip - map->start + map->pgoff;
  175. }
  176. static u64 vdso__map_ip(struct map *map, u64 ip)
  177. {
  178. return ip;
  179. }
  180. static inline int is_anon_memory(const char *filename)
  181. {
  182. return strcmp(filename, "//anon") == 0;
  183. }
  184. static struct map *map__new(struct mmap_event *event)
  185. {
  186. struct map *self = malloc(sizeof(*self));
  187. if (self != NULL) {
  188. const char *filename = event->filename;
  189. char newfilename[PATH_MAX];
  190. int anon;
  191. if (cwd) {
  192. int n = strcommon(filename);
  193. if (n == cwdlen) {
  194. snprintf(newfilename, sizeof(newfilename),
  195. ".%s", filename + n);
  196. filename = newfilename;
  197. }
  198. }
  199. anon = is_anon_memory(filename);
  200. if (anon) {
  201. snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
  202. filename = newfilename;
  203. }
  204. self->start = event->start;
  205. self->end = event->start + event->len;
  206. self->pgoff = event->pgoff;
  207. self->dso = dsos__findnew(filename);
  208. if (self->dso == NULL)
  209. goto out_delete;
  210. if (self->dso == vdso || anon)
  211. self->map_ip = vdso__map_ip;
  212. else
  213. self->map_ip = map__map_ip;
  214. }
  215. return self;
  216. out_delete:
  217. free(self);
  218. return NULL;
  219. }
  220. static struct map *map__clone(struct map *self)
  221. {
  222. struct map *map = malloc(sizeof(*self));
  223. if (!map)
  224. return NULL;
  225. memcpy(map, self, sizeof(*self));
  226. return map;
  227. }
  228. static int map__overlap(struct map *l, struct map *r)
  229. {
  230. if (l->start > r->start) {
  231. struct map *t = l;
  232. l = r;
  233. r = t;
  234. }
  235. if (l->end > r->start)
  236. return 1;
  237. return 0;
  238. }
  239. static size_t map__fprintf(struct map *self, FILE *fp)
  240. {
  241. return fprintf(fp, " %Lx-%Lx %Lx %s\n",
  242. self->start, self->end, self->pgoff, self->dso->name);
  243. }
  244. struct thread {
  245. struct rb_node rb_node;
  246. struct list_head maps;
  247. pid_t pid;
  248. char *comm;
  249. };
  250. static struct thread *thread__new(pid_t pid)
  251. {
  252. struct thread *self = malloc(sizeof(*self));
  253. if (self != NULL) {
  254. self->pid = pid;
  255. self->comm = malloc(32);
  256. if (self->comm)
  257. snprintf(self->comm, 32, ":%d", self->pid);
  258. INIT_LIST_HEAD(&self->maps);
  259. }
  260. return self;
  261. }
  262. static int thread__set_comm(struct thread *self, const char *comm)
  263. {
  264. if (self->comm)
  265. free(self->comm);
  266. self->comm = strdup(comm);
  267. return self->comm ? 0 : -ENOMEM;
  268. }
  269. static size_t thread__fprintf(struct thread *self, FILE *fp)
  270. {
  271. struct map *pos;
  272. size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm);
  273. list_for_each_entry(pos, &self->maps, node)
  274. ret += map__fprintf(pos, fp);
  275. return ret;
  276. }
  277. static struct rb_root threads;
  278. static struct thread *last_match;
  279. static struct thread *threads__findnew(pid_t pid)
  280. {
  281. struct rb_node **p = &threads.rb_node;
  282. struct rb_node *parent = NULL;
  283. struct thread *th;
  284. /*
  285. * Font-end cache - PID lookups come in blocks,
  286. * so most of the time we dont have to look up
  287. * the full rbtree:
  288. */
  289. if (last_match && last_match->pid == pid)
  290. return last_match;
  291. while (*p != NULL) {
  292. parent = *p;
  293. th = rb_entry(parent, struct thread, rb_node);
  294. if (th->pid == pid) {
  295. last_match = th;
  296. return th;
  297. }
  298. if (pid < th->pid)
  299. p = &(*p)->rb_left;
  300. else
  301. p = &(*p)->rb_right;
  302. }
  303. th = thread__new(pid);
  304. if (th != NULL) {
  305. rb_link_node(&th->rb_node, parent, p);
  306. rb_insert_color(&th->rb_node, &threads);
  307. last_match = th;
  308. }
  309. return th;
  310. }
  311. static void thread__insert_map(struct thread *self, struct map *map)
  312. {
  313. struct map *pos, *tmp;
  314. list_for_each_entry_safe(pos, tmp, &self->maps, node) {
  315. if (map__overlap(pos, map)) {
  316. if (verbose >= 2) {
  317. printf("overlapping maps:\n");
  318. map__fprintf(map, stdout);
  319. map__fprintf(pos, stdout);
  320. }
  321. if (map->start <= pos->start && map->end > pos->start)
  322. pos->start = map->end;
  323. if (map->end >= pos->end && map->start < pos->end)
  324. pos->end = map->start;
  325. if (verbose >= 2) {
  326. printf("after collision:\n");
  327. map__fprintf(pos, stdout);
  328. }
  329. if (pos->start >= pos->end) {
  330. list_del_init(&pos->node);
  331. free(pos);
  332. }
  333. }
  334. }
  335. list_add_tail(&map->node, &self->maps);
  336. }
  337. static int thread__fork(struct thread *self, struct thread *parent)
  338. {
  339. struct map *map;
  340. if (self->comm)
  341. free(self->comm);
  342. self->comm = strdup(parent->comm);
  343. if (!self->comm)
  344. return -ENOMEM;
  345. list_for_each_entry(map, &parent->maps, node) {
  346. struct map *new = map__clone(map);
  347. if (!new)
  348. return -ENOMEM;
  349. thread__insert_map(self, new);
  350. }
  351. return 0;
  352. }
  353. static struct map *thread__find_map(struct thread *self, u64 ip)
  354. {
  355. struct map *pos;
  356. if (self == NULL)
  357. return NULL;
  358. list_for_each_entry(pos, &self->maps, node)
  359. if (ip >= pos->start && ip <= pos->end)
  360. return pos;
  361. return NULL;
  362. }
  363. static size_t threads__fprintf(FILE *fp)
  364. {
  365. size_t ret = 0;
  366. struct rb_node *nd;
  367. for (nd = rb_first(&threads); nd; nd = rb_next(nd)) {
  368. struct thread *pos = rb_entry(nd, struct thread, rb_node);
  369. ret += thread__fprintf(pos, fp);
  370. }
  371. return ret;
  372. }
  373. /*
  374. * histogram, sorted on item, collects counts
  375. */
  376. static struct rb_root hist;
  377. struct hist_entry {
  378. struct rb_node rb_node;
  379. struct thread *thread;
  380. struct map *map;
  381. struct dso *dso;
  382. struct symbol *sym;
  383. struct symbol *parent;
  384. u64 ip;
  385. char level;
  386. u64 count;
  387. };
  388. /*
  389. * configurable sorting bits
  390. */
  391. struct sort_entry {
  392. struct list_head list;
  393. char *header;
  394. int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
  395. int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
  396. size_t (*print)(FILE *fp, struct hist_entry *);
  397. };
  398. static int64_t cmp_null(void *l, void *r)
  399. {
  400. if (!l && !r)
  401. return 0;
  402. else if (!l)
  403. return -1;
  404. else
  405. return 1;
  406. }
  407. /* --sort pid */
  408. static int64_t
  409. sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
  410. {
  411. return right->thread->pid - left->thread->pid;
  412. }
  413. static size_t
  414. sort__thread_print(FILE *fp, struct hist_entry *self)
  415. {
  416. return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid);
  417. }
  418. static struct sort_entry sort_thread = {
  419. .header = " Command: Pid",
  420. .cmp = sort__thread_cmp,
  421. .print = sort__thread_print,
  422. };
  423. /* --sort comm */
  424. static int64_t
  425. sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
  426. {
  427. return right->thread->pid - left->thread->pid;
  428. }
  429. static int64_t
  430. sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
  431. {
  432. char *comm_l = left->thread->comm;
  433. char *comm_r = right->thread->comm;
  434. if (!comm_l || !comm_r)
  435. return cmp_null(comm_l, comm_r);
  436. return strcmp(comm_l, comm_r);
  437. }
  438. static size_t
  439. sort__comm_print(FILE *fp, struct hist_entry *self)
  440. {
  441. return fprintf(fp, "%16s", self->thread->comm);
  442. }
  443. static struct sort_entry sort_comm = {
  444. .header = " Command",
  445. .cmp = sort__comm_cmp,
  446. .collapse = sort__comm_collapse,
  447. .print = sort__comm_print,
  448. };
  449. /* --sort dso */
  450. static int64_t
  451. sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
  452. {
  453. struct dso *dso_l = left->dso;
  454. struct dso *dso_r = right->dso;
  455. if (!dso_l || !dso_r)
  456. return cmp_null(dso_l, dso_r);
  457. return strcmp(dso_l->name, dso_r->name);
  458. }
  459. static size_t
  460. sort__dso_print(FILE *fp, struct hist_entry *self)
  461. {
  462. if (self->dso)
  463. return fprintf(fp, "%-25s", self->dso->name);
  464. return fprintf(fp, "%016llx ", (u64)self->ip);
  465. }
  466. static struct sort_entry sort_dso = {
  467. .header = "Shared Object ",
  468. .cmp = sort__dso_cmp,
  469. .print = sort__dso_print,
  470. };
  471. /* --sort symbol */
  472. static int64_t
  473. sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
  474. {
  475. u64 ip_l, ip_r;
  476. if (left->sym == right->sym)
  477. return 0;
  478. ip_l = left->sym ? left->sym->start : left->ip;
  479. ip_r = right->sym ? right->sym->start : right->ip;
  480. return (int64_t)(ip_r - ip_l);
  481. }
  482. static size_t
  483. sort__sym_print(FILE *fp, struct hist_entry *self)
  484. {
  485. size_t ret = 0;
  486. if (verbose)
  487. ret += fprintf(fp, "%#018llx ", (u64)self->ip);
  488. if (self->sym) {
  489. ret += fprintf(fp, "[%c] %s",
  490. self->dso == kernel_dso ? 'k' : '.', self->sym->name);
  491. } else {
  492. ret += fprintf(fp, "%#016llx", (u64)self->ip);
  493. }
  494. return ret;
  495. }
  496. static struct sort_entry sort_sym = {
  497. .header = "Symbol",
  498. .cmp = sort__sym_cmp,
  499. .print = sort__sym_print,
  500. };
  501. /* --sort parent */
  502. static int64_t
  503. sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
  504. {
  505. struct symbol *sym_l = left->parent;
  506. struct symbol *sym_r = right->parent;
  507. if (!sym_l || !sym_r)
  508. return cmp_null(sym_l, sym_r);
  509. return strcmp(sym_l->name, sym_r->name);
  510. }
  511. static size_t
  512. sort__parent_print(FILE *fp, struct hist_entry *self)
  513. {
  514. size_t ret = 0;
  515. ret += fprintf(fp, "%-20s", self->parent ? self->parent->name : "[other]");
  516. return ret;
  517. }
  518. static struct sort_entry sort_parent = {
  519. .header = "Parent symbol ",
  520. .cmp = sort__parent_cmp,
  521. .print = sort__parent_print,
  522. };
  523. static int sort__need_collapse = 0;
  524. static int sort__has_parent = 0;
  525. struct sort_dimension {
  526. char *name;
  527. struct sort_entry *entry;
  528. int taken;
  529. };
  530. static struct sort_dimension sort_dimensions[] = {
  531. { .name = "pid", .entry = &sort_thread, },
  532. { .name = "comm", .entry = &sort_comm, },
  533. { .name = "dso", .entry = &sort_dso, },
  534. { .name = "symbol", .entry = &sort_sym, },
  535. { .name = "parent", .entry = &sort_parent, },
  536. };
  537. static LIST_HEAD(hist_entry__sort_list);
  538. static int sort_dimension__add(char *tok)
  539. {
  540. int i;
  541. for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
  542. struct sort_dimension *sd = &sort_dimensions[i];
  543. if (sd->taken)
  544. continue;
  545. if (strncasecmp(tok, sd->name, strlen(tok)))
  546. continue;
  547. if (sd->entry->collapse)
  548. sort__need_collapse = 1;
  549. if (sd->entry == &sort_parent) {
  550. int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
  551. if (ret) {
  552. char err[BUFSIZ];
  553. regerror(ret, &parent_regex, err, sizeof(err));
  554. fprintf(stderr, "Invalid regex: %s\n%s",
  555. parent_pattern, err);
  556. exit(-1);
  557. }
  558. sort__has_parent = 1;
  559. }
  560. list_add_tail(&sd->entry->list, &hist_entry__sort_list);
  561. sd->taken = 1;
  562. return 0;
  563. }
  564. return -ESRCH;
  565. }
  566. static int64_t
  567. hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
  568. {
  569. struct sort_entry *se;
  570. int64_t cmp = 0;
  571. list_for_each_entry(se, &hist_entry__sort_list, list) {
  572. cmp = se->cmp(left, right);
  573. if (cmp)
  574. break;
  575. }
  576. return cmp;
  577. }
  578. static int64_t
  579. hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
  580. {
  581. struct sort_entry *se;
  582. int64_t cmp = 0;
  583. list_for_each_entry(se, &hist_entry__sort_list, list) {
  584. int64_t (*f)(struct hist_entry *, struct hist_entry *);
  585. f = se->collapse ?: se->cmp;
  586. cmp = f(left, right);
  587. if (cmp)
  588. break;
  589. }
  590. return cmp;
  591. }
  592. static size_t
  593. hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
  594. {
  595. struct sort_entry *se;
  596. size_t ret;
  597. if (exclude_other && !self->parent)
  598. return 0;
  599. if (total_samples) {
  600. double percent = self->count * 100.0 / total_samples;
  601. char *color = PERF_COLOR_NORMAL;
  602. /*
  603. * We color high-overhead entries in red, mid-overhead
  604. * entries in green - and keep the low overhead places
  605. * normal:
  606. */
  607. if (percent >= 5.0) {
  608. color = PERF_COLOR_RED;
  609. } else {
  610. if (percent >= 0.5)
  611. color = PERF_COLOR_GREEN;
  612. }
  613. ret = color_fprintf(fp, color, " %6.2f%%",
  614. (self->count * 100.0) / total_samples);
  615. } else
  616. ret = fprintf(fp, "%12Ld ", self->count);
  617. list_for_each_entry(se, &hist_entry__sort_list, list) {
  618. if (exclude_other && (se == &sort_parent))
  619. continue;
  620. fprintf(fp, " ");
  621. ret += se->print(fp, self);
  622. }
  623. ret += fprintf(fp, "\n");
  624. return ret;
  625. }
  626. /*
  627. *
  628. */
  629. static struct symbol *
  630. resolve_symbol(struct thread *thread, struct map **mapp,
  631. struct dso **dsop, u64 *ipp)
  632. {
  633. struct dso *dso = dsop ? *dsop : NULL;
  634. struct map *map = mapp ? *mapp : NULL;
  635. u64 ip = *ipp;
  636. if (!thread)
  637. return NULL;
  638. if (dso)
  639. goto got_dso;
  640. if (map)
  641. goto got_map;
  642. map = thread__find_map(thread, ip);
  643. if (map != NULL) {
  644. if (mapp)
  645. *mapp = map;
  646. got_map:
  647. ip = map->map_ip(map, ip);
  648. dso = map->dso;
  649. } else {
  650. /*
  651. * If this is outside of all known maps,
  652. * and is a negative address, try to look it
  653. * up in the kernel dso, as it might be a
  654. * vsyscall (which executes in user-mode):
  655. */
  656. if ((long long)ip < 0)
  657. dso = kernel_dso;
  658. }
  659. dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
  660. dprintf(" ...... map: %Lx -> %Lx\n", *ipp, ip);
  661. *ipp = ip;
  662. if (dsop)
  663. *dsop = dso;
  664. if (!dso)
  665. return NULL;
  666. got_dso:
  667. return dso->find_symbol(dso, ip);
  668. }
  669. static int call__match(struct symbol *sym)
  670. {
  671. if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))
  672. return 1;
  673. return 0;
  674. }
  675. /*
  676. * collect histogram counts
  677. */
  678. static int
  679. hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
  680. struct symbol *sym, u64 ip, struct ip_callchain *chain,
  681. char level, u64 count)
  682. {
  683. struct rb_node **p = &hist.rb_node;
  684. struct rb_node *parent = NULL;
  685. struct hist_entry *he;
  686. struct hist_entry entry = {
  687. .thread = thread,
  688. .map = map,
  689. .dso = dso,
  690. .sym = sym,
  691. .ip = ip,
  692. .level = level,
  693. .count = count,
  694. .parent = NULL,
  695. };
  696. int cmp;
  697. if (sort__has_parent && chain) {
  698. u64 context = PERF_CONTEXT_MAX;
  699. int i;
  700. for (i = 0; i < chain->nr; i++) {
  701. u64 ip = chain->ips[i];
  702. struct dso *dso = NULL;
  703. struct symbol *sym;
  704. if (ip >= PERF_CONTEXT_MAX) {
  705. context = ip;
  706. continue;
  707. }
  708. switch (context) {
  709. case PERF_CONTEXT_KERNEL:
  710. dso = kernel_dso;
  711. break;
  712. default:
  713. break;
  714. }
  715. sym = resolve_symbol(thread, NULL, &dso, &ip);
  716. if (sym && call__match(sym)) {
  717. entry.parent = sym;
  718. break;
  719. }
  720. }
  721. }
  722. while (*p != NULL) {
  723. parent = *p;
  724. he = rb_entry(parent, struct hist_entry, rb_node);
  725. cmp = hist_entry__cmp(&entry, he);
  726. if (!cmp) {
  727. he->count += count;
  728. return 0;
  729. }
  730. if (cmp < 0)
  731. p = &(*p)->rb_left;
  732. else
  733. p = &(*p)->rb_right;
  734. }
  735. he = malloc(sizeof(*he));
  736. if (!he)
  737. return -ENOMEM;
  738. *he = entry;
  739. rb_link_node(&he->rb_node, parent, p);
  740. rb_insert_color(&he->rb_node, &hist);
  741. return 0;
  742. }
  743. static void hist_entry__free(struct hist_entry *he)
  744. {
  745. free(he);
  746. }
  747. /*
  748. * collapse the histogram
  749. */
  750. static struct rb_root collapse_hists;
  751. static void collapse__insert_entry(struct hist_entry *he)
  752. {
  753. struct rb_node **p = &collapse_hists.rb_node;
  754. struct rb_node *parent = NULL;
  755. struct hist_entry *iter;
  756. int64_t cmp;
  757. while (*p != NULL) {
  758. parent = *p;
  759. iter = rb_entry(parent, struct hist_entry, rb_node);
  760. cmp = hist_entry__collapse(iter, he);
  761. if (!cmp) {
  762. iter->count += he->count;
  763. hist_entry__free(he);
  764. return;
  765. }
  766. if (cmp < 0)
  767. p = &(*p)->rb_left;
  768. else
  769. p = &(*p)->rb_right;
  770. }
  771. rb_link_node(&he->rb_node, parent, p);
  772. rb_insert_color(&he->rb_node, &collapse_hists);
  773. }
  774. static void collapse__resort(void)
  775. {
  776. struct rb_node *next;
  777. struct hist_entry *n;
  778. if (!sort__need_collapse)
  779. return;
  780. next = rb_first(&hist);
  781. while (next) {
  782. n = rb_entry(next, struct hist_entry, rb_node);
  783. next = rb_next(&n->rb_node);
  784. rb_erase(&n->rb_node, &hist);
  785. collapse__insert_entry(n);
  786. }
  787. }
  788. /*
  789. * reverse the map, sort on count.
  790. */
  791. static struct rb_root output_hists;
  792. static void output__insert_entry(struct hist_entry *he)
  793. {
  794. struct rb_node **p = &output_hists.rb_node;
  795. struct rb_node *parent = NULL;
  796. struct hist_entry *iter;
  797. while (*p != NULL) {
  798. parent = *p;
  799. iter = rb_entry(parent, struct hist_entry, rb_node);
  800. if (he->count > iter->count)
  801. p = &(*p)->rb_left;
  802. else
  803. p = &(*p)->rb_right;
  804. }
  805. rb_link_node(&he->rb_node, parent, p);
  806. rb_insert_color(&he->rb_node, &output_hists);
  807. }
  808. static void output__resort(void)
  809. {
  810. struct rb_node *next;
  811. struct hist_entry *n;
  812. struct rb_root *tree = &hist;
  813. if (sort__need_collapse)
  814. tree = &collapse_hists;
  815. next = rb_first(tree);
  816. while (next) {
  817. n = rb_entry(next, struct hist_entry, rb_node);
  818. next = rb_next(&n->rb_node);
  819. rb_erase(&n->rb_node, tree);
  820. output__insert_entry(n);
  821. }
  822. }
  823. static size_t output__fprintf(FILE *fp, u64 total_samples)
  824. {
  825. struct hist_entry *pos;
  826. struct sort_entry *se;
  827. struct rb_node *nd;
  828. size_t ret = 0;
  829. fprintf(fp, "\n");
  830. fprintf(fp, "#\n");
  831. fprintf(fp, "# (%Ld samples)\n", (u64)total_samples);
  832. fprintf(fp, "#\n");
  833. fprintf(fp, "# Overhead");
  834. list_for_each_entry(se, &hist_entry__sort_list, list) {
  835. if (exclude_other && (se == &sort_parent))
  836. continue;
  837. fprintf(fp, " %s", se->header);
  838. }
  839. fprintf(fp, "\n");
  840. fprintf(fp, "# ........");
  841. list_for_each_entry(se, &hist_entry__sort_list, list) {
  842. int i;
  843. if (exclude_other && (se == &sort_parent))
  844. continue;
  845. fprintf(fp, " ");
  846. for (i = 0; i < strlen(se->header); i++)
  847. fprintf(fp, ".");
  848. }
  849. fprintf(fp, "\n");
  850. fprintf(fp, "#\n");
  851. for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) {
  852. pos = rb_entry(nd, struct hist_entry, rb_node);
  853. ret += hist_entry__fprintf(fp, pos, total_samples);
  854. }
  855. if (sort_order == default_sort_order &&
  856. parent_pattern == default_parent_pattern) {
  857. fprintf(fp, "#\n");
  858. fprintf(fp, "# (For more details, try: perf report --sort comm,dso,symbol)\n");
  859. fprintf(fp, "#\n");
  860. }
  861. fprintf(fp, "\n");
  862. return ret;
  863. }
  864. static void register_idle_thread(void)
  865. {
  866. struct thread *thread = threads__findnew(0);
  867. if (thread == NULL ||
  868. thread__set_comm(thread, "[idle]")) {
  869. fprintf(stderr, "problem inserting idle task.\n");
  870. exit(-1);
  871. }
  872. }
  873. static unsigned long total = 0,
  874. total_mmap = 0,
  875. total_comm = 0,
  876. total_fork = 0,
  877. total_unknown = 0,
  878. total_lost = 0;
  879. static int validate_chain(struct ip_callchain *chain, event_t *event)
  880. {
  881. unsigned int chain_size;
  882. chain_size = event->header.size;
  883. chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
  884. if (chain->nr*sizeof(u64) > chain_size)
  885. return -1;
  886. return 0;
  887. }
  888. static int
  889. process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
  890. {
  891. char level;
  892. int show = 0;
  893. struct dso *dso = NULL;
  894. struct thread *thread = threads__findnew(event->ip.pid);
  895. u64 ip = event->ip.ip;
  896. u64 period = 1;
  897. struct map *map = NULL;
  898. void *more_data = event->ip.__more_data;
  899. struct ip_callchain *chain = NULL;
  900. if (event->header.type & PERF_SAMPLE_PERIOD) {
  901. period = *(u64 *)more_data;
  902. more_data += sizeof(u64);
  903. }
  904. dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p period: %Ld\n",
  905. (void *)(offset + head),
  906. (void *)(long)(event->header.size),
  907. event->header.misc,
  908. event->ip.pid,
  909. (void *)(long)ip,
  910. (long long)period);
  911. if (event->header.type & PERF_SAMPLE_CALLCHAIN) {
  912. int i;
  913. chain = (void *)more_data;
  914. dprintf("... chain: nr:%Lu\n", chain->nr);
  915. if (validate_chain(chain, event) < 0) {
  916. eprintf("call-chain problem with event, skipping it.\n");
  917. return 0;
  918. }
  919. if (dump_trace) {
  920. for (i = 0; i < chain->nr; i++)
  921. dprintf("..... %2d: %016Lx\n", i, chain->ips[i]);
  922. }
  923. }
  924. dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
  925. if (thread == NULL) {
  926. eprintf("problem processing %d event, skipping it.\n",
  927. event->header.type);
  928. return -1;
  929. }
  930. if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
  931. show = SHOW_KERNEL;
  932. level = 'k';
  933. dso = kernel_dso;
  934. dprintf(" ...... dso: %s\n", dso->name);
  935. } else if (event->header.misc & PERF_EVENT_MISC_USER) {
  936. show = SHOW_USER;
  937. level = '.';
  938. } else {
  939. show = SHOW_HV;
  940. level = 'H';
  941. dprintf(" ...... dso: [hypervisor]\n");
  942. }
  943. if (show & show_mask) {
  944. struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip);
  945. if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) {
  946. eprintf("problem incrementing symbol count, skipping event\n");
  947. return -1;
  948. }
  949. }
  950. total += period;
  951. return 0;
  952. }
  953. static int
  954. process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
  955. {
  956. struct thread *thread = threads__findnew(event->mmap.pid);
  957. struct map *map = map__new(&event->mmap);
  958. dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
  959. (void *)(offset + head),
  960. (void *)(long)(event->header.size),
  961. event->mmap.pid,
  962. (void *)(long)event->mmap.start,
  963. (void *)(long)event->mmap.len,
  964. (void *)(long)event->mmap.pgoff,
  965. event->mmap.filename);
  966. if (thread == NULL || map == NULL) {
  967. dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n");
  968. return 0;
  969. }
  970. thread__insert_map(thread, map);
  971. total_mmap++;
  972. return 0;
  973. }
  974. static int
  975. process_comm_event(event_t *event, unsigned long offset, unsigned long head)
  976. {
  977. struct thread *thread = threads__findnew(event->comm.pid);
  978. dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
  979. (void *)(offset + head),
  980. (void *)(long)(event->header.size),
  981. event->comm.comm, event->comm.pid);
  982. if (thread == NULL ||
  983. thread__set_comm(thread, event->comm.comm)) {
  984. dprintf("problem processing PERF_EVENT_COMM, skipping event.\n");
  985. return -1;
  986. }
  987. total_comm++;
  988. return 0;
  989. }
  990. static int
  991. process_fork_event(event_t *event, unsigned long offset, unsigned long head)
  992. {
  993. struct thread *thread = threads__findnew(event->fork.pid);
  994. struct thread *parent = threads__findnew(event->fork.ppid);
  995. dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
  996. (void *)(offset + head),
  997. (void *)(long)(event->header.size),
  998. event->fork.pid, event->fork.ppid);
  999. if (!thread || !parent || thread__fork(thread, parent)) {
  1000. dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
  1001. return -1;
  1002. }
  1003. total_fork++;
  1004. return 0;
  1005. }
  1006. static int
  1007. process_period_event(event_t *event, unsigned long offset, unsigned long head)
  1008. {
  1009. dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
  1010. (void *)(offset + head),
  1011. (void *)(long)(event->header.size),
  1012. event->period.time,
  1013. event->period.id,
  1014. event->period.sample_period);
  1015. return 0;
  1016. }
  1017. static int
  1018. process_lost_event(event_t *event, unsigned long offset, unsigned long head)
  1019. {
  1020. dprintf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n",
  1021. (void *)(offset + head),
  1022. (void *)(long)(event->header.size),
  1023. event->lost.id,
  1024. event->lost.lost);
  1025. total_lost += event->lost.lost;
  1026. return 0;
  1027. }
  1028. static void trace_event(event_t *event)
  1029. {
  1030. unsigned char *raw_event = (void *)event;
  1031. char *color = PERF_COLOR_BLUE;
  1032. int i, j;
  1033. if (!dump_trace)
  1034. return;
  1035. dprintf(".");
  1036. cdprintf("\n. ... raw event: size %d bytes\n", event->header.size);
  1037. for (i = 0; i < event->header.size; i++) {
  1038. if ((i & 15) == 0) {
  1039. dprintf(".");
  1040. cdprintf(" %04x: ", i);
  1041. }
  1042. cdprintf(" %02x", raw_event[i]);
  1043. if (((i & 15) == 15) || i == event->header.size-1) {
  1044. cdprintf(" ");
  1045. for (j = 0; j < 15-(i & 15); j++)
  1046. cdprintf(" ");
  1047. for (j = 0; j < (i & 15); j++) {
  1048. if (isprint(raw_event[i-15+j]))
  1049. cdprintf("%c", raw_event[i-15+j]);
  1050. else
  1051. cdprintf(".");
  1052. }
  1053. cdprintf("\n");
  1054. }
  1055. }
  1056. dprintf(".\n");
  1057. }
  1058. static int
  1059. process_event(event_t *event, unsigned long offset, unsigned long head)
  1060. {
  1061. trace_event(event);
  1062. if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
  1063. return process_overflow_event(event, offset, head);
  1064. switch (event->header.type) {
  1065. case PERF_EVENT_MMAP:
  1066. return process_mmap_event(event, offset, head);
  1067. case PERF_EVENT_COMM:
  1068. return process_comm_event(event, offset, head);
  1069. case PERF_EVENT_FORK:
  1070. return process_fork_event(event, offset, head);
  1071. case PERF_EVENT_PERIOD:
  1072. return process_period_event(event, offset, head);
  1073. case PERF_EVENT_LOST:
  1074. return process_lost_event(event, offset, head);
  1075. /*
  1076. * We dont process them right now but they are fine:
  1077. */
  1078. case PERF_EVENT_THROTTLE:
  1079. case PERF_EVENT_UNTHROTTLE:
  1080. return 0;
  1081. default:
  1082. return -1;
  1083. }
  1084. return 0;
  1085. }
  1086. static struct perf_header *header;
  1087. static int perf_header__has_sample(u64 sample_mask)
  1088. {
  1089. int i;
  1090. for (i = 0; i < header->attrs; i++) {
  1091. struct perf_header_attr *attr = header->attr[i];
  1092. if (!(attr->attr.sample_type & sample_mask))
  1093. return 0;
  1094. }
  1095. return 1;
  1096. }
  1097. static int __cmd_report(void)
  1098. {
  1099. int ret, rc = EXIT_FAILURE;
  1100. unsigned long offset = 0;
  1101. unsigned long head, shift;
  1102. struct stat stat;
  1103. event_t *event;
  1104. uint32_t size;
  1105. char *buf;
  1106. register_idle_thread();
  1107. input = open(input_name, O_RDONLY);
  1108. if (input < 0) {
  1109. fprintf(stderr, " failed to open file: %s", input_name);
  1110. if (!strcmp(input_name, "perf.data"))
  1111. fprintf(stderr, " (try 'perf record' first)");
  1112. fprintf(stderr, "\n");
  1113. exit(-1);
  1114. }
  1115. ret = fstat(input, &stat);
  1116. if (ret < 0) {
  1117. perror("failed to stat file");
  1118. exit(-1);
  1119. }
  1120. if (!stat.st_size) {
  1121. fprintf(stderr, "zero-sized file, nothing to do!\n");
  1122. exit(0);
  1123. }
  1124. header = perf_header__read(input);
  1125. head = header->data_offset;
  1126. if (sort__has_parent &&
  1127. !perf_header__has_sample(PERF_SAMPLE_CALLCHAIN)) {
  1128. fprintf(stderr, "selected --sort parent, but no callchain data\n");
  1129. exit(-1);
  1130. }
  1131. if (load_kernel() < 0) {
  1132. perror("failed to load kernel symbols");
  1133. return EXIT_FAILURE;
  1134. }
  1135. if (!full_paths) {
  1136. if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
  1137. perror("failed to get the current directory");
  1138. return EXIT_FAILURE;
  1139. }
  1140. cwdlen = strlen(cwd);
  1141. } else {
  1142. cwd = NULL;
  1143. cwdlen = 0;
  1144. }
  1145. shift = page_size * (head / page_size);
  1146. offset += shift;
  1147. head -= shift;
  1148. remap:
  1149. buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
  1150. MAP_SHARED, input, offset);
  1151. if (buf == MAP_FAILED) {
  1152. perror("failed to mmap file");
  1153. exit(-1);
  1154. }
  1155. more:
  1156. event = (event_t *)(buf + head);
  1157. size = event->header.size;
  1158. if (!size)
  1159. size = 8;
  1160. if (head + event->header.size >= page_size * mmap_window) {
  1161. int ret;
  1162. shift = page_size * (head / page_size);
  1163. ret = munmap(buf, page_size * mmap_window);
  1164. assert(ret == 0);
  1165. offset += shift;
  1166. head -= shift;
  1167. goto remap;
  1168. }
  1169. size = event->header.size;
  1170. dprintf("\n%p [%p]: event: %d\n",
  1171. (void *)(offset + head),
  1172. (void *)(long)event->header.size,
  1173. event->header.type);
  1174. if (!size || process_event(event, offset, head) < 0) {
  1175. dprintf("%p [%p]: skipping unknown header type: %d\n",
  1176. (void *)(offset + head),
  1177. (void *)(long)(event->header.size),
  1178. event->header.type);
  1179. total_unknown++;
  1180. /*
  1181. * assume we lost track of the stream, check alignment, and
  1182. * increment a single u64 in the hope to catch on again 'soon'.
  1183. */
  1184. if (unlikely(head & 7))
  1185. head &= ~7ULL;
  1186. size = 8;
  1187. }
  1188. head += size;
  1189. if (offset + head >= header->data_offset + header->data_size)
  1190. goto done;
  1191. if (offset + head < stat.st_size)
  1192. goto more;
  1193. done:
  1194. rc = EXIT_SUCCESS;
  1195. close(input);
  1196. dprintf(" IP events: %10ld\n", total);
  1197. dprintf(" mmap events: %10ld\n", total_mmap);
  1198. dprintf(" comm events: %10ld\n", total_comm);
  1199. dprintf(" fork events: %10ld\n", total_fork);
  1200. dprintf(" lost events: %10ld\n", total_lost);
  1201. dprintf(" unknown events: %10ld\n", total_unknown);
  1202. if (dump_trace)
  1203. return 0;
  1204. if (verbose >= 3)
  1205. threads__fprintf(stdout);
  1206. if (verbose >= 2)
  1207. dsos__fprintf(stdout);
  1208. collapse__resort();
  1209. output__resort();
  1210. output__fprintf(stdout, total);
  1211. return rc;
  1212. }
  1213. static const char * const report_usage[] = {
  1214. "perf report [<options>] <command>",
  1215. NULL
  1216. };
  1217. static const struct option options[] = {
  1218. OPT_STRING('i', "input", &input_name, "file",
  1219. "input file name"),
  1220. OPT_BOOLEAN('v', "verbose", &verbose,
  1221. "be more verbose (show symbol address, etc)"),
  1222. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  1223. "dump raw trace in ASCII"),
  1224. OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
  1225. OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
  1226. "sort by key(s): pid, comm, dso, symbol, parent"),
  1227. OPT_BOOLEAN('P', "full-paths", &full_paths,
  1228. "Don't shorten the pathnames taking into account the cwd"),
  1229. OPT_STRING('p', "parent", &parent_pattern, "regex",
  1230. "regex filter to identify parent, see: '--sort parent'"),
  1231. OPT_BOOLEAN('x', "exclude-other", &exclude_other,
  1232. "Only display entries with parent-match"),
  1233. OPT_END()
  1234. };
  1235. static void setup_sorting(void)
  1236. {
  1237. char *tmp, *tok, *str = strdup(sort_order);
  1238. for (tok = strtok_r(str, ", ", &tmp);
  1239. tok; tok = strtok_r(NULL, ", ", &tmp)) {
  1240. if (sort_dimension__add(tok) < 0) {
  1241. error("Unknown --sort key: `%s'", tok);
  1242. usage_with_options(report_usage, options);
  1243. }
  1244. }
  1245. free(str);
  1246. }
  1247. int cmd_report(int argc, const char **argv, const char *prefix)
  1248. {
  1249. symbol__init();
  1250. page_size = getpagesize();
  1251. argc = parse_options(argc, argv, options, report_usage, 0);
  1252. setup_sorting();
  1253. if (parent_pattern != default_parent_pattern)
  1254. sort_dimension__add("parent");
  1255. else
  1256. exclude_other = 0;
  1257. /*
  1258. * Any (unrecognized) arguments left?
  1259. */
  1260. if (argc)
  1261. usage_with_options(report_usage, options);
  1262. setup_pager();
  1263. return __cmd_report();
  1264. }