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" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 23 | #include "util/header.h" |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 24 | |
| 25 | #include "util/parse-options.h" |
| 26 | #include "util/parse-events.h" |
| 27 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 28 | #define SHOW_KERNEL 1 |
| 29 | #define SHOW_USER 2 |
| 30 | #define SHOW_HV 4 |
| 31 | |
Ingo Molnar | 23ac9cb | 2009-05-27 09:33:18 +0200 | [diff] [blame] | 32 | static char const *input_name = "perf.data"; |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 33 | |
Pekka Enberg | 114cfab | 2009-08-05 13:25:21 +0300 | [diff] [blame] | 34 | static char default_sort_order[] = "comm,dso,symbol"; |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 35 | static char *sort_order = default_sort_order; |
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; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 39 | static char *field_sep; |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 40 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 41 | static int input; |
| 42 | static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; |
| 43 | |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 44 | static int dump_trace = 0; |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 45 | #define dprintf(x...) do { if (dump_trace) printf(x); } while (0) |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 46 | #define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0) |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 47 | |
Arnaldo Carvalho de Melo | b78c07d | 2009-05-29 13:48:59 -0300 | [diff] [blame] | 48 | static int full_paths; |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 49 | static int show_nr_samples; |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 50 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 51 | static int show_threads; |
| 52 | static struct perf_read_values show_threads_values; |
| 53 | |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 54 | static char default_pretty_printing_style[] = "normal"; |
| 55 | static char *pretty_printing_style = default_pretty_printing_style; |
| 56 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 57 | static unsigned long page_size; |
| 58 | static unsigned long mmap_window = 32; |
| 59 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 60 | static char default_parent_pattern[] = "^sys_|^do_page_fault"; |
| 61 | static char *parent_pattern = default_parent_pattern; |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 62 | static regex_t parent_regex; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 63 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 64 | static int exclude_other = 1; |
Frederic Weisbecker | be90388 | 2009-07-05 07:39:18 +0200 | [diff] [blame] | 65 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 66 | static char callchain_default_opt[] = "fractal,0.5"; |
| 67 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 68 | static int callchain; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 69 | |
Frederic Weisbecker | 66e274f | 2009-08-12 11:07:25 +0200 | [diff] [blame] | 70 | static char __cwd[PATH_MAX]; |
| 71 | static char *cwd = __cwd; |
| 72 | static int cwdlen; |
| 73 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 74 | static |
| 75 | struct callchain_param callchain_param = { |
Frederic Weisbecker | b1a8834 | 2009-08-08 02:16:24 +0200 | [diff] [blame] | 76 | .mode = CHAIN_GRAPH_REL, |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 77 | .min_percent = 0.5 |
| 78 | }; |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 79 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 80 | static u64 sample_type; |
| 81 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 82 | static int repsep_fprintf(FILE *fp, const char *fmt, ...) |
| 83 | { |
| 84 | int n; |
| 85 | va_list ap; |
| 86 | |
| 87 | va_start(ap, fmt); |
| 88 | if (!field_sep) |
| 89 | n = vfprintf(fp, fmt, ap); |
| 90 | else { |
| 91 | char *bf = NULL; |
| 92 | n = vasprintf(&bf, fmt, ap); |
| 93 | if (n > 0) { |
| 94 | char *sep = bf; |
| 95 | while (1) { |
| 96 | sep = strchr(sep, *field_sep); |
| 97 | if (sep == NULL) |
| 98 | break; |
| 99 | *sep = '.'; |
| 100 | } |
| 101 | } |
| 102 | fputs(bf, fp); |
| 103 | free(bf); |
| 104 | } |
| 105 | va_end(ap); |
| 106 | return n; |
| 107 | } |
| 108 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 109 | struct thread { |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 110 | struct rb_node rb_node; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 111 | struct list_head maps; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 112 | pid_t pid; |
| 113 | char *comm; |
| 114 | }; |
| 115 | |
| 116 | static struct thread *thread__new(pid_t pid) |
| 117 | { |
| 118 | struct thread *self = malloc(sizeof(*self)); |
| 119 | |
| 120 | if (self != NULL) { |
| 121 | self->pid = pid; |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 122 | self->comm = malloc(32); |
Ingo Molnar | 0a520c6 | 2009-06-02 23:24:45 +0200 | [diff] [blame] | 123 | if (self->comm) |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 124 | snprintf(self->comm, 32, ":%d", self->pid); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 125 | INIT_LIST_HEAD(&self->maps); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return self; |
| 129 | } |
| 130 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 131 | static unsigned int dsos__col_width, |
| 132 | comms__col_width, |
| 133 | threads__col_width; |
| 134 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 135 | static int thread__set_comm(struct thread *self, const char *comm) |
| 136 | { |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 137 | if (self->comm) |
| 138 | free(self->comm); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 139 | self->comm = strdup(comm); |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 140 | if (!self->comm) |
| 141 | return -ENOMEM; |
| 142 | |
| 143 | if (!col_width_list_str && !field_sep && |
| 144 | (!comm_list || strlist__has_entry(comm_list, comm))) { |
| 145 | unsigned int slen = strlen(comm); |
| 146 | if (slen > comms__col_width) { |
| 147 | comms__col_width = slen; |
| 148 | threads__col_width = slen + 6; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return 0; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 153 | } |
| 154 | |
Arnaldo Carvalho de Melo | 9ac9954 | 2009-06-04 13:54:00 -0300 | [diff] [blame] | 155 | static size_t thread__fprintf(struct thread *self, FILE *fp) |
| 156 | { |
| 157 | struct map *pos; |
| 158 | size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm); |
| 159 | |
| 160 | list_for_each_entry(pos, &self->maps, node) |
| 161 | ret += map__fprintf(pos, fp); |
| 162 | |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 167 | static struct rb_root threads; |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 168 | static struct thread *last_match; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 169 | |
| 170 | static struct thread *threads__findnew(pid_t pid) |
| 171 | { |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 172 | struct rb_node **p = &threads.rb_node; |
| 173 | struct rb_node *parent = NULL; |
| 174 | struct thread *th; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 175 | |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 176 | /* |
| 177 | * Font-end cache - PID lookups come in blocks, |
| 178 | * so most of the time we dont have to look up |
| 179 | * the full rbtree: |
| 180 | */ |
| 181 | if (last_match && last_match->pid == pid) |
| 182 | return last_match; |
| 183 | |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 184 | while (*p != NULL) { |
| 185 | parent = *p; |
| 186 | th = rb_entry(parent, struct thread, rb_node); |
| 187 | |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 188 | if (th->pid == pid) { |
| 189 | last_match = th; |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 190 | return th; |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 191 | } |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 192 | |
| 193 | if (pid < th->pid) |
| 194 | p = &(*p)->rb_left; |
| 195 | else |
| 196 | p = &(*p)->rb_right; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 197 | } |
| 198 | |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 199 | th = thread__new(pid); |
| 200 | if (th != NULL) { |
| 201 | rb_link_node(&th->rb_node, parent, p); |
| 202 | rb_insert_color(&th->rb_node, &threads); |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 203 | last_match = th; |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 204 | } |
Ingo Molnar | eed4dcd | 2009-06-03 19:59:24 +0200 | [diff] [blame] | 205 | |
Arnaldo Carvalho de Melo | ce7e436 | 2009-05-19 09:30:23 -0300 | [diff] [blame] | 206 | return th; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void thread__insert_map(struct thread *self, struct map *map) |
| 210 | { |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 211 | struct map *pos, *tmp; |
| 212 | |
| 213 | list_for_each_entry_safe(pos, tmp, &self->maps, node) { |
| 214 | if (map__overlap(pos, map)) { |
Peter Zijlstra | 3d906ef | 2009-06-23 11:23:07 +0200 | [diff] [blame] | 215 | if (verbose >= 2) { |
| 216 | printf("overlapping maps:\n"); |
| 217 | map__fprintf(map, stdout); |
| 218 | map__fprintf(pos, stdout); |
| 219 | } |
| 220 | |
| 221 | if (map->start <= pos->start && map->end > pos->start) |
| 222 | pos->start = map->end; |
| 223 | |
| 224 | if (map->end >= pos->end && map->start < pos->end) |
| 225 | pos->end = map->start; |
| 226 | |
| 227 | if (verbose >= 2) { |
| 228 | printf("after collision:\n"); |
| 229 | map__fprintf(pos, stdout); |
| 230 | } |
| 231 | |
| 232 | if (pos->start >= pos->end) { |
| 233 | list_del_init(&pos->node); |
| 234 | free(pos); |
| 235 | } |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 239 | list_add_tail(&map->node, &self->maps); |
| 240 | } |
| 241 | |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 242 | static int thread__fork(struct thread *self, struct thread *parent) |
| 243 | { |
| 244 | struct map *map; |
| 245 | |
| 246 | if (self->comm) |
| 247 | free(self->comm); |
| 248 | self->comm = strdup(parent->comm); |
| 249 | if (!self->comm) |
| 250 | return -ENOMEM; |
| 251 | |
| 252 | list_for_each_entry(map, &parent->maps, node) { |
| 253 | struct map *new = map__clone(map); |
| 254 | if (!new) |
| 255 | return -ENOMEM; |
| 256 | thread__insert_map(self, new); |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 262 | static struct map *thread__find_map(struct thread *self, u64 ip) |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 263 | { |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 264 | struct map *pos; |
| 265 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 266 | if (self == NULL) |
| 267 | return NULL; |
| 268 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 269 | list_for_each_entry(pos, &self->maps, node) |
| 270 | if (ip >= pos->start && ip <= pos->end) |
| 271 | return pos; |
| 272 | |
| 273 | return NULL; |
| 274 | } |
| 275 | |
Arnaldo Carvalho de Melo | 9ac9954 | 2009-06-04 13:54:00 -0300 | [diff] [blame] | 276 | static size_t threads__fprintf(FILE *fp) |
| 277 | { |
| 278 | size_t ret = 0; |
| 279 | struct rb_node *nd; |
| 280 | |
| 281 | for (nd = rb_first(&threads); nd; nd = rb_next(nd)) { |
| 282 | struct thread *pos = rb_entry(nd, struct thread, rb_node); |
| 283 | |
| 284 | ret += thread__fprintf(pos, fp); |
| 285 | } |
| 286 | |
| 287 | return ret; |
| 288 | } |
| 289 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 290 | /* |
| 291 | * histogram, sorted on item, collects counts |
| 292 | */ |
| 293 | |
| 294 | static struct rb_root hist; |
| 295 | |
| 296 | struct hist_entry { |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 297 | struct rb_node rb_node; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 298 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 299 | struct thread *thread; |
| 300 | struct map *map; |
| 301 | struct dso *dso; |
| 302 | struct symbol *sym; |
| 303 | struct symbol *parent; |
| 304 | u64 ip; |
| 305 | char level; |
| 306 | struct callchain_node callchain; |
| 307 | struct rb_root sorted_chain; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 308 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 309 | u64 count; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 310 | }; |
| 311 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 312 | /* |
| 313 | * configurable sorting bits |
| 314 | */ |
| 315 | |
| 316 | struct sort_entry { |
| 317 | struct list_head list; |
| 318 | |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 319 | char *header; |
| 320 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 321 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 322 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 323 | size_t (*print)(FILE *fp, struct hist_entry *, unsigned int width); |
| 324 | unsigned int *width; |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 325 | bool elide; |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 326 | }; |
| 327 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 328 | static int64_t cmp_null(void *l, void *r) |
| 329 | { |
| 330 | if (!l && !r) |
| 331 | return 0; |
| 332 | else if (!l) |
| 333 | return -1; |
| 334 | else |
| 335 | return 1; |
| 336 | } |
| 337 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 338 | /* --sort pid */ |
| 339 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 340 | static int64_t |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 341 | sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) |
| 342 | { |
| 343 | return right->thread->pid - left->thread->pid; |
| 344 | } |
| 345 | |
| 346 | static size_t |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 347 | sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width) |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 348 | { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 349 | return repsep_fprintf(fp, "%*s:%5d", width - 6, |
| 350 | self->thread->comm ?: "", self->thread->pid); |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static struct sort_entry sort_thread = { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 354 | .header = "Command: Pid", |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 355 | .cmp = sort__thread_cmp, |
| 356 | .print = sort__thread_print, |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 357 | .width = &threads__col_width, |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 358 | }; |
| 359 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 360 | /* --sort comm */ |
| 361 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 362 | static int64_t |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 363 | sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) |
| 364 | { |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 365 | return right->thread->pid - left->thread->pid; |
| 366 | } |
| 367 | |
| 368 | static int64_t |
| 369 | sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) |
| 370 | { |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 371 | char *comm_l = left->thread->comm; |
| 372 | char *comm_r = right->thread->comm; |
| 373 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 374 | if (!comm_l || !comm_r) |
| 375 | return cmp_null(comm_l, comm_r); |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 376 | |
| 377 | return strcmp(comm_l, comm_r); |
| 378 | } |
| 379 | |
| 380 | static size_t |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 381 | sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 382 | { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 383 | return repsep_fprintf(fp, "%*s", width, self->thread->comm); |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static struct sort_entry sort_comm = { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 387 | .header = "Command", |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 388 | .cmp = sort__comm_cmp, |
| 389 | .collapse = sort__comm_collapse, |
| 390 | .print = sort__comm_print, |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 391 | .width = &comms__col_width, |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 392 | }; |
| 393 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 394 | /* --sort dso */ |
| 395 | |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 396 | static int64_t |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 397 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
| 398 | { |
| 399 | struct dso *dso_l = left->dso; |
| 400 | struct dso *dso_r = right->dso; |
| 401 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 402 | if (!dso_l || !dso_r) |
| 403 | return cmp_null(dso_l, dso_r); |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 404 | |
| 405 | return strcmp(dso_l->name, dso_r->name); |
| 406 | } |
| 407 | |
| 408 | static size_t |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 409 | sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width) |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 410 | { |
Ingo Molnar | 0a520c6 | 2009-06-02 23:24:45 +0200 | [diff] [blame] | 411 | if (self->dso) |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 412 | return repsep_fprintf(fp, "%-*s", width, self->dso->name); |
Ingo Molnar | 0a520c6 | 2009-06-02 23:24:45 +0200 | [diff] [blame] | 413 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 414 | return repsep_fprintf(fp, "%*llx", width, (u64)self->ip); |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static struct sort_entry sort_dso = { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 418 | .header = "Shared Object", |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 419 | .cmp = sort__dso_cmp, |
| 420 | .print = sort__dso_print, |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 421 | .width = &dsos__col_width, |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 422 | }; |
| 423 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 424 | /* --sort symbol */ |
| 425 | |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 426 | static int64_t |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 427 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 428 | { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 429 | u64 ip_l, ip_r; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 430 | |
| 431 | if (left->sym == right->sym) |
| 432 | return 0; |
| 433 | |
| 434 | ip_l = left->sym ? left->sym->start : left->ip; |
| 435 | ip_r = right->sym ? right->sym->start : right->ip; |
| 436 | |
| 437 | return (int64_t)(ip_r - ip_l); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 438 | } |
| 439 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 440 | static size_t |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 441 | sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used) |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 442 | { |
| 443 | size_t ret = 0; |
| 444 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 445 | if (verbose) |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 446 | ret += repsep_fprintf(fp, "%#018llx %c ", (u64)self->ip, |
| 447 | dso__symtab_origin(self->dso)); |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 448 | |
Arnaldo Carvalho de Melo | 60c1baf | 2009-07-11 12:18:33 -0300 | [diff] [blame] | 449 | ret += repsep_fprintf(fp, "[%c] ", self->level); |
Ingo Molnar | 8edd428 | 2009-06-05 14:13:18 +0200 | [diff] [blame] | 450 | if (self->sym) { |
Arnaldo Carvalho de Melo | 60c1baf | 2009-07-11 12:18:33 -0300 | [diff] [blame] | 451 | ret += repsep_fprintf(fp, "%s", self->sym->name); |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 452 | |
| 453 | if (self->sym->module) |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 454 | ret += repsep_fprintf(fp, "\t[%s]", |
| 455 | self->sym->module->name); |
Ingo Molnar | 8edd428 | 2009-06-05 14:13:18 +0200 | [diff] [blame] | 456 | } else { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 457 | ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip); |
Ingo Molnar | 8edd428 | 2009-06-05 14:13:18 +0200 | [diff] [blame] | 458 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 459 | |
| 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | static struct sort_entry sort_sym = { |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 464 | .header = "Symbol", |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 465 | .cmp = sort__sym_cmp, |
| 466 | .print = sort__sym_print, |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 467 | }; |
| 468 | |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 469 | /* --sort parent */ |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 470 | |
| 471 | static int64_t |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 472 | sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 473 | { |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 474 | struct symbol *sym_l = left->parent; |
| 475 | struct symbol *sym_r = right->parent; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 476 | |
| 477 | if (!sym_l || !sym_r) |
| 478 | return cmp_null(sym_l, sym_r); |
| 479 | |
| 480 | return strcmp(sym_l->name, sym_r->name); |
| 481 | } |
| 482 | |
| 483 | static size_t |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 484 | sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width) |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 485 | { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 486 | return repsep_fprintf(fp, "%-*s", width, |
| 487 | self->parent ? self->parent->name : "[other]"); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 488 | } |
| 489 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 490 | static unsigned int parent_symbol__col_width; |
| 491 | |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 492 | static struct sort_entry sort_parent = { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 493 | .header = "Parent symbol", |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 494 | .cmp = sort__parent_cmp, |
| 495 | .print = sort__parent_print, |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 496 | .width = &parent_symbol__col_width, |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 497 | }; |
| 498 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 499 | static int sort__need_collapse = 0; |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 500 | static int sort__has_parent = 0; |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 501 | |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 502 | struct sort_dimension { |
Ingo Molnar | 8edd428 | 2009-06-05 14:13:18 +0200 | [diff] [blame] | 503 | char *name; |
| 504 | struct sort_entry *entry; |
| 505 | int taken; |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | static struct sort_dimension sort_dimensions[] = { |
| 509 | { .name = "pid", .entry = &sort_thread, }, |
Peter Zijlstra | 992444b | 2009-05-27 20:20:27 +0200 | [diff] [blame] | 510 | { .name = "comm", .entry = &sort_comm, }, |
Peter Zijlstra | 55e5ec4 | 2009-05-27 20:20:28 +0200 | [diff] [blame] | 511 | { .name = "dso", .entry = &sort_dso, }, |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 512 | { .name = "symbol", .entry = &sort_sym, }, |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 513 | { .name = "parent", .entry = &sort_parent, }, |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 514 | }; |
| 515 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 516 | static LIST_HEAD(hist_entry__sort_list); |
| 517 | |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 518 | static int sort_dimension__add(char *tok) |
| 519 | { |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 520 | unsigned int i; |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 521 | |
| 522 | for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) { |
| 523 | struct sort_dimension *sd = &sort_dimensions[i]; |
| 524 | |
| 525 | if (sd->taken) |
| 526 | continue; |
| 527 | |
Ingo Molnar | 5352f35 | 2009-06-03 10:07:39 +0200 | [diff] [blame] | 528 | if (strncasecmp(tok, sd->name, strlen(tok))) |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 529 | continue; |
| 530 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 531 | if (sd->entry->collapse) |
| 532 | sort__need_collapse = 1; |
| 533 | |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 534 | if (sd->entry == &sort_parent) { |
| 535 | int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 536 | if (ret) { |
| 537 | char err[BUFSIZ]; |
| 538 | |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 539 | regerror(ret, &parent_regex, err, sizeof(err)); |
| 540 | fprintf(stderr, "Invalid regex: %s\n%s", |
| 541 | parent_pattern, err); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 542 | exit(-1); |
| 543 | } |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 544 | sort__has_parent = 1; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 545 | } |
| 546 | |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 547 | list_add_tail(&sd->entry->list, &hist_entry__sort_list); |
| 548 | sd->taken = 1; |
Ingo Molnar | 5352f35 | 2009-06-03 10:07:39 +0200 | [diff] [blame] | 549 | |
Peter Zijlstra | 37f440c | 2009-05-27 20:20:26 +0200 | [diff] [blame] | 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | return -ESRCH; |
| 554 | } |
| 555 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 556 | static int64_t |
| 557 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 558 | { |
| 559 | struct sort_entry *se; |
| 560 | int64_t cmp = 0; |
| 561 | |
| 562 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 563 | cmp = se->cmp(left, right); |
| 564 | if (cmp) |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | return cmp; |
| 569 | } |
| 570 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 571 | static int64_t |
| 572 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 573 | { |
| 574 | struct sort_entry *se; |
| 575 | int64_t cmp = 0; |
| 576 | |
| 577 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 578 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 579 | |
| 580 | f = se->collapse ?: se->cmp; |
| 581 | |
| 582 | cmp = f(left, right); |
| 583 | if (cmp) |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | return cmp; |
| 588 | } |
| 589 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 590 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask) |
| 591 | { |
| 592 | int i; |
| 593 | size_t ret = 0; |
| 594 | |
| 595 | ret += fprintf(fp, "%s", " "); |
| 596 | |
| 597 | for (i = 0; i < depth; i++) |
| 598 | if (depth_mask & (1 << i)) |
| 599 | ret += fprintf(fp, "| "); |
| 600 | else |
| 601 | ret += fprintf(fp, " "); |
| 602 | |
| 603 | ret += fprintf(fp, "\n"); |
| 604 | |
| 605 | return ret; |
| 606 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 607 | static size_t |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 608 | ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth, |
| 609 | int depth_mask, int count, u64 total_samples, |
| 610 | int hits) |
| 611 | { |
| 612 | int i; |
| 613 | size_t ret = 0; |
| 614 | |
| 615 | ret += fprintf(fp, "%s", " "); |
| 616 | for (i = 0; i < depth; i++) { |
| 617 | if (depth_mask & (1 << i)) |
| 618 | ret += fprintf(fp, "|"); |
| 619 | else |
| 620 | ret += fprintf(fp, " "); |
| 621 | if (!count && i == depth - 1) { |
| 622 | double percent; |
| 623 | |
| 624 | percent = hits * 100.0 / total_samples; |
Frederic Weisbecker | 24b57c6 | 2009-07-02 20:14:35 +0200 | [diff] [blame] | 625 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 626 | } else |
| 627 | ret += fprintf(fp, "%s", " "); |
| 628 | } |
| 629 | if (chain->sym) |
| 630 | ret += fprintf(fp, "%s\n", chain->sym->name); |
| 631 | else |
| 632 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
| 633 | |
| 634 | return ret; |
| 635 | } |
| 636 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 637 | static struct symbol *rem_sq_bracket; |
| 638 | static struct callchain_list rem_hits; |
| 639 | |
| 640 | static void init_rem_hits(void) |
| 641 | { |
| 642 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 643 | if (!rem_sq_bracket) { |
| 644 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | strcpy(rem_sq_bracket->name, "[...]"); |
| 649 | rem_hits.sym = rem_sq_bracket; |
| 650 | } |
| 651 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 652 | static size_t |
| 653 | callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
| 654 | u64 total_samples, int depth, int depth_mask) |
| 655 | { |
| 656 | struct rb_node *node, *next; |
| 657 | struct callchain_node *child; |
| 658 | struct callchain_list *chain; |
| 659 | int new_depth_mask = depth_mask; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 660 | u64 new_total; |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 661 | u64 remaining; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 662 | size_t ret = 0; |
| 663 | int i; |
| 664 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 665 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
Frederic Weisbecker | 1953287 | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 666 | new_total = self->children_hit; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 667 | else |
| 668 | new_total = total_samples; |
| 669 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 670 | remaining = new_total; |
| 671 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 672 | node = rb_first(&self->rb_root); |
| 673 | while (node) { |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 674 | u64 cumul; |
| 675 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 676 | child = rb_entry(node, struct callchain_node, rb_node); |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 677 | cumul = cumul_hits(child); |
| 678 | remaining -= cumul; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 679 | |
| 680 | /* |
| 681 | * The depth mask manages the output of pipes that show |
| 682 | * 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] | 683 | * level for the last child of this depth. |
| 684 | * Except if we have remaining filtered hits. They will |
| 685 | * supersede the last child |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 686 | */ |
| 687 | next = rb_next(node); |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 688 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 689 | new_depth_mask &= ~(1 << (depth - 1)); |
| 690 | |
| 691 | /* |
| 692 | * But we keep the older depth mask for the line seperator |
| 693 | * to keep the level link until we reach the last child |
| 694 | */ |
| 695 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask); |
| 696 | i = 0; |
| 697 | list_for_each_entry(chain, &child->val, list) { |
| 698 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 699 | continue; |
| 700 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 701 | new_depth_mask, i++, |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 702 | new_total, |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 703 | cumul); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 704 | } |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 705 | ret += callchain__fprintf_graph(fp, child, new_total, |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 706 | depth + 1, |
| 707 | new_depth_mask | (1 << depth)); |
| 708 | node = next; |
| 709 | } |
| 710 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 711 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 712 | remaining && remaining != new_total) { |
| 713 | |
| 714 | if (!rem_sq_bracket) |
| 715 | return ret; |
| 716 | |
| 717 | new_depth_mask &= ~(1 << (depth - 1)); |
| 718 | |
| 719 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
| 720 | new_depth_mask, 0, new_total, |
| 721 | remaining); |
| 722 | } |
| 723 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | static size_t |
| 728 | callchain__fprintf_flat(FILE *fp, struct callchain_node *self, |
| 729 | u64 total_samples) |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 730 | { |
| 731 | struct callchain_list *chain; |
| 732 | size_t ret = 0; |
| 733 | |
| 734 | if (!self) |
| 735 | return 0; |
| 736 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 737 | ret += callchain__fprintf_flat(fp, self->parent, total_samples); |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 738 | |
| 739 | |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 740 | list_for_each_entry(chain, &self->val, list) { |
| 741 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 742 | continue; |
| 743 | if (chain->sym) |
| 744 | ret += fprintf(fp, " %s\n", chain->sym->name); |
| 745 | else |
| 746 | ret += fprintf(fp, " %p\n", |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 747 | (void *)(long)chain->ip); |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 748 | } |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 749 | |
| 750 | return ret; |
| 751 | } |
| 752 | |
| 753 | static size_t |
| 754 | hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, |
| 755 | u64 total_samples) |
| 756 | { |
| 757 | struct rb_node *rb_node; |
| 758 | struct callchain_node *chain; |
| 759 | size_t ret = 0; |
| 760 | |
| 761 | rb_node = rb_first(&self->sorted_chain); |
| 762 | while (rb_node) { |
| 763 | double percent; |
| 764 | |
| 765 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 766 | percent = chain->hit * 100.0 / total_samples; |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 767 | switch (callchain_param.mode) { |
| 768 | case CHAIN_FLAT: |
Frederic Weisbecker | 24b57c6 | 2009-07-02 20:14:35 +0200 | [diff] [blame] | 769 | ret += percent_color_fprintf(fp, " %6.2f%%\n", |
| 770 | percent); |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 771 | ret += callchain__fprintf_flat(fp, chain, total_samples); |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 772 | break; |
| 773 | case CHAIN_GRAPH_ABS: /* Falldown */ |
| 774 | case CHAIN_GRAPH_REL: |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 775 | ret += callchain__fprintf_graph(fp, chain, |
| 776 | total_samples, 1, 1); |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 777 | default: |
| 778 | break; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 779 | } |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 780 | ret += fprintf(fp, "\n"); |
| 781 | rb_node = rb_next(rb_node); |
| 782 | } |
| 783 | |
| 784 | return ret; |
| 785 | } |
| 786 | |
| 787 | |
| 788 | static size_t |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 789 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 790 | { |
| 791 | struct sort_entry *se; |
| 792 | size_t ret; |
| 793 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 794 | if (exclude_other && !self->parent) |
| 795 | return 0; |
| 796 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 797 | if (total_samples) |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 798 | ret = percent_color_fprintf(fp, |
| 799 | field_sep ? "%.2f" : " %6.2f%%", |
| 800 | (self->count * 100.0) / total_samples); |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 801 | else |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 802 | ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count); |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 803 | |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 804 | if (show_nr_samples) { |
| 805 | if (field_sep) |
| 806 | fprintf(fp, "%c%lld", *field_sep, self->count); |
| 807 | else |
| 808 | fprintf(fp, "%11lld", self->count); |
| 809 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 810 | |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 811 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 812 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 813 | continue; |
| 814 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 815 | fprintf(fp, "%s", field_sep ?: " "); |
| 816 | ret += se->print(fp, self, se->width ? *se->width : 0); |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 817 | } |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 818 | |
| 819 | ret += fprintf(fp, "\n"); |
| 820 | |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 821 | if (callchain) |
| 822 | hist_entry_callchain__fprintf(fp, self, total_samples); |
| 823 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | /* |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 828 | * |
| 829 | */ |
| 830 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 831 | static void dso__calc_col_width(struct dso *self) |
| 832 | { |
| 833 | if (!col_width_list_str && !field_sep && |
| 834 | (!dso_list || strlist__has_entry(dso_list, self->name))) { |
| 835 | unsigned int slen = strlen(self->name); |
| 836 | if (slen > dsos__col_width) |
| 837 | dsos__col_width = slen; |
| 838 | } |
| 839 | |
| 840 | self->slen_calculated = 1; |
| 841 | } |
| 842 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 843 | static struct symbol * |
| 844 | resolve_symbol(struct thread *thread, struct map **mapp, |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 845 | struct dso **dsop, u64 *ipp) |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 846 | { |
| 847 | struct dso *dso = dsop ? *dsop : NULL; |
| 848 | struct map *map = mapp ? *mapp : NULL; |
Peter Zijlstra | 520f2c3 | 2009-06-22 16:52:51 +0200 | [diff] [blame] | 849 | u64 ip = *ipp; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 850 | |
| 851 | if (!thread) |
| 852 | return NULL; |
| 853 | |
| 854 | if (dso) |
| 855 | goto got_dso; |
| 856 | |
| 857 | if (map) |
| 858 | goto got_map; |
| 859 | |
| 860 | map = thread__find_map(thread, ip); |
| 861 | if (map != NULL) { |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 862 | /* |
| 863 | * We have to do this here as we may have a dso |
| 864 | * with no symbol hit that has a name longer than |
| 865 | * the ones with symbols sampled. |
| 866 | */ |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 867 | if (!sort_dso.elide && !map->dso->slen_calculated) |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 868 | dso__calc_col_width(map->dso); |
| 869 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 870 | if (mapp) |
| 871 | *mapp = map; |
| 872 | got_map: |
| 873 | ip = map->map_ip(map, ip); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 874 | |
| 875 | dso = map->dso; |
| 876 | } else { |
| 877 | /* |
| 878 | * If this is outside of all known maps, |
| 879 | * and is a negative address, try to look it |
| 880 | * up in the kernel dso, as it might be a |
| 881 | * vsyscall (which executes in user-mode): |
| 882 | */ |
| 883 | if ((long long)ip < 0) |
| 884 | dso = kernel_dso; |
| 885 | } |
| 886 | dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>"); |
Peter Zijlstra | 520f2c3 | 2009-06-22 16:52:51 +0200 | [diff] [blame] | 887 | dprintf(" ...... map: %Lx -> %Lx\n", *ipp, ip); |
| 888 | *ipp = ip; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 889 | |
| 890 | if (dsop) |
| 891 | *dsop = dso; |
| 892 | |
| 893 | if (!dso) |
| 894 | return NULL; |
| 895 | got_dso: |
| 896 | return dso->find_symbol(dso, ip); |
| 897 | } |
| 898 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 899 | static int call__match(struct symbol *sym) |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 900 | { |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 901 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 902 | return 1; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 903 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 904 | return 0; |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 907 | static struct symbol ** |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 908 | resolve_callchain(struct thread *thread, struct map *map __used, |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 909 | struct ip_callchain *chain, struct hist_entry *entry) |
| 910 | { |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 911 | u64 context = PERF_CONTEXT_MAX; |
Ingo Molnar | 029e5b1 | 2009-07-03 13:17:28 +0200 | [diff] [blame] | 912 | struct symbol **syms = NULL; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 913 | unsigned int i; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 914 | |
| 915 | if (callchain) { |
| 916 | syms = calloc(chain->nr, sizeof(*syms)); |
| 917 | if (!syms) { |
| 918 | fprintf(stderr, "Can't allocate memory for symbols\n"); |
| 919 | exit(-1); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | for (i = 0; i < chain->nr; i++) { |
| 924 | u64 ip = chain->ips[i]; |
| 925 | struct dso *dso = NULL; |
| 926 | struct symbol *sym; |
| 927 | |
| 928 | if (ip >= PERF_CONTEXT_MAX) { |
| 929 | context = ip; |
| 930 | continue; |
| 931 | } |
| 932 | |
| 933 | switch (context) { |
Ingo Molnar | 88a69df | 2009-07-01 11:17:20 +0200 | [diff] [blame] | 934 | case PERF_CONTEXT_HV: |
| 935 | dso = hypervisor_dso; |
| 936 | break; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 937 | case PERF_CONTEXT_KERNEL: |
| 938 | dso = kernel_dso; |
| 939 | break; |
| 940 | default: |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | sym = resolve_symbol(thread, NULL, &dso, &ip); |
| 945 | |
| 946 | if (sym) { |
| 947 | if (sort__has_parent && call__match(sym) && |
| 948 | !entry->parent) |
| 949 | entry->parent = sym; |
| 950 | if (!callchain) |
| 951 | break; |
| 952 | syms[i] = sym; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | return syms; |
| 957 | } |
| 958 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 959 | /* |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 960 | * collect histogram counts |
| 961 | */ |
| 962 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 963 | static int |
| 964 | hist_entry__add(struct thread *thread, struct map *map, struct dso *dso, |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 965 | struct symbol *sym, u64 ip, struct ip_callchain *chain, |
| 966 | char level, u64 count) |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 967 | { |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 968 | struct rb_node **p = &hist.rb_node; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 969 | struct rb_node *parent = NULL; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 970 | struct hist_entry *he; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 971 | struct symbol **syms = NULL; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 972 | struct hist_entry entry = { |
| 973 | .thread = thread, |
| 974 | .map = map, |
| 975 | .dso = dso, |
| 976 | .sym = sym, |
| 977 | .ip = ip, |
| 978 | .level = level, |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 979 | .count = count, |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 980 | .parent = NULL, |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 981 | .sorted_chain = RB_ROOT |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 982 | }; |
| 983 | int cmp; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 984 | |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 985 | if ((sort__has_parent || callchain) && chain) |
| 986 | syms = resolve_callchain(thread, map, chain, &entry); |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 987 | |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 988 | while (*p != NULL) { |
| 989 | parent = *p; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 990 | he = rb_entry(parent, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 991 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 992 | cmp = hist_entry__cmp(&entry, he); |
| 993 | |
| 994 | if (!cmp) { |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 995 | he->count += count; |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 996 | if (callchain) { |
| 997 | append_chain(&he->callchain, chain, syms); |
| 998 | free(syms); |
| 999 | } |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | if (cmp < 0) |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1004 | p = &(*p)->rb_left; |
| 1005 | else |
| 1006 | p = &(*p)->rb_right; |
| 1007 | } |
| 1008 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1009 | he = malloc(sizeof(*he)); |
| 1010 | if (!he) |
| 1011 | return -ENOMEM; |
| 1012 | *he = entry; |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 1013 | if (callchain) { |
| 1014 | callchain_init(&he->callchain); |
Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 1015 | append_chain(&he->callchain, chain, syms); |
| 1016 | free(syms); |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 1017 | } |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1018 | rb_link_node(&he->rb_node, parent, p); |
| 1019 | rb_insert_color(&he->rb_node, &hist); |
| 1020 | |
| 1021 | return 0; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1022 | } |
| 1023 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 1024 | static void hist_entry__free(struct hist_entry *he) |
| 1025 | { |
| 1026 | free(he); |
| 1027 | } |
| 1028 | |
| 1029 | /* |
| 1030 | * collapse the histogram |
| 1031 | */ |
| 1032 | |
| 1033 | static struct rb_root collapse_hists; |
| 1034 | |
| 1035 | static void collapse__insert_entry(struct hist_entry *he) |
| 1036 | { |
| 1037 | struct rb_node **p = &collapse_hists.rb_node; |
| 1038 | struct rb_node *parent = NULL; |
| 1039 | struct hist_entry *iter; |
| 1040 | int64_t cmp; |
| 1041 | |
| 1042 | while (*p != NULL) { |
| 1043 | parent = *p; |
| 1044 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1045 | |
| 1046 | cmp = hist_entry__collapse(iter, he); |
| 1047 | |
| 1048 | if (!cmp) { |
| 1049 | iter->count += he->count; |
| 1050 | hist_entry__free(he); |
| 1051 | return; |
| 1052 | } |
| 1053 | |
| 1054 | if (cmp < 0) |
| 1055 | p = &(*p)->rb_left; |
| 1056 | else |
| 1057 | p = &(*p)->rb_right; |
| 1058 | } |
| 1059 | |
| 1060 | rb_link_node(&he->rb_node, parent, p); |
| 1061 | rb_insert_color(&he->rb_node, &collapse_hists); |
| 1062 | } |
| 1063 | |
| 1064 | static void collapse__resort(void) |
| 1065 | { |
| 1066 | struct rb_node *next; |
| 1067 | struct hist_entry *n; |
| 1068 | |
| 1069 | if (!sort__need_collapse) |
| 1070 | return; |
| 1071 | |
| 1072 | next = rb_first(&hist); |
| 1073 | while (next) { |
| 1074 | n = rb_entry(next, struct hist_entry, rb_node); |
| 1075 | next = rb_next(&n->rb_node); |
| 1076 | |
| 1077 | rb_erase(&n->rb_node, &hist); |
| 1078 | collapse__insert_entry(n); |
| 1079 | } |
| 1080 | } |
| 1081 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1082 | /* |
| 1083 | * reverse the map, sort on count. |
| 1084 | */ |
| 1085 | |
| 1086 | static struct rb_root output_hists; |
| 1087 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1088 | static void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1089 | { |
| 1090 | struct rb_node **p = &output_hists.rb_node; |
| 1091 | struct rb_node *parent = NULL; |
| 1092 | struct hist_entry *iter; |
| 1093 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1094 | if (callchain) |
| 1095 | callchain_param.sort(&he->sorted_chain, &he->callchain, |
| 1096 | min_callchain_hits, &callchain_param); |
Frederic Weisbecker | f55c555 | 2009-06-26 16:28:01 +0200 | [diff] [blame] | 1097 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1098 | while (*p != NULL) { |
| 1099 | parent = *p; |
| 1100 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1101 | |
| 1102 | if (he->count > iter->count) |
| 1103 | p = &(*p)->rb_left; |
| 1104 | else |
| 1105 | p = &(*p)->rb_right; |
| 1106 | } |
| 1107 | |
| 1108 | rb_link_node(&he->rb_node, parent, p); |
| 1109 | rb_insert_color(&he->rb_node, &output_hists); |
| 1110 | } |
| 1111 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1112 | static void output__resort(u64 total_samples) |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1113 | { |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 1114 | struct rb_node *next; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1115 | struct hist_entry *n; |
Arnaldo Carvalho de Melo | a4c43be | 2009-06-03 23:02:33 -0300 | [diff] [blame] | 1116 | struct rb_root *tree = &hist; |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1117 | u64 min_callchain_hits; |
| 1118 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1119 | min_callchain_hits = total_samples * (callchain_param.min_percent / 100); |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1120 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 1121 | if (sort__need_collapse) |
Arnaldo Carvalho de Melo | a4c43be | 2009-06-03 23:02:33 -0300 | [diff] [blame] | 1122 | tree = &collapse_hists; |
| 1123 | |
| 1124 | next = rb_first(tree); |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 1125 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1126 | while (next) { |
| 1127 | n = rb_entry(next, struct hist_entry, rb_node); |
| 1128 | next = rb_next(&n->rb_node); |
| 1129 | |
Arnaldo Carvalho de Melo | a4c43be | 2009-06-03 23:02:33 -0300 | [diff] [blame] | 1130 | rb_erase(&n->rb_node, tree); |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1131 | output__insert_entry(n, min_callchain_hits); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 1135 | static size_t output__fprintf(FILE *fp, u64 total_samples) |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1136 | { |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1137 | struct hist_entry *pos; |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 1138 | struct sort_entry *se; |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1139 | struct rb_node *nd; |
| 1140 | size_t ret = 0; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1141 | unsigned int width; |
| 1142 | char *col_width = col_width_list_str; |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 1143 | int raw_printing_style; |
| 1144 | |
| 1145 | raw_printing_style = !strcmp(pretty_printing_style, "raw"); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1146 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 1147 | init_rem_hits(); |
| 1148 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1149 | fprintf(fp, "# Samples: %Ld\n", (u64)total_samples); |
Ingo Molnar | 05ca061 | 2009-06-04 14:21:16 +0200 | [diff] [blame] | 1150 | fprintf(fp, "#\n"); |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1151 | |
| 1152 | fprintf(fp, "# Overhead"); |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 1153 | if (show_nr_samples) { |
| 1154 | if (field_sep) |
| 1155 | fprintf(fp, "%cSamples", *field_sep); |
| 1156 | else |
| 1157 | fputs(" Samples ", fp); |
| 1158 | } |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1159 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1160 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1161 | continue; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1162 | if (field_sep) { |
| 1163 | fprintf(fp, "%c%s", *field_sep, se->header); |
| 1164 | continue; |
| 1165 | } |
| 1166 | width = strlen(se->header); |
| 1167 | if (se->width) { |
| 1168 | if (col_width_list_str) { |
| 1169 | if (col_width) { |
| 1170 | *se->width = atoi(col_width); |
| 1171 | col_width = strchr(col_width, ','); |
| 1172 | if (col_width) |
| 1173 | ++col_width; |
| 1174 | } |
| 1175 | } |
| 1176 | width = *se->width = max(*se->width, width); |
| 1177 | } |
| 1178 | fprintf(fp, " %*s", width, se->header); |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1179 | } |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1180 | fprintf(fp, "\n"); |
| 1181 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1182 | if (field_sep) |
| 1183 | goto print_entries; |
| 1184 | |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1185 | fprintf(fp, "# ........"); |
Arnaldo Carvalho de Melo | e3d7e18 | 2009-07-11 12:18:37 -0300 | [diff] [blame] | 1186 | if (show_nr_samples) |
| 1187 | fprintf(fp, " .........."); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 1188 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1189 | unsigned int i; |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1190 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1191 | if (se->elide) |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1192 | continue; |
| 1193 | |
Ingo Molnar | 4593bba | 2009-06-02 15:34:25 +0200 | [diff] [blame] | 1194 | fprintf(fp, " "); |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1195 | if (se->width) |
| 1196 | width = *se->width; |
| 1197 | else |
| 1198 | width = strlen(se->header); |
| 1199 | for (i = 0; i < width; i++) |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1200 | fprintf(fp, "."); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 1201 | } |
Peter Zijlstra | ca8cdee | 2009-05-28 11:08:33 +0200 | [diff] [blame] | 1202 | fprintf(fp, "\n"); |
| 1203 | |
| 1204 | fprintf(fp, "#\n"); |
Ingo Molnar | 2d65537 | 2009-05-27 21:36:22 +0200 | [diff] [blame] | 1205 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1206 | print_entries: |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1207 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { |
| 1208 | pos = rb_entry(nd, struct hist_entry, rb_node); |
| 1209 | ret += hist_entry__fprintf(fp, pos, total_samples); |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1210 | } |
| 1211 | |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1212 | if (sort_order == default_sort_order && |
| 1213 | parent_pattern == default_parent_pattern) { |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 1214 | fprintf(fp, "#\n"); |
Pekka Enberg | 114cfab | 2009-08-05 13:25:21 +0300 | [diff] [blame] | 1215 | 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] | 1216 | fprintf(fp, "#\n"); |
| 1217 | } |
Peter Zijlstra | 71dd894 | 2009-06-04 15:16:56 +0200 | [diff] [blame] | 1218 | fprintf(fp, "\n"); |
Ingo Molnar | bd74137 | 2009-06-04 14:13:04 +0200 | [diff] [blame] | 1219 | |
Frederic Weisbecker | 2544603 | 2009-08-08 02:16:25 +0200 | [diff] [blame] | 1220 | free(rem_sq_bracket); |
| 1221 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1222 | if (show_threads) |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 1223 | perf_read_values_display(fp, &show_threads_values, |
| 1224 | raw_printing_style); |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1225 | |
Arnaldo Carvalho de Melo | 3a4b8cc | 2009-05-26 16:19:04 -0300 | [diff] [blame] | 1226 | return ret; |
| 1227 | } |
| 1228 | |
Peter Zijlstra | 436224a | 2009-06-02 21:02:36 +0200 | [diff] [blame] | 1229 | static void register_idle_thread(void) |
| 1230 | { |
| 1231 | struct thread *thread = threads__findnew(0); |
| 1232 | |
| 1233 | if (thread == NULL || |
| 1234 | thread__set_comm(thread, "[idle]")) { |
| 1235 | fprintf(stderr, "problem inserting idle task.\n"); |
| 1236 | exit(-1); |
| 1237 | } |
| 1238 | } |
| 1239 | |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1240 | static unsigned long total = 0, |
| 1241 | total_mmap = 0, |
| 1242 | total_comm = 0, |
| 1243 | total_fork = 0, |
Peter Zijlstra | 9d91a6f | 2009-06-18 11:40:28 +0200 | [diff] [blame] | 1244 | total_unknown = 0, |
| 1245 | total_lost = 0; |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1246 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 1247 | static int validate_chain(struct ip_callchain *chain, event_t *event) |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1248 | { |
| 1249 | unsigned int chain_size; |
| 1250 | |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1251 | chain_size = event->header.size; |
| 1252 | chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event; |
| 1253 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 1254 | if (chain->nr*sizeof(u64) > chain_size) |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1255 | return -1; |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1260 | static int |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1261 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1262 | { |
| 1263 | char level; |
| 1264 | int show = 0; |
| 1265 | struct dso *dso = NULL; |
| 1266 | struct thread *thread = threads__findnew(event->ip.pid); |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 1267 | u64 ip = event->ip.ip; |
| 1268 | u64 period = 1; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1269 | struct map *map = NULL; |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1270 | void *more_data = event->ip.__more_data; |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 1271 | struct ip_callchain *chain = NULL; |
Anton Blanchard | d8db1b5 | 2009-07-01 09:00:48 +1000 | [diff] [blame] | 1272 | int cpumode; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1273 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1274 | if (sample_type & PERF_SAMPLE_PERIOD) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 1275 | period = *(u64 *)more_data; |
| 1276 | more_data += sizeof(u64); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1277 | } |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 1278 | |
Arnaldo Carvalho de Melo | 94a2475 | 2009-08-11 16:21:38 -0300 | [diff] [blame] | 1279 | dprintf("%p [%p]: PERF_EVENT_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n", |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1280 | (void *)(offset + head), |
| 1281 | (void *)(long)(event->header.size), |
| 1282 | event->header.misc, |
Arnaldo Carvalho de Melo | 94a2475 | 2009-08-11 16:21:38 -0300 | [diff] [blame] | 1283 | event->ip.pid, event->ip.tid, |
Peter Zijlstra | 4502d77 | 2009-06-10 15:03:06 +0200 | [diff] [blame] | 1284 | (void *)(long)ip, |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 1285 | (long long)period); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1286 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1287 | if (sample_type & PERF_SAMPLE_CALLCHAIN) { |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1288 | unsigned int i; |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1289 | |
| 1290 | chain = (void *)more_data; |
| 1291 | |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 1292 | dprintf("... chain: nr:%Lu\n", chain->nr); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1293 | |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1294 | if (validate_chain(chain, event) < 0) { |
| 1295 | eprintf("call-chain problem with event, skipping it.\n"); |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | if (dump_trace) { |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1300 | for (i = 0; i < chain->nr; i++) |
Peter Zijlstra | 2a0a50f | 2009-06-18 22:20:45 +0200 | [diff] [blame] | 1301 | dprintf("..... %2d: %016Lx\n", i, chain->ips[i]); |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1305 | dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 1306 | |
| 1307 | if (thread == NULL) { |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1308 | eprintf("problem processing %d event, skipping it.\n", |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1309 | event->header.type); |
| 1310 | return -1; |
| 1311 | } |
| 1312 | |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 1313 | if (comm_list && !strlist__has_entry(comm_list, thread->comm)) |
| 1314 | return 0; |
| 1315 | |
Anton Blanchard | d8db1b5 | 2009-07-01 09:00:48 +1000 | [diff] [blame] | 1316 | cpumode = event->header.misc & PERF_EVENT_MISC_CPUMODE_MASK; |
| 1317 | |
| 1318 | if (cpumode == PERF_EVENT_MISC_KERNEL) { |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1319 | show = SHOW_KERNEL; |
| 1320 | level = 'k'; |
| 1321 | |
| 1322 | dso = kernel_dso; |
| 1323 | |
| 1324 | dprintf(" ...... dso: %s\n", dso->name); |
| 1325 | |
Anton Blanchard | d8db1b5 | 2009-07-01 09:00:48 +1000 | [diff] [blame] | 1326 | } else if (cpumode == PERF_EVENT_MISC_USER) { |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1327 | |
| 1328 | show = SHOW_USER; |
| 1329 | level = '.'; |
| 1330 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1331 | } else { |
| 1332 | show = SHOW_HV; |
| 1333 | level = 'H'; |
Anton Blanchard | fb9c818 | 2009-07-01 09:00:49 +1000 | [diff] [blame] | 1334 | |
| 1335 | dso = hypervisor_dso; |
| 1336 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1337 | dprintf(" ...... dso: [hypervisor]\n"); |
| 1338 | } |
| 1339 | |
| 1340 | if (show & show_mask) { |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 1341 | struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip); |
Peter Zijlstra | fc54db5 | 2009-06-05 14:04:59 +0200 | [diff] [blame] | 1342 | |
Arnaldo Carvalho de Melo | 8fd101f | 2009-08-12 18:19:57 -0300 | [diff] [blame] | 1343 | if (dso_list && (!dso || !dso->name || |
| 1344 | !strlist__has_entry(dso_list, dso->name))) |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 1345 | return 0; |
| 1346 | |
Arnaldo Carvalho de Melo | 8fd101f | 2009-08-12 18:19:57 -0300 | [diff] [blame] | 1347 | if (sym_list && (!sym || !strlist__has_entry(sym_list, sym->name))) |
Arnaldo Carvalho de Melo | 7bec7a9 | 2009-06-30 19:01:22 -0300 | [diff] [blame] | 1348 | return 0; |
| 1349 | |
Peter Zijlstra | 6e7d6fd | 2009-06-17 15:51:44 +0200 | [diff] [blame] | 1350 | if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) { |
Ingo Molnar | 7522060 | 2009-06-18 08:00:17 +0200 | [diff] [blame] | 1351 | eprintf("problem incrementing symbol count, skipping event\n"); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1352 | return -1; |
| 1353 | } |
| 1354 | } |
Peter Zijlstra | ea1900e | 2009-06-10 21:45:22 +0200 | [diff] [blame] | 1355 | total += period; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static int |
| 1361 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) |
| 1362 | { |
| 1363 | struct thread *thread = threads__findnew(event->mmap.pid); |
Frederic Weisbecker | 66e274f | 2009-08-12 11:07:25 +0200 | [diff] [blame] | 1364 | struct map *map = map__new(&event->mmap, cwd, cwdlen); |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1365 | |
Arnaldo Carvalho de Melo | 94a2475 | 2009-08-11 16:21:38 -0300 | [diff] [blame] | 1366 | dprintf("%p [%p]: PERF_EVENT_MMAP %d/%d: [%p(%p) @ %p]: %s\n", |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1367 | (void *)(offset + head), |
| 1368 | (void *)(long)(event->header.size), |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1369 | event->mmap.pid, |
Arnaldo Carvalho de Melo | 94a2475 | 2009-08-11 16:21:38 -0300 | [diff] [blame] | 1370 | event->mmap.tid, |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1371 | (void *)(long)event->mmap.start, |
| 1372 | (void *)(long)event->mmap.len, |
| 1373 | (void *)(long)event->mmap.pgoff, |
| 1374 | event->mmap.filename); |
| 1375 | |
| 1376 | if (thread == NULL || map == NULL) { |
| 1377 | dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n"); |
Ingo Molnar | df97992 | 2009-06-04 13:41:22 +0200 | [diff] [blame] | 1378 | return 0; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | thread__insert_map(thread, map); |
| 1382 | total_mmap++; |
| 1383 | |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | static int |
| 1388 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) |
| 1389 | { |
| 1390 | struct thread *thread = threads__findnew(event->comm.pid); |
| 1391 | |
| 1392 | dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n", |
| 1393 | (void *)(offset + head), |
| 1394 | (void *)(long)(event->header.size), |
| 1395 | event->comm.comm, event->comm.pid); |
| 1396 | |
| 1397 | if (thread == NULL || |
| 1398 | thread__set_comm(thread, event->comm.comm)) { |
| 1399 | dprintf("problem processing PERF_EVENT_COMM, skipping event.\n"); |
| 1400 | return -1; |
| 1401 | } |
| 1402 | total_comm++; |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static int |
Peter Zijlstra | 27d028d | 2009-07-23 16:52:41 +0200 | [diff] [blame] | 1408 | process_task_event(event_t *event, unsigned long offset, unsigned long head) |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1409 | { |
| 1410 | struct thread *thread = threads__findnew(event->fork.pid); |
| 1411 | struct thread *parent = threads__findnew(event->fork.ppid); |
| 1412 | |
Peter Zijlstra | 27d028d | 2009-07-23 16:52:41 +0200 | [diff] [blame] | 1413 | dprintf("%p [%p]: PERF_EVENT_%s: (%d:%d):(%d:%d)\n", |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1414 | (void *)(offset + head), |
| 1415 | (void *)(long)(event->header.size), |
Peter Zijlstra | 27d028d | 2009-07-23 16:52:41 +0200 | [diff] [blame] | 1416 | event->header.type == PERF_EVENT_FORK ? "FORK" : "EXIT", |
| 1417 | event->fork.pid, event->fork.tid, |
| 1418 | event->fork.ppid, event->fork.ptid); |
| 1419 | |
| 1420 | /* |
| 1421 | * A thread clone will have the same PID for both |
| 1422 | * parent and child. |
| 1423 | */ |
| 1424 | if (thread == parent) |
| 1425 | return 0; |
| 1426 | |
| 1427 | if (event->header.type == PERF_EVENT_EXIT) |
| 1428 | return 0; |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (!thread || !parent || thread__fork(thread, parent)) { |
| 1431 | dprintf("problem processing PERF_EVENT_FORK, skipping event.\n"); |
| 1432 | return -1; |
| 1433 | } |
| 1434 | total_fork++; |
| 1435 | |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static int |
Peter Zijlstra | 9d91a6f | 2009-06-18 11:40:28 +0200 | [diff] [blame] | 1440 | process_lost_event(event_t *event, unsigned long offset, unsigned long head) |
| 1441 | { |
| 1442 | dprintf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n", |
| 1443 | (void *)(offset + head), |
| 1444 | (void *)(long)(event->header.size), |
| 1445 | event->lost.id, |
| 1446 | event->lost.lost); |
| 1447 | |
| 1448 | total_lost += event->lost.lost; |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1453 | static void trace_event(event_t *event) |
| 1454 | { |
| 1455 | unsigned char *raw_event = (void *)event; |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1456 | char *color = PERF_COLOR_BLUE; |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1457 | int i, j; |
| 1458 | |
| 1459 | if (!dump_trace) |
| 1460 | return; |
| 1461 | |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1462 | dprintf("."); |
| 1463 | cdprintf("\n. ... raw event: size %d bytes\n", event->header.size); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1464 | |
| 1465 | for (i = 0; i < event->header.size; i++) { |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1466 | if ((i & 15) == 0) { |
| 1467 | dprintf("."); |
| 1468 | cdprintf(" %04x: ", i); |
| 1469 | } |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1470 | |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1471 | cdprintf(" %02x", raw_event[i]); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1472 | |
| 1473 | if (((i & 15) == 15) || i == event->header.size-1) { |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1474 | cdprintf(" "); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1475 | for (j = 0; j < 15-(i & 15); j++) |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1476 | cdprintf(" "); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1477 | for (j = 0; j < (i & 15); j++) { |
Peter Zijlstra | a73c7d8 | 2009-06-18 09:44:20 +0200 | [diff] [blame] | 1478 | if (isprint(raw_event[i-15+j])) |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1479 | cdprintf("%c", raw_event[i-15+j]); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1480 | else |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1481 | cdprintf("."); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1482 | } |
Ingo Molnar | 3efa1cc9 | 2009-06-14 15:04:15 +0200 | [diff] [blame] | 1483 | cdprintf("\n"); |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | dprintf(".\n"); |
| 1487 | } |
| 1488 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 1489 | static struct perf_header *header; |
| 1490 | |
| 1491 | static struct perf_counter_attr *perf_header__find_attr(u64 id) |
| 1492 | { |
| 1493 | int i; |
| 1494 | |
| 1495 | for (i = 0; i < header->attrs; i++) { |
| 1496 | struct perf_header_attr *attr = header->attr[i]; |
| 1497 | int j; |
| 1498 | |
| 1499 | for (j = 0; j < attr->ids; j++) { |
| 1500 | if (attr->id[j] == id) |
| 1501 | return &attr->attr; |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | return NULL; |
| 1506 | } |
| 1507 | |
Ingo Molnar | b2fef07 | 2009-06-05 18:07:51 +0200 | [diff] [blame] | 1508 | static int |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 1509 | process_read_event(event_t *event, unsigned long offset, unsigned long head) |
| 1510 | { |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 1511 | struct perf_counter_attr *attr = perf_header__find_attr(event->read.id); |
| 1512 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1513 | if (show_threads) { |
| 1514 | char *name = attr ? __event_name(attr->type, attr->config) |
| 1515 | : "unknown"; |
| 1516 | perf_read_values_add_value(&show_threads_values, |
| 1517 | event->read.pid, event->read.tid, |
| 1518 | event->read.id, |
| 1519 | name, |
| 1520 | event->read.value); |
| 1521 | } |
| 1522 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 1523 | dprintf("%p [%p]: PERF_EVENT_READ: %d %d %s %Lu\n", |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 1524 | (void *)(offset + head), |
| 1525 | (void *)(long)(event->header.size), |
| 1526 | event->read.pid, |
| 1527 | event->read.tid, |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 1528 | attr ? __event_name(attr->type, attr->config) |
| 1529 | : "FAIL", |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 1530 | event->read.value); |
| 1531 | |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
| 1535 | static int |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1536 | process_event(event_t *event, unsigned long offset, unsigned long head) |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1537 | { |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1538 | trace_event(event); |
| 1539 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1540 | switch (event->header.type) { |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1541 | case PERF_EVENT_SAMPLE: |
| 1542 | return process_sample_event(event, offset, head); |
| 1543 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1544 | case PERF_EVENT_MMAP: |
| 1545 | return process_mmap_event(event, offset, head); |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1546 | |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1547 | case PERF_EVENT_COMM: |
| 1548 | return process_comm_event(event, offset, head); |
Ingo Molnar | ed966aa | 2009-06-03 10:39:26 +0200 | [diff] [blame] | 1549 | |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1550 | case PERF_EVENT_FORK: |
Peter Zijlstra | 27d028d | 2009-07-23 16:52:41 +0200 | [diff] [blame] | 1551 | case PERF_EVENT_EXIT: |
| 1552 | return process_task_event(event, offset, head); |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1553 | |
Peter Zijlstra | 9d91a6f | 2009-06-18 11:40:28 +0200 | [diff] [blame] | 1554 | case PERF_EVENT_LOST: |
| 1555 | return process_lost_event(event, offset, head); |
| 1556 | |
Peter Zijlstra | e9ea2fd | 2009-06-24 22:46:04 +0200 | [diff] [blame] | 1557 | case PERF_EVENT_READ: |
| 1558 | return process_read_event(event, offset, head); |
| 1559 | |
Ingo Molnar | d11444d | 2009-06-03 23:29:14 +0200 | [diff] [blame] | 1560 | /* |
| 1561 | * We dont process them right now but they are fine: |
| 1562 | */ |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1563 | |
Ingo Molnar | d11444d | 2009-06-03 23:29:14 +0200 | [diff] [blame] | 1564 | case PERF_EVENT_THROTTLE: |
| 1565 | case PERF_EVENT_UNTHROTTLE: |
| 1566 | return 0; |
| 1567 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1568 | default: |
| 1569 | return -1; |
| 1570 | } |
| 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1575 | static u64 perf_header__sample_type(void) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1576 | { |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1577 | u64 sample_type = 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1578 | int i; |
| 1579 | |
| 1580 | for (i = 0; i < header->attrs; i++) { |
| 1581 | struct perf_header_attr *attr = header->attr[i]; |
| 1582 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1583 | if (!sample_type) |
| 1584 | sample_type = attr->attr.sample_type; |
| 1585 | else if (sample_type != attr->attr.sample_type) |
| 1586 | die("non matching sample_type"); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1587 | } |
| 1588 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1589 | return sample_type; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1590 | } |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 1591 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1592 | static int __cmd_report(void) |
| 1593 | { |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1594 | int ret, rc = EXIT_FAILURE; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1595 | unsigned long offset = 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1596 | unsigned long head, shift; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1597 | struct stat stat; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1598 | event_t *event; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1599 | uint32_t size; |
Ingo Molnar | 7505172 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1600 | char *buf; |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1601 | |
| 1602 | register_idle_thread(); |
| 1603 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1604 | if (show_threads) |
| 1605 | perf_read_values_init(&show_threads_values); |
| 1606 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1607 | input = open(input_name, O_RDONLY); |
| 1608 | if (input < 0) { |
Ingo Molnar | a14832f | 2009-06-07 17:58:23 +0200 | [diff] [blame] | 1609 | fprintf(stderr, " failed to open file: %s", input_name); |
| 1610 | if (!strcmp(input_name, "perf.data")) |
| 1611 | fprintf(stderr, " (try 'perf record' first)"); |
| 1612 | fprintf(stderr, "\n"); |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1613 | exit(-1); |
| 1614 | } |
| 1615 | |
| 1616 | ret = fstat(input, &stat); |
| 1617 | if (ret < 0) { |
| 1618 | perror("failed to stat file"); |
| 1619 | exit(-1); |
| 1620 | } |
| 1621 | |
| 1622 | if (!stat.st_size) { |
| 1623 | fprintf(stderr, "zero-sized file, nothing to do!\n"); |
| 1624 | exit(0); |
| 1625 | } |
| 1626 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1627 | header = perf_header__read(input); |
| 1628 | head = header->data_offset; |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 1629 | |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 1630 | sample_type = perf_header__sample_type(); |
| 1631 | |
Frederic Weisbecker | 91b4eae | 2009-07-05 07:39:17 +0200 | [diff] [blame] | 1632 | if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { |
| 1633 | if (sort__has_parent) { |
| 1634 | fprintf(stderr, "selected --sort parent, but no" |
| 1635 | " callchain data. Did you call" |
| 1636 | " perf record without -g?\n"); |
| 1637 | exit(-1); |
| 1638 | } |
| 1639 | if (callchain) { |
| 1640 | fprintf(stderr, "selected -c but no callchain data." |
| 1641 | " Did you call perf record without" |
| 1642 | " -g?\n"); |
| 1643 | exit(-1); |
| 1644 | } |
Frederic Weisbecker | b1a8834 | 2009-08-08 02:16:24 +0200 | [diff] [blame] | 1645 | } else if (callchain_param.mode != CHAIN_NONE && !callchain) { |
| 1646 | callchain = 1; |
| 1647 | if (register_callchain_param(&callchain_param) < 0) { |
| 1648 | fprintf(stderr, "Can't register callchain" |
| 1649 | " params\n"); |
| 1650 | exit(-1); |
| 1651 | } |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 1652 | } |
| 1653 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1654 | if (load_kernel() < 0) { |
| 1655 | perror("failed to load kernel symbols"); |
| 1656 | return EXIT_FAILURE; |
| 1657 | } |
| 1658 | |
| 1659 | if (!full_paths) { |
| 1660 | if (getcwd(__cwd, sizeof(__cwd)) == NULL) { |
| 1661 | perror("failed to get the current directory"); |
| 1662 | return EXIT_FAILURE; |
| 1663 | } |
| 1664 | cwdlen = strlen(cwd); |
| 1665 | } else { |
| 1666 | cwd = NULL; |
| 1667 | cwdlen = 0; |
| 1668 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1669 | |
| 1670 | shift = page_size * (head / page_size); |
| 1671 | offset += shift; |
| 1672 | head -= shift; |
| 1673 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1674 | remap: |
| 1675 | buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, |
| 1676 | MAP_SHARED, input, offset); |
| 1677 | if (buf == MAP_FAILED) { |
| 1678 | perror("failed to mmap file"); |
| 1679 | exit(-1); |
| 1680 | } |
| 1681 | |
| 1682 | more: |
| 1683 | event = (event_t *)(buf + head); |
| 1684 | |
| 1685 | size = event->header.size; |
| 1686 | if (!size) |
| 1687 | size = 8; |
| 1688 | |
| 1689 | if (head + event->header.size >= page_size * mmap_window) { |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1690 | int ret; |
| 1691 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1692 | shift = page_size * (head / page_size); |
| 1693 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1694 | ret = munmap(buf, page_size * mmap_window); |
| 1695 | assert(ret == 0); |
| 1696 | |
| 1697 | offset += shift; |
| 1698 | head -= shift; |
| 1699 | goto remap; |
| 1700 | } |
| 1701 | |
| 1702 | size = event->header.size; |
| 1703 | |
Ingo Molnar | 8465b05 | 2009-06-14 14:44:07 +0200 | [diff] [blame] | 1704 | dprintf("\n%p [%p]: event: %d\n", |
Ingo Molnar | b2fef07 | 2009-06-05 18:07:51 +0200 | [diff] [blame] | 1705 | (void *)(offset + head), |
| 1706 | (void *)(long)event->header.size, |
| 1707 | event->header.type); |
| 1708 | |
Ingo Molnar | d80d338 | 2009-06-03 23:14:49 +0200 | [diff] [blame] | 1709 | if (!size || process_event(event, offset, head) < 0) { |
| 1710 | |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 1711 | dprintf("%p [%p]: skipping unknown header type: %d\n", |
| 1712 | (void *)(offset + head), |
| 1713 | (void *)(long)(event->header.size), |
| 1714 | event->header.type); |
Peter Zijlstra | b7a16ea | 2009-05-27 13:35:35 +0200 | [diff] [blame] | 1715 | |
Ingo Molnar | 3e70611 | 2009-05-26 18:53:17 +0200 | [diff] [blame] | 1716 | total_unknown++; |
Peter Zijlstra | 6142f9e | 2009-05-26 20:51:47 +0200 | [diff] [blame] | 1717 | |
| 1718 | /* |
| 1719 | * assume we lost track of the stream, check alignment, and |
| 1720 | * increment a single u64 in the hope to catch on again 'soon'. |
| 1721 | */ |
| 1722 | |
| 1723 | if (unlikely(head & 7)) |
| 1724 | head &= ~7ULL; |
| 1725 | |
| 1726 | size = 8; |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1727 | } |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1728 | |
Peter Zijlstra | 6142f9e | 2009-05-26 20:51:47 +0200 | [diff] [blame] | 1729 | head += size; |
Ingo Molnar | f49515b | 2009-05-26 19:03:36 +0200 | [diff] [blame] | 1730 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1731 | if (offset + head >= header->data_offset + header->data_size) |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 1732 | goto done; |
| 1733 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1734 | if (offset + head < (unsigned long)stat.st_size) |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1735 | goto more; |
| 1736 | |
Peter Zijlstra | f597055 | 2009-06-18 23:22:55 +0200 | [diff] [blame] | 1737 | done: |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1738 | rc = EXIT_SUCCESS; |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1739 | close(input); |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1740 | |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 1741 | dprintf(" IP events: %10ld\n", total); |
| 1742 | dprintf(" mmap events: %10ld\n", total_mmap); |
| 1743 | dprintf(" comm events: %10ld\n", total_comm); |
Peter Zijlstra | 62fc445 | 2009-06-04 16:53:49 +0200 | [diff] [blame] | 1744 | dprintf(" fork events: %10ld\n", total_fork); |
Peter Zijlstra | 9d91a6f | 2009-06-18 11:40:28 +0200 | [diff] [blame] | 1745 | dprintf(" lost events: %10ld\n", total_lost); |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 1746 | dprintf(" unknown events: %10ld\n", total_unknown); |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1747 | |
Ingo Molnar | 3502973 | 2009-06-03 09:38:58 +0200 | [diff] [blame] | 1748 | if (dump_trace) |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1749 | return 0; |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1750 | |
Arnaldo Carvalho de Melo | 9ac9954 | 2009-06-04 13:54:00 -0300 | [diff] [blame] | 1751 | if (verbose >= 3) |
| 1752 | threads__fprintf(stdout); |
| 1753 | |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1754 | if (verbose >= 2) |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 1755 | dsos__fprintf(stdout); |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 1756 | |
Peter Zijlstra | 8229289 | 2009-06-03 12:37:36 +0200 | [diff] [blame] | 1757 | collapse__resort(); |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1758 | output__resort(total); |
Peter Zijlstra | e7fb08b | 2009-05-27 20:20:24 +0200 | [diff] [blame] | 1759 | output__fprintf(stdout, total); |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1760 | |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1761 | if (show_threads) |
| 1762 | perf_read_values_destroy(&show_threads_values); |
| 1763 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1764 | return rc; |
| 1765 | } |
| 1766 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 1767 | static int |
| 1768 | parse_callchain_opt(const struct option *opt __used, const char *arg, |
| 1769 | int unset __used) |
| 1770 | { |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1771 | char *tok; |
| 1772 | char *endptr; |
| 1773 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 1774 | callchain = 1; |
| 1775 | |
| 1776 | if (!arg) |
| 1777 | return 0; |
| 1778 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1779 | tok = strtok((char *)arg, ","); |
| 1780 | if (!tok) |
| 1781 | return -1; |
| 1782 | |
| 1783 | /* get the output mode */ |
| 1784 | if (!strncmp(tok, "graph", strlen(arg))) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1785 | callchain_param.mode = CHAIN_GRAPH_ABS; |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 1786 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1787 | else if (!strncmp(tok, "flat", strlen(arg))) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1788 | callchain_param.mode = CHAIN_FLAT; |
| 1789 | |
| 1790 | else if (!strncmp(tok, "fractal", strlen(arg))) |
| 1791 | callchain_param.mode = CHAIN_GRAPH_REL; |
| 1792 | |
Frederic Weisbecker | b1a8834 | 2009-08-08 02:16:24 +0200 | [diff] [blame] | 1793 | else if (!strncmp(tok, "none", strlen(arg))) { |
| 1794 | callchain_param.mode = CHAIN_NONE; |
| 1795 | callchain = 0; |
| 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 1800 | else |
| 1801 | return -1; |
| 1802 | |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1803 | /* get the min percentage */ |
| 1804 | tok = strtok(NULL, ","); |
| 1805 | if (!tok) |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1806 | goto setup; |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1807 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1808 | callchain_param.min_percent = strtod(tok, &endptr); |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1809 | if (tok == endptr) |
| 1810 | return -1; |
| 1811 | |
Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 1812 | setup: |
| 1813 | if (register_callchain_param(&callchain_param) < 0) { |
| 1814 | fprintf(stderr, "Can't register callchain params\n"); |
| 1815 | return -1; |
| 1816 | } |
Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 1817 | return 0; |
| 1818 | } |
| 1819 | |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1820 | static const char * const report_usage[] = { |
| 1821 | "perf report [<options>] <command>", |
| 1822 | NULL |
| 1823 | }; |
| 1824 | |
| 1825 | static const struct option options[] = { |
| 1826 | OPT_STRING('i', "input", &input_name, "file", |
| 1827 | "input file name"), |
Arnaldo Carvalho de Melo | 815e777 | 2009-05-26 19:46:14 -0300 | [diff] [blame] | 1828 | OPT_BOOLEAN('v', "verbose", &verbose, |
| 1829 | "be more verbose (show symbol address, etc)"), |
Ingo Molnar | 97b07b6 | 2009-05-26 18:48:58 +0200 | [diff] [blame] | 1830 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 1831 | "dump raw trace in ASCII"), |
Peter Zijlstra | 450aaa2 | 2009-05-27 20:20:23 +0200 | [diff] [blame] | 1832 | OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 1833 | OPT_BOOLEAN('m', "modules", &modules, |
| 1834 | "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] | 1835 | OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples, |
| 1836 | "Show a column with the number of samples"), |
Brice Goglin | 8d51327 | 2009-08-07 13:55:24 +0200 | [diff] [blame] | 1837 | OPT_BOOLEAN('T', "threads", &show_threads, |
| 1838 | "Show per-thread event counters"), |
Brice Goglin | 9f86669 | 2009-08-10 15:26:32 +0200 | [diff] [blame] | 1839 | OPT_STRING(0, "pretty", &pretty_printing_style, "key", |
| 1840 | "pretty printing style key: normal raw"), |
Ingo Molnar | 63299f0 | 2009-05-28 10:52:00 +0200 | [diff] [blame] | 1841 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 1842 | "sort by key(s): pid, comm, dso, symbol, parent"), |
Arnaldo Carvalho de Melo | b78c07d | 2009-05-29 13:48:59 -0300 | [diff] [blame] | 1843 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
| 1844 | "Don't shorten the pathnames taking into account the cwd"), |
Ingo Molnar | b25bcf2 | 2009-06-18 07:01:03 +0200 | [diff] [blame] | 1845 | OPT_STRING('p', "parent", &parent_pattern, "regex", |
| 1846 | "regex filter to identify parent, see: '--sort parent'"), |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1847 | OPT_BOOLEAN('x', "exclude-other", &exclude_other, |
| 1848 | "Only display entries with parent-match"), |
Anton Blanchard | 1483b19f | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 1849 | OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent", |
Frederic Weisbecker | c20ab37 | 2009-07-02 20:14:33 +0200 | [diff] [blame] | 1850 | "Display callchains using output_type and min percent threshold. " |
Anton Blanchard | 1483b19f | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 1851 | "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt), |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 1852 | OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]", |
| 1853 | "only consider symbols in these dsos"), |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 1854 | OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]", |
| 1855 | "only consider symbols in these comms"), |
Arnaldo Carvalho de Melo | 7bec7a9 | 2009-06-30 19:01:22 -0300 | [diff] [blame] | 1856 | OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]", |
| 1857 | "only consider these symbols"), |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1858 | OPT_STRING('w', "column-widths", &col_width_list_str, |
| 1859 | "width[,width...]", |
| 1860 | "don't try to adjust column width, use these fixed values"), |
| 1861 | OPT_STRING('t', "field-separator", &field_sep, "separator", |
| 1862 | "separator for columns, no spaces will be added between " |
| 1863 | "columns '.' is reserved."), |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1864 | OPT_END() |
| 1865 | }; |
| 1866 | |
Ingo Molnar | 5352f35 | 2009-06-03 10:07:39 +0200 | [diff] [blame] | 1867 | static void setup_sorting(void) |
| 1868 | { |
| 1869 | char *tmp, *tok, *str = strdup(sort_order); |
| 1870 | |
| 1871 | for (tok = strtok_r(str, ", ", &tmp); |
| 1872 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 1873 | if (sort_dimension__add(tok) < 0) { |
| 1874 | error("Unknown --sort key: `%s'", tok); |
| 1875 | usage_with_options(report_usage, options); |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | free(str); |
| 1880 | } |
| 1881 | |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 1882 | 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] | 1883 | struct sort_entry *se, const char *list_name, |
| 1884 | FILE *fp) |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 1885 | { |
| 1886 | if (list_str) { |
| 1887 | *list = strlist__new(true, list_str); |
| 1888 | if (!*list) { |
| 1889 | fprintf(stderr, "problems parsing %s list\n", |
| 1890 | list_name); |
| 1891 | exit(129); |
| 1892 | } |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1893 | if (strlist__nr_entries(*list) == 1) { |
| 1894 | fprintf(fp, "# %s: %s\n", list_name, |
| 1895 | strlist__entry(*list, 0)->s); |
| 1896 | se->elide = true; |
| 1897 | } |
Arnaldo Carvalho de Melo | cc8b88b | 2009-06-30 19:01:21 -0300 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1901 | int cmd_report(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1902 | { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1903 | symbol__init(); |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1904 | |
| 1905 | page_size = getpagesize(); |
| 1906 | |
Ingo Molnar | edc52de | 2009-06-04 16:24:37 +0200 | [diff] [blame] | 1907 | argc = parse_options(argc, argv, options, report_usage, 0); |
Ingo Molnar | 53cb8bc | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1908 | |
Peter Zijlstra | 1aa1673 | 2009-05-27 20:20:25 +0200 | [diff] [blame] | 1909 | setup_sorting(); |
| 1910 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1911 | if (parent_pattern != default_parent_pattern) { |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1912 | sort_dimension__add("parent"); |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1913 | sort_parent.elide = 1; |
| 1914 | } else |
Ingo Molnar | b8e6d82 | 2009-06-18 14:32:19 +0200 | [diff] [blame] | 1915 | exclude_other = 0; |
| 1916 | |
Ingo Molnar | edc52de | 2009-06-04 16:24:37 +0200 | [diff] [blame] | 1917 | /* |
| 1918 | * Any (unrecognized) arguments left? |
| 1919 | */ |
| 1920 | if (argc) |
| 1921 | usage_with_options(report_usage, options); |
| 1922 | |
Ingo Molnar | a930d2c | 2009-05-27 09:50:13 +0200 | [diff] [blame] | 1923 | setup_pager(); |
| 1924 | |
Arnaldo Carvalho de Melo | 021191b | 2009-07-11 12:18:35 -0300 | [diff] [blame] | 1925 | setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout); |
| 1926 | setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout); |
| 1927 | 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] | 1928 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 1929 | if (field_sep && *field_sep == '.') { |
| 1930 | fputs("'.' is the only non valid --field-separator argument\n", |
| 1931 | stderr); |
| 1932 | exit(129); |
| 1933 | } |
| 1934 | |
Arnaldo Carvalho de Melo | 8fa66bd | 2009-05-18 12:45:42 -0300 | [diff] [blame] | 1935 | return __cmd_report(); |
| 1936 | } |