blob: 5141cdccbb658e00917a42a7ffc84376b1ea476a [file] [log] [blame]
Ingo Molnarbf9e1872009-06-02 23:37:05 +02001/*
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 */
Ingo Molnar16f762a2009-05-27 09:10:38 +02008#include "builtin.h"
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02009
Ingo Molnarbf9e1872009-06-02 23:37:05 +020010#include "util/util.h"
11
Ingo Molnar8fc03212009-06-04 15:19:47 +020012#include "util/color.h"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -030013#include <linux/list.h>
Ingo Molnara930d2c2009-05-27 09:50:13 +020014#include "util/cache.h"
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -030015#include <linux/rbtree.h>
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030016#include "util/symbol.h"
Arnaldo Carvalho de Meloa0055ae2009-06-01 17:50:19 -030017#include "util/string.h"
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +020018#include "util/callchain.h"
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -030019#include "util/strlist.h"
Brice Goglin8d513272009-08-07 13:55:24 +020020#include "util/values.h"
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030021
Ingo Molnar53cb8bc2009-05-26 09:17:18 +020022#include "perf.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +020023#include "util/debug.h"
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020024#include "util/header.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020025#include "util/session.h"
Ingo Molnar53cb8bc2009-05-26 09:17:18 +020026
27#include "util/parse-options.h"
28#include "util/parse-events.h"
29
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020030#include "util/thread.h"
John Kacurdd68ada2009-09-24 18:02:49 +020031#include "util/sort.h"
John Kacur3d1d07e2009-09-28 15:32:55 +020032#include "util/hist.h"
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020033
Ingo Molnar23ac9cb2009-05-27 09:33:18 +020034static char const *input_name = "perf.data";
Ingo Molnarbd741372009-06-04 14:13:04 +020035
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -030036static char *dso_list_str, *comm_list_str, *sym_list_str,
37 *col_width_list_str;
Arnaldo Carvalho de Melo7bec7a92009-06-30 19:01:22 -030038static struct strlist *dso_list, *comm_list, *sym_list;
Ingo Molnarbd741372009-06-04 14:13:04 +020039
Peter Zijlstrafa6963b2009-08-19 11:18:26 +020040static int force;
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -020041static bool use_callchain;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030042
Arnaldo Carvalho de Meloe3d7e182009-07-11 12:18:37 -030043static int show_nr_samples;
Ingo Molnar97b07b62009-05-26 18:48:58 +020044
Brice Goglin8d513272009-08-07 13:55:24 +020045static int show_threads;
46static struct perf_read_values show_threads_values;
47
Brice Goglin9f866692009-08-10 15:26:32 +020048static char default_pretty_printing_style[] = "normal";
49static char *pretty_printing_style = default_pretty_printing_style;
50
Ingo Molnarb8e6d822009-06-18 14:32:19 +020051static int exclude_other = 1;
Frederic Weisbeckerbe903882009-07-05 07:39:18 +020052
Frederic Weisbecker805d1272009-07-05 07:39:21 +020053static char callchain_default_opt[] = "fractal,0.5";
54
Peter Zijlstrae6e18ec2009-06-25 11:27:12 +020055static u64 sample_type;
56
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020057struct symbol_conf symbol_conf;
58
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020059
60static size_t
61callchain__fprintf_left_margin(FILE *fp, int left_margin)
62{
63 int i;
64 int ret;
65
66 ret = fprintf(fp, " ");
67
68 for (i = 0; i < left_margin; i++)
69 ret += fprintf(fp, " ");
70
71 return ret;
72}
73
74static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
75 int left_margin)
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020076{
77 int i;
78 size_t ret = 0;
79
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020080 ret += callchain__fprintf_left_margin(fp, left_margin);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020081
82 for (i = 0; i < depth; i++)
83 if (depth_mask & (1 << i))
84 ret += fprintf(fp, "| ");
85 else
86 ret += fprintf(fp, " ");
87
88 ret += fprintf(fp, "\n");
89
90 return ret;
91}
Peter Zijlstra1aa16732009-05-27 20:20:25 +020092static size_t
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020093ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth,
94 int depth_mask, int count, u64 total_samples,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020095 int hits, int left_margin)
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020096{
97 int i;
98 size_t ret = 0;
99
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200100 ret += callchain__fprintf_left_margin(fp, left_margin);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200101 for (i = 0; i < depth; i++) {
102 if (depth_mask & (1 << i))
103 ret += fprintf(fp, "|");
104 else
105 ret += fprintf(fp, " ");
106 if (!count && i == depth - 1) {
107 double percent;
108
109 percent = hits * 100.0 / total_samples;
Frederic Weisbecker24b57c62009-07-02 20:14:35 +0200110 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200111 } else
112 ret += fprintf(fp, "%s", " ");
113 }
114 if (chain->sym)
115 ret += fprintf(fp, "%s\n", chain->sym->name);
116 else
117 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
118
119 return ret;
120}
121
Frederic Weisbecker25446032009-08-08 02:16:25 +0200122static struct symbol *rem_sq_bracket;
123static struct callchain_list rem_hits;
124
125static void init_rem_hits(void)
126{
127 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
128 if (!rem_sq_bracket) {
129 fprintf(stderr, "Not enough memory to display remaining hits\n");
130 return;
131 }
132
133 strcpy(rem_sq_bracket->name, "[...]");
134 rem_hits.sym = rem_sq_bracket;
135}
136
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200137static size_t
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200138__callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200139 u64 total_samples, int depth, int depth_mask,
140 int left_margin)
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200141{
142 struct rb_node *node, *next;
143 struct callchain_node *child;
144 struct callchain_list *chain;
145 int new_depth_mask = depth_mask;
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200146 u64 new_total;
Frederic Weisbecker25446032009-08-08 02:16:25 +0200147 u64 remaining;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200148 size_t ret = 0;
149 int i;
150
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200151 if (callchain_param.mode == CHAIN_GRAPH_REL)
Frederic Weisbecker19532872009-08-07 07:11:05 +0200152 new_total = self->children_hit;
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200153 else
154 new_total = total_samples;
155
Frederic Weisbecker25446032009-08-08 02:16:25 +0200156 remaining = new_total;
157
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200158 node = rb_first(&self->rb_root);
159 while (node) {
Frederic Weisbecker25446032009-08-08 02:16:25 +0200160 u64 cumul;
161
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200162 child = rb_entry(node, struct callchain_node, rb_node);
Frederic Weisbecker25446032009-08-08 02:16:25 +0200163 cumul = cumul_hits(child);
164 remaining -= cumul;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200165
166 /*
167 * The depth mask manages the output of pipes that show
168 * the depth. We don't want to keep the pipes of the current
Frederic Weisbecker25446032009-08-08 02:16:25 +0200169 * level for the last child of this depth.
170 * Except if we have remaining filtered hits. They will
171 * supersede the last child
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200172 */
173 next = rb_next(node);
Frederic Weisbecker25446032009-08-08 02:16:25 +0200174 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200175 new_depth_mask &= ~(1 << (depth - 1));
176
177 /*
178 * But we keep the older depth mask for the line seperator
179 * to keep the level link until we reach the last child
180 */
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200181 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
182 left_margin);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200183 i = 0;
184 list_for_each_entry(chain, &child->val, list) {
185 if (chain->ip >= PERF_CONTEXT_MAX)
186 continue;
187 ret += ipchain__fprintf_graph(fp, chain, depth,
188 new_depth_mask, i++,
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200189 new_total,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200190 cumul,
191 left_margin);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200192 }
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200193 ret += __callchain__fprintf_graph(fp, child, new_total,
194 depth + 1,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200195 new_depth_mask | (1 << depth),
196 left_margin);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200197 node = next;
198 }
199
Frederic Weisbecker25446032009-08-08 02:16:25 +0200200 if (callchain_param.mode == CHAIN_GRAPH_REL &&
201 remaining && remaining != new_total) {
202
203 if (!rem_sq_bracket)
204 return ret;
205
206 new_depth_mask &= ~(1 << (depth - 1));
207
208 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
209 new_depth_mask, 0, new_total,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200210 remaining, left_margin);
Frederic Weisbecker25446032009-08-08 02:16:25 +0200211 }
212
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200213 return ret;
214}
215
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200216
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200217static size_t
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200218callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200219 u64 total_samples, int left_margin)
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200220{
221 struct callchain_list *chain;
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200222 bool printed = false;
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200223 int i = 0;
224 int ret = 0;
225
226 list_for_each_entry(chain, &self->val, list) {
227 if (chain->ip >= PERF_CONTEXT_MAX)
228 continue;
229
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200230 if (!i++ && sort__first_dimension == SORT_SYM)
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200231 continue;
232
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200233 if (!printed) {
234 ret += callchain__fprintf_left_margin(fp, left_margin);
235 ret += fprintf(fp, "|\n");
236 ret += callchain__fprintf_left_margin(fp, left_margin);
237 ret += fprintf(fp, "---");
238
239 left_margin += 3;
240 printed = true;
241 } else
242 ret += callchain__fprintf_left_margin(fp, left_margin);
243
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200244 if (chain->sym)
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200245 ret += fprintf(fp, " %s\n", chain->sym->name);
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200246 else
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200247 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200248 }
249
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200250 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
Frederic Weisbeckeraf0a6fa2009-10-22 23:23:22 +0200251
252 return ret;
253}
254
255static size_t
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200256callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
257 u64 total_samples)
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200258{
259 struct callchain_list *chain;
260 size_t ret = 0;
261
262 if (!self)
263 return 0;
264
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200265 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200266
267
Frederic Weisbecker44249612009-07-01 05:35:14 +0200268 list_for_each_entry(chain, &self->val, list) {
269 if (chain->ip >= PERF_CONTEXT_MAX)
270 continue;
271 if (chain->sym)
272 ret += fprintf(fp, " %s\n", chain->sym->name);
273 else
274 ret += fprintf(fp, " %p\n",
Ingo Molnarf37a2912009-07-01 12:37:06 +0200275 (void *)(long)chain->ip);
Frederic Weisbecker44249612009-07-01 05:35:14 +0200276 }
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200277
278 return ret;
279}
280
281static size_t
282hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200283 u64 total_samples, int left_margin)
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200284{
285 struct rb_node *rb_node;
286 struct callchain_node *chain;
287 size_t ret = 0;
288
289 rb_node = rb_first(&self->sorted_chain);
290 while (rb_node) {
291 double percent;
292
293 chain = rb_entry(rb_node, struct callchain_node, rb_node);
294 percent = chain->hit * 100.0 / total_samples;
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200295 switch (callchain_param.mode) {
296 case CHAIN_FLAT:
Frederic Weisbecker24b57c62009-07-02 20:14:35 +0200297 ret += percent_color_fprintf(fp, " %6.2f%%\n",
298 percent);
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200299 ret += callchain__fprintf_flat(fp, chain, total_samples);
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200300 break;
301 case CHAIN_GRAPH_ABS: /* Falldown */
302 case CHAIN_GRAPH_REL:
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200303 ret += callchain__fprintf_graph(fp, chain, total_samples,
304 left_margin);
Ingo Molnar83a09442009-08-15 12:26:57 +0200305 case CHAIN_NONE:
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200306 default:
307 break;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200308 }
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200309 ret += fprintf(fp, "\n");
310 rb_node = rb_next(rb_node);
311 }
312
313 return ret;
314}
315
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200316static size_t hist_entry__fprintf(FILE *fp, struct hist_entry *self,
317 struct perf_session *session,
318 u64 total_samples)
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200319{
320 struct sort_entry *se;
321 size_t ret;
322
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200323 if (exclude_other && !self->parent)
324 return 0;
325
Frederic Weisbecker1e11fd82009-07-02 20:14:34 +0200326 if (total_samples)
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300327 ret = percent_color_fprintf(fp,
328 field_sep ? "%.2f" : " %6.2f%%",
329 (self->count * 100.0) / total_samples);
Frederic Weisbecker1e11fd82009-07-02 20:14:34 +0200330 else
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300331 ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count);
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200332
Arnaldo Carvalho de Meloe3d7e182009-07-11 12:18:37 -0300333 if (show_nr_samples) {
334 if (field_sep)
335 fprintf(fp, "%c%lld", *field_sep, self->count);
336 else
337 fprintf(fp, "%11lld", self->count);
338 }
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200339
Peter Zijlstra71dd8942009-06-04 15:16:56 +0200340 list_for_each_entry(se, &hist_entry__sort_list, list) {
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300341 if (se->elide)
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200342 continue;
343
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300344 fprintf(fp, "%s", field_sep ?: " ");
345 ret += se->print(fp, self, se->width ? *se->width : 0);
Peter Zijlstra71dd8942009-06-04 15:16:56 +0200346 }
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200347
348 ret += fprintf(fp, "\n");
349
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200350 if (session->use_callchain) {
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200351 int left_margin = 0;
352
353 if (sort__first_dimension == SORT_COMM) {
354 se = list_first_entry(&hist_entry__sort_list, typeof(*se),
355 list);
356 left_margin = se->width ? *se->width : 0;
357 left_margin -= thread__comm_len(self->thread);
358 }
359
360 hist_entry_callchain__fprintf(fp, self, total_samples,
361 left_margin);
362 }
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200363
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200364 return ret;
365}
366
367/*
Peter Zijlstra6e7d6fd2009-06-17 15:51:44 +0200368 *
369 */
370
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300371static void dso__calc_col_width(struct dso *self)
372{
373 if (!col_width_list_str && !field_sep &&
374 (!dso_list || strlist__has_entry(dso_list, self->name))) {
375 unsigned int slen = strlen(self->name);
376 if (slen > dsos__col_width)
377 dsos__col_width = slen;
378 }
379
380 self->slen_calculated = 1;
381}
382
Frederic Weisbecker5b447a62009-08-31 06:45:18 +0200383static void thread__comm_adjust(struct thread *self)
Frederic Weisbecker4273b002009-08-18 16:03:46 +0200384{
Frederic Weisbecker5b447a62009-08-31 06:45:18 +0200385 char *comm = self->comm;
Frederic Weisbecker4273b002009-08-18 16:03:46 +0200386
387 if (!col_width_list_str && !field_sep &&
388 (!comm_list || strlist__has_entry(comm_list, comm))) {
389 unsigned int slen = strlen(comm);
390
391 if (slen > comms__col_width) {
392 comms__col_width = slen;
393 threads__col_width = slen + 6;
394 }
395 }
Frederic Weisbecker5b447a62009-08-31 06:45:18 +0200396}
397
398static int thread__set_comm_adjust(struct thread *self, const char *comm)
399{
400 int ret = thread__set_comm(self, comm);
401
402 if (ret)
403 return ret;
404
405 thread__comm_adjust(self);
Frederic Weisbecker4273b002009-08-18 16:03:46 +0200406
407 return 0;
408}
409
Peter Zijlstra6e7d6fd2009-06-17 15:51:44 +0200410/*
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200411 * collect histogram counts
412 */
413
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200414static int perf_session__add_hist_entry(struct perf_session *self,
415 struct addr_location *al,
416 struct ip_callchain *chain, u64 count)
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300417{
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300418 struct symbol **syms = NULL, *parent = NULL;
419 bool hit;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200420 struct hist_entry *he;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300421
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200422 if ((sort__has_parent || self->use_callchain) && chain)
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200423 syms = perf_session__resolve_callchain(self, al->thread,
424 chain, &parent);
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200425 he = __perf_session__add_hist_entry(self, al, parent, count, &hit);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300426 if (he == NULL)
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200427 return -ENOMEM;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300428
429 if (hit)
430 he->count += count;
431
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200432 if (self->use_callchain) {
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300433 if (!hit)
434 callchain_init(&he->callchain);
Frederic Weisbecker44249612009-07-01 05:35:14 +0200435 append_chain(&he->callchain, chain, syms);
436 free(syms);
Frederic Weisbeckerf55c5552009-06-26 16:28:01 +0200437 }
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200438
439 return 0;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300440}
441
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200442static size_t perf_session__fprintf_hist_entries(struct perf_session *self,
443 u64 total_samples, FILE *fp)
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300444{
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200445 struct hist_entry *pos;
Ingo Molnar2d655372009-05-27 21:36:22 +0200446 struct sort_entry *se;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300447 struct rb_node *nd;
448 size_t ret = 0;
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300449 unsigned int width;
450 char *col_width = col_width_list_str;
Brice Goglin9f866692009-08-10 15:26:32 +0200451 int raw_printing_style;
452
453 raw_printing_style = !strcmp(pretty_printing_style, "raw");
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300454
Frederic Weisbecker25446032009-08-08 02:16:25 +0200455 init_rem_hits();
456
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300457 fprintf(fp, "# Samples: %Ld\n", (u64)total_samples);
Ingo Molnar05ca0612009-06-04 14:21:16 +0200458 fprintf(fp, "#\n");
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200459
460 fprintf(fp, "# Overhead");
Arnaldo Carvalho de Meloe3d7e182009-07-11 12:18:37 -0300461 if (show_nr_samples) {
462 if (field_sep)
463 fprintf(fp, "%cSamples", *field_sep);
464 else
465 fputs(" Samples ", fp);
466 }
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200467 list_for_each_entry(se, &hist_entry__sort_list, list) {
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300468 if (se->elide)
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200469 continue;
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300470 if (field_sep) {
471 fprintf(fp, "%c%s", *field_sep, se->header);
472 continue;
473 }
474 width = strlen(se->header);
475 if (se->width) {
476 if (col_width_list_str) {
477 if (col_width) {
478 *se->width = atoi(col_width);
479 col_width = strchr(col_width, ',');
480 if (col_width)
481 ++col_width;
482 }
483 }
484 width = *se->width = max(*se->width, width);
485 }
486 fprintf(fp, " %*s", width, se->header);
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200487 }
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200488 fprintf(fp, "\n");
489
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300490 if (field_sep)
491 goto print_entries;
492
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200493 fprintf(fp, "# ........");
Arnaldo Carvalho de Meloe3d7e182009-07-11 12:18:37 -0300494 if (show_nr_samples)
495 fprintf(fp, " ..........");
Ingo Molnar2d655372009-05-27 21:36:22 +0200496 list_for_each_entry(se, &hist_entry__sort_list, list) {
Ingo Molnarf37a2912009-07-01 12:37:06 +0200497 unsigned int i;
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200498
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300499 if (se->elide)
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200500 continue;
501
Ingo Molnar4593bba2009-06-02 15:34:25 +0200502 fprintf(fp, " ");
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300503 if (se->width)
504 width = *se->width;
505 else
506 width = strlen(se->header);
507 for (i = 0; i < width; i++)
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200508 fprintf(fp, ".");
Ingo Molnar2d655372009-05-27 21:36:22 +0200509 }
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200510 fprintf(fp, "\n");
511
512 fprintf(fp, "#\n");
Ingo Molnar2d655372009-05-27 21:36:22 +0200513
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300514print_entries:
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200515 for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) {
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200516 pos = rb_entry(nd, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200517 ret += hist_entry__fprintf(fp, pos, self, total_samples);
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300518 }
519
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200520 if (sort_order == default_sort_order &&
521 parent_pattern == default_parent_pattern) {
Ingo Molnarbd741372009-06-04 14:13:04 +0200522 fprintf(fp, "#\n");
Pekka Enberg114cfab2009-08-05 13:25:21 +0300523 fprintf(fp, "# (For a higher level overview, try: perf report --sort comm,dso)\n");
Ingo Molnarbd741372009-06-04 14:13:04 +0200524 fprintf(fp, "#\n");
525 }
Peter Zijlstra71dd8942009-06-04 15:16:56 +0200526 fprintf(fp, "\n");
Ingo Molnarbd741372009-06-04 14:13:04 +0200527
Frederic Weisbecker25446032009-08-08 02:16:25 +0200528 free(rem_sq_bracket);
529
Brice Goglin8d513272009-08-07 13:55:24 +0200530 if (show_threads)
Brice Goglin9f866692009-08-10 15:26:32 +0200531 perf_read_values_display(fp, &show_threads_values,
532 raw_printing_style);
Brice Goglin8d513272009-08-07 13:55:24 +0200533
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300534 return ret;
535}
536
Peter Zijlstra2a0a50f2009-06-18 22:20:45 +0200537static int validate_chain(struct ip_callchain *chain, event_t *event)
Ingo Molnar75220602009-06-18 08:00:17 +0200538{
539 unsigned int chain_size;
540
Ingo Molnar75220602009-06-18 08:00:17 +0200541 chain_size = event->header.size;
542 chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
543
Paul Mackerras9cffa8d2009-06-19 22:21:42 +1000544 if (chain->nr*sizeof(u64) > chain_size)
Ingo Molnar75220602009-06-18 08:00:17 +0200545 return -1;
546
547 return 0;
548}
549
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200550static int process_sample_event(event_t *event, struct perf_session *session)
Ingo Molnar75051722009-06-03 23:14:49 +0200551{
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900552 struct sample_data data;
Anton Blanchardd8db1b52009-07-01 09:00:48 +1000553 int cpumode;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200554 struct addr_location al;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900555 struct thread *thread;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +0200556
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900557 memset(&data, 0, sizeof(data));
558 data.period = 1;
559
560 event__parse_sample(event, sample_type, &data);
Peter Zijlstraea1900e2009-06-10 21:45:22 +0200561
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200562 dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
Ingo Molnar75051722009-06-03 23:14:49 +0200563 event->header.misc,
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900564 data.pid, data.tid,
565 (void *)(long)data.ip,
566 (long long)data.period);
Ingo Molnar75051722009-06-03 23:14:49 +0200567
Peter Zijlstrae6e18ec2009-06-25 11:27:12 +0200568 if (sample_type & PERF_SAMPLE_CALLCHAIN) {
Ingo Molnarf37a2912009-07-01 12:37:06 +0200569 unsigned int i;
Ingo Molnar3efa1cc92009-06-14 15:04:15 +0200570
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900571 dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
Ingo Molnar3efa1cc92009-06-14 15:04:15 +0200572
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900573 if (validate_chain(data.callchain, event) < 0) {
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -0200574 pr_debug("call-chain problem with event, "
575 "skipping it.\n");
Ingo Molnar75220602009-06-18 08:00:17 +0200576 return 0;
577 }
578
579 if (dump_trace) {
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900580 for (i = 0; i < data.callchain->nr; i++)
581 dump_printf("..... %2d: %016Lx\n",
582 i, data.callchain->ips[i]);
Ingo Molnar3efa1cc92009-06-14 15:04:15 +0200583 }
584 }
585
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200586 thread = perf_session__findnew(session, data.pid);
Ingo Molnar75051722009-06-03 23:14:49 +0200587 if (thread == NULL) {
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -0200588 pr_debug("problem processing %d event, skipping it.\n",
Ingo Molnar75051722009-06-03 23:14:49 +0200589 event->header.type);
590 return -1;
591 }
592
Julia Lawallf39cdf22009-10-17 08:43:17 +0200593 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
594
Arnaldo Carvalho de Melocc8b88b2009-06-30 19:01:21 -0300595 if (comm_list && !strlist__has_entry(comm_list, thread->comm))
596 return 0;
597
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200598 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
Anton Blanchardd8db1b52009-07-01 09:00:48 +1000599
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200600 thread__find_addr_location(thread, session, cpumode,
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900601 MAP__FUNCTION, data.ip, &al, NULL);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200602 /*
603 * We have to do this here as we may have a dso with no symbol hit that
604 * has a name longer than the ones with symbols sampled.
605 */
606 if (al.map && !sort_dso.elide && !al.map->dso->slen_calculated)
607 dso__calc_col_width(al.map->dso);
Ingo Molnar75051722009-06-03 23:14:49 +0200608
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300609 if (dso_list &&
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200610 (!al.map || !al.map->dso ||
611 !(strlist__has_entry(dso_list, al.map->dso->short_name) ||
612 (al.map->dso->short_name != al.map->dso->long_name &&
613 strlist__has_entry(dso_list, al.map->dso->long_name)))))
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300614 return 0;
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -0300615
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200616 if (sym_list && al.sym && !strlist__has_entry(sym_list, al.sym->name))
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300617 return 0;
Arnaldo Carvalho de Melo7bec7a92009-06-30 19:01:22 -0300618
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200619 if (perf_session__add_hist_entry(session, &al, data.callchain, data.period)) {
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -0200620 pr_debug("problem incrementing symbol count, skipping event\n");
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300621 return -1;
Ingo Molnar75051722009-06-03 23:14:49 +0200622 }
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300623
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900624 event__stats.total += data.period;
Ingo Molnar75051722009-06-03 23:14:49 +0200625
626 return 0;
627}
628
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200629static int process_comm_event(event_t *event, struct perf_session *session)
Ingo Molnar75051722009-06-03 23:14:49 +0200630{
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200631 struct thread *thread = perf_session__findnew(session, event->comm.pid);
Ingo Molnar75051722009-06-03 23:14:49 +0200632
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200633 dump_printf(": %s:%d\n", event->comm.comm, event->comm.pid);
Ingo Molnar75051722009-06-03 23:14:49 +0200634
635 if (thread == NULL ||
Frederic Weisbecker4273b002009-08-18 16:03:46 +0200636 thread__set_comm_adjust(thread, event->comm.comm)) {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200637 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
Ingo Molnar75051722009-06-03 23:14:49 +0200638 return -1;
639 }
Ingo Molnar75051722009-06-03 23:14:49 +0200640
641 return 0;
642}
643
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200644static int process_read_event(event_t *event, struct perf_session *session __used)
Peter Zijlstrae9ea2fd2009-06-24 22:46:04 +0200645{
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200646 struct perf_event_attr *attr;
Frederic Weisbecker0d3a5c82009-08-16 20:56:37 +0200647
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200648 attr = perf_header__find_attr(event->read.id, &session->header);
Peter Zijlstra8f18aec2009-08-06 19:40:28 +0200649
Brice Goglin8d513272009-08-07 13:55:24 +0200650 if (show_threads) {
Ingo Molnar83a09442009-08-15 12:26:57 +0200651 const char *name = attr ? __event_name(attr->type, attr->config)
Brice Goglin8d513272009-08-07 13:55:24 +0200652 : "unknown";
653 perf_read_values_add_value(&show_threads_values,
654 event->read.pid, event->read.tid,
655 event->read.id,
656 name,
657 event->read.value);
658 }
659
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200660 dump_printf(": %d %d %s %Lu\n", event->read.pid, event->read.tid,
661 attr ? __event_name(attr->type, attr->config) : "FAIL",
662 event->read.value);
Peter Zijlstrae9ea2fd2009-06-24 22:46:04 +0200663
664 return 0;
665}
666
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200667static int sample_type_check(u64 type, struct perf_session *session)
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300668{
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200669 sample_type = type;
Ingo Molnar8465b052009-06-14 14:44:07 +0200670
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200671 if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
672 if (sort__has_parent) {
673 fprintf(stderr, "selected --sort parent, but no"
674 " callchain data. Did you call"
675 " perf record without -g?\n");
676 return -1;
677 }
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200678 if (session->use_callchain) {
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200679 fprintf(stderr, "selected -g but no callchain data."
680 " Did you call perf record without"
681 " -g?\n");
682 return -1;
683 }
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200684 } else if (callchain_param.mode != CHAIN_NONE && !session->use_callchain) {
685 session->use_callchain = true;
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200686 if (register_callchain_param(&callchain_param) < 0) {
687 fprintf(stderr, "Can't register callchain"
688 " params\n");
689 return -1;
690 }
Ingo Molnard80d3382009-06-03 23:14:49 +0200691 }
692
693 return 0;
694}
695
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -0200696static struct perf_event_ops event_ops = {
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200697 .process_sample_event = process_sample_event,
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200698 .process_mmap_event = event__process_mmap,
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200699 .process_comm_event = process_comm_event,
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200700 .process_exit_event = event__process_task,
701 .process_fork_event = event__process_task,
702 .process_lost_event = event__process_lost,
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200703 .process_read_event = process_read_event,
704 .sample_type_check = sample_type_check,
705};
706
707
Ingo Molnard80d3382009-06-03 23:14:49 +0200708static int __cmd_report(void)
709{
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200710 int ret;
Arnaldo Carvalho de Melod8f66242009-12-13 19:50:24 -0200711 struct perf_session *session;
Ingo Molnard80d3382009-06-03 23:14:49 +0200712
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200713 session = perf_session__new(input_name, O_RDONLY, force, &symbol_conf);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200714 if (session == NULL)
715 return -ENOMEM;
716
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200717 session->use_callchain = use_callchain;
718
Brice Goglin8d513272009-08-07 13:55:24 +0200719 if (show_threads)
720 perf_read_values_init(&show_threads_values);
721
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -0200722 ret = perf_session__process_events(session, &event_ops);
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200723 if (ret)
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200724 goto out_delete;
Ingo Molnar97b07b62009-05-26 18:48:58 +0200725
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200726 if (dump_trace) {
727 event__print_totals();
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200728 goto out_delete;
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200729 }
Ingo Molnar97b07b62009-05-26 18:48:58 +0200730
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300731 if (verbose > 3)
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200732 perf_session__fprintf(session, stdout);
Arnaldo Carvalho de Melo9ac99542009-06-04 13:54:00 -0300733
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300734 if (verbose > 2)
Ingo Molnar16f762a2009-05-27 09:10:38 +0200735 dsos__fprintf(stdout);
Ingo Molnar16f762a2009-05-27 09:10:38 +0200736
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200737 perf_session__collapse_resort(session);
738 perf_session__output_resort(session, event__stats.total);
739 perf_session__fprintf_hist_entries(session, event__stats.total, stdout);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300740
Brice Goglin8d513272009-08-07 13:55:24 +0200741 if (show_threads)
742 perf_read_values_destroy(&show_threads_values);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200743out_delete:
744 perf_session__delete(session);
Frederic Weisbecker016e92f2009-10-07 12:47:31 +0200745 return ret;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300746}
747
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200748static int
749parse_callchain_opt(const struct option *opt __used, const char *arg,
750 int unset __used)
751{
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200752 char *tok;
753 char *endptr;
754
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200755 use_callchain = true;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200756
757 if (!arg)
758 return 0;
759
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200760 tok = strtok((char *)arg, ",");
761 if (!tok)
762 return -1;
763
764 /* get the output mode */
765 if (!strncmp(tok, "graph", strlen(arg)))
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200766 callchain_param.mode = CHAIN_GRAPH_ABS;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200767
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200768 else if (!strncmp(tok, "flat", strlen(arg)))
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200769 callchain_param.mode = CHAIN_FLAT;
770
771 else if (!strncmp(tok, "fractal", strlen(arg)))
772 callchain_param.mode = CHAIN_GRAPH_REL;
773
Frederic Weisbeckerb1a88342009-08-08 02:16:24 +0200774 else if (!strncmp(tok, "none", strlen(arg))) {
775 callchain_param.mode = CHAIN_NONE;
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200776 use_callchain = true;
Frederic Weisbeckerb1a88342009-08-08 02:16:24 +0200777
778 return 0;
779 }
780
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200781 else
782 return -1;
783
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200784 /* get the min percentage */
785 tok = strtok(NULL, ",");
786 if (!tok)
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200787 goto setup;
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200788
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200789 callchain_param.min_percent = strtod(tok, &endptr);
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200790 if (tok == endptr)
791 return -1;
792
Frederic Weisbecker805d1272009-07-05 07:39:21 +0200793setup:
794 if (register_callchain_param(&callchain_param) < 0) {
795 fprintf(stderr, "Can't register callchain params\n");
796 return -1;
797 }
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +0200798 return 0;
799}
800
John Kacurdd68ada2009-09-24 18:02:49 +0200801//static const char * const report_usage[] = {
802const char * const report_usage[] = {
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200803 "perf report [<options>] <command>",
804 NULL
805};
806
807static const struct option options[] = {
808 OPT_STRING('i', "input", &input_name, "file",
809 "input file name"),
Arnaldo Carvalho de Melo815e7772009-05-26 19:46:14 -0300810 OPT_BOOLEAN('v', "verbose", &verbose,
811 "be more verbose (show symbol address, etc)"),
Ingo Molnar97b07b62009-05-26 18:48:58 +0200812 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
813 "dump raw trace in ASCII"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200814 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
815 "file", "vmlinux pathname"),
Peter Zijlstrafa6963b2009-08-19 11:18:26 +0200816 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200817 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
Mike Galbraith42976482009-07-02 08:09:46 +0200818 "load module symbols - WARNING: use only with -k and LIVE kernel"),
Arnaldo Carvalho de Meloe3d7e182009-07-11 12:18:37 -0300819 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
820 "Show a column with the number of samples"),
Brice Goglin8d513272009-08-07 13:55:24 +0200821 OPT_BOOLEAN('T', "threads", &show_threads,
822 "Show per-thread event counters"),
Brice Goglin9f866692009-08-10 15:26:32 +0200823 OPT_STRING(0, "pretty", &pretty_printing_style, "key",
824 "pretty printing style key: normal raw"),
Ingo Molnar63299f02009-05-28 10:52:00 +0200825 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
Ingo Molnarb25bcf22009-06-18 07:01:03 +0200826 "sort by key(s): pid, comm, dso, symbol, parent"),
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -0200827 OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths,
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300828 "Don't shorten the pathnames taking into account the cwd"),
Ingo Molnarb25bcf22009-06-18 07:01:03 +0200829 OPT_STRING('p', "parent", &parent_pattern, "regex",
830 "regex filter to identify parent, see: '--sort parent'"),
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200831 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
832 "Only display entries with parent-match"),
Anton Blanchard1483b19f2009-07-16 15:44:29 +0200833 OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
Frederic Weisbeckerc20ab372009-07-02 20:14:33 +0200834 "Display callchains using output_type and min percent threshold. "
Anton Blanchard1483b19f2009-07-16 15:44:29 +0200835 "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -0300836 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
837 "only consider symbols in these dsos"),
Arnaldo Carvalho de Melocc8b88b2009-06-30 19:01:21 -0300838 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
839 "only consider symbols in these comms"),
Arnaldo Carvalho de Melo7bec7a92009-06-30 19:01:22 -0300840 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]",
841 "only consider these symbols"),
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300842 OPT_STRING('w', "column-widths", &col_width_list_str,
843 "width[,width...]",
844 "don't try to adjust column width, use these fixed values"),
845 OPT_STRING('t', "field-separator", &field_sep, "separator",
846 "separator for columns, no spaces will be added between "
847 "columns '.' is reserved."),
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200848 OPT_END()
849};
850
Ingo Molnar5352f352009-06-03 10:07:39 +0200851static void setup_sorting(void)
852{
853 char *tmp, *tok, *str = strdup(sort_order);
854
855 for (tok = strtok_r(str, ", ", &tmp);
856 tok; tok = strtok_r(NULL, ", ", &tmp)) {
857 if (sort_dimension__add(tok) < 0) {
858 error("Unknown --sort key: `%s'", tok);
859 usage_with_options(report_usage, options);
860 }
861 }
862
863 free(str);
864}
865
Arnaldo Carvalho de Melocc8b88b2009-06-30 19:01:21 -0300866static void setup_list(struct strlist **list, const char *list_str,
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300867 struct sort_entry *se, const char *list_name,
868 FILE *fp)
Arnaldo Carvalho de Melocc8b88b2009-06-30 19:01:21 -0300869{
870 if (list_str) {
871 *list = strlist__new(true, list_str);
872 if (!*list) {
873 fprintf(stderr, "problems parsing %s list\n",
874 list_name);
875 exit(129);
876 }
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300877 if (strlist__nr_entries(*list) == 1) {
878 fprintf(fp, "# %s: %s\n", list_name,
879 strlist__entry(*list, 0)->s);
880 se->elide = true;
881 }
Arnaldo Carvalho de Melocc8b88b2009-06-30 19:01:21 -0300882 }
883}
884
Ingo Molnarf37a2912009-07-01 12:37:06 +0200885int cmd_report(int argc, const char **argv, const char *prefix __used)
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200886{
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200887 if (symbol__init(&symbol_conf) < 0)
888 return -1;
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200889
Ingo Molnaredc52de2009-06-04 16:24:37 +0200890 argc = parse_options(argc, argv, options, report_usage, 0);
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200891
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200892 setup_sorting();
893
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300894 if (parent_pattern != default_parent_pattern) {
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200895 sort_dimension__add("parent");
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300896 sort_parent.elide = 1;
897 } else
Ingo Molnarb8e6d822009-06-18 14:32:19 +0200898 exclude_other = 0;
899
Ingo Molnaredc52de2009-06-04 16:24:37 +0200900 /*
901 * Any (unrecognized) arguments left?
902 */
903 if (argc)
904 usage_with_options(report_usage, options);
905
Ingo Molnara930d2c2009-05-27 09:50:13 +0200906 setup_pager();
907
Arnaldo Carvalho de Melo021191b2009-07-11 12:18:35 -0300908 setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout);
909 setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout);
910 setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300911
Arnaldo Carvalho de Melo52d422d2009-07-10 22:47:28 -0300912 if (field_sep && *field_sep == '.') {
913 fputs("'.' is the only non valid --field-separator argument\n",
914 stderr);
915 exit(129);
916 }
917
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300918 return __cmd_report();
919}