Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 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 | */ |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 8 | #include "builtin.h" |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 9 | |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 10 | #include "util/util.h" |
| 11 | |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 12 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 5da5025 | 2009-07-01 14:46:08 -0300 | [diff] [blame] | 13 | #include <linux/list.h> |
Ingo Molnar | a930d2c | 2009-05-27 09:50:13 +0200 | [diff] [blame] | 14 | #include "util/cache.h" |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 15 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 16 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 17 | #include "util/string.h" |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 18 | #include "util/callchain.h" |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 19 | #include "util/strlist.h" |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 20 | #include "util/values.h" |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 21 | |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 22 | #include "perf.h" |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 23 | #include "util/debug.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 24 | #include "util/header.h" |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 25 | |
| 26 | #include "util/parse-options.h" |
| 27 | #include "util/parse-events.h" |
| 28 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 29 | #include "util/data_map.h" |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 30 | #include "util/thread.h" |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 31 | #include "util/sort.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 32 | #include "util/hist.h" |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 33 | |
Ingo Molnar | 23ac9cb | 2009-05-27 09:33:18 +0200 | [diff] [blame] | 34 | static char const *input_name = "perf.data"; |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 35 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 36 | static char *dso_list_str, *comm_list_str, *sym_list_str, |
| 37 | *col_width_list_str; |
Arnaldo Carvalho de Melo | 7bec7a9 | 2009-06-30 19:01:22 -0300 | [diff] [blame] | 38 | static struct strlist *dso_list, *comm_list, *sym_list; |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 39 | |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 40 | static int force; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 41 | |
Arnaldo Carvalho de Melo | b78c07d | 2009-05-29 13:48:59 -0300 | [diff] [blame] | 42 | static int full_paths; |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 43 | static int show_nr_samples; |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 44 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 45 | static int show_threads; |
| 46 | static struct perf_read_values show_threads_values; |
| 47 | |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 48 | static char default_pretty_printing_style[] = "normal"; |
| 49 | static char *pretty_printing_style = default_pretty_printing_style; |
| 50 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 51 | static int exclude_other = 1; |
Frederic Weisbecker | be90388 | 2009-07-05 07:39:18 +0200 | [diff] [blame] | 52 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 53 | static char callchain_default_opt[] = "fractal,0.5"; |
| 54 | |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 55 | static struct perf_header *header; |
| 56 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 57 | static u64 sample_type; |
| 58 | |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 59 | struct symbol_conf symbol_conf; |
| 60 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 61 | |
| 62 | static size_t |
| 63 | callchain__fprintf_left_margin(FILE *fp, int left_margin) |
| 64 | { |
| 65 | int i; |
| 66 | int ret; |
| 67 | |
| 68 | ret = fprintf(fp, " "); |
| 69 | |
| 70 | for (i = 0; i < left_margin; i++) |
| 71 | ret += fprintf(fp, " "); |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, |
| 77 | int left_margin) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 78 | { |
| 79 | int i; |
| 80 | size_t ret = 0; |
| 81 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 82 | ret += callchain__fprintf_left_margin(fp, left_margin); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 83 | |
| 84 | for (i = 0; i < depth; i++) |
| 85 | if (depth_mask & (1 << i)) |
| 86 | ret += fprintf(fp, "| "); |
| 87 | else |
| 88 | ret += fprintf(fp, " "); |
| 89 | |
| 90 | ret += fprintf(fp, "\n"); |
| 91 | |
| 92 | return ret; |
| 93 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 94 | static size_t |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 95 | ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth, |
| 96 | int depth_mask, int count, u64 total_samples, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 97 | int hits, int left_margin) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | size_t ret = 0; |
| 101 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 102 | ret += callchain__fprintf_left_margin(fp, left_margin); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 103 | for (i = 0; i < depth; i++) { |
| 104 | if (depth_mask & (1 << i)) |
| 105 | ret += fprintf(fp, "|"); |
| 106 | else |
| 107 | ret += fprintf(fp, " "); |
| 108 | if (!count && i == depth - 1) { |
| 109 | double percent; |
| 110 | |
| 111 | percent = hits * 100.0 / total_samples; |
Frederic Weisbecker | 24b57c6 | 2009-07-02 20:14:35 +0200 | [diff] [blame] | 112 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 113 | } else |
| 114 | ret += fprintf(fp, "%s", " "); |
| 115 | } |
| 116 | if (chain->sym) |
| 117 | ret += fprintf(fp, "%s\n", chain->sym->name); |
| 118 | else |
| 119 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 124 | static struct symbol *rem_sq_bracket; |
| 125 | static struct callchain_list rem_hits; |
| 126 | |
| 127 | static void init_rem_hits(void) |
| 128 | { |
| 129 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 130 | if (!rem_sq_bracket) { |
| 131 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | strcpy(rem_sq_bracket->name, "[...]"); |
| 136 | rem_hits.sym = rem_sq_bracket; |
| 137 | } |
| 138 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 139 | static size_t |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 140 | __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 141 | u64 total_samples, int depth, int depth_mask, |
| 142 | int left_margin) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 143 | { |
| 144 | struct rb_node *node, *next; |
| 145 | struct callchain_node *child; |
| 146 | struct callchain_list *chain; |
| 147 | int new_depth_mask = depth_mask; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 148 | u64 new_total; |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 149 | u64 remaining; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 150 | size_t ret = 0; |
| 151 | int i; |
| 152 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 153 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 154 | new_total = self->children_hit; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 155 | else |
| 156 | new_total = total_samples; |
| 157 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 158 | remaining = new_total; |
| 159 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 160 | node = rb_first(&self->rb_root); |
| 161 | while (node) { |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 162 | u64 cumul; |
| 163 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 164 | child = rb_entry(node, struct callchain_node, rb_node); |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 165 | cumul = cumul_hits(child); |
| 166 | remaining -= cumul; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * The depth mask manages the output of pipes that show |
| 170 | * the depth. We don't want to keep the pipes of the current |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 171 | * level for the last child of this depth. |
| 172 | * Except if we have remaining filtered hits. They will |
| 173 | * supersede the last child |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 174 | */ |
| 175 | next = rb_next(node); |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 176 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 177 | new_depth_mask &= ~(1 << (depth - 1)); |
| 178 | |
| 179 | /* |
| 180 | * But we keep the older depth mask for the line seperator |
| 181 | * to keep the level link until we reach the last child |
| 182 | */ |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 183 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
| 184 | left_margin); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 185 | i = 0; |
| 186 | list_for_each_entry(chain, &child->val, list) { |
| 187 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 188 | continue; |
| 189 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 190 | new_depth_mask, i++, |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 191 | new_total, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 192 | cumul, |
| 193 | left_margin); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 194 | } |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 195 | ret += __callchain__fprintf_graph(fp, child, new_total, |
| 196 | depth + 1, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 197 | new_depth_mask | (1 << depth), |
| 198 | left_margin); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 199 | node = next; |
| 200 | } |
| 201 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 202 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 203 | remaining && remaining != new_total) { |
| 204 | |
| 205 | if (!rem_sq_bracket) |
| 206 | return ret; |
| 207 | |
| 208 | new_depth_mask &= ~(1 << (depth - 1)); |
| 209 | |
| 210 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
| 211 | new_depth_mask, 0, new_total, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 212 | remaining, left_margin); |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 215 | return ret; |
| 216 | } |
| 217 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 218 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 219 | static size_t |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 220 | callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 221 | u64 total_samples, int left_margin) |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 222 | { |
| 223 | struct callchain_list *chain; |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 224 | bool printed = false; |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 225 | int i = 0; |
| 226 | int ret = 0; |
| 227 | |
| 228 | list_for_each_entry(chain, &self->val, list) { |
| 229 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 230 | continue; |
| 231 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 232 | if (!i++ && sort__first_dimension == SORT_SYM) |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 233 | continue; |
| 234 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 235 | if (!printed) { |
| 236 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 237 | ret += fprintf(fp, "|\n"); |
| 238 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 239 | ret += fprintf(fp, "---"); |
| 240 | |
| 241 | left_margin += 3; |
| 242 | printed = true; |
| 243 | } else |
| 244 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 245 | |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 246 | if (chain->sym) |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 247 | ret += fprintf(fp, " %s\n", chain->sym->name); |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 248 | else |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 249 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 252 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 253 | |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | static size_t |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 258 | callchain__fprintf_flat(FILE *fp, struct callchain_node *self, |
| 259 | u64 total_samples) |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 260 | { |
| 261 | struct callchain_list *chain; |
| 262 | size_t ret = 0; |
| 263 | |
| 264 | if (!self) |
| 265 | return 0; |
| 266 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 267 | ret += callchain__fprintf_flat(fp, self->parent, total_samples); |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 268 | |
| 269 | |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 270 | list_for_each_entry(chain, &self->val, list) { |
| 271 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 272 | continue; |
| 273 | if (chain->sym) |
| 274 | ret += fprintf(fp, " %s\n", chain->sym->name); |
| 275 | else |
| 276 | ret += fprintf(fp, " %p\n", |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 277 | (void *)(long)chain->ip); |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 278 | } |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | static size_t |
| 284 | hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 285 | u64 total_samples, int left_margin) |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 286 | { |
| 287 | struct rb_node *rb_node; |
| 288 | struct callchain_node *chain; |
| 289 | size_t ret = 0; |
| 290 | |
| 291 | rb_node = rb_first(&self->sorted_chain); |
| 292 | while (rb_node) { |
| 293 | double percent; |
| 294 | |
| 295 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 296 | percent = chain->hit * 100.0 / total_samples; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 297 | switch (callchain_param.mode) { |
| 298 | case CHAIN_FLAT: |
Frederic Weisbecker | 24b57c6 | 2009-07-02 20:14:35 +0200 | [diff] [blame] | 299 | ret += percent_color_fprintf(fp, " %6.2f%%\n", |
| 300 | percent); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 301 | ret += callchain__fprintf_flat(fp, chain, total_samples); |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 302 | break; |
| 303 | case CHAIN_GRAPH_ABS: /* Falldown */ |
| 304 | case CHAIN_GRAPH_REL: |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 305 | ret += callchain__fprintf_graph(fp, chain, total_samples, |
| 306 | left_margin); |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 307 | case CHAIN_NONE: |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 308 | default: |
| 309 | break; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 310 | } |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 311 | ret += fprintf(fp, "\n"); |
| 312 | rb_node = rb_next(rb_node); |
| 313 | } |
| 314 | |
| 315 | return ret; |
| 316 | } |
| 317 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 318 | static size_t |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 319 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 320 | { |
| 321 | struct sort_entry *se; |
| 322 | size_t ret; |
| 323 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 324 | if (exclude_other && !self->parent) |
| 325 | return 0; |
| 326 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 327 | if (total_samples) |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 328 | ret = percent_color_fprintf(fp, |
| 329 | field_sep ? "%.2f" : " %6.2f%%", |
| 330 | (self->count * 100.0) / total_samples); |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 331 | else |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 332 | ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count); |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 333 | |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 334 | if (show_nr_samples) { |
| 335 | if (field_sep) |
| 336 | fprintf(fp, "%c%lld", *field_sep, self->count); |
| 337 | else |
| 338 | fprintf(fp, "%11lld", self->count); |
| 339 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 340 | |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 341 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 342 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 343 | continue; |
| 344 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 345 | fprintf(fp, "%s", field_sep ?: " "); |
| 346 | ret += se->print(fp, self, se->width ? *se->width : 0); |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 347 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 348 | |
| 349 | ret += fprintf(fp, "\n"); |
| 350 | |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 351 | if (callchain) { |
| 352 | int left_margin = 0; |
| 353 | |
| 354 | if (sort__first_dimension == SORT_COMM) { |
| 355 | se = list_first_entry(&hist_entry__sort_list, typeof(*se), |
| 356 | list); |
| 357 | left_margin = se->width ? *se->width : 0; |
| 358 | left_margin -= thread__comm_len(self->thread); |
| 359 | } |
| 360 | |
| 361 | hist_entry_callchain__fprintf(fp, self, total_samples, |
| 362 | left_margin); |
| 363 | } |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 364 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | /* |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 369 | * |
| 370 | */ |
| 371 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 372 | static void dso__calc_col_width(struct dso *self) |
| 373 | { |
| 374 | if (!col_width_list_str && !field_sep && |
| 375 | (!dso_list || strlist__has_entry(dso_list, self->name))) { |
| 376 | unsigned int slen = strlen(self->name); |
| 377 | if (slen > dsos__col_width) |
| 378 | dsos__col_width = slen; |
| 379 | } |
| 380 | |
| 381 | self->slen_calculated = 1; |
| 382 | } |
| 383 | |
Frederic Weisbecker | 5b447a6 | 2009-08-31 06:45:18 +0200 | [diff] [blame] | 384 | static void thread__comm_adjust(struct thread *self) |
Frederic Weisbecker | 4273b00 | 2009-08-18 16:03:46 +0200 | [diff] [blame] | 385 | { |
Frederic Weisbecker | 5b447a6 | 2009-08-31 06:45:18 +0200 | [diff] [blame] | 386 | char *comm = self->comm; |
Frederic Weisbecker | 4273b00 | 2009-08-18 16:03:46 +0200 | [diff] [blame] | 387 | |
| 388 | if (!col_width_list_str && !field_sep && |
| 389 | (!comm_list || strlist__has_entry(comm_list, comm))) { |
| 390 | unsigned int slen = strlen(comm); |
| 391 | |
| 392 | if (slen > comms__col_width) { |
| 393 | comms__col_width = slen; |
| 394 | threads__col_width = slen + 6; |
| 395 | } |
| 396 | } |
Frederic Weisbecker | 5b447a6 | 2009-08-31 06:45:18 +0200 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static int thread__set_comm_adjust(struct thread *self, const char *comm) |
| 400 | { |
| 401 | int ret = thread__set_comm(self, comm); |
| 402 | |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | |
| 406 | thread__comm_adjust(self); |
Frederic Weisbecker | 4273b00 | 2009-08-18 16:03:46 +0200 | [diff] [blame] | 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 411 | static int call__match(struct symbol *sym) |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 412 | { |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 413 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 414 | return 1; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 415 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 416 | return 0; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Arnaldo Carvalho de Melo | 50e5095 | 2009-11-22 14:59:22 -0200 | [diff] [blame] | 419 | static struct symbol **resolve_callchain(struct thread *thread, |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 420 | struct ip_callchain *chain, |
| 421 | struct symbol **parent) |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 422 | { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 423 | u8 cpumode = PERF_RECORD_MISC_USER; |
Ingo Molnar | 029e5b1 | 2009-07-03 13:17:28 +0200 | [diff] [blame] | 424 | struct symbol **syms = NULL; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 425 | unsigned int i; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 426 | |
| 427 | if (callchain) { |
| 428 | syms = calloc(chain->nr, sizeof(*syms)); |
| 429 | if (!syms) { |
| 430 | fprintf(stderr, "Can't allocate memory for symbols\n"); |
| 431 | exit(-1); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | for (i = 0; i < chain->nr; i++) { |
| 436 | u64 ip = chain->ips[i]; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 437 | struct addr_location al; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 438 | |
| 439 | if (ip >= PERF_CONTEXT_MAX) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 440 | switch (ip) { |
| 441 | case PERF_CONTEXT_HV: |
| 442 | cpumode = PERF_RECORD_MISC_HYPERVISOR; break; |
| 443 | case PERF_CONTEXT_KERNEL: |
| 444 | cpumode = PERF_RECORD_MISC_KERNEL; break; |
| 445 | case PERF_CONTEXT_USER: |
| 446 | cpumode = PERF_RECORD_MISC_USER; break; |
| 447 | default: |
| 448 | break; |
| 449 | } |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 450 | continue; |
| 451 | } |
| 452 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 453 | thread__find_addr_location(thread, cpumode, MAP__FUNCTION, |
| 454 | ip, &al, NULL); |
| 455 | if (al.sym != NULL) { |
| 456 | if (sort__has_parent && !*parent && |
| 457 | call__match(al.sym)) |
| 458 | *parent = al.sym; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 459 | if (!callchain) |
| 460 | break; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 461 | syms[i] = al.sym; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | return syms; |
| 466 | } |
| 467 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 468 | /* |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 469 | * collect histogram counts |
| 470 | */ |
| 471 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 472 | static int hist_entry__add(struct addr_location *al, |
| 473 | struct ip_callchain *chain, u64 count) |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 474 | { |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 475 | struct symbol **syms = NULL, *parent = NULL; |
| 476 | bool hit; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 477 | struct hist_entry *he; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 478 | |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 479 | if ((sort__has_parent || callchain) && chain) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 480 | syms = resolve_callchain(al->thread, chain, &parent); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 481 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 482 | he = __hist_entry__add(al, parent, count, &hit); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 483 | if (he == NULL) |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 484 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 485 | |
| 486 | if (hit) |
| 487 | he->count += count; |
| 488 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 489 | if (callchain) { |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 490 | if (!hit) |
| 491 | callchain_init(&he->callchain); |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 492 | append_chain(&he->callchain, chain, syms); |
| 493 | free(syms); |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 494 | } |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 495 | |
| 496 | return 0; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 497 | } |
| 498 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 499 | static size_t output__fprintf(FILE *fp, u64 total_samples) |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 500 | { |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 501 | struct hist_entry *pos; |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 502 | struct sort_entry *se; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 503 | struct rb_node *nd; |
| 504 | size_t ret = 0; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 505 | unsigned int width; |
| 506 | char *col_width = col_width_list_str; |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 507 | int raw_printing_style; |
| 508 | |
| 509 | raw_printing_style = !strcmp(pretty_printing_style, "raw"); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 510 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 511 | init_rem_hits(); |
| 512 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 513 | fprintf(fp, "# Samples: %Ld\n", (u64)total_samples); |
Ingo Molnar | 05ca061 | 2009-06-04 14:21:16 +0200 | [diff] [blame] | 514 | fprintf(fp, "#\n"); |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 515 | |
| 516 | fprintf(fp, "# Overhead"); |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 517 | if (show_nr_samples) { |
| 518 | if (field_sep) |
| 519 | fprintf(fp, "%cSamples", *field_sep); |
| 520 | else |
| 521 | fputs(" Samples ", fp); |
| 522 | } |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 523 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 524 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 525 | continue; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 526 | if (field_sep) { |
| 527 | fprintf(fp, "%c%s", *field_sep, se->header); |
| 528 | continue; |
| 529 | } |
| 530 | width = strlen(se->header); |
| 531 | if (se->width) { |
| 532 | if (col_width_list_str) { |
| 533 | if (col_width) { |
| 534 | *se->width = atoi(col_width); |
| 535 | col_width = strchr(col_width, ','); |
| 536 | if (col_width) |
| 537 | ++col_width; |
| 538 | } |
| 539 | } |
| 540 | width = *se->width = max(*se->width, width); |
| 541 | } |
| 542 | fprintf(fp, " %*s", width, se->header); |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 543 | } |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 544 | fprintf(fp, "\n"); |
| 545 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 546 | if (field_sep) |
| 547 | goto print_entries; |
| 548 | |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 549 | fprintf(fp, "# ........"); |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 550 | if (show_nr_samples) |
| 551 | fprintf(fp, " .........."); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 552 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 553 | unsigned int i; |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 554 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 555 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 556 | continue; |
| 557 | |
Ingo Molnar | 4593bba | 2009-06-02 15:34:25 +0200 | [diff] [blame] | 558 | fprintf(fp, " "); |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 559 | if (se->width) |
| 560 | width = *se->width; |
| 561 | else |
| 562 | width = strlen(se->header); |
| 563 | for (i = 0; i < width; i++) |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 564 | fprintf(fp, "."); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 565 | } |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 566 | fprintf(fp, "\n"); |
| 567 | |
| 568 | fprintf(fp, "#\n"); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 569 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 570 | print_entries: |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 571 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { |
| 572 | pos = rb_entry(nd, struct hist_entry, rb_node); |
| 573 | ret += hist_entry__fprintf(fp, pos, total_samples); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 574 | } |
| 575 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 576 | if (sort_order == default_sort_order && |
| 577 | parent_pattern == default_parent_pattern) { |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 578 | fprintf(fp, "#\n"); |
Pekka Enberg | 114cfab | 2009-08-05 13:25:21 +0300 | [diff] [blame] | 579 | fprintf(fp, "# (For a higher level overview, try: perf report --sort comm,dso)\n"); |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 580 | fprintf(fp, "#\n"); |
| 581 | } |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 582 | fprintf(fp, "\n"); |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 583 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 584 | free(rem_sq_bracket); |
| 585 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 586 | if (show_threads) |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 587 | perf_read_values_display(fp, &show_threads_values, |
| 588 | raw_printing_style); |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 589 | |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 593 | static int validate_chain(struct ip_callchain *chain, event_t *event) |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 594 | { |
| 595 | unsigned int chain_size; |
| 596 | |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 597 | chain_size = event->header.size; |
| 598 | chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event; |
| 599 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 600 | if (chain->nr*sizeof(u64) > chain_size) |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 601 | return -1; |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 606 | static int process_sample_event(event_t *event) |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 607 | { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 608 | u64 ip = event->ip.ip; |
| 609 | u64 period = 1; |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 610 | void *more_data = event->ip.__more_data; |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 611 | struct ip_callchain *chain = NULL; |
Anton Blanchard | d8db1b5 | 2009-07-01 09:00:48 +1000 | [diff] [blame] | 612 | int cpumode; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 613 | struct addr_location al; |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 614 | struct thread *thread = threads__findnew(event->ip.pid); |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 615 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 616 | if (sample_type & PERF_SAMPLE_PERIOD) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 617 | period = *(u64 *)more_data; |
| 618 | more_data += sizeof(u64); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 619 | } |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 620 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 621 | dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 622 | event->header.misc, |
Arnaldo Carvalho de Melo | 94a2475 | 2009-08-11 16:21:38 -0300 | [diff] [blame] | 623 | event->ip.pid, event->ip.tid, |
Peter Zijlstra | 4502d77 | 2009-06-10 15:03:06 +0200 | [diff] [blame] | 624 | (void *)(long)ip, |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 625 | (long long)period); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 626 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 627 | if (sample_type & PERF_SAMPLE_CALLCHAIN) { |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 628 | unsigned int i; |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 629 | |
| 630 | chain = (void *)more_data; |
| 631 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 632 | dump_printf("... chain: nr:%Lu\n", chain->nr); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 633 | |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 634 | if (validate_chain(chain, event) < 0) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 635 | pr_debug("call-chain problem with event, " |
| 636 | "skipping it.\n"); |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | if (dump_trace) { |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 641 | for (i = 0; i < chain->nr; i++) |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 642 | dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 646 | if (thread == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 647 | pr_debug("problem processing %d event, skipping it.\n", |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 648 | event->header.type); |
| 649 | return -1; |
| 650 | } |
| 651 | |
Julia Lawall | f39cdf2 | 2009-10-17 08:43:17 +0200 | [diff] [blame] | 652 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 653 | |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 654 | if (comm_list && !strlist__has_entry(comm_list, thread->comm)) |
| 655 | return 0; |
| 656 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 657 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Anton Blanchard | d8db1b5 | 2009-07-01 09:00:48 +1000 | [diff] [blame] | 658 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 659 | thread__find_addr_location(thread, cpumode, |
| 660 | MAP__FUNCTION, ip, &al, NULL); |
| 661 | /* |
| 662 | * We have to do this here as we may have a dso with no symbol hit that |
| 663 | * has a name longer than the ones with symbols sampled. |
| 664 | */ |
| 665 | if (al.map && !sort_dso.elide && !al.map->dso->slen_calculated) |
| 666 | dso__calc_col_width(al.map->dso); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 667 | |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 668 | if (dso_list && |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 669 | (!al.map || !al.map->dso || |
| 670 | !(strlist__has_entry(dso_list, al.map->dso->short_name) || |
| 671 | (al.map->dso->short_name != al.map->dso->long_name && |
| 672 | strlist__has_entry(dso_list, al.map->dso->long_name))))) |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 673 | return 0; |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 674 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 675 | if (sym_list && al.sym && !strlist__has_entry(sym_list, al.sym->name)) |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 676 | return 0; |
Arnaldo Carvalho de Melo | 7bec7a9 | 2009-06-30 19:01:22 -0300 | [diff] [blame] | 677 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 678 | if (hist_entry__add(&al, chain, period)) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 679 | pr_debug("problem incrementing symbol count, skipping event\n"); |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 680 | return -1; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 681 | } |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 682 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 683 | event__stats.total += period; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 688 | static int process_comm_event(event_t *event) |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 689 | { |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 690 | struct thread *thread = threads__findnew(event->comm.pid); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 691 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 692 | dump_printf(": %s:%d\n", event->comm.comm, event->comm.pid); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 693 | |
| 694 | if (thread == NULL || |
Frederic Weisbecker | 4273b00 | 2009-08-18 16:03:46 +0200 | [diff] [blame] | 695 | thread__set_comm_adjust(thread, event->comm.comm)) { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 696 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 697 | return -1; |
| 698 | } |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 703 | static int process_read_event(event_t *event) |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 704 | { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 705 | struct perf_event_attr *attr; |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 706 | |
| 707 | attr = perf_header__find_attr(event->read.id, header); |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 708 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 709 | if (show_threads) { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 710 | const char *name = attr ? __event_name(attr->type, attr->config) |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 711 | : "unknown"; |
| 712 | perf_read_values_add_value(&show_threads_values, |
| 713 | event->read.pid, event->read.tid, |
| 714 | event->read.id, |
| 715 | name, |
| 716 | event->read.value); |
| 717 | } |
| 718 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 719 | dump_printf(": %d %d %s %Lu\n", event->read.pid, event->read.tid, |
| 720 | attr ? __event_name(attr->type, attr->config) : "FAIL", |
| 721 | event->read.value); |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 726 | static int sample_type_check(u64 type) |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 727 | { |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 728 | sample_type = type; |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 729 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 730 | if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { |
| 731 | if (sort__has_parent) { |
| 732 | fprintf(stderr, "selected --sort parent, but no" |
| 733 | " callchain data. Did you call" |
| 734 | " perf record without -g?\n"); |
| 735 | return -1; |
| 736 | } |
| 737 | if (callchain) { |
| 738 | fprintf(stderr, "selected -g but no callchain data." |
| 739 | " Did you call perf record without" |
| 740 | " -g?\n"); |
| 741 | return -1; |
| 742 | } |
| 743 | } else if (callchain_param.mode != CHAIN_NONE && !callchain) { |
| 744 | callchain = 1; |
| 745 | if (register_callchain_param(&callchain_param) < 0) { |
| 746 | fprintf(stderr, "Can't register callchain" |
| 747 | " params\n"); |
| 748 | return -1; |
| 749 | } |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 755 | static struct perf_file_handler file_handler = { |
| 756 | .process_sample_event = process_sample_event, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 757 | .process_mmap_event = event__process_mmap, |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 758 | .process_comm_event = process_comm_event, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 759 | .process_exit_event = event__process_task, |
| 760 | .process_fork_event = event__process_task, |
| 761 | .process_lost_event = event__process_lost, |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 762 | .process_read_event = process_read_event, |
| 763 | .sample_type_check = sample_type_check, |
| 764 | }; |
| 765 | |
| 766 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 767 | static int __cmd_report(void) |
| 768 | { |
Frederic Weisbecker | 5b447a6 | 2009-08-31 06:45:18 +0200 | [diff] [blame] | 769 | struct thread *idle; |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 770 | int ret; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 771 | |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 772 | idle = register_idle_thread(); |
Frederic Weisbecker | 5b447a6 | 2009-08-31 06:45:18 +0200 | [diff] [blame] | 773 | thread__comm_adjust(idle); |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 774 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 775 | if (show_threads) |
| 776 | perf_read_values_init(&show_threads_values); |
| 777 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 778 | register_perf_file_handler(&file_handler); |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 779 | |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 780 | ret = mmap_dispatch_perf_file(&header, input_name, force, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 781 | full_paths, &event__cwdlen, &event__cwd); |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 782 | if (ret) |
| 783 | return ret; |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 784 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 785 | if (dump_trace) { |
| 786 | event__print_totals(); |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 787 | return 0; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 788 | } |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 789 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 790 | if (verbose > 3) |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 791 | threads__fprintf(stdout); |
Arnaldo Carvalho de Melo | 9ac9954 | 2009-06-04 13:54:00 -0300 | [diff] [blame] | 792 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 793 | if (verbose > 2) |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 794 | dsos__fprintf(stdout); |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 795 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 796 | collapse__resort(); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 797 | output__resort(event__stats.total); |
| 798 | output__fprintf(stdout, event__stats.total); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 799 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 800 | if (show_threads) |
| 801 | perf_read_values_destroy(&show_threads_values); |
| 802 | |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 803 | return ret; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 804 | } |
| 805 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 806 | static int |
| 807 | parse_callchain_opt(const struct option *opt __used, const char *arg, |
| 808 | int unset __used) |
| 809 | { |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 810 | char *tok; |
| 811 | char *endptr; |
| 812 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 813 | callchain = 1; |
| 814 | |
| 815 | if (!arg) |
| 816 | return 0; |
| 817 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 818 | tok = strtok((char *)arg, ","); |
| 819 | if (!tok) |
| 820 | return -1; |
| 821 | |
| 822 | /* get the output mode */ |
| 823 | if (!strncmp(tok, "graph", strlen(arg))) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 824 | callchain_param.mode = CHAIN_GRAPH_ABS; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 825 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 826 | else if (!strncmp(tok, "flat", strlen(arg))) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 827 | callchain_param.mode = CHAIN_FLAT; |
| 828 | |
| 829 | else if (!strncmp(tok, "fractal", strlen(arg))) |
| 830 | callchain_param.mode = CHAIN_GRAPH_REL; |
| 831 | |
Frederic Weisbecker | b1a8834 | 2009-08-08 02:16:24 +0200 | [diff] [blame] | 832 | else if (!strncmp(tok, "none", strlen(arg))) { |
| 833 | callchain_param.mode = CHAIN_NONE; |
| 834 | callchain = 0; |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 839 | else |
| 840 | return -1; |
| 841 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 842 | /* get the min percentage */ |
| 843 | tok = strtok(NULL, ","); |
| 844 | if (!tok) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 845 | goto setup; |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 846 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 847 | callchain_param.min_percent = strtod(tok, &endptr); |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 848 | if (tok == endptr) |
| 849 | return -1; |
| 850 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 851 | setup: |
| 852 | if (register_callchain_param(&callchain_param) < 0) { |
| 853 | fprintf(stderr, "Can't register callchain params\n"); |
| 854 | return -1; |
| 855 | } |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 859 | //static const char * const report_usage[] = { |
| 860 | const char * const report_usage[] = { |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 861 | "perf report [<options>] <command>", |
| 862 | NULL |
| 863 | }; |
| 864 | |
| 865 | static const struct option options[] = { |
| 866 | OPT_STRING('i', "input", &input_name, "file", |
| 867 | "input file name"), |
Arnaldo Carvalho de Melo | 815e777 | 2009-05-26 19:46:14 -0300 | [diff] [blame] | 868 | OPT_BOOLEAN('v', "verbose", &verbose, |
| 869 | "be more verbose (show symbol address, etc)"), |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 870 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 871 | "dump raw trace in ASCII"), |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 872 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 873 | "file", "vmlinux pathname"), |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 874 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 875 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 876 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 877 | OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples, |
| 878 | "Show a column with the number of samples"), |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 879 | OPT_BOOLEAN('T', "threads", &show_threads, |
| 880 | "Show per-thread event counters"), |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 881 | OPT_STRING(0, "pretty", &pretty_printing_style, "key", |
| 882 | "pretty printing style key: normal raw"), |
Ingo Molnar | 63299f0 | 2009-05-28 10:52:00 +0200 | [diff] [blame] | 883 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 884 | "sort by key(s): pid, comm, dso, symbol, parent"), |
Arnaldo Carvalho de Melo | b78c07d | 2009-05-29 13:48:59 -0300 | [diff] [blame] | 885 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
| 886 | "Don't shorten the pathnames taking into account the cwd"), |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 887 | OPT_STRING('p', "parent", &parent_pattern, "regex", |
| 888 | "regex filter to identify parent, see: '--sort parent'"), |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 889 | OPT_BOOLEAN('x', "exclude-other", &exclude_other, |
| 890 | "Only display entries with parent-match"), |
Anton Blanchard | 1483b19f | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 891 | OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent", |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 892 | "Display callchains using output_type and min percent threshold. " |
Anton Blanchard | 1483b19f | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 893 | "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt), |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 894 | OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]", |
| 895 | "only consider symbols in these dsos"), |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 896 | OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]", |
| 897 | "only consider symbols in these comms"), |
Arnaldo Carvalho de Melo | 7bec7a9 | 2009-06-30 19:01:22 -0300 | [diff] [blame] | 898 | OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]", |
| 899 | "only consider these symbols"), |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 900 | OPT_STRING('w', "column-widths", &col_width_list_str, |
| 901 | "width[,width...]", |
| 902 | "don't try to adjust column width, use these fixed values"), |
| 903 | OPT_STRING('t', "field-separator", &field_sep, "separator", |
| 904 | "separator for columns, no spaces will be added between " |
| 905 | "columns '.' is reserved."), |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 906 | OPT_END() |
| 907 | }; |
| 908 | |
Ingo Molnar | 5352f35 | 2009-06-03 10:07:39 +0200 | [diff] [blame] | 909 | static void setup_sorting(void) |
| 910 | { |
| 911 | char *tmp, *tok, *str = strdup(sort_order); |
| 912 | |
| 913 | for (tok = strtok_r(str, ", ", &tmp); |
| 914 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 915 | if (sort_dimension__add(tok) < 0) { |
| 916 | error("Unknown --sort key: `%s'", tok); |
| 917 | usage_with_options(report_usage, options); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | free(str); |
| 922 | } |
| 923 | |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 924 | static void setup_list(struct strlist **list, const char *list_str, |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 925 | struct sort_entry *se, const char *list_name, |
| 926 | FILE *fp) |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 927 | { |
| 928 | if (list_str) { |
| 929 | *list = strlist__new(true, list_str); |
| 930 | if (!*list) { |
| 931 | fprintf(stderr, "problems parsing %s list\n", |
| 932 | list_name); |
| 933 | exit(129); |
| 934 | } |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 935 | if (strlist__nr_entries(*list) == 1) { |
| 936 | fprintf(fp, "# %s: %s\n", list_name, |
| 937 | strlist__entry(*list, 0)->s); |
| 938 | se->elide = true; |
| 939 | } |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 943 | int cmd_report(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 944 | { |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 945 | if (symbol__init(&symbol_conf) < 0) |
| 946 | return -1; |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 947 | |
Ingo Molnar | edc52de | 2009-06-04 16:24:37 +0200 | [diff] [blame] | 948 | argc = parse_options(argc, argv, options, report_usage, 0); |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 949 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 950 | setup_sorting(); |
| 951 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 952 | if (parent_pattern != default_parent_pattern) { |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 953 | sort_dimension__add("parent"); |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 954 | sort_parent.elide = 1; |
| 955 | } else |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 956 | exclude_other = 0; |
| 957 | |
Ingo Molnar | edc52de | 2009-06-04 16:24:37 +0200 | [diff] [blame] | 958 | /* |
| 959 | * Any (unrecognized) arguments left? |
| 960 | */ |
| 961 | if (argc) |
| 962 | usage_with_options(report_usage, options); |
| 963 | |
Ingo Molnar | a930d2c | 2009-05-27 09:50:13 +0200 | [diff] [blame] | 964 | setup_pager(); |
| 965 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 966 | setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout); |
| 967 | setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout); |
| 968 | setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 969 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 970 | if (field_sep && *field_sep == '.') { |
| 971 | fputs("'.' is the only non valid --field-separator argument\n", |
| 972 | stderr); |
| 973 | exit(129); |
| 974 | } |
| 975 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 976 | return __cmd_report(); |
| 977 | } |