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 | |
| 10 | #include "session.h" |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 11 | #include "sort.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 12 | #include "util.h" |
| 13 | |
| 14 | static int perf_session__open(struct perf_session *self, bool force) |
| 15 | { |
| 16 | struct stat input_stat; |
| 17 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 18 | if (!strcmp(self->filename, "-")) { |
| 19 | self->fd_pipe = true; |
| 20 | self->fd = STDIN_FILENO; |
| 21 | |
| 22 | if (perf_header__read(self, self->fd) < 0) |
| 23 | pr_err("incompatible file format"); |
| 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 28 | self->fd = open(self->filename, O_RDONLY); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 29 | if (self->fd < 0) { |
Andy Isaacson | 0f2c3de | 2010-06-11 20:36:15 -0700 | [diff] [blame] | 30 | int err = errno; |
| 31 | |
| 32 | pr_err("failed to open %s: %s", self->filename, strerror(err)); |
| 33 | if (err == ENOENT && !strcmp(self->filename, "perf.data")) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 34 | pr_err(" (try 'perf record' first)"); |
| 35 | pr_err("\n"); |
| 36 | return -errno; |
| 37 | } |
| 38 | |
| 39 | if (fstat(self->fd, &input_stat) < 0) |
| 40 | goto out_close; |
| 41 | |
| 42 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { |
| 43 | pr_err("file %s not owned by current user or root\n", |
| 44 | self->filename); |
| 45 | goto out_close; |
| 46 | } |
| 47 | |
| 48 | if (!input_stat.st_size) { |
| 49 | pr_info("zero-sized file (%s), nothing to do!\n", |
| 50 | self->filename); |
| 51 | goto out_close; |
| 52 | } |
| 53 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 54 | if (perf_header__read(self, self->fd) < 0) { |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 55 | pr_err("incompatible file format"); |
| 56 | goto out_close; |
| 57 | } |
| 58 | |
| 59 | self->size = input_stat.st_size; |
| 60 | return 0; |
| 61 | |
| 62 | out_close: |
| 63 | close(self->fd); |
| 64 | self->fd = -1; |
| 65 | return -1; |
| 66 | } |
| 67 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 68 | void perf_session__update_sample_type(struct perf_session *self) |
| 69 | { |
| 70 | self->sample_type = perf_header__sample_type(&self->header); |
| 71 | } |
| 72 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 73 | void perf_session__set_sample_type(struct perf_session *session, u64 type) |
| 74 | { |
| 75 | session->sample_type = type; |
| 76 | } |
| 77 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 78 | int perf_session__create_kernel_maps(struct perf_session *self) |
| 79 | { |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 80 | int ret = machine__create_kernel_maps(&self->host_machine); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 81 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 82 | if (ret >= 0) |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 83 | ret = machines__create_guest_kernel_maps(&self->machines); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 84 | return ret; |
| 85 | } |
| 86 | |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 87 | static void perf_session__destroy_kernel_maps(struct perf_session *self) |
| 88 | { |
| 89 | machine__destroy_kernel_maps(&self->host_machine); |
| 90 | machines__destroy_guest_kernel_maps(&self->machines); |
| 91 | } |
| 92 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 93 | struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 94 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 95 | size_t len = filename ? strlen(filename) + 1 : 0; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 96 | struct perf_session *self = zalloc(sizeof(*self) + len); |
| 97 | |
| 98 | if (self == NULL) |
| 99 | goto out; |
| 100 | |
| 101 | if (perf_header__init(&self->header) < 0) |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 102 | goto out_free; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 103 | |
| 104 | memcpy(self->filename, filename, len); |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 105 | self->threads = RB_ROOT; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 106 | INIT_LIST_HEAD(&self->dead_threads); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 107 | self->hists_tree = RB_ROOT; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 108 | self->last_match = NULL; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 109 | /* |
| 110 | * On 64bit we can mmap the data file in one go. No need for tiny mmap |
| 111 | * slices. On 32bit we use 32MB. |
| 112 | */ |
| 113 | #if BITS_PER_LONG == 64 |
| 114 | self->mmap_window = ULLONG_MAX; |
| 115 | #else |
| 116 | self->mmap_window = 32 * 1024 * 1024ULL; |
| 117 | #endif |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 118 | self->machines = RB_ROOT; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 119 | self->repipe = repipe; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 120 | INIT_LIST_HEAD(&self->ordered_samples.samples); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 121 | INIT_LIST_HEAD(&self->ordered_samples.sample_cache); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 122 | INIT_LIST_HEAD(&self->ordered_samples.to_free); |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 123 | machine__init(&self->host_machine, "", HOST_KERNEL_ID); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 124 | |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 125 | if (mode == O_RDONLY) { |
| 126 | if (perf_session__open(self, force) < 0) |
| 127 | goto out_delete; |
| 128 | } else if (mode == O_WRONLY) { |
| 129 | /* |
| 130 | * In O_RDONLY mode this will be performed when reading the |
| 131 | * kernel MMAP event, in event__process_mmap(). |
| 132 | */ |
| 133 | if (perf_session__create_kernel_maps(self) < 0) |
| 134 | goto out_delete; |
| 135 | } |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 136 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 137 | perf_session__update_sample_type(self); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 138 | out: |
| 139 | return self; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 140 | out_free: |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 141 | free(self); |
| 142 | return NULL; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 143 | out_delete: |
| 144 | perf_session__delete(self); |
| 145 | return NULL; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 146 | } |
| 147 | |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 148 | static void perf_session__delete_dead_threads(struct perf_session *self) |
| 149 | { |
| 150 | struct thread *n, *t; |
| 151 | |
| 152 | list_for_each_entry_safe(t, n, &self->dead_threads, node) { |
| 153 | list_del(&t->node); |
| 154 | thread__delete(t); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static void perf_session__delete_threads(struct perf_session *self) |
| 159 | { |
| 160 | struct rb_node *nd = rb_first(&self->threads); |
| 161 | |
| 162 | while (nd) { |
| 163 | struct thread *t = rb_entry(nd, struct thread, rb_node); |
| 164 | |
| 165 | rb_erase(&t->rb_node, &self->threads); |
| 166 | nd = rb_next(nd); |
| 167 | thread__delete(t); |
| 168 | } |
| 169 | } |
| 170 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 171 | void perf_session__delete(struct perf_session *self) |
| 172 | { |
| 173 | perf_header__exit(&self->header); |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 174 | perf_session__destroy_kernel_maps(self); |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 175 | perf_session__delete_dead_threads(self); |
| 176 | perf_session__delete_threads(self); |
| 177 | machine__exit(&self->host_machine); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 178 | close(self->fd); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 179 | free(self); |
| 180 | } |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 181 | |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 182 | void perf_session__remove_thread(struct perf_session *self, struct thread *th) |
| 183 | { |
Arnaldo Carvalho de Melo | 70597f2 | 2010-08-02 18:59:28 -0300 | [diff] [blame] | 184 | self->last_match = NULL; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 185 | rb_erase(&th->rb_node, &self->threads); |
| 186 | /* |
| 187 | * We may have references to this thread, for instance in some hist_entry |
| 188 | * instances, so just move them to a separate list. |
| 189 | */ |
| 190 | list_add_tail(&th->node, &self->dead_threads); |
| 191 | } |
| 192 | |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 193 | static bool symbol__match_parent_regex(struct symbol *sym) |
| 194 | { |
| 195 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
| 196 | return 1; |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 201 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
| 202 | struct thread *thread, |
| 203 | struct ip_callchain *chain, |
| 204 | struct symbol **parent) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 205 | { |
| 206 | u8 cpumode = PERF_RECORD_MISC_USER; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 207 | unsigned int i; |
Arnaldo Carvalho de Melo | ad5b217 | 2010-04-02 10:04:18 -0300 | [diff] [blame] | 208 | struct map_symbol *syms = calloc(chain->nr, sizeof(*syms)); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 209 | |
Arnaldo Carvalho de Melo | ad5b217 | 2010-04-02 10:04:18 -0300 | [diff] [blame] | 210 | if (!syms) |
| 211 | return NULL; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 212 | |
| 213 | for (i = 0; i < chain->nr; i++) { |
| 214 | u64 ip = chain->ips[i]; |
| 215 | struct addr_location al; |
| 216 | |
| 217 | if (ip >= PERF_CONTEXT_MAX) { |
| 218 | switch (ip) { |
| 219 | case PERF_CONTEXT_HV: |
| 220 | cpumode = PERF_RECORD_MISC_HYPERVISOR; break; |
| 221 | case PERF_CONTEXT_KERNEL: |
| 222 | cpumode = PERF_RECORD_MISC_KERNEL; break; |
| 223 | case PERF_CONTEXT_USER: |
| 224 | cpumode = PERF_RECORD_MISC_USER; break; |
| 225 | default: |
| 226 | break; |
| 227 | } |
| 228 | continue; |
| 229 | } |
| 230 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 231 | al.filtered = false; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 232 | thread__find_addr_location(thread, self, cpumode, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 233 | MAP__FUNCTION, thread->pid, ip, &al, NULL); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 234 | if (al.sym != NULL) { |
| 235 | if (sort__has_parent && !*parent && |
| 236 | symbol__match_parent_regex(al.sym)) |
| 237 | *parent = al.sym; |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 238 | if (!symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 239 | break; |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 240 | syms[i].map = al.map; |
| 241 | syms[i].sym = al.sym; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | return syms; |
| 246 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 247 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 248 | static int process_event_synth_stub(event_t *event __used, |
| 249 | struct perf_session *session __used) |
| 250 | { |
| 251 | dump_printf(": unhandled!\n"); |
| 252 | return 0; |
| 253 | } |
| 254 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 255 | static int process_event_stub(event_t *event __used, |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 256 | struct sample_data *sample __used, |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 257 | struct perf_session *session __used) |
| 258 | { |
| 259 | dump_printf(": unhandled!\n"); |
| 260 | return 0; |
| 261 | } |
| 262 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 263 | static int process_finished_round_stub(event_t *event __used, |
| 264 | struct perf_session *session __used, |
| 265 | struct perf_event_ops *ops __used) |
| 266 | { |
| 267 | dump_printf(": unhandled!\n"); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int process_finished_round(event_t *event, |
| 272 | struct perf_session *session, |
| 273 | struct perf_event_ops *ops); |
| 274 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 275 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) |
| 276 | { |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 277 | if (handler->sample == NULL) |
| 278 | handler->sample = process_event_stub; |
| 279 | if (handler->mmap == NULL) |
| 280 | handler->mmap = process_event_stub; |
| 281 | if (handler->comm == NULL) |
| 282 | handler->comm = process_event_stub; |
| 283 | if (handler->fork == NULL) |
| 284 | handler->fork = process_event_stub; |
| 285 | if (handler->exit == NULL) |
| 286 | handler->exit = process_event_stub; |
| 287 | if (handler->lost == NULL) |
Arnaldo Carvalho de Melo | 37982ba | 2010-11-26 18:31:54 -0200 | [diff] [blame] | 288 | handler->lost = event__process_lost; |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 289 | if (handler->read == NULL) |
| 290 | handler->read = process_event_stub; |
| 291 | if (handler->throttle == NULL) |
| 292 | handler->throttle = process_event_stub; |
| 293 | if (handler->unthrottle == NULL) |
| 294 | handler->unthrottle = process_event_stub; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 295 | if (handler->attr == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 296 | handler->attr = process_event_synth_stub; |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 297 | if (handler->event_type == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 298 | handler->event_type = process_event_synth_stub; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 299 | if (handler->tracing_data == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 300 | handler->tracing_data = process_event_synth_stub; |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 301 | if (handler->build_id == NULL) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 302 | handler->build_id = process_event_synth_stub; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 303 | if (handler->finished_round == NULL) { |
| 304 | if (handler->ordered_samples) |
| 305 | handler->finished_round = process_finished_round; |
| 306 | else |
| 307 | handler->finished_round = process_finished_round_stub; |
| 308 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 309 | } |
| 310 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 311 | void mem_bswap_64(void *src, int byte_size) |
| 312 | { |
| 313 | u64 *m = src; |
| 314 | |
| 315 | while (byte_size > 0) { |
| 316 | *m = bswap_64(*m); |
| 317 | byte_size -= sizeof(u64); |
| 318 | ++m; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static void event__all64_swap(event_t *self) |
| 323 | { |
| 324 | struct perf_event_header *hdr = &self->header; |
| 325 | mem_bswap_64(hdr + 1, self->header.size - sizeof(*hdr)); |
| 326 | } |
| 327 | |
| 328 | static void event__comm_swap(event_t *self) |
| 329 | { |
| 330 | self->comm.pid = bswap_32(self->comm.pid); |
| 331 | self->comm.tid = bswap_32(self->comm.tid); |
| 332 | } |
| 333 | |
| 334 | static void event__mmap_swap(event_t *self) |
| 335 | { |
| 336 | self->mmap.pid = bswap_32(self->mmap.pid); |
| 337 | self->mmap.tid = bswap_32(self->mmap.tid); |
| 338 | self->mmap.start = bswap_64(self->mmap.start); |
| 339 | self->mmap.len = bswap_64(self->mmap.len); |
| 340 | self->mmap.pgoff = bswap_64(self->mmap.pgoff); |
| 341 | } |
| 342 | |
| 343 | static void event__task_swap(event_t *self) |
| 344 | { |
| 345 | self->fork.pid = bswap_32(self->fork.pid); |
| 346 | self->fork.tid = bswap_32(self->fork.tid); |
| 347 | self->fork.ppid = bswap_32(self->fork.ppid); |
| 348 | self->fork.ptid = bswap_32(self->fork.ptid); |
| 349 | self->fork.time = bswap_64(self->fork.time); |
| 350 | } |
| 351 | |
| 352 | static void event__read_swap(event_t *self) |
| 353 | { |
| 354 | self->read.pid = bswap_32(self->read.pid); |
| 355 | self->read.tid = bswap_32(self->read.tid); |
| 356 | self->read.value = bswap_64(self->read.value); |
| 357 | self->read.time_enabled = bswap_64(self->read.time_enabled); |
| 358 | self->read.time_running = bswap_64(self->read.time_running); |
| 359 | self->read.id = bswap_64(self->read.id); |
| 360 | } |
| 361 | |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 362 | static void event__attr_swap(event_t *self) |
| 363 | { |
| 364 | size_t size; |
| 365 | |
| 366 | self->attr.attr.type = bswap_32(self->attr.attr.type); |
| 367 | self->attr.attr.size = bswap_32(self->attr.attr.size); |
| 368 | self->attr.attr.config = bswap_64(self->attr.attr.config); |
| 369 | self->attr.attr.sample_period = bswap_64(self->attr.attr.sample_period); |
| 370 | self->attr.attr.sample_type = bswap_64(self->attr.attr.sample_type); |
| 371 | self->attr.attr.read_format = bswap_64(self->attr.attr.read_format); |
| 372 | self->attr.attr.wakeup_events = bswap_32(self->attr.attr.wakeup_events); |
| 373 | self->attr.attr.bp_type = bswap_32(self->attr.attr.bp_type); |
| 374 | self->attr.attr.bp_addr = bswap_64(self->attr.attr.bp_addr); |
| 375 | self->attr.attr.bp_len = bswap_64(self->attr.attr.bp_len); |
| 376 | |
| 377 | size = self->header.size; |
| 378 | size -= (void *)&self->attr.id - (void *)self; |
| 379 | mem_bswap_64(self->attr.id, size); |
| 380 | } |
| 381 | |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 382 | static void event__event_type_swap(event_t *self) |
| 383 | { |
| 384 | self->event_type.event_type.event_id = |
| 385 | bswap_64(self->event_type.event_type.event_id); |
| 386 | } |
| 387 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 388 | static void event__tracing_data_swap(event_t *self) |
| 389 | { |
| 390 | self->tracing_data.size = bswap_32(self->tracing_data.size); |
| 391 | } |
| 392 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 393 | typedef void (*event__swap_op)(event_t *self); |
| 394 | |
| 395 | static event__swap_op event__swap_ops[] = { |
| 396 | [PERF_RECORD_MMAP] = event__mmap_swap, |
| 397 | [PERF_RECORD_COMM] = event__comm_swap, |
| 398 | [PERF_RECORD_FORK] = event__task_swap, |
| 399 | [PERF_RECORD_EXIT] = event__task_swap, |
| 400 | [PERF_RECORD_LOST] = event__all64_swap, |
| 401 | [PERF_RECORD_READ] = event__read_swap, |
| 402 | [PERF_RECORD_SAMPLE] = event__all64_swap, |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 403 | [PERF_RECORD_HEADER_ATTR] = event__attr_swap, |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 404 | [PERF_RECORD_HEADER_EVENT_TYPE] = event__event_type_swap, |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 405 | [PERF_RECORD_HEADER_TRACING_DATA] = event__tracing_data_swap, |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 406 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 407 | [PERF_RECORD_HEADER_MAX] = NULL, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 408 | }; |
| 409 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 410 | struct sample_queue { |
| 411 | u64 timestamp; |
Thomas Gleixner | 28990f7 | 2010-11-30 17:49:35 +0000 | [diff] [blame] | 412 | event_t *event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 413 | struct list_head list; |
| 414 | }; |
| 415 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 416 | static void perf_session_free_sample_buffers(struct perf_session *session) |
| 417 | { |
| 418 | struct ordered_samples *os = &session->ordered_samples; |
| 419 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 420 | while (!list_empty(&os->to_free)) { |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 421 | struct sample_queue *sq; |
| 422 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 423 | sq = list_entry(os->to_free.next, struct sample_queue, list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 424 | list_del(&sq->list); |
| 425 | free(sq); |
| 426 | } |
| 427 | } |
| 428 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 429 | static void flush_sample_queue(struct perf_session *s, |
| 430 | struct perf_event_ops *ops) |
| 431 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 432 | struct ordered_samples *os = &s->ordered_samples; |
| 433 | struct list_head *head = &os->samples; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 434 | struct sample_queue *tmp, *iter; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 435 | struct sample_data sample; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 436 | u64 limit = os->next_flush; |
| 437 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 438 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 439 | if (!ops->ordered_samples || !limit) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 440 | return; |
| 441 | |
| 442 | list_for_each_entry_safe(iter, tmp, head, list) { |
| 443 | if (iter->timestamp > limit) |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 444 | break; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 445 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 446 | event__parse_sample(iter->event, s->sample_type, &sample); |
| 447 | ops->sample(iter->event, &sample, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 448 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 449 | os->last_flush = iter->timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 450 | list_del(&iter->list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 451 | list_add(&iter->list, &os->sample_cache); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 452 | } |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 453 | |
| 454 | if (list_empty(head)) { |
| 455 | os->last_sample = NULL; |
| 456 | } else if (last_ts <= limit) { |
| 457 | os->last_sample = |
| 458 | list_entry(head->prev, struct sample_queue, list); |
| 459 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 460 | } |
| 461 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 462 | /* |
| 463 | * When perf record finishes a pass on every buffers, it records this pseudo |
| 464 | * event. |
| 465 | * We record the max timestamp t found in the pass n. |
| 466 | * Assuming these timestamps are monotonic across cpus, we know that if |
| 467 | * a buffer still has events with timestamps below t, they will be all |
| 468 | * available and then read in the pass n + 1. |
| 469 | * Hence when we start to read the pass n + 2, we can safely flush every |
| 470 | * events with timestamps below t. |
| 471 | * |
| 472 | * ============ PASS n ================= |
| 473 | * CPU 0 | CPU 1 |
| 474 | * | |
| 475 | * cnt1 timestamps | cnt2 timestamps |
| 476 | * 1 | 2 |
| 477 | * 2 | 3 |
| 478 | * - | 4 <--- max recorded |
| 479 | * |
| 480 | * ============ PASS n + 1 ============== |
| 481 | * CPU 0 | CPU 1 |
| 482 | * | |
| 483 | * cnt1 timestamps | cnt2 timestamps |
| 484 | * 3 | 5 |
| 485 | * 4 | 6 |
| 486 | * 5 | 7 <---- max recorded |
| 487 | * |
| 488 | * Flush every events below timestamp 4 |
| 489 | * |
| 490 | * ============ PASS n + 2 ============== |
| 491 | * CPU 0 | CPU 1 |
| 492 | * | |
| 493 | * cnt1 timestamps | cnt2 timestamps |
| 494 | * 6 | 8 |
| 495 | * 7 | 9 |
| 496 | * - | 10 |
| 497 | * |
| 498 | * Flush every events below timestamp 7 |
| 499 | * etc... |
| 500 | */ |
| 501 | static int process_finished_round(event_t *event __used, |
| 502 | struct perf_session *session, |
| 503 | struct perf_event_ops *ops) |
| 504 | { |
| 505 | flush_sample_queue(session, ops); |
| 506 | session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 511 | /* The queue is ordered by time */ |
| 512 | static void __queue_sample_event(struct sample_queue *new, |
| 513 | struct perf_session *s) |
| 514 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 515 | struct ordered_samples *os = &s->ordered_samples; |
| 516 | struct sample_queue *sample = os->last_sample; |
| 517 | u64 timestamp = new->timestamp; |
| 518 | struct list_head *p; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 519 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 520 | os->last_sample = new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 521 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 522 | if (!sample) { |
| 523 | list_add(&new->list, &os->samples); |
| 524 | os->max_timestamp = timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
| 528 | /* |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 529 | * last_sample might point to some random place in the list as it's |
| 530 | * the last queued event. We expect that the new event is close to |
| 531 | * this. |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 532 | */ |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 533 | if (sample->timestamp <= timestamp) { |
| 534 | while (sample->timestamp <= timestamp) { |
| 535 | p = sample->list.next; |
| 536 | if (p == &os->samples) { |
| 537 | list_add_tail(&new->list, &os->samples); |
| 538 | os->max_timestamp = timestamp; |
| 539 | return; |
| 540 | } |
| 541 | sample = list_entry(p, struct sample_queue, list); |
| 542 | } |
| 543 | list_add_tail(&new->list, &sample->list); |
| 544 | } else { |
| 545 | while (sample->timestamp > timestamp) { |
| 546 | p = sample->list.prev; |
| 547 | if (p == &os->samples) { |
| 548 | list_add(&new->list, &os->samples); |
| 549 | return; |
| 550 | } |
| 551 | sample = list_entry(p, struct sample_queue, list); |
| 552 | } |
| 553 | list_add(&new->list, &sample->list); |
| 554 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 557 | #define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct sample_queue)) |
| 558 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 559 | static int queue_sample_event(event_t *event, struct sample_data *data, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 560 | struct perf_session *s) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 561 | { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 562 | struct ordered_samples *os = &s->ordered_samples; |
| 563 | struct list_head *sc = &os->sample_cache; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 564 | u64 timestamp = data->time; |
| 565 | struct sample_queue *new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 566 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 567 | if (timestamp < s->ordered_samples.last_flush) { |
| 568 | printf("Warning: Timestamp below last timeslice flush\n"); |
| 569 | return -EINVAL; |
| 570 | } |
| 571 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 572 | if (!list_empty(sc)) { |
| 573 | new = list_entry(sc->next, struct sample_queue, list); |
| 574 | list_del(&new->list); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 575 | } else if (os->sample_buffer) { |
| 576 | new = os->sample_buffer + os->sample_buffer_idx; |
| 577 | if (++os->sample_buffer_idx == MAX_SAMPLE_BUFFER) |
| 578 | os->sample_buffer = NULL; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 579 | } else { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 580 | os->sample_buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new)); |
| 581 | if (!os->sample_buffer) |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 582 | return -ENOMEM; |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 583 | list_add(&os->sample_buffer->list, &os->to_free); |
| 584 | os->sample_buffer_idx = 2; |
| 585 | new = os->sample_buffer + 1; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 586 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 587 | |
| 588 | new->timestamp = timestamp; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 589 | new->event = event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 590 | |
| 591 | __queue_sample_event(new, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 596 | static int perf_session__process_sample(event_t *event, |
| 597 | struct sample_data *sample, |
| 598 | struct perf_session *s, |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 599 | struct perf_event_ops *ops) |
| 600 | { |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 601 | if (!ops->ordered_samples) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 602 | return ops->sample(event, sample, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 603 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 604 | queue_sample_event(event, sample, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 608 | static void callchain__dump(struct sample_data *sample) |
| 609 | { |
| 610 | unsigned int i; |
| 611 | |
| 612 | if (!dump_trace) |
| 613 | return; |
| 614 | |
| 615 | printf("... chain: nr:%Lu\n", sample->callchain->nr); |
| 616 | |
| 617 | for (i = 0; i < sample->callchain->nr; i++) |
| 618 | printf("..... %2d: %016Lx\n", i, sample->callchain->ips[i]); |
| 619 | } |
| 620 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 621 | static int perf_session__process_event(struct perf_session *self, |
| 622 | event_t *event, |
| 623 | struct perf_event_ops *ops, |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 624 | u64 file_offset) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 625 | { |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 626 | struct sample_data sample; |
| 627 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 628 | trace_event(event); |
| 629 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 630 | if (self->header.needs_swap && event__swap_ops[event->header.type]) |
| 631 | event__swap_ops[event->header.type](event); |
| 632 | |
| 633 | if (event->header.type == PERF_RECORD_SAMPLE) |
| 634 | event__parse_sample(event, self->sample_type, &sample); |
| 635 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 636 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 637 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 638 | file_offset, event->header.size, |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 639 | event__name[event->header.type]); |
Arnaldo Carvalho de Melo | cee75ac | 2010-05-14 13:16:55 -0300 | [diff] [blame] | 640 | hists__inc_nr_events(&self->hists, event->header.type); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | switch (event->header.type) { |
| 644 | case PERF_RECORD_SAMPLE: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 645 | dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc, |
| 646 | sample.pid, sample.tid, sample.ip, sample.period); |
| 647 | |
| 648 | if (self->sample_type & PERF_SAMPLE_CALLCHAIN) { |
| 649 | if (!ip_callchain__valid(sample.callchain, event)) { |
| 650 | pr_debug("call-chain problem with event, " |
| 651 | "skipping it.\n"); |
| 652 | ++self->hists.stats.nr_invalid_chains; |
| 653 | self->hists.stats.total_invalid_chains += sample.period; |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | callchain__dump(&sample); |
| 658 | } |
| 659 | |
| 660 | return perf_session__process_sample(event, &sample, self, ops); |
| 661 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 662 | case PERF_RECORD_MMAP: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 663 | return ops->mmap(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 664 | case PERF_RECORD_COMM: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 665 | return ops->comm(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 666 | case PERF_RECORD_FORK: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 667 | return ops->fork(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 668 | case PERF_RECORD_EXIT: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 669 | return ops->exit(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 670 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 671 | return ops->lost(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 672 | case PERF_RECORD_READ: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 673 | return ops->read(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 674 | case PERF_RECORD_THROTTLE: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 675 | return ops->throttle(event, &sample, self); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 676 | case PERF_RECORD_UNTHROTTLE: |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 677 | return ops->unthrottle(event, &sample, self); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 678 | case PERF_RECORD_HEADER_ATTR: |
| 679 | return ops->attr(event, self); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 680 | case PERF_RECORD_HEADER_EVENT_TYPE: |
| 681 | return ops->event_type(event, self); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 682 | case PERF_RECORD_HEADER_TRACING_DATA: |
| 683 | /* setup for reading amidst mmap */ |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 684 | lseek(self->fd, file_offset, SEEK_SET); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 685 | return ops->tracing_data(event, self); |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 686 | case PERF_RECORD_HEADER_BUILD_ID: |
| 687 | return ops->build_id(event, self); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 688 | case PERF_RECORD_FINISHED_ROUND: |
| 689 | return ops->finished_round(event, self, ops); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 690 | default: |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 691 | ++self->hists.stats.nr_unknown_events; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 692 | return -1; |
| 693 | } |
| 694 | } |
| 695 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 696 | void perf_event_header__bswap(struct perf_event_header *self) |
| 697 | { |
| 698 | self->type = bswap_32(self->type); |
| 699 | self->misc = bswap_16(self->misc); |
| 700 | self->size = bswap_16(self->size); |
| 701 | } |
| 702 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 703 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) |
| 704 | { |
| 705 | struct thread *thread = perf_session__findnew(self, 0); |
| 706 | |
| 707 | if (thread == NULL || thread__set_comm(thread, "swapper")) { |
| 708 | pr_err("problem inserting idle task.\n"); |
| 709 | thread = NULL; |
| 710 | } |
| 711 | |
| 712 | return thread; |
| 713 | } |
| 714 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 715 | int do_read(int fd, void *buf, size_t size) |
| 716 | { |
| 717 | void *buf_start = buf; |
| 718 | |
| 719 | while (size) { |
| 720 | int ret = read(fd, buf, size); |
| 721 | |
| 722 | if (ret <= 0) |
| 723 | return ret; |
| 724 | |
| 725 | size -= ret; |
| 726 | buf += ret; |
| 727 | } |
| 728 | |
| 729 | return buf - buf_start; |
| 730 | } |
| 731 | |
| 732 | #define session_done() (*(volatile int *)(&session_done)) |
| 733 | volatile int session_done; |
| 734 | |
| 735 | static int __perf_session__process_pipe_events(struct perf_session *self, |
| 736 | struct perf_event_ops *ops) |
| 737 | { |
| 738 | event_t event; |
| 739 | uint32_t size; |
| 740 | int skip = 0; |
| 741 | u64 head; |
| 742 | int err; |
| 743 | void *p; |
| 744 | |
| 745 | perf_event_ops__fill_defaults(ops); |
| 746 | |
| 747 | head = 0; |
| 748 | more: |
| 749 | err = do_read(self->fd, &event, sizeof(struct perf_event_header)); |
| 750 | if (err <= 0) { |
| 751 | if (err == 0) |
| 752 | goto done; |
| 753 | |
| 754 | pr_err("failed to read event header\n"); |
| 755 | goto out_err; |
| 756 | } |
| 757 | |
| 758 | if (self->header.needs_swap) |
| 759 | perf_event_header__bswap(&event.header); |
| 760 | |
| 761 | size = event.header.size; |
| 762 | if (size == 0) |
| 763 | size = 8; |
| 764 | |
| 765 | p = &event; |
| 766 | p += sizeof(struct perf_event_header); |
| 767 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 768 | if (size - sizeof(struct perf_event_header)) { |
| 769 | err = do_read(self->fd, p, |
| 770 | size - sizeof(struct perf_event_header)); |
| 771 | if (err <= 0) { |
| 772 | if (err == 0) { |
| 773 | pr_err("unexpected end of event stream\n"); |
| 774 | goto done; |
| 775 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 776 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 777 | pr_err("failed to read event data\n"); |
| 778 | goto out_err; |
| 779 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | if (size == 0 || |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 783 | (skip = perf_session__process_event(self, &event, ops, head)) < 0) { |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 784 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", |
| 785 | head, event.header.size, event.header.type); |
| 786 | /* |
| 787 | * assume we lost track of the stream, check alignment, and |
| 788 | * increment a single u64 in the hope to catch on again 'soon'. |
| 789 | */ |
| 790 | if (unlikely(head & 7)) |
| 791 | head &= ~7ULL; |
| 792 | |
| 793 | size = 8; |
| 794 | } |
| 795 | |
| 796 | head += size; |
| 797 | |
| 798 | dump_printf("\n%#Lx [%#x]: event: %d\n", |
| 799 | head, event.header.size, event.header.type); |
| 800 | |
| 801 | if (skip > 0) |
| 802 | head += skip; |
| 803 | |
| 804 | if (!session_done()) |
| 805 | goto more; |
| 806 | done: |
| 807 | err = 0; |
| 808 | out_err: |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 809 | perf_session_free_sample_buffers(self); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 810 | return err; |
| 811 | } |
| 812 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 813 | int __perf_session__process_events(struct perf_session *session, |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 814 | u64 data_offset, u64 data_size, |
| 815 | u64 file_size, struct perf_event_ops *ops) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 816 | { |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 817 | u64 head, page_offset, file_offset, file_pos, progress_next; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 818 | int err, mmap_prot, mmap_flags, map_idx = 0; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 819 | struct ui_progress *progress; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 820 | size_t page_size, mmap_size; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 821 | char *buf, *mmaps[8]; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 822 | event_t *event; |
| 823 | uint32_t size; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 824 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 825 | perf_event_ops__fill_defaults(ops); |
| 826 | |
Arnaldo Carvalho de Melo | 1b75962 | 2010-01-14 18:30:04 -0200 | [diff] [blame] | 827 | page_size = sysconf(_SC_PAGESIZE); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 828 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 829 | page_offset = page_size * (data_offset / page_size); |
| 830 | file_offset = page_offset; |
| 831 | head = data_offset - page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 832 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 833 | if (data_offset + data_size < file_size) |
| 834 | file_size = data_offset + data_size; |
| 835 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 836 | progress_next = file_size / 16; |
| 837 | progress = ui_progress__new("Processing events...", file_size); |
| 838 | if (progress == NULL) |
| 839 | return -1; |
| 840 | |
| 841 | mmap_size = session->mmap_window; |
| 842 | if (mmap_size > file_size) |
| 843 | mmap_size = file_size; |
| 844 | |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 845 | memset(mmaps, 0, sizeof(mmaps)); |
| 846 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 847 | mmap_prot = PROT_READ; |
| 848 | mmap_flags = MAP_SHARED; |
| 849 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 850 | if (session->header.needs_swap) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 851 | mmap_prot |= PROT_WRITE; |
| 852 | mmap_flags = MAP_PRIVATE; |
| 853 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 854 | remap: |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 855 | buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, session->fd, |
| 856 | file_offset); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 857 | if (buf == MAP_FAILED) { |
| 858 | pr_err("failed to mmap file\n"); |
| 859 | err = -errno; |
| 860 | goto out_err; |
| 861 | } |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 862 | mmaps[map_idx] = buf; |
| 863 | map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 864 | file_pos = file_offset + head; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 865 | |
| 866 | more: |
| 867 | event = (event_t *)(buf + head); |
| 868 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 869 | if (session->header.needs_swap) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 870 | perf_event_header__bswap(&event->header); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 871 | size = event->header.size; |
| 872 | if (size == 0) |
| 873 | size = 8; |
| 874 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 875 | if (head + event->header.size >= mmap_size) { |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 876 | if (mmaps[map_idx]) { |
| 877 | munmap(mmaps[map_idx], mmap_size); |
| 878 | mmaps[map_idx] = NULL; |
| 879 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 880 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 881 | page_offset = page_size * (head / page_size); |
| 882 | file_offset += page_offset; |
| 883 | head -= page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 884 | goto remap; |
| 885 | } |
| 886 | |
| 887 | size = event->header.size; |
| 888 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 889 | dump_printf("\n%#Lx [%#x]: event: %d\n", |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 890 | file_pos, event->header.size, event->header.type); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 891 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 892 | if (size == 0 || |
| 893 | perf_session__process_event(session, event, ops, file_pos) < 0) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 894 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 895 | file_offset + head, event->header.size, |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 896 | event->header.type); |
| 897 | /* |
| 898 | * assume we lost track of the stream, check alignment, and |
| 899 | * increment a single u64 in the hope to catch on again 'soon'. |
| 900 | */ |
| 901 | if (unlikely(head & 7)) |
| 902 | head &= ~7ULL; |
| 903 | |
| 904 | size = 8; |
| 905 | } |
| 906 | |
| 907 | head += size; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 908 | file_pos += size; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 909 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 910 | if (file_pos >= progress_next) { |
| 911 | progress_next += file_size / 16; |
| 912 | ui_progress__update(progress, file_pos); |
| 913 | } |
| 914 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 915 | if (file_pos < file_size) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 916 | goto more; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 917 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 918 | err = 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 919 | /* do the final flush for ordered samples */ |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 920 | session->ordered_samples.next_flush = ULLONG_MAX; |
| 921 | flush_sample_queue(session, ops); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 922 | out_err: |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 923 | ui_progress__delete(progress); |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 924 | |
| 925 | if (ops->lost == event__process_lost && |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 926 | session->hists.stats.total_lost != 0) { |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 927 | ui__warning("Processed %Lu events and LOST %Lu!\n\n" |
| 928 | "Check IO/CPU overload!\n\n", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 929 | session->hists.stats.total_period, |
| 930 | session->hists.stats.total_lost); |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 931 | } |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 932 | |
| 933 | if (session->hists.stats.nr_unknown_events != 0) { |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 934 | ui__warning("Found %u unknown events!\n\n" |
| 935 | "Is this an older tool processing a perf.data " |
| 936 | "file generated by a more recent tool?\n\n" |
| 937 | "If that is not the case, consider " |
| 938 | "reporting to linux-kernel@vger.kernel.org.\n\n", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 939 | session->hists.stats.nr_unknown_events); |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 940 | } |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 941 | |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame^] | 942 | if (session->hists.stats.nr_invalid_chains != 0) { |
| 943 | ui__warning("Found invalid callchains!\n\n" |
| 944 | "%u out of %u events were discarded for this reason.\n\n" |
| 945 | "Consider reporting to linux-kernel@vger.kernel.org.\n\n", |
| 946 | session->hists.stats.nr_invalid_chains, |
| 947 | session->hists.stats.nr_events[PERF_RECORD_SAMPLE]); |
| 948 | } |
| 949 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 950 | perf_session_free_sample_buffers(session); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 951 | return err; |
| 952 | } |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 953 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 954 | int perf_session__process_events(struct perf_session *self, |
| 955 | struct perf_event_ops *ops) |
| 956 | { |
| 957 | int err; |
| 958 | |
| 959 | if (perf_session__register_idle_thread(self) == NULL) |
| 960 | return -ENOMEM; |
| 961 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 962 | if (!self->fd_pipe) |
| 963 | err = __perf_session__process_events(self, |
| 964 | self->header.data_offset, |
| 965 | self->header.data_size, |
| 966 | self->size, ops); |
| 967 | else |
| 968 | err = __perf_session__process_pipe_events(self, ops); |
Dave Martin | 88ca895 | 2010-07-27 11:46:12 -0300 | [diff] [blame] | 969 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 970 | return err; |
| 971 | } |
| 972 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 973 | 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] | 974 | { |
| 975 | if (!(self->sample_type & PERF_SAMPLE_RAW)) { |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 976 | pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); |
| 977 | return false; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 978 | } |
| 979 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 980 | return true; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 981 | } |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 982 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 983 | 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] | 984 | const char *symbol_name, |
| 985 | u64 addr) |
| 986 | { |
| 987 | char *bracket; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 988 | enum map_type i; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 989 | struct ref_reloc_sym *ref; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 990 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 991 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
| 992 | if (ref == NULL) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 993 | return -ENOMEM; |
| 994 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 995 | ref->name = strdup(symbol_name); |
| 996 | if (ref->name == NULL) { |
| 997 | free(ref); |
| 998 | return -ENOMEM; |
| 999 | } |
| 1000 | |
| 1001 | bracket = strchr(ref->name, ']'); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1002 | if (bracket) |
| 1003 | *bracket = '\0'; |
| 1004 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1005 | ref->addr = addr; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1006 | |
| 1007 | for (i = 0; i < MAP__NR_TYPES; ++i) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1008 | struct kmap *kmap = map__kmap(maps[i]); |
| 1009 | kmap->ref_reloc_sym = ref; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1010 | } |
| 1011 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1014 | |
| 1015 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) |
| 1016 | { |
| 1017 | return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + |
| 1018 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
| 1019 | machines__fprintf_dsos(&self->machines, fp); |
| 1020 | } |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 1021 | |
| 1022 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, |
| 1023 | bool with_hits) |
| 1024 | { |
| 1025 | size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits); |
| 1026 | return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
| 1027 | } |