Xiao Guangrong | b8f46c5 | 2010-02-03 11:53:14 +0800 | [diff] [blame] | 1 | #define _FILE_OFFSET_BITS 64 |
| 2 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 3 | #include <linux/kernel.h> |
| 4 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 5 | #include <byteswap.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | a41794c | 2010-05-18 18:29:23 -0300 | [diff] [blame] | 8 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 9 | |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 10 | #include "evlist.h" |
| 11 | #include "evsel.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 12 | #include "session.h" |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 13 | #include "sort.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 14 | #include "util.h" |
| 15 | |
| 16 | static int perf_session__open(struct perf_session *self, bool force) |
| 17 | { |
| 18 | struct stat input_stat; |
| 19 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 20 | if (!strcmp(self->filename, "-")) { |
| 21 | self->fd_pipe = true; |
| 22 | self->fd = STDIN_FILENO; |
| 23 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 24 | if (perf_session__read_header(self, self->fd) < 0) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 25 | pr_err("incompatible file format"); |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 30 | self->fd = open(self->filename, O_RDONLY); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 31 | if (self->fd < 0) { |
Andy Isaacson | 0f2c3de | 2010-06-11 20:36:15 -0700 | [diff] [blame] | 32 | int err = errno; |
| 33 | |
| 34 | pr_err("failed to open %s: %s", self->filename, strerror(err)); |
| 35 | if (err == ENOENT && !strcmp(self->filename, "perf.data")) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 36 | pr_err(" (try 'perf record' first)"); |
| 37 | pr_err("\n"); |
| 38 | return -errno; |
| 39 | } |
| 40 | |
| 41 | if (fstat(self->fd, &input_stat) < 0) |
| 42 | goto out_close; |
| 43 | |
| 44 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { |
| 45 | pr_err("file %s not owned by current user or root\n", |
| 46 | self->filename); |
| 47 | goto out_close; |
| 48 | } |
| 49 | |
| 50 | if (!input_stat.st_size) { |
| 51 | pr_info("zero-sized file (%s), nothing to do!\n", |
| 52 | self->filename); |
| 53 | goto out_close; |
| 54 | } |
| 55 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 56 | if (perf_session__read_header(self, self->fd) < 0) { |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 57 | pr_err("incompatible file format"); |
| 58 | goto out_close; |
| 59 | } |
| 60 | |
| 61 | self->size = input_stat.st_size; |
| 62 | return 0; |
| 63 | |
| 64 | out_close: |
| 65 | close(self->fd); |
| 66 | self->fd = -1; |
| 67 | return -1; |
| 68 | } |
| 69 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 70 | static void perf_session__id_header_size(struct perf_session *session) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 71 | { |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 72 | struct perf_sample *data; |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 73 | u64 sample_type = session->sample_type; |
| 74 | u16 size = 0; |
| 75 | |
| 76 | if (!session->sample_id_all) |
| 77 | goto out; |
| 78 | |
| 79 | if (sample_type & PERF_SAMPLE_TID) |
| 80 | size += sizeof(data->tid) * 2; |
| 81 | |
| 82 | if (sample_type & PERF_SAMPLE_TIME) |
| 83 | size += sizeof(data->time); |
| 84 | |
| 85 | if (sample_type & PERF_SAMPLE_ID) |
| 86 | size += sizeof(data->id); |
| 87 | |
| 88 | if (sample_type & PERF_SAMPLE_STREAM_ID) |
| 89 | size += sizeof(data->stream_id); |
| 90 | |
| 91 | if (sample_type & PERF_SAMPLE_CPU) |
| 92 | size += sizeof(data->cpu) * 2; |
| 93 | out: |
| 94 | session->id_hdr_size = size; |
| 95 | } |
| 96 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 97 | void perf_session__update_sample_type(struct perf_session *self) |
| 98 | { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 99 | self->sample_type = perf_evlist__sample_type(self->evlist); |
Frederic Weisbecker | a285412 | 2011-05-21 19:33:04 +0200 | [diff] [blame] | 100 | self->sample_size = perf_sample_size(self->sample_type); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 101 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 102 | perf_session__id_header_size(self); |
| 103 | } |
| 104 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 105 | int perf_session__create_kernel_maps(struct perf_session *self) |
| 106 | { |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 107 | int ret = machine__create_kernel_maps(&self->host_machine); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 108 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 109 | if (ret >= 0) |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 110 | ret = machines__create_guest_kernel_maps(&self->machines); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 111 | return ret; |
| 112 | } |
| 113 | |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 114 | static void perf_session__destroy_kernel_maps(struct perf_session *self) |
| 115 | { |
| 116 | machine__destroy_kernel_maps(&self->host_machine); |
| 117 | machines__destroy_guest_kernel_maps(&self->machines); |
| 118 | } |
| 119 | |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 120 | struct perf_session *perf_session__new(const char *filename, int mode, |
| 121 | bool force, bool repipe, |
| 122 | struct perf_event_ops *ops) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 123 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 124 | size_t len = filename ? strlen(filename) + 1 : 0; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 125 | struct perf_session *self = zalloc(sizeof(*self) + len); |
| 126 | |
| 127 | if (self == NULL) |
| 128 | goto out; |
| 129 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 130 | memcpy(self->filename, filename, len); |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 131 | self->threads = RB_ROOT; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 132 | INIT_LIST_HEAD(&self->dead_threads); |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 133 | self->last_match = NULL; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 134 | /* |
| 135 | * On 64bit we can mmap the data file in one go. No need for tiny mmap |
| 136 | * slices. On 32bit we use 32MB. |
| 137 | */ |
| 138 | #if BITS_PER_LONG == 64 |
| 139 | self->mmap_window = ULLONG_MAX; |
| 140 | #else |
| 141 | self->mmap_window = 32 * 1024 * 1024ULL; |
| 142 | #endif |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 143 | self->machines = RB_ROOT; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 144 | self->repipe = repipe; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 145 | INIT_LIST_HEAD(&self->ordered_samples.samples); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 146 | INIT_LIST_HEAD(&self->ordered_samples.sample_cache); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 147 | INIT_LIST_HEAD(&self->ordered_samples.to_free); |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 148 | machine__init(&self->host_machine, "", HOST_KERNEL_ID); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 149 | |
Arnaldo Carvalho de Melo | 64abebf | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 150 | if (mode == O_RDONLY) { |
| 151 | if (perf_session__open(self, force) < 0) |
| 152 | goto out_delete; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 153 | perf_session__update_sample_type(self); |
Arnaldo Carvalho de Melo | 64abebf | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 154 | } else if (mode == O_WRONLY) { |
| 155 | /* |
| 156 | * In O_RDONLY mode this will be performed when reading the |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 157 | * kernel MMAP event, in perf_event__process_mmap(). |
Arnaldo Carvalho de Melo | 64abebf | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 158 | */ |
| 159 | if (perf_session__create_kernel_maps(self) < 0) |
| 160 | goto out_delete; |
| 161 | } |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 162 | |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 163 | if (ops && ops->ordering_requires_timestamps && |
| 164 | ops->ordered_samples && !self->sample_id_all) { |
| 165 | dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); |
| 166 | ops->ordered_samples = false; |
| 167 | } |
| 168 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 169 | out: |
| 170 | return self; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 171 | out_delete: |
| 172 | perf_session__delete(self); |
| 173 | return NULL; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 174 | } |
| 175 | |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 176 | static void perf_session__delete_dead_threads(struct perf_session *self) |
| 177 | { |
| 178 | struct thread *n, *t; |
| 179 | |
| 180 | list_for_each_entry_safe(t, n, &self->dead_threads, node) { |
| 181 | list_del(&t->node); |
| 182 | thread__delete(t); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | static void perf_session__delete_threads(struct perf_session *self) |
| 187 | { |
| 188 | struct rb_node *nd = rb_first(&self->threads); |
| 189 | |
| 190 | while (nd) { |
| 191 | struct thread *t = rb_entry(nd, struct thread, rb_node); |
| 192 | |
| 193 | rb_erase(&t->rb_node, &self->threads); |
| 194 | nd = rb_next(nd); |
| 195 | thread__delete(t); |
| 196 | } |
| 197 | } |
| 198 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 199 | void perf_session__delete(struct perf_session *self) |
| 200 | { |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 201 | perf_session__destroy_kernel_maps(self); |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 202 | perf_session__delete_dead_threads(self); |
| 203 | perf_session__delete_threads(self); |
| 204 | machine__exit(&self->host_machine); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 205 | close(self->fd); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 206 | free(self); |
| 207 | } |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 208 | |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 209 | void perf_session__remove_thread(struct perf_session *self, struct thread *th) |
| 210 | { |
Arnaldo Carvalho de Melo | 70597f2 | 2010-08-02 18:59:28 -0300 | [diff] [blame] | 211 | self->last_match = NULL; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 212 | rb_erase(&th->rb_node, &self->threads); |
| 213 | /* |
| 214 | * We may have references to this thread, for instance in some hist_entry |
| 215 | * instances, so just move them to a separate list. |
| 216 | */ |
| 217 | list_add_tail(&th->node, &self->dead_threads); |
| 218 | } |
| 219 | |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 220 | static bool symbol__match_parent_regex(struct symbol *sym) |
| 221 | { |
| 222 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
| 223 | return 1; |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 228 | int perf_session__resolve_callchain(struct perf_session *self, |
| 229 | struct thread *thread, |
| 230 | struct ip_callchain *chain, |
| 231 | struct symbol **parent) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 232 | { |
| 233 | u8 cpumode = PERF_RECORD_MISC_USER; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 234 | unsigned int i; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 235 | int err; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 236 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 237 | callchain_cursor_reset(&self->callchain_cursor); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 238 | |
| 239 | for (i = 0; i < chain->nr; i++) { |
| 240 | u64 ip = chain->ips[i]; |
| 241 | struct addr_location al; |
| 242 | |
| 243 | if (ip >= PERF_CONTEXT_MAX) { |
| 244 | switch (ip) { |
| 245 | case PERF_CONTEXT_HV: |
| 246 | cpumode = PERF_RECORD_MISC_HYPERVISOR; break; |
| 247 | case PERF_CONTEXT_KERNEL: |
| 248 | cpumode = PERF_RECORD_MISC_KERNEL; break; |
| 249 | case PERF_CONTEXT_USER: |
| 250 | cpumode = PERF_RECORD_MISC_USER; break; |
| 251 | default: |
| 252 | break; |
| 253 | } |
| 254 | continue; |
| 255 | } |
| 256 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 257 | al.filtered = false; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 258 | thread__find_addr_location(thread, self, cpumode, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 259 | MAP__FUNCTION, thread->pid, ip, &al, NULL); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 260 | if (al.sym != NULL) { |
| 261 | if (sort__has_parent && !*parent && |
| 262 | symbol__match_parent_regex(al.sym)) |
| 263 | *parent = al.sym; |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 264 | if (!symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 265 | break; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 266 | } |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 267 | |
| 268 | err = callchain_cursor_append(&self->callchain_cursor, |
| 269 | ip, al.map, al.sym); |
| 270 | if (err) |
| 271 | return err; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 272 | } |
| 273 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 274 | return 0; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 275 | } |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 276 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 277 | static int process_event_synth_stub(union perf_event *event __used, |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 278 | struct perf_session *session __used) |
| 279 | { |
| 280 | dump_printf(": unhandled!\n"); |
| 281 | return 0; |
| 282 | } |
| 283 | |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 284 | static int process_event_sample_stub(union perf_event *event __used, |
| 285 | struct perf_sample *sample __used, |
| 286 | struct perf_evsel *evsel __used, |
| 287 | struct perf_session *session __used) |
| 288 | { |
| 289 | dump_printf(": unhandled!\n"); |
| 290 | return 0; |
| 291 | } |
| 292 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 293 | static int process_event_stub(union perf_event *event __used, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 294 | struct perf_sample *sample __used, |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 295 | struct perf_session *session __used) |
| 296 | { |
| 297 | dump_printf(": unhandled!\n"); |
| 298 | return 0; |
| 299 | } |
| 300 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 301 | static int process_finished_round_stub(union perf_event *event __used, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 302 | struct perf_session *session __used, |
| 303 | struct perf_event_ops *ops __used) |
| 304 | { |
| 305 | dump_printf(": unhandled!\n"); |
| 306 | return 0; |
| 307 | } |
| 308 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 309 | static int process_finished_round(union perf_event *event, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 310 | struct perf_session *session, |
| 311 | struct perf_event_ops *ops); |
| 312 | |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 313 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) |
| 314 | { |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 315 | if (handler->sample == NULL) |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 316 | handler->sample = process_event_sample_stub; |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 317 | if (handler->mmap == NULL) |
| 318 | handler->mmap = process_event_stub; |
| 319 | if (handler->comm == NULL) |
| 320 | handler->comm = process_event_stub; |
| 321 | if (handler->fork == NULL) |
| 322 | handler->fork = process_event_stub; |
| 323 | if (handler->exit == NULL) |
| 324 | handler->exit = process_event_stub; |
| 325 | if (handler->lost == NULL) |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 326 | handler->lost = perf_event__process_lost; |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 327 | if (handler->read == NULL) |
| 328 | handler->read = process_event_stub; |
| 329 | if (handler->throttle == NULL) |
| 330 | handler->throttle = process_event_stub; |
| 331 | if (handler->unthrottle == NULL) |
| 332 | handler->unthrottle = process_event_stub; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 333 | if (handler->attr == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 334 | handler->attr = process_event_synth_stub; |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 335 | if (handler->event_type == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 336 | handler->event_type = process_event_synth_stub; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 337 | if (handler->tracing_data == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 338 | handler->tracing_data = process_event_synth_stub; |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 339 | if (handler->build_id == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 340 | handler->build_id = process_event_synth_stub; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 341 | if (handler->finished_round == NULL) { |
| 342 | if (handler->ordered_samples) |
| 343 | handler->finished_round = process_finished_round; |
| 344 | else |
| 345 | handler->finished_round = process_finished_round_stub; |
| 346 | } |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 347 | } |
| 348 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 349 | void mem_bswap_64(void *src, int byte_size) |
| 350 | { |
| 351 | u64 *m = src; |
| 352 | |
| 353 | while (byte_size > 0) { |
| 354 | *m = bswap_64(*m); |
| 355 | byte_size -= sizeof(u64); |
| 356 | ++m; |
| 357 | } |
| 358 | } |
| 359 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 360 | static void perf_event__all64_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 361 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 362 | struct perf_event_header *hdr = &event->header; |
| 363 | mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr)); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 364 | } |
| 365 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 366 | static void perf_event__comm_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 367 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 368 | event->comm.pid = bswap_32(event->comm.pid); |
| 369 | event->comm.tid = bswap_32(event->comm.tid); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 370 | } |
| 371 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 372 | static void perf_event__mmap_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 373 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 374 | event->mmap.pid = bswap_32(event->mmap.pid); |
| 375 | event->mmap.tid = bswap_32(event->mmap.tid); |
| 376 | event->mmap.start = bswap_64(event->mmap.start); |
| 377 | event->mmap.len = bswap_64(event->mmap.len); |
| 378 | event->mmap.pgoff = bswap_64(event->mmap.pgoff); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 379 | } |
| 380 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 381 | static void perf_event__task_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 382 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 383 | event->fork.pid = bswap_32(event->fork.pid); |
| 384 | event->fork.tid = bswap_32(event->fork.tid); |
| 385 | event->fork.ppid = bswap_32(event->fork.ppid); |
| 386 | event->fork.ptid = bswap_32(event->fork.ptid); |
| 387 | event->fork.time = bswap_64(event->fork.time); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 388 | } |
| 389 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 390 | static void perf_event__read_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 391 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 392 | event->read.pid = bswap_32(event->read.pid); |
| 393 | event->read.tid = bswap_32(event->read.tid); |
| 394 | event->read.value = bswap_64(event->read.value); |
| 395 | event->read.time_enabled = bswap_64(event->read.time_enabled); |
| 396 | event->read.time_running = bswap_64(event->read.time_running); |
| 397 | event->read.id = bswap_64(event->read.id); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 398 | } |
| 399 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 400 | static void perf_event__attr_swap(union perf_event *event) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 401 | { |
| 402 | size_t size; |
| 403 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 404 | event->attr.attr.type = bswap_32(event->attr.attr.type); |
| 405 | event->attr.attr.size = bswap_32(event->attr.attr.size); |
| 406 | event->attr.attr.config = bswap_64(event->attr.attr.config); |
| 407 | event->attr.attr.sample_period = bswap_64(event->attr.attr.sample_period); |
| 408 | event->attr.attr.sample_type = bswap_64(event->attr.attr.sample_type); |
| 409 | event->attr.attr.read_format = bswap_64(event->attr.attr.read_format); |
| 410 | event->attr.attr.wakeup_events = bswap_32(event->attr.attr.wakeup_events); |
| 411 | event->attr.attr.bp_type = bswap_32(event->attr.attr.bp_type); |
| 412 | event->attr.attr.bp_addr = bswap_64(event->attr.attr.bp_addr); |
| 413 | event->attr.attr.bp_len = bswap_64(event->attr.attr.bp_len); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 414 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 415 | size = event->header.size; |
| 416 | size -= (void *)&event->attr.id - (void *)event; |
| 417 | mem_bswap_64(event->attr.id, size); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 418 | } |
| 419 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 420 | static void perf_event__event_type_swap(union perf_event *event) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 421 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 422 | event->event_type.event_type.event_id = |
| 423 | bswap_64(event->event_type.event_type.event_id); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 424 | } |
| 425 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 426 | static void perf_event__tracing_data_swap(union perf_event *event) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 427 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 428 | event->tracing_data.size = bswap_32(event->tracing_data.size); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 429 | } |
| 430 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 431 | typedef void (*perf_event__swap_op)(union perf_event *event); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 432 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 433 | static perf_event__swap_op perf_event__swap_ops[] = { |
| 434 | [PERF_RECORD_MMAP] = perf_event__mmap_swap, |
| 435 | [PERF_RECORD_COMM] = perf_event__comm_swap, |
| 436 | [PERF_RECORD_FORK] = perf_event__task_swap, |
| 437 | [PERF_RECORD_EXIT] = perf_event__task_swap, |
| 438 | [PERF_RECORD_LOST] = perf_event__all64_swap, |
| 439 | [PERF_RECORD_READ] = perf_event__read_swap, |
| 440 | [PERF_RECORD_SAMPLE] = perf_event__all64_swap, |
| 441 | [PERF_RECORD_HEADER_ATTR] = perf_event__attr_swap, |
| 442 | [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, |
| 443 | [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap, |
| 444 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, |
| 445 | [PERF_RECORD_HEADER_MAX] = NULL, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 446 | }; |
| 447 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 448 | struct sample_queue { |
| 449 | u64 timestamp; |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 450 | u64 file_offset; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 451 | union perf_event *event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 452 | struct list_head list; |
| 453 | }; |
| 454 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 455 | static void perf_session_free_sample_buffers(struct perf_session *session) |
| 456 | { |
| 457 | struct ordered_samples *os = &session->ordered_samples; |
| 458 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 459 | while (!list_empty(&os->to_free)) { |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 460 | struct sample_queue *sq; |
| 461 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 462 | sq = list_entry(os->to_free.next, struct sample_queue, list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 463 | list_del(&sq->list); |
| 464 | free(sq); |
| 465 | } |
| 466 | } |
| 467 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 468 | static int perf_session_deliver_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 469 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 470 | struct perf_sample *sample, |
Thomas Gleixner | f74725d | 2010-12-07 12:48:53 +0000 | [diff] [blame] | 471 | struct perf_event_ops *ops, |
| 472 | u64 file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 473 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 474 | static void flush_sample_queue(struct perf_session *s, |
| 475 | struct perf_event_ops *ops) |
| 476 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 477 | struct ordered_samples *os = &s->ordered_samples; |
| 478 | struct list_head *head = &os->samples; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 479 | struct sample_queue *tmp, *iter; |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 480 | struct perf_sample sample; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 481 | u64 limit = os->next_flush; |
| 482 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame^] | 483 | int ret; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 484 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 485 | if (!ops->ordered_samples || !limit) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 486 | return; |
| 487 | |
| 488 | list_for_each_entry_safe(iter, tmp, head, list) { |
| 489 | if (iter->timestamp > limit) |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 490 | break; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 491 | |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame^] | 492 | ret = perf_session__parse_sample(s, iter->event, &sample); |
| 493 | if (ret) |
| 494 | pr_err("Can't parse sample, err = %d\n", ret); |
| 495 | else |
| 496 | perf_session_deliver_event(s, iter->event, &sample, ops, |
| 497 | iter->file_offset); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 498 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 499 | os->last_flush = iter->timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 500 | list_del(&iter->list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 501 | list_add(&iter->list, &os->sample_cache); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 502 | } |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 503 | |
| 504 | if (list_empty(head)) { |
| 505 | os->last_sample = NULL; |
| 506 | } else if (last_ts <= limit) { |
| 507 | os->last_sample = |
| 508 | list_entry(head->prev, struct sample_queue, list); |
| 509 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 510 | } |
| 511 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 512 | /* |
| 513 | * When perf record finishes a pass on every buffers, it records this pseudo |
| 514 | * event. |
| 515 | * We record the max timestamp t found in the pass n. |
| 516 | * Assuming these timestamps are monotonic across cpus, we know that if |
| 517 | * a buffer still has events with timestamps below t, they will be all |
| 518 | * available and then read in the pass n + 1. |
| 519 | * Hence when we start to read the pass n + 2, we can safely flush every |
| 520 | * events with timestamps below t. |
| 521 | * |
| 522 | * ============ PASS n ================= |
| 523 | * CPU 0 | CPU 1 |
| 524 | * | |
| 525 | * cnt1 timestamps | cnt2 timestamps |
| 526 | * 1 | 2 |
| 527 | * 2 | 3 |
| 528 | * - | 4 <--- max recorded |
| 529 | * |
| 530 | * ============ PASS n + 1 ============== |
| 531 | * CPU 0 | CPU 1 |
| 532 | * | |
| 533 | * cnt1 timestamps | cnt2 timestamps |
| 534 | * 3 | 5 |
| 535 | * 4 | 6 |
| 536 | * 5 | 7 <---- max recorded |
| 537 | * |
| 538 | * Flush every events below timestamp 4 |
| 539 | * |
| 540 | * ============ PASS n + 2 ============== |
| 541 | * CPU 0 | CPU 1 |
| 542 | * | |
| 543 | * cnt1 timestamps | cnt2 timestamps |
| 544 | * 6 | 8 |
| 545 | * 7 | 9 |
| 546 | * - | 10 |
| 547 | * |
| 548 | * Flush every events below timestamp 7 |
| 549 | * etc... |
| 550 | */ |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 551 | static int process_finished_round(union perf_event *event __used, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 552 | struct perf_session *session, |
| 553 | struct perf_event_ops *ops) |
| 554 | { |
| 555 | flush_sample_queue(session, ops); |
| 556 | session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 561 | /* The queue is ordered by time */ |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 562 | static void __queue_event(struct sample_queue *new, struct perf_session *s) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 563 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 564 | struct ordered_samples *os = &s->ordered_samples; |
| 565 | struct sample_queue *sample = os->last_sample; |
| 566 | u64 timestamp = new->timestamp; |
| 567 | struct list_head *p; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 568 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 569 | os->last_sample = new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 570 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 571 | if (!sample) { |
| 572 | list_add(&new->list, &os->samples); |
| 573 | os->max_timestamp = timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 574 | return; |
| 575 | } |
| 576 | |
| 577 | /* |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 578 | * last_sample might point to some random place in the list as it's |
| 579 | * the last queued event. We expect that the new event is close to |
| 580 | * this. |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 581 | */ |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 582 | if (sample->timestamp <= timestamp) { |
| 583 | while (sample->timestamp <= timestamp) { |
| 584 | p = sample->list.next; |
| 585 | if (p == &os->samples) { |
| 586 | list_add_tail(&new->list, &os->samples); |
| 587 | os->max_timestamp = timestamp; |
| 588 | return; |
| 589 | } |
| 590 | sample = list_entry(p, struct sample_queue, list); |
| 591 | } |
| 592 | list_add_tail(&new->list, &sample->list); |
| 593 | } else { |
| 594 | while (sample->timestamp > timestamp) { |
| 595 | p = sample->list.prev; |
| 596 | if (p == &os->samples) { |
| 597 | list_add(&new->list, &os->samples); |
| 598 | return; |
| 599 | } |
| 600 | sample = list_entry(p, struct sample_queue, list); |
| 601 | } |
| 602 | list_add(&new->list, &sample->list); |
| 603 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 606 | #define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct sample_queue)) |
| 607 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 608 | static int perf_session_queue_event(struct perf_session *s, union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 609 | struct perf_sample *sample, u64 file_offset) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 610 | { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 611 | struct ordered_samples *os = &s->ordered_samples; |
| 612 | struct list_head *sc = &os->sample_cache; |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 613 | u64 timestamp = sample->time; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 614 | struct sample_queue *new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 615 | |
Thomas Gleixner | 79a14c1 | 2010-12-07 12:48:44 +0000 | [diff] [blame] | 616 | if (!timestamp || timestamp == ~0ULL) |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 617 | return -ETIME; |
| 618 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 619 | if (timestamp < s->ordered_samples.last_flush) { |
| 620 | printf("Warning: Timestamp below last timeslice flush\n"); |
| 621 | return -EINVAL; |
| 622 | } |
| 623 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 624 | if (!list_empty(sc)) { |
| 625 | new = list_entry(sc->next, struct sample_queue, list); |
| 626 | list_del(&new->list); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 627 | } else if (os->sample_buffer) { |
| 628 | new = os->sample_buffer + os->sample_buffer_idx; |
| 629 | if (++os->sample_buffer_idx == MAX_SAMPLE_BUFFER) |
| 630 | os->sample_buffer = NULL; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 631 | } else { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 632 | os->sample_buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new)); |
| 633 | if (!os->sample_buffer) |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 634 | return -ENOMEM; |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 635 | list_add(&os->sample_buffer->list, &os->to_free); |
| 636 | os->sample_buffer_idx = 2; |
| 637 | new = os->sample_buffer + 1; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 638 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 639 | |
| 640 | new->timestamp = timestamp; |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 641 | new->file_offset = file_offset; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 642 | new->event = event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 643 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 644 | __queue_event(new, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 649 | static void callchain__printf(struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 650 | { |
| 651 | unsigned int i; |
| 652 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 653 | printf("... chain: nr:%" PRIu64 "\n", sample->callchain->nr); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 654 | |
| 655 | for (i = 0; i < sample->callchain->nr; i++) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 656 | printf("..... %2d: %016" PRIx64 "\n", |
| 657 | i, sample->callchain->ips[i]); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 658 | } |
| 659 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 660 | static void perf_session__print_tstamp(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 661 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 662 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 663 | { |
| 664 | if (event->header.type != PERF_RECORD_SAMPLE && |
| 665 | !session->sample_id_all) { |
| 666 | fputs("-1 -1 ", stdout); |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | if ((session->sample_type & PERF_SAMPLE_CPU)) |
| 671 | printf("%u ", sample->cpu); |
| 672 | |
| 673 | if (session->sample_type & PERF_SAMPLE_TIME) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 674 | printf("%" PRIu64 " ", sample->time); |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 675 | } |
| 676 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 677 | static void dump_event(struct perf_session *session, union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 678 | u64 file_offset, struct perf_sample *sample) |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 679 | { |
| 680 | if (!dump_trace) |
| 681 | return; |
| 682 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 683 | printf("\n%#" PRIx64 " [%#x]: event: %d\n", |
| 684 | file_offset, event->header.size, event->header.type); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 685 | |
| 686 | trace_event(event); |
| 687 | |
| 688 | if (sample) |
| 689 | perf_session__print_tstamp(session, event, sample); |
| 690 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 691 | printf("%#" PRIx64 " [%#x]: PERF_RECORD_%s", file_offset, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 692 | event->header.size, perf_event__name(event->header.type)); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 695 | static void dump_sample(struct perf_session *session, union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 696 | struct perf_sample *sample) |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 697 | { |
Arnaldo Carvalho de Melo | ddbc24b | 2010-12-09 12:20:20 -0200 | [diff] [blame] | 698 | if (!dump_trace) |
| 699 | return; |
| 700 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 701 | printf("(IP, %d): %d/%d: %#" PRIx64 " period: %" PRIu64 "\n", |
| 702 | event->header.misc, sample->pid, sample->tid, sample->ip, |
| 703 | sample->period); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 704 | |
| 705 | if (session->sample_type & PERF_SAMPLE_CALLCHAIN) |
Arnaldo Carvalho de Melo | ddbc24b | 2010-12-09 12:20:20 -0200 | [diff] [blame] | 706 | callchain__printf(sample); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 709 | static int perf_session_deliver_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 710 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 711 | struct perf_sample *sample, |
Thomas Gleixner | f74725d | 2010-12-07 12:48:53 +0000 | [diff] [blame] | 712 | struct perf_event_ops *ops, |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 713 | u64 file_offset) |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 714 | { |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 715 | struct perf_evsel *evsel; |
| 716 | |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 717 | dump_event(session, event, file_offset, sample); |
| 718 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 719 | switch (event->header.type) { |
| 720 | case PERF_RECORD_SAMPLE: |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 721 | dump_sample(session, event, sample); |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 722 | evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
| 723 | if (evsel == NULL) { |
| 724 | ++session->hists.stats.nr_unknown_id; |
| 725 | return -1; |
| 726 | } |
| 727 | return ops->sample(event, sample, evsel, session); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 728 | case PERF_RECORD_MMAP: |
| 729 | return ops->mmap(event, sample, session); |
| 730 | case PERF_RECORD_COMM: |
| 731 | return ops->comm(event, sample, session); |
| 732 | case PERF_RECORD_FORK: |
| 733 | return ops->fork(event, sample, session); |
| 734 | case PERF_RECORD_EXIT: |
| 735 | return ops->exit(event, sample, session); |
| 736 | case PERF_RECORD_LOST: |
| 737 | return ops->lost(event, sample, session); |
| 738 | case PERF_RECORD_READ: |
| 739 | return ops->read(event, sample, session); |
| 740 | case PERF_RECORD_THROTTLE: |
| 741 | return ops->throttle(event, sample, session); |
| 742 | case PERF_RECORD_UNTHROTTLE: |
| 743 | return ops->unthrottle(event, sample, session); |
| 744 | default: |
| 745 | ++session->hists.stats.nr_unknown_events; |
| 746 | return -1; |
| 747 | } |
| 748 | } |
| 749 | |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 750 | static int perf_session__preprocess_sample(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 751 | union perf_event *event, struct perf_sample *sample) |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 752 | { |
| 753 | if (event->header.type != PERF_RECORD_SAMPLE || |
| 754 | !(session->sample_type & PERF_SAMPLE_CALLCHAIN)) |
| 755 | return 0; |
| 756 | |
| 757 | if (!ip_callchain__valid(sample->callchain, event)) { |
| 758 | pr_debug("call-chain problem with event, skipping it.\n"); |
| 759 | ++session->hists.stats.nr_invalid_chains; |
| 760 | session->hists.stats.total_invalid_chains += sample->period; |
| 761 | return -EINVAL; |
| 762 | } |
| 763 | return 0; |
| 764 | } |
| 765 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 766 | static int perf_session__process_user_event(struct perf_session *session, union perf_event *event, |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 767 | struct perf_event_ops *ops, u64 file_offset) |
| 768 | { |
| 769 | dump_event(session, event, file_offset, NULL); |
| 770 | |
| 771 | /* These events are processed right away */ |
| 772 | switch (event->header.type) { |
| 773 | case PERF_RECORD_HEADER_ATTR: |
| 774 | return ops->attr(event, session); |
| 775 | case PERF_RECORD_HEADER_EVENT_TYPE: |
| 776 | return ops->event_type(event, session); |
| 777 | case PERF_RECORD_HEADER_TRACING_DATA: |
| 778 | /* setup for reading amidst mmap */ |
| 779 | lseek(session->fd, file_offset, SEEK_SET); |
| 780 | return ops->tracing_data(event, session); |
| 781 | case PERF_RECORD_HEADER_BUILD_ID: |
| 782 | return ops->build_id(event, session); |
| 783 | case PERF_RECORD_FINISHED_ROUND: |
| 784 | return ops->finished_round(event, session, ops); |
| 785 | default: |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | } |
| 789 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 790 | static int perf_session__process_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 791 | union perf_event *event, |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 792 | struct perf_event_ops *ops, |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 793 | u64 file_offset) |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 794 | { |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 795 | struct perf_sample sample; |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 796 | int ret; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 797 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 798 | if (session->header.needs_swap && |
| 799 | perf_event__swap_ops[event->header.type]) |
| 800 | perf_event__swap_ops[event->header.type](event); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 801 | |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 802 | if (event->header.type >= PERF_RECORD_HEADER_MAX) |
| 803 | return -EINVAL; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 804 | |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 805 | hists__inc_nr_events(&session->hists, event->header.type); |
| 806 | |
| 807 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 808 | return perf_session__process_user_event(session, event, ops, file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 809 | |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 810 | /* |
| 811 | * For all kernel events we get the sample data |
| 812 | */ |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame^] | 813 | ret = perf_session__parse_sample(session, event, &sample); |
| 814 | if (ret) |
| 815 | return ret; |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 816 | |
| 817 | /* Preprocess sample records - precheck callchains */ |
| 818 | if (perf_session__preprocess_sample(session, event, &sample)) |
| 819 | return 0; |
| 820 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 821 | if (ops->ordered_samples) { |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 822 | ret = perf_session_queue_event(session, event, &sample, |
| 823 | file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 824 | if (ret != -ETIME) |
| 825 | return ret; |
| 826 | } |
| 827 | |
Thomas Gleixner | f74725d | 2010-12-07 12:48:53 +0000 | [diff] [blame] | 828 | return perf_session_deliver_event(session, event, &sample, ops, |
| 829 | file_offset); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 830 | } |
| 831 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 832 | void perf_event_header__bswap(struct perf_event_header *self) |
| 833 | { |
| 834 | self->type = bswap_32(self->type); |
| 835 | self->misc = bswap_16(self->misc); |
| 836 | self->size = bswap_16(self->size); |
| 837 | } |
| 838 | |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 839 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) |
| 840 | { |
| 841 | struct thread *thread = perf_session__findnew(self, 0); |
| 842 | |
| 843 | if (thread == NULL || thread__set_comm(thread, "swapper")) { |
| 844 | pr_err("problem inserting idle task.\n"); |
| 845 | thread = NULL; |
| 846 | } |
| 847 | |
| 848 | return thread; |
| 849 | } |
| 850 | |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 851 | static void perf_session__warn_about_errors(const struct perf_session *session, |
| 852 | const struct perf_event_ops *ops) |
| 853 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 854 | if (ops->lost == perf_event__process_lost && |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 855 | session->hists.stats.total_lost != 0) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 856 | ui__warning("Processed %" PRIu64 " events and LOST %" PRIu64 |
| 857 | "!\n\nCheck IO/CPU overload!\n\n", |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 858 | session->hists.stats.total_period, |
| 859 | session->hists.stats.total_lost); |
| 860 | } |
| 861 | |
| 862 | if (session->hists.stats.nr_unknown_events != 0) { |
| 863 | ui__warning("Found %u unknown events!\n\n" |
| 864 | "Is this an older tool processing a perf.data " |
| 865 | "file generated by a more recent tool?\n\n" |
| 866 | "If that is not the case, consider " |
| 867 | "reporting to linux-kernel@vger.kernel.org.\n\n", |
| 868 | session->hists.stats.nr_unknown_events); |
| 869 | } |
| 870 | |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 871 | if (session->hists.stats.nr_unknown_id != 0) { |
| 872 | ui__warning("%u samples with id not present in the header\n", |
| 873 | session->hists.stats.nr_unknown_id); |
| 874 | } |
| 875 | |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 876 | if (session->hists.stats.nr_invalid_chains != 0) { |
| 877 | ui__warning("Found invalid callchains!\n\n" |
| 878 | "%u out of %u events were discarded for this reason.\n\n" |
| 879 | "Consider reporting to linux-kernel@vger.kernel.org.\n\n", |
| 880 | session->hists.stats.nr_invalid_chains, |
| 881 | session->hists.stats.nr_events[PERF_RECORD_SAMPLE]); |
| 882 | } |
| 883 | } |
| 884 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 885 | #define session_done() (*(volatile int *)(&session_done)) |
| 886 | volatile int session_done; |
| 887 | |
| 888 | static int __perf_session__process_pipe_events(struct perf_session *self, |
| 889 | struct perf_event_ops *ops) |
| 890 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 891 | union perf_event event; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 892 | uint32_t size; |
| 893 | int skip = 0; |
| 894 | u64 head; |
| 895 | int err; |
| 896 | void *p; |
| 897 | |
| 898 | perf_event_ops__fill_defaults(ops); |
| 899 | |
| 900 | head = 0; |
| 901 | more: |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 902 | err = readn(self->fd, &event, sizeof(struct perf_event_header)); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 903 | if (err <= 0) { |
| 904 | if (err == 0) |
| 905 | goto done; |
| 906 | |
| 907 | pr_err("failed to read event header\n"); |
| 908 | goto out_err; |
| 909 | } |
| 910 | |
| 911 | if (self->header.needs_swap) |
| 912 | perf_event_header__bswap(&event.header); |
| 913 | |
| 914 | size = event.header.size; |
| 915 | if (size == 0) |
| 916 | size = 8; |
| 917 | |
| 918 | p = &event; |
| 919 | p += sizeof(struct perf_event_header); |
| 920 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 921 | if (size - sizeof(struct perf_event_header)) { |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 922 | err = readn(self->fd, p, size - sizeof(struct perf_event_header)); |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 923 | if (err <= 0) { |
| 924 | if (err == 0) { |
| 925 | pr_err("unexpected end of event stream\n"); |
| 926 | goto done; |
| 927 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 928 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 929 | pr_err("failed to read event data\n"); |
| 930 | goto out_err; |
| 931 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | if (size == 0 || |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 935 | (skip = perf_session__process_event(self, &event, ops, head)) < 0) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 936 | dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 937 | head, event.header.size, event.header.type); |
| 938 | /* |
| 939 | * assume we lost track of the stream, check alignment, and |
| 940 | * increment a single u64 in the hope to catch on again 'soon'. |
| 941 | */ |
| 942 | if (unlikely(head & 7)) |
| 943 | head &= ~7ULL; |
| 944 | |
| 945 | size = 8; |
| 946 | } |
| 947 | |
| 948 | head += size; |
| 949 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 950 | if (skip > 0) |
| 951 | head += skip; |
| 952 | |
| 953 | if (!session_done()) |
| 954 | goto more; |
| 955 | done: |
| 956 | err = 0; |
| 957 | out_err: |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 958 | perf_session__warn_about_errors(self, ops); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 959 | perf_session_free_sample_buffers(self); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 960 | return err; |
| 961 | } |
| 962 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 963 | int __perf_session__process_events(struct perf_session *session, |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 964 | u64 data_offset, u64 data_size, |
| 965 | u64 file_size, struct perf_event_ops *ops) |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 966 | { |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 967 | u64 head, page_offset, file_offset, file_pos, progress_next; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 968 | int err, mmap_prot, mmap_flags, map_idx = 0; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 969 | struct ui_progress *progress; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 970 | size_t page_size, mmap_size; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 971 | char *buf, *mmaps[8]; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 972 | union perf_event *event; |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 973 | uint32_t size; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 974 | |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 975 | perf_event_ops__fill_defaults(ops); |
| 976 | |
Arnaldo Carvalho de Melo | 1b75962 | 2010-01-14 18:30:04 -0200 | [diff] [blame] | 977 | page_size = sysconf(_SC_PAGESIZE); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 978 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 979 | page_offset = page_size * (data_offset / page_size); |
| 980 | file_offset = page_offset; |
| 981 | head = data_offset - page_offset; |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 982 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 983 | if (data_offset + data_size < file_size) |
| 984 | file_size = data_offset + data_size; |
| 985 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 986 | progress_next = file_size / 16; |
| 987 | progress = ui_progress__new("Processing events...", file_size); |
| 988 | if (progress == NULL) |
| 989 | return -1; |
| 990 | |
| 991 | mmap_size = session->mmap_window; |
| 992 | if (mmap_size > file_size) |
| 993 | mmap_size = file_size; |
| 994 | |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 995 | memset(mmaps, 0, sizeof(mmaps)); |
| 996 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 997 | mmap_prot = PROT_READ; |
| 998 | mmap_flags = MAP_SHARED; |
| 999 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1000 | if (session->header.needs_swap) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1001 | mmap_prot |= PROT_WRITE; |
| 1002 | mmap_flags = MAP_PRIVATE; |
| 1003 | } |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1004 | remap: |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1005 | buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, session->fd, |
| 1006 | file_offset); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1007 | if (buf == MAP_FAILED) { |
| 1008 | pr_err("failed to mmap file\n"); |
| 1009 | err = -errno; |
| 1010 | goto out_err; |
| 1011 | } |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1012 | mmaps[map_idx] = buf; |
| 1013 | map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1014 | file_pos = file_offset + head; |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1015 | |
| 1016 | more: |
Frederic Weisbecker | eac9eac | 2011-05-21 17:07:24 +0200 | [diff] [blame] | 1017 | /* |
| 1018 | * Ensure we have enough space remaining to read |
| 1019 | * the size of the event in the headers. |
| 1020 | */ |
| 1021 | if (head + sizeof(event->header) > mmap_size) |
| 1022 | goto remap; |
| 1023 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1024 | event = (union perf_event *)(buf + head); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1025 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1026 | if (session->header.needs_swap) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1027 | perf_event_header__bswap(&event->header); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1028 | |
Arnaldo Carvalho de Melo | 3d03e2e | 2011-01-10 21:37:57 -0200 | [diff] [blame] | 1029 | if (head + event->header.size > mmap_size) { |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1030 | if (mmaps[map_idx]) { |
| 1031 | munmap(mmaps[map_idx], mmap_size); |
| 1032 | mmaps[map_idx] = NULL; |
| 1033 | } |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1034 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1035 | page_offset = page_size * (head / page_size); |
| 1036 | file_offset += page_offset; |
| 1037 | head -= page_offset; |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1038 | goto remap; |
| 1039 | } |
| 1040 | |
| 1041 | size = event->header.size; |
| 1042 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1043 | if (size == 0 || |
| 1044 | perf_session__process_event(session, event, ops, file_pos) < 0) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1045 | dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1046 | file_offset + head, event->header.size, |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1047 | event->header.type); |
| 1048 | /* |
| 1049 | * assume we lost track of the stream, check alignment, and |
| 1050 | * increment a single u64 in the hope to catch on again 'soon'. |
| 1051 | */ |
| 1052 | if (unlikely(head & 7)) |
| 1053 | head &= ~7ULL; |
| 1054 | |
| 1055 | size = 8; |
| 1056 | } |
| 1057 | |
| 1058 | head += size; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1059 | file_pos += size; |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1060 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1061 | if (file_pos >= progress_next) { |
| 1062 | progress_next += file_size / 16; |
| 1063 | ui_progress__update(progress, file_pos); |
| 1064 | } |
| 1065 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1066 | if (file_pos < file_size) |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1067 | goto more; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1068 | |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1069 | err = 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 1070 | /* do the final flush for ordered samples */ |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1071 | session->ordered_samples.next_flush = ULLONG_MAX; |
| 1072 | flush_sample_queue(session, ops); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1073 | out_err: |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 1074 | ui_progress__delete(progress); |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1075 | perf_session__warn_about_errors(session, ops); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 1076 | perf_session_free_sample_buffers(session); |
Arnaldo Carvalho de Melo | 06aae59 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1077 | return err; |
| 1078 | } |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1079 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1080 | int perf_session__process_events(struct perf_session *self, |
| 1081 | struct perf_event_ops *ops) |
| 1082 | { |
| 1083 | int err; |
| 1084 | |
| 1085 | if (perf_session__register_idle_thread(self) == NULL) |
| 1086 | return -ENOMEM; |
| 1087 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1088 | if (!self->fd_pipe) |
| 1089 | err = __perf_session__process_events(self, |
| 1090 | self->header.data_offset, |
| 1091 | self->header.data_size, |
| 1092 | self->size, ops); |
| 1093 | else |
| 1094 | err = __perf_session__process_pipe_events(self, ops); |
Dave Martin | 88ca895 | 2010-07-27 11:46:12 -0300 | [diff] [blame] | 1095 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1096 | return err; |
| 1097 | } |
| 1098 | |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1099 | bool perf_session__has_traces(struct perf_session *self, const char *msg) |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1100 | { |
| 1101 | if (!(self->sample_type & PERF_SAMPLE_RAW)) { |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1102 | pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); |
| 1103 | return false; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1104 | } |
| 1105 | |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1106 | return true; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1107 | } |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1108 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1109 | int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1110 | const char *symbol_name, |
| 1111 | u64 addr) |
| 1112 | { |
| 1113 | char *bracket; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1114 | enum map_type i; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1115 | struct ref_reloc_sym *ref; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1116 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1117 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
| 1118 | if (ref == NULL) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1119 | return -ENOMEM; |
| 1120 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1121 | ref->name = strdup(symbol_name); |
| 1122 | if (ref->name == NULL) { |
| 1123 | free(ref); |
| 1124 | return -ENOMEM; |
| 1125 | } |
| 1126 | |
| 1127 | bracket = strchr(ref->name, ']'); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1128 | if (bracket) |
| 1129 | *bracket = '\0'; |
| 1130 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1131 | ref->addr = addr; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1132 | |
| 1133 | for (i = 0; i < MAP__NR_TYPES; ++i) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1134 | struct kmap *kmap = map__kmap(maps[i]); |
| 1135 | kmap->ref_reloc_sym = ref; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1138 | return 0; |
| 1139 | } |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1140 | |
| 1141 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) |
| 1142 | { |
| 1143 | return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + |
| 1144 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
| 1145 | machines__fprintf_dsos(&self->machines, fp); |
| 1146 | } |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 1147 | |
| 1148 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, |
| 1149 | bool with_hits) |
| 1150 | { |
| 1151 | size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits); |
| 1152 | return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
| 1153 | } |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1154 | |
| 1155 | size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) |
| 1156 | { |
| 1157 | struct perf_evsel *pos; |
| 1158 | size_t ret = fprintf(fp, "Aggregated stats:\n"); |
| 1159 | |
| 1160 | ret += hists__fprintf_nr_events(&session->hists, fp); |
| 1161 | |
| 1162 | list_for_each_entry(pos, &session->evlist->entries, node) { |
| 1163 | ret += fprintf(fp, "%s stats:\n", event_name(pos)); |
| 1164 | ret += hists__fprintf_nr_events(&pos->hists, fp); |
| 1165 | } |
| 1166 | |
| 1167 | return ret; |
| 1168 | } |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1169 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 1170 | struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, |
| 1171 | unsigned int type) |
| 1172 | { |
| 1173 | struct perf_evsel *pos; |
| 1174 | |
| 1175 | list_for_each_entry(pos, &session->evlist->entries, node) { |
| 1176 | if (pos->attr.type == type) |
| 1177 | return pos; |
| 1178 | } |
| 1179 | return NULL; |
| 1180 | } |
| 1181 | |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1182 | void perf_session__print_symbols(union perf_event *event, |
| 1183 | struct perf_sample *sample, |
| 1184 | struct perf_session *session) |
| 1185 | { |
| 1186 | struct addr_location al; |
| 1187 | const char *symname, *dsoname; |
| 1188 | struct callchain_cursor *cursor = &session->callchain_cursor; |
| 1189 | struct callchain_cursor_node *node; |
| 1190 | |
| 1191 | if (perf_event__preprocess_sample(event, session, &al, sample, |
| 1192 | NULL) < 0) { |
| 1193 | error("problem processing %d event, skipping it.\n", |
| 1194 | event->header.type); |
| 1195 | return; |
| 1196 | } |
| 1197 | |
| 1198 | if (symbol_conf.use_callchain && sample->callchain) { |
| 1199 | |
| 1200 | if (perf_session__resolve_callchain(session, al.thread, |
| 1201 | sample->callchain, NULL) != 0) { |
| 1202 | if (verbose) |
| 1203 | error("Failed to resolve callchain. Skipping\n"); |
| 1204 | return; |
| 1205 | } |
| 1206 | callchain_cursor_commit(cursor); |
| 1207 | |
| 1208 | while (1) { |
| 1209 | node = callchain_cursor_current(cursor); |
| 1210 | if (!node) |
| 1211 | break; |
| 1212 | |
| 1213 | if (node->sym && node->sym->name) |
| 1214 | symname = node->sym->name; |
| 1215 | else |
| 1216 | symname = ""; |
| 1217 | |
| 1218 | if (node->map && node->map->dso && node->map->dso->name) |
| 1219 | dsoname = node->map->dso->name; |
| 1220 | else |
| 1221 | dsoname = ""; |
| 1222 | |
| 1223 | printf("\t%16" PRIx64 " %s (%s)\n", node->ip, symname, dsoname); |
| 1224 | |
| 1225 | callchain_cursor_advance(cursor); |
| 1226 | } |
| 1227 | |
| 1228 | } else { |
| 1229 | if (al.sym && al.sym->name) |
| 1230 | symname = al.sym->name; |
| 1231 | else |
| 1232 | symname = ""; |
| 1233 | |
| 1234 | if (al.map && al.map->dso && al.map->dso->name) |
| 1235 | dsoname = al.map->dso->name; |
| 1236 | else |
| 1237 | dsoname = ""; |
| 1238 | |
| 1239 | printf("%16" PRIx64 " %s (%s)", al.addr, symname, dsoname); |
| 1240 | } |
| 1241 | } |