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 | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 13 | #include "tool.h" |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 14 | #include "sort.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 15 | #include "util.h" |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 16 | #include "cpumap.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 17 | |
| 18 | static int perf_session__open(struct perf_session *self, bool force) |
| 19 | { |
| 20 | struct stat input_stat; |
| 21 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 22 | if (!strcmp(self->filename, "-")) { |
| 23 | self->fd_pipe = true; |
| 24 | self->fd = STDIN_FILENO; |
| 25 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 26 | if (perf_session__read_header(self, self->fd) < 0) |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame^] | 27 | pr_err("incompatible file format (rerun with -v to learn more)"); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 32 | self->fd = open(self->filename, O_RDONLY); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 33 | if (self->fd < 0) { |
Andy Isaacson | 0f2c3de | 2010-06-11 20:36:15 -0700 | [diff] [blame] | 34 | int err = errno; |
| 35 | |
| 36 | pr_err("failed to open %s: %s", self->filename, strerror(err)); |
| 37 | if (err == ENOENT && !strcmp(self->filename, "perf.data")) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 38 | pr_err(" (try 'perf record' first)"); |
| 39 | pr_err("\n"); |
| 40 | return -errno; |
| 41 | } |
| 42 | |
| 43 | if (fstat(self->fd, &input_stat) < 0) |
| 44 | goto out_close; |
| 45 | |
| 46 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { |
| 47 | pr_err("file %s not owned by current user or root\n", |
| 48 | self->filename); |
| 49 | goto out_close; |
| 50 | } |
| 51 | |
| 52 | if (!input_stat.st_size) { |
| 53 | pr_info("zero-sized file (%s), nothing to do!\n", |
| 54 | self->filename); |
| 55 | goto out_close; |
| 56 | } |
| 57 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 58 | if (perf_session__read_header(self, self->fd) < 0) { |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame^] | 59 | pr_err("incompatible file format (rerun with -v to learn more)"); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 60 | goto out_close; |
| 61 | } |
| 62 | |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 63 | if (!perf_evlist__valid_sample_type(self->evlist)) { |
| 64 | pr_err("non matching sample_type"); |
| 65 | goto out_close; |
| 66 | } |
| 67 | |
| 68 | if (!perf_evlist__valid_sample_id_all(self->evlist)) { |
| 69 | pr_err("non matching sample_id_all"); |
| 70 | goto out_close; |
| 71 | } |
| 72 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 73 | self->size = input_stat.st_size; |
| 74 | return 0; |
| 75 | |
| 76 | out_close: |
| 77 | close(self->fd); |
| 78 | self->fd = -1; |
| 79 | return -1; |
| 80 | } |
| 81 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 82 | void perf_session__update_sample_type(struct perf_session *self) |
| 83 | { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 84 | self->sample_type = perf_evlist__sample_type(self->evlist); |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 85 | self->sample_size = __perf_evsel__sample_size(self->sample_type); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 86 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); |
Arnaldo Carvalho de Melo | 81e36bf | 2011-11-11 22:28:50 -0200 | [diff] [blame] | 87 | self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 88 | self->host_machine.id_hdr_size = self->id_hdr_size; |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 89 | } |
| 90 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 91 | int perf_session__create_kernel_maps(struct perf_session *self) |
| 92 | { |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 93 | int ret = machine__create_kernel_maps(&self->host_machine); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 94 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 95 | if (ret >= 0) |
Arnaldo Carvalho de Melo | d118f8b | 2010-05-10 12:51:05 -0300 | [diff] [blame] | 96 | ret = machines__create_guest_kernel_maps(&self->machines); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 97 | return ret; |
| 98 | } |
| 99 | |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 100 | static void perf_session__destroy_kernel_maps(struct perf_session *self) |
| 101 | { |
| 102 | machine__destroy_kernel_maps(&self->host_machine); |
| 103 | machines__destroy_guest_kernel_maps(&self->machines); |
| 104 | } |
| 105 | |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 106 | struct perf_session *perf_session__new(const char *filename, int mode, |
| 107 | bool force, bool repipe, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 108 | struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 109 | { |
Robert Richter | efad141 | 2011-12-07 10:02:54 +0100 | [diff] [blame] | 110 | struct perf_session *self; |
| 111 | struct stat st; |
| 112 | size_t len; |
| 113 | |
| 114 | if (!filename || !strlen(filename)) { |
| 115 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) |
| 116 | filename = "-"; |
| 117 | else |
| 118 | filename = "perf.data"; |
| 119 | } |
| 120 | |
| 121 | len = strlen(filename); |
| 122 | self = zalloc(sizeof(*self) + len); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 123 | |
| 124 | if (self == NULL) |
| 125 | goto out; |
| 126 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 127 | memcpy(self->filename, filename, len); |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 128 | /* |
| 129 | * On 64bit we can mmap the data file in one go. No need for tiny mmap |
| 130 | * slices. On 32bit we use 32MB. |
| 131 | */ |
| 132 | #if BITS_PER_LONG == 64 |
| 133 | self->mmap_window = ULLONG_MAX; |
| 134 | #else |
| 135 | self->mmap_window = 32 * 1024 * 1024ULL; |
| 136 | #endif |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 137 | self->machines = RB_ROOT; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 138 | self->repipe = repipe; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 139 | INIT_LIST_HEAD(&self->ordered_samples.samples); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 140 | INIT_LIST_HEAD(&self->ordered_samples.sample_cache); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 141 | INIT_LIST_HEAD(&self->ordered_samples.to_free); |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 142 | machine__init(&self->host_machine, "", HOST_KERNEL_ID); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 143 | |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 144 | if (mode == O_RDONLY) { |
| 145 | if (perf_session__open(self, force) < 0) |
| 146 | goto out_delete; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 147 | perf_session__update_sample_type(self); |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 148 | } else if (mode == O_WRONLY) { |
| 149 | /* |
| 150 | * 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] | 151 | * kernel MMAP event, in perf_event__process_mmap(). |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 152 | */ |
| 153 | if (perf_session__create_kernel_maps(self) < 0) |
| 154 | goto out_delete; |
| 155 | } |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 156 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 157 | if (tool && tool->ordering_requires_timestamps && |
| 158 | tool->ordered_samples && !self->sample_id_all) { |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 159 | dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 160 | tool->ordered_samples = false; |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 161 | } |
| 162 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 163 | out: |
| 164 | return self; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 165 | out_delete: |
| 166 | perf_session__delete(self); |
| 167 | return NULL; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 168 | } |
| 169 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 170 | static void machine__delete_dead_threads(struct machine *machine) |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 171 | { |
| 172 | struct thread *n, *t; |
| 173 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 174 | list_for_each_entry_safe(t, n, &machine->dead_threads, node) { |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 175 | list_del(&t->node); |
| 176 | thread__delete(t); |
| 177 | } |
| 178 | } |
| 179 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 180 | static void perf_session__delete_dead_threads(struct perf_session *session) |
| 181 | { |
| 182 | machine__delete_dead_threads(&session->host_machine); |
| 183 | } |
| 184 | |
| 185 | static void machine__delete_threads(struct machine *self) |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 186 | { |
| 187 | struct rb_node *nd = rb_first(&self->threads); |
| 188 | |
| 189 | while (nd) { |
| 190 | struct thread *t = rb_entry(nd, struct thread, rb_node); |
| 191 | |
| 192 | rb_erase(&t->rb_node, &self->threads); |
| 193 | nd = rb_next(nd); |
| 194 | thread__delete(t); |
| 195 | } |
| 196 | } |
| 197 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 198 | static void perf_session__delete_threads(struct perf_session *session) |
| 199 | { |
| 200 | machine__delete_threads(&session->host_machine); |
| 201 | } |
| 202 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 203 | void perf_session__delete(struct perf_session *self) |
| 204 | { |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 205 | perf_session__destroy_kernel_maps(self); |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 206 | perf_session__delete_dead_threads(self); |
| 207 | perf_session__delete_threads(self); |
| 208 | machine__exit(&self->host_machine); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 209 | close(self->fd); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 210 | free(self); |
| 211 | } |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 212 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 213 | void machine__remove_thread(struct machine *self, struct thread *th) |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 214 | { |
Arnaldo Carvalho de Melo | 70597f2 | 2010-08-02 18:59:28 -0300 | [diff] [blame] | 215 | self->last_match = NULL; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 216 | rb_erase(&th->rb_node, &self->threads); |
| 217 | /* |
| 218 | * We may have references to this thread, for instance in some hist_entry |
| 219 | * instances, so just move them to a separate list. |
| 220 | */ |
| 221 | list_add_tail(&th->node, &self->dead_threads); |
| 222 | } |
| 223 | |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 224 | static bool symbol__match_parent_regex(struct symbol *sym) |
| 225 | { |
| 226 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
| 227 | return 1; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 232 | static const u8 cpumodes[] = { |
| 233 | PERF_RECORD_MISC_USER, |
| 234 | PERF_RECORD_MISC_KERNEL, |
| 235 | PERF_RECORD_MISC_GUEST_USER, |
| 236 | PERF_RECORD_MISC_GUEST_KERNEL |
| 237 | }; |
| 238 | #define NCPUMODES (sizeof(cpumodes)/sizeof(u8)) |
| 239 | |
| 240 | static void ip__resolve_ams(struct machine *self, struct thread *thread, |
| 241 | struct addr_map_symbol *ams, |
| 242 | u64 ip) |
| 243 | { |
| 244 | struct addr_location al; |
| 245 | size_t i; |
| 246 | u8 m; |
| 247 | |
| 248 | memset(&al, 0, sizeof(al)); |
| 249 | |
| 250 | for (i = 0; i < NCPUMODES; i++) { |
| 251 | m = cpumodes[i]; |
| 252 | /* |
| 253 | * We cannot use the header.misc hint to determine whether a |
| 254 | * branch stack address is user, kernel, guest, hypervisor. |
| 255 | * Branches may straddle the kernel/user/hypervisor boundaries. |
| 256 | * Thus, we have to try consecutively until we find a match |
| 257 | * or else, the symbol is unknown |
| 258 | */ |
| 259 | thread__find_addr_location(thread, self, m, MAP__FUNCTION, |
| 260 | ip, &al, NULL); |
| 261 | if (al.sym) |
| 262 | goto found; |
| 263 | } |
| 264 | found: |
| 265 | ams->addr = ip; |
| 266 | ams->sym = al.sym; |
| 267 | ams->map = al.map; |
| 268 | } |
| 269 | |
| 270 | struct branch_info *machine__resolve_bstack(struct machine *self, |
| 271 | struct thread *thr, |
| 272 | struct branch_stack *bs) |
| 273 | { |
| 274 | struct branch_info *bi; |
| 275 | unsigned int i; |
| 276 | |
| 277 | bi = calloc(bs->nr, sizeof(struct branch_info)); |
| 278 | if (!bi) |
| 279 | return NULL; |
| 280 | |
| 281 | for (i = 0; i < bs->nr; i++) { |
| 282 | ip__resolve_ams(self, thr, &bi[i].to, bs->entries[i].to); |
| 283 | ip__resolve_ams(self, thr, &bi[i].from, bs->entries[i].from); |
| 284 | bi[i].flags = bs->entries[i].flags; |
| 285 | } |
| 286 | return bi; |
| 287 | } |
| 288 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 289 | int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, |
| 290 | struct thread *thread, |
| 291 | struct ip_callchain *chain, |
| 292 | struct symbol **parent) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 293 | { |
| 294 | u8 cpumode = PERF_RECORD_MISC_USER; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 295 | unsigned int i; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 296 | int err; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 297 | |
Arnaldo Carvalho de Melo | 246d4ce | 2011-11-11 23:10:26 -0200 | [diff] [blame] | 298 | callchain_cursor_reset(&evsel->hists.callchain_cursor); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 299 | |
| 300 | for (i = 0; i < chain->nr; i++) { |
Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 301 | u64 ip; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 302 | struct addr_location al; |
| 303 | |
Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 304 | if (callchain_param.order == ORDER_CALLEE) |
| 305 | ip = chain->ips[i]; |
| 306 | else |
| 307 | ip = chain->ips[chain->nr - i - 1]; |
| 308 | |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 309 | if (ip >= PERF_CONTEXT_MAX) { |
| 310 | switch (ip) { |
| 311 | case PERF_CONTEXT_HV: |
| 312 | cpumode = PERF_RECORD_MISC_HYPERVISOR; break; |
| 313 | case PERF_CONTEXT_KERNEL: |
| 314 | cpumode = PERF_RECORD_MISC_KERNEL; break; |
| 315 | case PERF_CONTEXT_USER: |
| 316 | cpumode = PERF_RECORD_MISC_USER; break; |
| 317 | default: |
| 318 | break; |
| 319 | } |
| 320 | continue; |
| 321 | } |
| 322 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 323 | al.filtered = false; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 324 | thread__find_addr_location(thread, self, cpumode, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 325 | MAP__FUNCTION, ip, &al, NULL); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 326 | if (al.sym != NULL) { |
| 327 | if (sort__has_parent && !*parent && |
| 328 | symbol__match_parent_regex(al.sym)) |
| 329 | *parent = al.sym; |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 330 | if (!symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 331 | break; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 332 | } |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 333 | |
Arnaldo Carvalho de Melo | 246d4ce | 2011-11-11 23:10:26 -0200 | [diff] [blame] | 334 | err = callchain_cursor_append(&evsel->hists.callchain_cursor, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 335 | ip, al.map, al.sym); |
| 336 | if (err) |
| 337 | return err; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 338 | } |
| 339 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 340 | return 0; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 341 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 342 | |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 343 | static int process_event_synth_tracing_data_stub(union perf_event *event __used, |
| 344 | struct perf_session *session __used) |
| 345 | { |
| 346 | dump_printf(": unhandled!\n"); |
| 347 | return 0; |
| 348 | } |
| 349 | |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 350 | static int process_event_synth_attr_stub(union perf_event *event __used, |
| 351 | struct perf_evlist **pevlist __used) |
| 352 | { |
| 353 | dump_printf(": unhandled!\n"); |
| 354 | return 0; |
| 355 | } |
| 356 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 357 | static int process_event_sample_stub(struct perf_tool *tool __used, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 358 | union perf_event *event __used, |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 359 | struct perf_sample *sample __used, |
| 360 | struct perf_evsel *evsel __used, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 361 | struct machine *machine __used) |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 362 | { |
| 363 | dump_printf(": unhandled!\n"); |
| 364 | return 0; |
| 365 | } |
| 366 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 367 | static int process_event_stub(struct perf_tool *tool __used, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 368 | union perf_event *event __used, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 369 | struct perf_sample *sample __used, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 370 | struct machine *machine __used) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 371 | { |
| 372 | dump_printf(": unhandled!\n"); |
| 373 | return 0; |
| 374 | } |
| 375 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 376 | static int process_finished_round_stub(struct perf_tool *tool __used, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 377 | union perf_event *event __used, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 378 | struct perf_session *perf_session __used) |
| 379 | { |
| 380 | dump_printf(": unhandled!\n"); |
| 381 | return 0; |
| 382 | } |
| 383 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 384 | static int process_event_type_stub(struct perf_tool *tool __used, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 385 | union perf_event *event __used) |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 386 | { |
| 387 | dump_printf(": unhandled!\n"); |
| 388 | return 0; |
| 389 | } |
| 390 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 391 | static int process_finished_round(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 392 | union perf_event *event, |
| 393 | struct perf_session *session); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 394 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 395 | static void perf_tool__fill_defaults(struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 396 | { |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 397 | if (tool->sample == NULL) |
| 398 | tool->sample = process_event_sample_stub; |
| 399 | if (tool->mmap == NULL) |
| 400 | tool->mmap = process_event_stub; |
| 401 | if (tool->comm == NULL) |
| 402 | tool->comm = process_event_stub; |
| 403 | if (tool->fork == NULL) |
| 404 | tool->fork = process_event_stub; |
| 405 | if (tool->exit == NULL) |
| 406 | tool->exit = process_event_stub; |
| 407 | if (tool->lost == NULL) |
| 408 | tool->lost = perf_event__process_lost; |
| 409 | if (tool->read == NULL) |
| 410 | tool->read = process_event_sample_stub; |
| 411 | if (tool->throttle == NULL) |
| 412 | tool->throttle = process_event_stub; |
| 413 | if (tool->unthrottle == NULL) |
| 414 | tool->unthrottle = process_event_stub; |
| 415 | if (tool->attr == NULL) |
| 416 | tool->attr = process_event_synth_attr_stub; |
| 417 | if (tool->event_type == NULL) |
| 418 | tool->event_type = process_event_type_stub; |
| 419 | if (tool->tracing_data == NULL) |
| 420 | tool->tracing_data = process_event_synth_tracing_data_stub; |
| 421 | if (tool->build_id == NULL) |
| 422 | tool->build_id = process_finished_round_stub; |
| 423 | if (tool->finished_round == NULL) { |
| 424 | if (tool->ordered_samples) |
| 425 | tool->finished_round = process_finished_round; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 426 | else |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 427 | tool->finished_round = process_finished_round_stub; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 428 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 429 | } |
| 430 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 431 | void mem_bswap_64(void *src, int byte_size) |
| 432 | { |
| 433 | u64 *m = src; |
| 434 | |
| 435 | while (byte_size > 0) { |
| 436 | *m = bswap_64(*m); |
| 437 | byte_size -= sizeof(u64); |
| 438 | ++m; |
| 439 | } |
| 440 | } |
| 441 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 442 | static void perf_event__all64_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 443 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 444 | struct perf_event_header *hdr = &event->header; |
| 445 | mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr)); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 446 | } |
| 447 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 448 | static void perf_event__comm_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 449 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 450 | event->comm.pid = bswap_32(event->comm.pid); |
| 451 | event->comm.tid = bswap_32(event->comm.tid); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 452 | } |
| 453 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 454 | static void perf_event__mmap_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 455 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 456 | event->mmap.pid = bswap_32(event->mmap.pid); |
| 457 | event->mmap.tid = bswap_32(event->mmap.tid); |
| 458 | event->mmap.start = bswap_64(event->mmap.start); |
| 459 | event->mmap.len = bswap_64(event->mmap.len); |
| 460 | event->mmap.pgoff = bswap_64(event->mmap.pgoff); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 461 | } |
| 462 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 463 | static void perf_event__task_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 464 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 465 | event->fork.pid = bswap_32(event->fork.pid); |
| 466 | event->fork.tid = bswap_32(event->fork.tid); |
| 467 | event->fork.ppid = bswap_32(event->fork.ppid); |
| 468 | event->fork.ptid = bswap_32(event->fork.ptid); |
| 469 | event->fork.time = bswap_64(event->fork.time); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 470 | } |
| 471 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 472 | static void perf_event__read_swap(union perf_event *event) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 473 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 474 | event->read.pid = bswap_32(event->read.pid); |
| 475 | event->read.tid = bswap_32(event->read.tid); |
| 476 | event->read.value = bswap_64(event->read.value); |
| 477 | event->read.time_enabled = bswap_64(event->read.time_enabled); |
| 478 | event->read.time_running = bswap_64(event->read.time_running); |
| 479 | event->read.id = bswap_64(event->read.id); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 480 | } |
| 481 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 482 | /* exported for swapping attributes in file header */ |
| 483 | void perf_event__attr_swap(struct perf_event_attr *attr) |
| 484 | { |
| 485 | attr->type = bswap_32(attr->type); |
| 486 | attr->size = bswap_32(attr->size); |
| 487 | attr->config = bswap_64(attr->config); |
| 488 | attr->sample_period = bswap_64(attr->sample_period); |
| 489 | attr->sample_type = bswap_64(attr->sample_type); |
| 490 | attr->read_format = bswap_64(attr->read_format); |
| 491 | attr->wakeup_events = bswap_32(attr->wakeup_events); |
| 492 | attr->bp_type = bswap_32(attr->bp_type); |
| 493 | attr->bp_addr = bswap_64(attr->bp_addr); |
| 494 | attr->bp_len = bswap_64(attr->bp_len); |
| 495 | } |
| 496 | |
| 497 | static void perf_event__hdr_attr_swap(union perf_event *event) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 498 | { |
| 499 | size_t size; |
| 500 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 501 | perf_event__attr_swap(&event->attr.attr); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 502 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 503 | size = event->header.size; |
| 504 | size -= (void *)&event->attr.id - (void *)event; |
| 505 | mem_bswap_64(event->attr.id, size); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 506 | } |
| 507 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 508 | static void perf_event__event_type_swap(union perf_event *event) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 509 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 510 | event->event_type.event_type.event_id = |
| 511 | bswap_64(event->event_type.event_type.event_id); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 514 | static void perf_event__tracing_data_swap(union perf_event *event) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 515 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 516 | event->tracing_data.size = bswap_32(event->tracing_data.size); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 517 | } |
| 518 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 519 | typedef void (*perf_event__swap_op)(union perf_event *event); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 520 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 521 | static perf_event__swap_op perf_event__swap_ops[] = { |
| 522 | [PERF_RECORD_MMAP] = perf_event__mmap_swap, |
| 523 | [PERF_RECORD_COMM] = perf_event__comm_swap, |
| 524 | [PERF_RECORD_FORK] = perf_event__task_swap, |
| 525 | [PERF_RECORD_EXIT] = perf_event__task_swap, |
| 526 | [PERF_RECORD_LOST] = perf_event__all64_swap, |
| 527 | [PERF_RECORD_READ] = perf_event__read_swap, |
| 528 | [PERF_RECORD_SAMPLE] = perf_event__all64_swap, |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 529 | [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 530 | [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, |
| 531 | [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap, |
| 532 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, |
| 533 | [PERF_RECORD_HEADER_MAX] = NULL, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 534 | }; |
| 535 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 536 | struct sample_queue { |
| 537 | u64 timestamp; |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 538 | u64 file_offset; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 539 | union perf_event *event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 540 | struct list_head list; |
| 541 | }; |
| 542 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 543 | static void perf_session_free_sample_buffers(struct perf_session *session) |
| 544 | { |
| 545 | struct ordered_samples *os = &session->ordered_samples; |
| 546 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 547 | while (!list_empty(&os->to_free)) { |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 548 | struct sample_queue *sq; |
| 549 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 550 | sq = list_entry(os->to_free.next, struct sample_queue, list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 551 | list_del(&sq->list); |
| 552 | free(sq); |
| 553 | } |
| 554 | } |
| 555 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 556 | static int perf_session_deliver_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 557 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 558 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 559 | struct perf_tool *tool, |
Thomas Gleixner | f74725d | 2010-12-07 12:48:53 +0000 | [diff] [blame] | 560 | u64 file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 561 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 562 | static void flush_sample_queue(struct perf_session *s, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 563 | struct perf_tool *tool) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 564 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 565 | struct ordered_samples *os = &s->ordered_samples; |
| 566 | struct list_head *head = &os->samples; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 567 | struct sample_queue *tmp, *iter; |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 568 | struct perf_sample sample; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 569 | u64 limit = os->next_flush; |
| 570 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; |
Arnaldo Carvalho de Melo | 8866056 | 2011-10-29 12:41:45 -0200 | [diff] [blame] | 571 | unsigned idx = 0, progress_next = os->nr_samples / 16; |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 572 | int ret; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 573 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 574 | if (!tool->ordered_samples || !limit) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 575 | return; |
| 576 | |
| 577 | list_for_each_entry_safe(iter, tmp, head, list) { |
| 578 | if (iter->timestamp > limit) |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 579 | break; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 580 | |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 581 | ret = perf_session__parse_sample(s, iter->event, &sample); |
| 582 | if (ret) |
| 583 | pr_err("Can't parse sample, err = %d\n", ret); |
| 584 | else |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 585 | perf_session_deliver_event(s, iter->event, &sample, tool, |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 586 | iter->file_offset); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 587 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 588 | os->last_flush = iter->timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 589 | list_del(&iter->list); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 590 | list_add(&iter->list, &os->sample_cache); |
Arnaldo Carvalho de Melo | 8866056 | 2011-10-29 12:41:45 -0200 | [diff] [blame] | 591 | if (++idx >= progress_next) { |
| 592 | progress_next += os->nr_samples / 16; |
| 593 | ui_progress__update(idx, os->nr_samples, |
| 594 | "Processing time ordered events..."); |
| 595 | } |
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 | |
| 598 | if (list_empty(head)) { |
| 599 | os->last_sample = NULL; |
| 600 | } else if (last_ts <= limit) { |
| 601 | os->last_sample = |
| 602 | list_entry(head->prev, struct sample_queue, list); |
| 603 | } |
Arnaldo Carvalho de Melo | 8866056 | 2011-10-29 12:41:45 -0200 | [diff] [blame] | 604 | |
| 605 | os->nr_samples = 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 608 | /* |
| 609 | * When perf record finishes a pass on every buffers, it records this pseudo |
| 610 | * event. |
| 611 | * We record the max timestamp t found in the pass n. |
| 612 | * Assuming these timestamps are monotonic across cpus, we know that if |
| 613 | * a buffer still has events with timestamps below t, they will be all |
| 614 | * available and then read in the pass n + 1. |
| 615 | * Hence when we start to read the pass n + 2, we can safely flush every |
| 616 | * events with timestamps below t. |
| 617 | * |
| 618 | * ============ PASS n ================= |
| 619 | * CPU 0 | CPU 1 |
| 620 | * | |
| 621 | * cnt1 timestamps | cnt2 timestamps |
| 622 | * 1 | 2 |
| 623 | * 2 | 3 |
| 624 | * - | 4 <--- max recorded |
| 625 | * |
| 626 | * ============ PASS n + 1 ============== |
| 627 | * CPU 0 | CPU 1 |
| 628 | * | |
| 629 | * cnt1 timestamps | cnt2 timestamps |
| 630 | * 3 | 5 |
| 631 | * 4 | 6 |
| 632 | * 5 | 7 <---- max recorded |
| 633 | * |
| 634 | * Flush every events below timestamp 4 |
| 635 | * |
| 636 | * ============ PASS n + 2 ============== |
| 637 | * CPU 0 | CPU 1 |
| 638 | * | |
| 639 | * cnt1 timestamps | cnt2 timestamps |
| 640 | * 6 | 8 |
| 641 | * 7 | 9 |
| 642 | * - | 10 |
| 643 | * |
| 644 | * Flush every events below timestamp 7 |
| 645 | * etc... |
| 646 | */ |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 647 | static int process_finished_round(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 648 | union perf_event *event __used, |
| 649 | struct perf_session *session) |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 650 | { |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 651 | flush_sample_queue(session, tool); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 652 | session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 657 | /* The queue is ordered by time */ |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 658 | static void __queue_event(struct sample_queue *new, struct perf_session *s) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 659 | { |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 660 | struct ordered_samples *os = &s->ordered_samples; |
| 661 | struct sample_queue *sample = os->last_sample; |
| 662 | u64 timestamp = new->timestamp; |
| 663 | struct list_head *p; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 664 | |
Arnaldo Carvalho de Melo | 8866056 | 2011-10-29 12:41:45 -0200 | [diff] [blame] | 665 | ++os->nr_samples; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 666 | os->last_sample = new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 667 | |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 668 | if (!sample) { |
| 669 | list_add(&new->list, &os->samples); |
| 670 | os->max_timestamp = timestamp; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 671 | return; |
| 672 | } |
| 673 | |
| 674 | /* |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 675 | * last_sample might point to some random place in the list as it's |
| 676 | * the last queued event. We expect that the new event is close to |
| 677 | * this. |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 678 | */ |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 679 | if (sample->timestamp <= timestamp) { |
| 680 | while (sample->timestamp <= timestamp) { |
| 681 | p = sample->list.next; |
| 682 | if (p == &os->samples) { |
| 683 | list_add_tail(&new->list, &os->samples); |
| 684 | os->max_timestamp = timestamp; |
| 685 | return; |
| 686 | } |
| 687 | sample = list_entry(p, struct sample_queue, list); |
| 688 | } |
| 689 | list_add_tail(&new->list, &sample->list); |
| 690 | } else { |
| 691 | while (sample->timestamp > timestamp) { |
| 692 | p = sample->list.prev; |
| 693 | if (p == &os->samples) { |
| 694 | list_add(&new->list, &os->samples); |
| 695 | return; |
| 696 | } |
| 697 | sample = list_entry(p, struct sample_queue, list); |
| 698 | } |
| 699 | list_add(&new->list, &sample->list); |
| 700 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 703 | #define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct sample_queue)) |
| 704 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 705 | 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] | 706 | struct perf_sample *sample, u64 file_offset) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 707 | { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 708 | struct ordered_samples *os = &s->ordered_samples; |
| 709 | struct list_head *sc = &os->sample_cache; |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 710 | u64 timestamp = sample->time; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 711 | struct sample_queue *new; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 712 | |
Thomas Gleixner | 79a14c1 | 2010-12-07 12:48:44 +0000 | [diff] [blame] | 713 | if (!timestamp || timestamp == ~0ULL) |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 714 | return -ETIME; |
| 715 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 716 | if (timestamp < s->ordered_samples.last_flush) { |
| 717 | printf("Warning: Timestamp below last timeslice flush\n"); |
| 718 | return -EINVAL; |
| 719 | } |
| 720 | |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 721 | if (!list_empty(sc)) { |
| 722 | new = list_entry(sc->next, struct sample_queue, list); |
| 723 | list_del(&new->list); |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 724 | } else if (os->sample_buffer) { |
| 725 | new = os->sample_buffer + os->sample_buffer_idx; |
| 726 | if (++os->sample_buffer_idx == MAX_SAMPLE_BUFFER) |
| 727 | os->sample_buffer = NULL; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 728 | } else { |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 729 | os->sample_buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new)); |
| 730 | if (!os->sample_buffer) |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 731 | return -ENOMEM; |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 732 | list_add(&os->sample_buffer->list, &os->to_free); |
| 733 | os->sample_buffer_idx = 2; |
| 734 | new = os->sample_buffer + 1; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 735 | } |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 736 | |
| 737 | new->timestamp = timestamp; |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 738 | new->file_offset = file_offset; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 739 | new->event = event; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 740 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 741 | __queue_event(new, s); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 746 | static void callchain__printf(struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 747 | { |
| 748 | unsigned int i; |
| 749 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 750 | printf("... chain: nr:%" PRIu64 "\n", sample->callchain->nr); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 751 | |
| 752 | for (i = 0; i < sample->callchain->nr; i++) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 753 | printf("..... %2d: %016" PRIx64 "\n", |
| 754 | i, sample->callchain->ips[i]); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 755 | } |
| 756 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 757 | static void branch_stack__printf(struct perf_sample *sample) |
| 758 | { |
| 759 | uint64_t i; |
| 760 | |
| 761 | printf("... branch stack: nr:%" PRIu64 "\n", sample->branch_stack->nr); |
| 762 | |
| 763 | for (i = 0; i < sample->branch_stack->nr; i++) |
| 764 | printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 "\n", |
| 765 | i, sample->branch_stack->entries[i].from, |
| 766 | sample->branch_stack->entries[i].to); |
| 767 | } |
| 768 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 769 | static void perf_session__print_tstamp(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 770 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 771 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 772 | { |
| 773 | if (event->header.type != PERF_RECORD_SAMPLE && |
| 774 | !session->sample_id_all) { |
| 775 | fputs("-1 -1 ", stdout); |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | if ((session->sample_type & PERF_SAMPLE_CPU)) |
| 780 | printf("%u ", sample->cpu); |
| 781 | |
| 782 | if (session->sample_type & PERF_SAMPLE_TIME) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 783 | printf("%" PRIu64 " ", sample->time); |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 784 | } |
| 785 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 786 | 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] | 787 | u64 file_offset, struct perf_sample *sample) |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 788 | { |
| 789 | if (!dump_trace) |
| 790 | return; |
| 791 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 792 | printf("\n%#" PRIx64 " [%#x]: event: %d\n", |
| 793 | file_offset, event->header.size, event->header.type); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 794 | |
| 795 | trace_event(event); |
| 796 | |
| 797 | if (sample) |
| 798 | perf_session__print_tstamp(session, event, sample); |
| 799 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 800 | printf("%#" PRIx64 " [%#x]: PERF_RECORD_%s", file_offset, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 801 | event->header.size, perf_event__name(event->header.type)); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 804 | 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] | 805 | struct perf_sample *sample) |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 806 | { |
Arnaldo Carvalho de Melo | ddbc24b | 2010-12-09 12:20:20 -0200 | [diff] [blame] | 807 | if (!dump_trace) |
| 808 | return; |
| 809 | |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 810 | 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] | 811 | event->header.misc, sample->pid, sample->tid, sample->ip, |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 812 | sample->period, sample->addr); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 813 | |
| 814 | if (session->sample_type & PERF_SAMPLE_CALLCHAIN) |
Arnaldo Carvalho de Melo | ddbc24b | 2010-12-09 12:20:20 -0200 | [diff] [blame] | 815 | callchain__printf(sample); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 816 | |
| 817 | if (session->sample_type & PERF_SAMPLE_BRANCH_STACK) |
| 818 | branch_stack__printf(sample); |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 821 | static struct machine * |
| 822 | perf_session__find_machine_for_cpumode(struct perf_session *session, |
| 823 | union perf_event *event) |
| 824 | { |
| 825 | const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 826 | |
| 827 | if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) |
| 828 | return perf_session__find_machine(session, event->ip.pid); |
| 829 | |
| 830 | return perf_session__find_host_machine(session); |
| 831 | } |
| 832 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 833 | static int perf_session_deliver_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 834 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 835 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 836 | struct perf_tool *tool, |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 837 | u64 file_offset) |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 838 | { |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 839 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 840 | struct machine *machine; |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 841 | |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 842 | dump_event(session, event, file_offset, sample); |
| 843 | |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 844 | evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
| 845 | if (evsel != NULL && event->header.type != PERF_RECORD_SAMPLE) { |
| 846 | /* |
| 847 | * XXX We're leaving PERF_RECORD_SAMPLE unnacounted here |
| 848 | * because the tools right now may apply filters, discarding |
| 849 | * some of the samples. For consistency, in the future we |
| 850 | * should have something like nr_filtered_samples and remove |
| 851 | * the sample->period from total_sample_period, etc, KISS for |
| 852 | * now tho. |
| 853 | * |
| 854 | * Also testing against NULL allows us to handle files without |
| 855 | * attr.sample_id_all and/or without PERF_SAMPLE_ID. In the |
| 856 | * future probably it'll be a good idea to restrict event |
| 857 | * processing via perf_session to files with both set. |
| 858 | */ |
| 859 | hists__inc_nr_events(&evsel->hists, event->header.type); |
| 860 | } |
| 861 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 862 | machine = perf_session__find_machine_for_cpumode(session, event); |
| 863 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 864 | switch (event->header.type) { |
| 865 | case PERF_RECORD_SAMPLE: |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 866 | dump_sample(session, event, sample); |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 867 | if (evsel == NULL) { |
| 868 | ++session->hists.stats.nr_unknown_id; |
| 869 | return -1; |
| 870 | } |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 871 | if (machine == NULL) { |
| 872 | ++session->hists.stats.nr_unprocessable_samples; |
| 873 | return -1; |
| 874 | } |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 875 | return tool->sample(tool, event, sample, evsel, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 876 | case PERF_RECORD_MMAP: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 877 | return tool->mmap(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 878 | case PERF_RECORD_COMM: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 879 | return tool->comm(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 880 | case PERF_RECORD_FORK: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 881 | return tool->fork(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 882 | case PERF_RECORD_EXIT: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 883 | return tool->exit(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 884 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 885 | if (tool->lost == perf_event__process_lost) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 886 | session->hists.stats.total_lost += event->lost.lost; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 887 | return tool->lost(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 888 | case PERF_RECORD_READ: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 889 | return tool->read(tool, event, sample, evsel, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 890 | case PERF_RECORD_THROTTLE: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 891 | return tool->throttle(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 892 | case PERF_RECORD_UNTHROTTLE: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 893 | return tool->unthrottle(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 894 | default: |
| 895 | ++session->hists.stats.nr_unknown_events; |
| 896 | return -1; |
| 897 | } |
| 898 | } |
| 899 | |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 900 | static int perf_session__preprocess_sample(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 901 | union perf_event *event, struct perf_sample *sample) |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 902 | { |
| 903 | if (event->header.type != PERF_RECORD_SAMPLE || |
| 904 | !(session->sample_type & PERF_SAMPLE_CALLCHAIN)) |
| 905 | return 0; |
| 906 | |
| 907 | if (!ip_callchain__valid(sample->callchain, event)) { |
| 908 | pr_debug("call-chain problem with event, skipping it.\n"); |
| 909 | ++session->hists.stats.nr_invalid_chains; |
| 910 | session->hists.stats.total_invalid_chains += sample->period; |
| 911 | return -EINVAL; |
| 912 | } |
| 913 | return 0; |
| 914 | } |
| 915 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 916 | static int perf_session__process_user_event(struct perf_session *session, union perf_event *event, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 917 | struct perf_tool *tool, u64 file_offset) |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 918 | { |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 919 | int err; |
| 920 | |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 921 | dump_event(session, event, file_offset, NULL); |
| 922 | |
| 923 | /* These events are processed right away */ |
| 924 | switch (event->header.type) { |
| 925 | case PERF_RECORD_HEADER_ATTR: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 926 | err = tool->attr(event, &session->evlist); |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 927 | if (err == 0) |
| 928 | perf_session__update_sample_type(session); |
| 929 | return err; |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 930 | case PERF_RECORD_HEADER_EVENT_TYPE: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 931 | return tool->event_type(tool, event); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 932 | case PERF_RECORD_HEADER_TRACING_DATA: |
| 933 | /* setup for reading amidst mmap */ |
| 934 | lseek(session->fd, file_offset, SEEK_SET); |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 935 | return tool->tracing_data(event, session); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 936 | case PERF_RECORD_HEADER_BUILD_ID: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 937 | return tool->build_id(tool, event, session); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 938 | case PERF_RECORD_FINISHED_ROUND: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 939 | return tool->finished_round(tool, event, session); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 940 | default: |
| 941 | return -EINVAL; |
| 942 | } |
| 943 | } |
| 944 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 945 | static int perf_session__process_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 946 | union perf_event *event, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 947 | struct perf_tool *tool, |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 948 | u64 file_offset) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 949 | { |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 950 | struct perf_sample sample; |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 951 | int ret; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 952 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 953 | if (session->header.needs_swap && |
| 954 | perf_event__swap_ops[event->header.type]) |
| 955 | perf_event__swap_ops[event->header.type](event); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 956 | |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 957 | if (event->header.type >= PERF_RECORD_HEADER_MAX) |
| 958 | return -EINVAL; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 959 | |
Thomas Gleixner | 9aefcab | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 960 | hists__inc_nr_events(&session->hists, event->header.type); |
| 961 | |
| 962 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 963 | return perf_session__process_user_event(session, event, tool, file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 964 | |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 965 | /* |
| 966 | * For all kernel events we get the sample data |
| 967 | */ |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 968 | ret = perf_session__parse_sample(session, event, &sample); |
| 969 | if (ret) |
| 970 | return ret; |
Thomas Gleixner | 3dfc2c0 | 2010-12-07 12:48:58 +0000 | [diff] [blame] | 971 | |
| 972 | /* Preprocess sample records - precheck callchains */ |
| 973 | if (perf_session__preprocess_sample(session, event, &sample)) |
| 974 | return 0; |
| 975 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 976 | if (tool->ordered_samples) { |
Thomas Gleixner | e4c2df1 | 2010-12-07 12:48:50 +0000 | [diff] [blame] | 977 | ret = perf_session_queue_event(session, event, &sample, |
| 978 | file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 979 | if (ret != -ETIME) |
| 980 | return ret; |
| 981 | } |
| 982 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 983 | return perf_session_deliver_event(session, event, &sample, tool, |
Thomas Gleixner | f74725d | 2010-12-07 12:48:53 +0000 | [diff] [blame] | 984 | file_offset); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 985 | } |
| 986 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 987 | void perf_event_header__bswap(struct perf_event_header *self) |
| 988 | { |
| 989 | self->type = bswap_32(self->type); |
| 990 | self->misc = bswap_16(self->misc); |
| 991 | self->size = bswap_16(self->size); |
| 992 | } |
| 993 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 994 | struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) |
| 995 | { |
| 996 | return machine__findnew_thread(&session->host_machine, pid); |
| 997 | } |
| 998 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 999 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) |
| 1000 | { |
| 1001 | struct thread *thread = perf_session__findnew(self, 0); |
| 1002 | |
| 1003 | if (thread == NULL || thread__set_comm(thread, "swapper")) { |
| 1004 | pr_err("problem inserting idle task.\n"); |
| 1005 | thread = NULL; |
| 1006 | } |
| 1007 | |
| 1008 | return thread; |
| 1009 | } |
| 1010 | |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1011 | static void perf_session__warn_about_errors(const struct perf_session *session, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1012 | const struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1013 | { |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1014 | if (tool->lost == perf_event__process_lost && |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1015 | session->hists.stats.nr_events[PERF_RECORD_LOST] != 0) { |
| 1016 | ui__warning("Processed %d events and lost %d chunks!\n\n" |
| 1017 | "Check IO/CPU overload!\n\n", |
| 1018 | session->hists.stats.nr_events[0], |
| 1019 | session->hists.stats.nr_events[PERF_RECORD_LOST]); |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | if (session->hists.stats.nr_unknown_events != 0) { |
| 1023 | ui__warning("Found %u unknown events!\n\n" |
| 1024 | "Is this an older tool processing a perf.data " |
| 1025 | "file generated by a more recent tool?\n\n" |
| 1026 | "If that is not the case, consider " |
| 1027 | "reporting to linux-kernel@vger.kernel.org.\n\n", |
| 1028 | session->hists.stats.nr_unknown_events); |
| 1029 | } |
| 1030 | |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1031 | if (session->hists.stats.nr_unknown_id != 0) { |
| 1032 | ui__warning("%u samples with id not present in the header\n", |
| 1033 | session->hists.stats.nr_unknown_id); |
| 1034 | } |
| 1035 | |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1036 | if (session->hists.stats.nr_invalid_chains != 0) { |
| 1037 | ui__warning("Found invalid callchains!\n\n" |
| 1038 | "%u out of %u events were discarded for this reason.\n\n" |
| 1039 | "Consider reporting to linux-kernel@vger.kernel.org.\n\n", |
| 1040 | session->hists.stats.nr_invalid_chains, |
| 1041 | session->hists.stats.nr_events[PERF_RECORD_SAMPLE]); |
| 1042 | } |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1043 | |
| 1044 | if (session->hists.stats.nr_unprocessable_samples != 0) { |
| 1045 | ui__warning("%u unprocessable samples recorded.\n" |
| 1046 | "Do you have a KVM guest running and not using 'perf kvm'?\n", |
| 1047 | session->hists.stats.nr_unprocessable_samples); |
| 1048 | } |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1051 | #define session_done() (*(volatile int *)(&session_done)) |
| 1052 | volatile int session_done; |
| 1053 | |
| 1054 | static int __perf_session__process_pipe_events(struct perf_session *self, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1055 | struct perf_tool *tool) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1056 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1057 | union perf_event event; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1058 | uint32_t size; |
| 1059 | int skip = 0; |
| 1060 | u64 head; |
| 1061 | int err; |
| 1062 | void *p; |
| 1063 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1064 | perf_tool__fill_defaults(tool); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1065 | |
| 1066 | head = 0; |
| 1067 | more: |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 1068 | err = readn(self->fd, &event, sizeof(struct perf_event_header)); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1069 | if (err <= 0) { |
| 1070 | if (err == 0) |
| 1071 | goto done; |
| 1072 | |
| 1073 | pr_err("failed to read event header\n"); |
| 1074 | goto out_err; |
| 1075 | } |
| 1076 | |
| 1077 | if (self->header.needs_swap) |
| 1078 | perf_event_header__bswap(&event.header); |
| 1079 | |
| 1080 | size = event.header.size; |
| 1081 | if (size == 0) |
| 1082 | size = 8; |
| 1083 | |
| 1084 | p = &event; |
| 1085 | p += sizeof(struct perf_event_header); |
| 1086 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1087 | if (size - sizeof(struct perf_event_header)) { |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 1088 | err = readn(self->fd, p, size - sizeof(struct perf_event_header)); |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1089 | if (err <= 0) { |
| 1090 | if (err == 0) { |
| 1091 | pr_err("unexpected end of event stream\n"); |
| 1092 | goto done; |
| 1093 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1094 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1095 | pr_err("failed to read event data\n"); |
| 1096 | goto out_err; |
| 1097 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1098 | } |
| 1099 | |
Namhyung Kim | 29c9862 | 2011-12-28 00:35:48 +0900 | [diff] [blame] | 1100 | if ((skip = perf_session__process_event(self, &event, tool, head)) < 0) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1101 | dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1102 | head, event.header.size, event.header.type); |
| 1103 | /* |
| 1104 | * assume we lost track of the stream, check alignment, and |
| 1105 | * increment a single u64 in the hope to catch on again 'soon'. |
| 1106 | */ |
| 1107 | if (unlikely(head & 7)) |
| 1108 | head &= ~7ULL; |
| 1109 | |
| 1110 | size = 8; |
| 1111 | } |
| 1112 | |
| 1113 | head += size; |
| 1114 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1115 | if (skip > 0) |
| 1116 | head += skip; |
| 1117 | |
| 1118 | if (!session_done()) |
| 1119 | goto more; |
| 1120 | done: |
| 1121 | err = 0; |
| 1122 | out_err: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1123 | perf_session__warn_about_errors(self, tool); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 1124 | perf_session_free_sample_buffers(self); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1125 | return err; |
| 1126 | } |
| 1127 | |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1128 | static union perf_event * |
| 1129 | fetch_mmaped_event(struct perf_session *session, |
| 1130 | u64 head, size_t mmap_size, char *buf) |
| 1131 | { |
| 1132 | union perf_event *event; |
| 1133 | |
| 1134 | /* |
| 1135 | * Ensure we have enough space remaining to read |
| 1136 | * the size of the event in the headers. |
| 1137 | */ |
| 1138 | if (head + sizeof(event->header) > mmap_size) |
| 1139 | return NULL; |
| 1140 | |
| 1141 | event = (union perf_event *)(buf + head); |
| 1142 | |
| 1143 | if (session->header.needs_swap) |
| 1144 | perf_event_header__bswap(&event->header); |
| 1145 | |
| 1146 | if (head + event->header.size > mmap_size) |
| 1147 | return NULL; |
| 1148 | |
| 1149 | return event; |
| 1150 | } |
| 1151 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1152 | int __perf_session__process_events(struct perf_session *session, |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1153 | u64 data_offset, u64 data_size, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1154 | u64 file_size, struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1155 | { |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1156 | u64 head, page_offset, file_offset, file_pos, progress_next; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1157 | int err, mmap_prot, mmap_flags, map_idx = 0; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1158 | size_t page_size, mmap_size; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1159 | char *buf, *mmaps[8]; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1160 | union perf_event *event; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1161 | uint32_t size; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1162 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1163 | perf_tool__fill_defaults(tool); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1164 | |
Arnaldo Carvalho de Melo | 1b75962 | 2010-01-14 18:30:04 -0200 | [diff] [blame] | 1165 | page_size = sysconf(_SC_PAGESIZE); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1166 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1167 | page_offset = page_size * (data_offset / page_size); |
| 1168 | file_offset = page_offset; |
| 1169 | head = data_offset - page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1170 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1171 | if (data_offset + data_size < file_size) |
| 1172 | file_size = data_offset + data_size; |
| 1173 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1174 | progress_next = file_size / 16; |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1175 | |
| 1176 | mmap_size = session->mmap_window; |
| 1177 | if (mmap_size > file_size) |
| 1178 | mmap_size = file_size; |
| 1179 | |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1180 | memset(mmaps, 0, sizeof(mmaps)); |
| 1181 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1182 | mmap_prot = PROT_READ; |
| 1183 | mmap_flags = MAP_SHARED; |
| 1184 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1185 | if (session->header.needs_swap) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1186 | mmap_prot |= PROT_WRITE; |
| 1187 | mmap_flags = MAP_PRIVATE; |
| 1188 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1189 | remap: |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1190 | buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, session->fd, |
| 1191 | file_offset); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1192 | if (buf == MAP_FAILED) { |
| 1193 | pr_err("failed to mmap file\n"); |
| 1194 | err = -errno; |
| 1195 | goto out_err; |
| 1196 | } |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1197 | mmaps[map_idx] = buf; |
| 1198 | map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1199 | file_pos = file_offset + head; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1200 | |
| 1201 | more: |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1202 | event = fetch_mmaped_event(session, head, mmap_size, buf); |
| 1203 | if (!event) { |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1204 | if (mmaps[map_idx]) { |
| 1205 | munmap(mmaps[map_idx], mmap_size); |
| 1206 | mmaps[map_idx] = NULL; |
| 1207 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1208 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1209 | page_offset = page_size * (head / page_size); |
| 1210 | file_offset += page_offset; |
| 1211 | head -= page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1212 | goto remap; |
| 1213 | } |
| 1214 | |
| 1215 | size = event->header.size; |
| 1216 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1217 | if (size == 0 || |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1218 | perf_session__process_event(session, event, tool, file_pos) < 0) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1219 | dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1220 | file_offset + head, event->header.size, |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1221 | event->header.type); |
| 1222 | /* |
| 1223 | * assume we lost track of the stream, check alignment, and |
| 1224 | * increment a single u64 in the hope to catch on again 'soon'. |
| 1225 | */ |
| 1226 | if (unlikely(head & 7)) |
| 1227 | head &= ~7ULL; |
| 1228 | |
| 1229 | size = 8; |
| 1230 | } |
| 1231 | |
| 1232 | head += size; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1233 | file_pos += size; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1234 | |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1235 | if (file_pos >= progress_next) { |
| 1236 | progress_next += file_size / 16; |
Arnaldo Carvalho de Melo | ca59bcb | 2011-10-25 13:29:11 -0200 | [diff] [blame] | 1237 | ui_progress__update(file_pos, file_size, |
| 1238 | "Processing events..."); |
Thomas Gleixner | 55b4462 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1241 | if (file_pos < file_size) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1242 | goto more; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1243 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1244 | err = 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 1245 | /* do the final flush for ordered samples */ |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1246 | session->ordered_samples.next_flush = ULLONG_MAX; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1247 | flush_sample_queue(session, tool); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1248 | out_err: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1249 | perf_session__warn_about_errors(session, tool); |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 1250 | perf_session_free_sample_buffers(session); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1251 | return err; |
| 1252 | } |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1253 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1254 | int perf_session__process_events(struct perf_session *self, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1255 | struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1256 | { |
| 1257 | int err; |
| 1258 | |
| 1259 | if (perf_session__register_idle_thread(self) == NULL) |
| 1260 | return -ENOMEM; |
| 1261 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1262 | if (!self->fd_pipe) |
| 1263 | err = __perf_session__process_events(self, |
| 1264 | self->header.data_offset, |
| 1265 | self->header.data_size, |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1266 | self->size, tool); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1267 | else |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1268 | err = __perf_session__process_pipe_events(self, tool); |
Dave Martin | 88ca895 | 2010-07-27 11:46:12 -0300 | [diff] [blame] | 1269 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1270 | return err; |
| 1271 | } |
| 1272 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1273 | 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] | 1274 | { |
| 1275 | if (!(self->sample_type & PERF_SAMPLE_RAW)) { |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1276 | pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); |
| 1277 | return false; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1278 | } |
| 1279 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1280 | return true; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1281 | } |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1282 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1283 | int maps__set_kallsyms_ref_reloc_sym(struct map **maps, |
| 1284 | const char *symbol_name, u64 addr) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1285 | { |
| 1286 | char *bracket; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1287 | enum map_type i; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1288 | struct ref_reloc_sym *ref; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1289 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1290 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
| 1291 | if (ref == NULL) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1292 | return -ENOMEM; |
| 1293 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1294 | ref->name = strdup(symbol_name); |
| 1295 | if (ref->name == NULL) { |
| 1296 | free(ref); |
| 1297 | return -ENOMEM; |
| 1298 | } |
| 1299 | |
| 1300 | bracket = strchr(ref->name, ']'); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1301 | if (bracket) |
| 1302 | *bracket = '\0'; |
| 1303 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1304 | ref->addr = addr; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1305 | |
| 1306 | for (i = 0; i < MAP__NR_TYPES; ++i) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1307 | struct kmap *kmap = map__kmap(maps[i]); |
| 1308 | kmap->ref_reloc_sym = ref; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1311 | return 0; |
| 1312 | } |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1313 | |
| 1314 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) |
| 1315 | { |
| 1316 | return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + |
| 1317 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
| 1318 | machines__fprintf_dsos(&self->machines, fp); |
| 1319 | } |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 1320 | |
| 1321 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, |
| 1322 | bool with_hits) |
| 1323 | { |
| 1324 | size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits); |
| 1325 | return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
| 1326 | } |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1327 | |
| 1328 | size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) |
| 1329 | { |
| 1330 | struct perf_evsel *pos; |
| 1331 | size_t ret = fprintf(fp, "Aggregated stats:\n"); |
| 1332 | |
| 1333 | ret += hists__fprintf_nr_events(&session->hists, fp); |
| 1334 | |
| 1335 | list_for_each_entry(pos, &session->evlist->entries, node) { |
| 1336 | ret += fprintf(fp, "%s stats:\n", event_name(pos)); |
| 1337 | ret += hists__fprintf_nr_events(&pos->hists, fp); |
| 1338 | } |
| 1339 | |
| 1340 | return ret; |
| 1341 | } |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1342 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 1343 | size_t perf_session__fprintf(struct perf_session *session, FILE *fp) |
| 1344 | { |
| 1345 | /* |
| 1346 | * FIXME: Here we have to actually print all the machines in this |
| 1347 | * session, not just the host... |
| 1348 | */ |
| 1349 | return machine__fprintf(&session->host_machine, fp); |
| 1350 | } |
| 1351 | |
| 1352 | void perf_session__remove_thread(struct perf_session *session, |
| 1353 | struct thread *th) |
| 1354 | { |
| 1355 | /* |
| 1356 | * FIXME: This one makes no sense, we need to remove the thread from |
| 1357 | * the machine it belongs to, perf_session can have many machines, so |
| 1358 | * doing it always on ->host_machine is wrong. Fix when auditing all |
| 1359 | * the 'perf kvm' code. |
| 1360 | */ |
| 1361 | machine__remove_thread(&session->host_machine, th); |
| 1362 | } |
| 1363 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 1364 | struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, |
| 1365 | unsigned int type) |
| 1366 | { |
| 1367 | struct perf_evsel *pos; |
| 1368 | |
| 1369 | list_for_each_entry(pos, &session->evlist->entries, node) { |
| 1370 | if (pos->attr.type == type) |
| 1371 | return pos; |
| 1372 | } |
| 1373 | return NULL; |
| 1374 | } |
| 1375 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1376 | void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, |
| 1377 | struct machine *machine, struct perf_evsel *evsel, |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 1378 | int print_sym, int print_dso, int print_symoffset) |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1379 | { |
| 1380 | struct addr_location al; |
Arnaldo Carvalho de Melo | 246d4ce | 2011-11-11 23:10:26 -0200 | [diff] [blame] | 1381 | struct callchain_cursor *cursor = &evsel->hists.callchain_cursor; |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1382 | struct callchain_cursor_node *node; |
| 1383 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1384 | if (perf_event__preprocess_sample(event, machine, &al, sample, |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1385 | NULL) < 0) { |
| 1386 | error("problem processing %d event, skipping it.\n", |
| 1387 | event->header.type); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | if (symbol_conf.use_callchain && sample->callchain) { |
| 1392 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1393 | if (machine__resolve_callchain(machine, evsel, al.thread, |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1394 | sample->callchain, NULL) != 0) { |
| 1395 | if (verbose) |
| 1396 | error("Failed to resolve callchain. Skipping\n"); |
| 1397 | return; |
| 1398 | } |
| 1399 | callchain_cursor_commit(cursor); |
| 1400 | |
| 1401 | while (1) { |
| 1402 | node = callchain_cursor_current(cursor); |
| 1403 | if (!node) |
| 1404 | break; |
| 1405 | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 1406 | printf("\t%16" PRIx64, node->ip); |
| 1407 | if (print_sym) { |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 1408 | printf(" "); |
| 1409 | symbol__fprintf_symname(node->sym, stdout); |
David Ahern | 610723f | 2011-05-27 14:28:44 -0600 | [diff] [blame] | 1410 | } |
| 1411 | if (print_dso) { |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 1412 | printf(" ("); |
| 1413 | map__fprintf_dsoname(al.map, stdout); |
| 1414 | printf(")"); |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 1415 | } |
| 1416 | printf("\n"); |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1417 | |
| 1418 | callchain_cursor_advance(cursor); |
| 1419 | } |
| 1420 | |
| 1421 | } else { |
David Ahern | adc4bf9 | 2011-05-30 09:16:27 -0600 | [diff] [blame] | 1422 | printf("%16" PRIx64, sample->ip); |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 1423 | if (print_sym) { |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 1424 | printf(" "); |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 1425 | if (print_symoffset) |
| 1426 | symbol__fprintf_symname_offs(al.sym, &al, |
| 1427 | stdout); |
| 1428 | else |
| 1429 | symbol__fprintf_symname(al.sym, stdout); |
David Ahern | 610723f | 2011-05-27 14:28:44 -0600 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | if (print_dso) { |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 1433 | printf(" ("); |
| 1434 | map__fprintf_dsoname(al.map, stdout); |
| 1435 | printf(")"); |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 1436 | } |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1437 | } |
| 1438 | } |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 1439 | |
| 1440 | int perf_session__cpu_bitmap(struct perf_session *session, |
| 1441 | const char *cpu_list, unsigned long *cpu_bitmap) |
| 1442 | { |
| 1443 | int i; |
| 1444 | struct cpu_map *map; |
| 1445 | |
| 1446 | for (i = 0; i < PERF_TYPE_MAX; ++i) { |
| 1447 | struct perf_evsel *evsel; |
| 1448 | |
| 1449 | evsel = perf_session__find_first_evtype(session, i); |
| 1450 | if (!evsel) |
| 1451 | continue; |
| 1452 | |
| 1453 | if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) { |
| 1454 | pr_err("File does not contain CPU events. " |
| 1455 | "Remove -c option to proceed.\n"); |
| 1456 | return -1; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | map = cpu_map__new(cpu_list); |
David Ahern | 47fbe53 | 2011-11-13 10:45:27 -0700 | [diff] [blame] | 1461 | if (map == NULL) { |
| 1462 | pr_err("Invalid cpu_list\n"); |
| 1463 | return -1; |
| 1464 | } |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 1465 | |
| 1466 | for (i = 0; i < map->nr; i++) { |
| 1467 | int cpu = map->map[i]; |
| 1468 | |
| 1469 | if (cpu >= MAX_NR_CPUS) { |
| 1470 | pr_err("Requested CPU %d too large. " |
| 1471 | "Consider raising MAX_NR_CPUS\n", cpu); |
| 1472 | return -1; |
| 1473 | } |
| 1474 | |
| 1475 | set_bit(cpu, cpu_bitmap); |
| 1476 | } |
| 1477 | |
| 1478 | return 0; |
| 1479 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1480 | |
| 1481 | void perf_session__fprintf_info(struct perf_session *session, FILE *fp, |
| 1482 | bool full) |
| 1483 | { |
| 1484 | struct stat st; |
| 1485 | int ret; |
| 1486 | |
| 1487 | if (session == NULL || fp == NULL) |
| 1488 | return; |
| 1489 | |
| 1490 | ret = fstat(session->fd, &st); |
| 1491 | if (ret == -1) |
| 1492 | return; |
| 1493 | |
| 1494 | fprintf(fp, "# ========\n"); |
| 1495 | fprintf(fp, "# captured on: %s", ctime(&st.st_ctime)); |
| 1496 | perf_header__fprintf_info(session, fp, full); |
| 1497 | fprintf(fp, "# ========\n#\n"); |
| 1498 | } |