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