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