Xiao Guangrong | b8f46c5 | 2010-02-03 11:53:14 +0800 | [diff] [blame] | 1 | #define _FILE_OFFSET_BITS 64 |
| 2 | |
Arnaldo Carvalho de Melo | a9072bc | 2011-10-26 12:41:38 -0200 | [diff] [blame] | 3 | #include "util.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 4 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 5 | #include <byteswap.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 9 | #include <linux/list.h> |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 12 | #include <sys/utsname.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 13 | |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 14 | #include "evlist.h" |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 15 | #include "evsel.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 16 | #include "header.h" |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 17 | #include "../perf.h" |
| 18 | #include "trace-event.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 19 | #include "session.h" |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 20 | #include "symbol.h" |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 21 | #include "debug.h" |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 22 | #include "cpumap.h" |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame^] | 23 | #include "pmu.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 24 | |
Stephane Eranian | a1ac1d3 | 2010-06-17 11:39:01 +0200 | [diff] [blame] | 25 | static bool no_buildid_cache = false; |
| 26 | |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 27 | static int trace_event_count; |
| 28 | static struct perf_trace_event_type *trace_events; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 29 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 30 | static u32 header_argc; |
| 31 | static const char **header_argv; |
| 32 | |
Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 33 | int perf_header__push_event(u64 id, const char *name) |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 34 | { |
Ulrich Drepper | f3054c7 | 2012-04-23 09:04:29 -0400 | [diff] [blame] | 35 | struct perf_trace_event_type *nevents; |
| 36 | |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 37 | if (strlen(name) > MAX_EVENT_NAME) |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 38 | pr_warning("Event %s will be truncated\n", name); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 39 | |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 40 | nevents = realloc(trace_events, (trace_event_count + 1) * sizeof(*trace_events)); |
Ulrich Drepper | f3054c7 | 2012-04-23 09:04:29 -0400 | [diff] [blame] | 41 | if (nevents == NULL) |
| 42 | return -ENOMEM; |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 43 | trace_events = nevents; |
Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 44 | |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 45 | memset(&trace_events[trace_event_count], 0, sizeof(struct perf_trace_event_type)); |
| 46 | trace_events[trace_event_count].event_id = id; |
| 47 | strncpy(trace_events[trace_event_count].name, name, MAX_EVENT_NAME - 1); |
| 48 | trace_event_count++; |
Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 49 | return 0; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | char *perf_header__find_event(u64 id) |
| 53 | { |
| 54 | int i; |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 55 | for (i = 0 ; i < trace_event_count; i++) { |
| 56 | if (trace_events[i].event_id == id) |
| 57 | return trace_events[i].name; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 58 | } |
| 59 | return NULL; |
| 60 | } |
| 61 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 62 | /* |
| 63 | * magic2 = "PERFILE2" |
| 64 | * must be a numerical value to let the endianness |
| 65 | * determine the memory layout. That way we are able |
| 66 | * to detect endianness when reading the perf.data file |
| 67 | * back. |
| 68 | * |
| 69 | * we check for legacy (PERFFILE) format. |
| 70 | */ |
| 71 | static const char *__perf_magic1 = "PERFFILE"; |
| 72 | static const u64 __perf_magic2 = 0x32454c4946524550ULL; |
| 73 | static const u64 __perf_magic2_sw = 0x50455246494c4532ULL; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 74 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 75 | #define PERF_MAGIC __perf_magic2 |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 76 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 77 | struct perf_file_attr { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 78 | struct perf_event_attr attr; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 79 | struct perf_file_section ids; |
| 80 | }; |
| 81 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 82 | void perf_header__set_feat(struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 83 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 84 | set_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 85 | } |
| 86 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 87 | void perf_header__clear_feat(struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | baa2f6c | 2010-11-26 19:39:15 -0200 | [diff] [blame] | 88 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 89 | clear_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | baa2f6c | 2010-11-26 19:39:15 -0200 | [diff] [blame] | 90 | } |
| 91 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 92 | bool perf_header__has_feat(const struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 93 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 94 | return test_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 95 | } |
| 96 | |
Arnaldo Carvalho de Melo | 3726cc7 | 2009-11-17 01:18:12 -0200 | [diff] [blame] | 97 | static int do_write(int fd, const void *buf, size_t size) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 98 | { |
| 99 | while (size) { |
| 100 | int ret = write(fd, buf, size); |
| 101 | |
| 102 | if (ret < 0) |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 103 | return -errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 104 | |
| 105 | size -= ret; |
| 106 | buf += ret; |
| 107 | } |
Arnaldo Carvalho de Melo | 3726cc7 | 2009-11-17 01:18:12 -0200 | [diff] [blame] | 108 | |
| 109 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Arnaldo Carvalho de Melo | f92cb24 | 2010-01-04 16:19:28 -0200 | [diff] [blame] | 112 | #define NAME_ALIGN 64 |
| 113 | |
| 114 | static int write_padded(int fd, const void *bf, size_t count, |
| 115 | size_t count_aligned) |
| 116 | { |
| 117 | static const char zero_buf[NAME_ALIGN]; |
| 118 | int err = do_write(fd, bf, count); |
| 119 | |
| 120 | if (!err) |
| 121 | err = do_write(fd, zero_buf, count_aligned - count); |
| 122 | |
| 123 | return err; |
| 124 | } |
| 125 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 126 | static int do_write_string(int fd, const char *str) |
| 127 | { |
| 128 | u32 len, olen; |
| 129 | int ret; |
| 130 | |
| 131 | olen = strlen(str) + 1; |
| 132 | len = ALIGN(olen, NAME_ALIGN); |
| 133 | |
| 134 | /* write len, incl. \0 */ |
| 135 | ret = do_write(fd, &len, sizeof(len)); |
| 136 | if (ret < 0) |
| 137 | return ret; |
| 138 | |
| 139 | return write_padded(fd, str, olen, len); |
| 140 | } |
| 141 | |
| 142 | static char *do_read_string(int fd, struct perf_header *ph) |
| 143 | { |
| 144 | ssize_t sz, ret; |
| 145 | u32 len; |
| 146 | char *buf; |
| 147 | |
| 148 | sz = read(fd, &len, sizeof(len)); |
| 149 | if (sz < (ssize_t)sizeof(len)) |
| 150 | return NULL; |
| 151 | |
| 152 | if (ph->needs_swap) |
| 153 | len = bswap_32(len); |
| 154 | |
| 155 | buf = malloc(len); |
| 156 | if (!buf) |
| 157 | return NULL; |
| 158 | |
| 159 | ret = read(fd, buf, len); |
| 160 | if (ret == (ssize_t)len) { |
| 161 | /* |
| 162 | * strings are padded by zeroes |
| 163 | * thus the actual strlen of buf |
| 164 | * may be less than len |
| 165 | */ |
| 166 | return buf; |
| 167 | } |
| 168 | |
| 169 | free(buf); |
| 170 | return NULL; |
| 171 | } |
| 172 | |
| 173 | int |
| 174 | perf_header__set_cmdline(int argc, const char **argv) |
| 175 | { |
| 176 | int i; |
| 177 | |
David Ahern | 56e6f60 | 2012-07-29 20:53:51 -0600 | [diff] [blame] | 178 | /* |
| 179 | * If header_argv has already been set, do not override it. |
| 180 | * This allows a command to set the cmdline, parse args and |
| 181 | * then call another builtin function that implements a |
| 182 | * command -- e.g, cmd_kvm calling cmd_record. |
| 183 | */ |
| 184 | if (header_argv) |
| 185 | return 0; |
| 186 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 187 | header_argc = (u32)argc; |
| 188 | |
| 189 | /* do not include NULL termination */ |
| 190 | header_argv = calloc(argc, sizeof(char *)); |
| 191 | if (!header_argv) |
| 192 | return -ENOMEM; |
| 193 | |
| 194 | /* |
| 195 | * must copy argv contents because it gets moved |
| 196 | * around during option parsing |
| 197 | */ |
| 198 | for (i = 0; i < argc ; i++) |
| 199 | header_argv[i] = argv[i]; |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Robert Richter | 1b54950 | 2011-12-07 10:02:53 +0100 | [diff] [blame] | 204 | #define dsos__for_each_with_build_id(pos, head) \ |
| 205 | list_for_each_entry(pos, head, node) \ |
| 206 | if (!pos->has_build_id) \ |
| 207 | continue; \ |
| 208 | else |
| 209 | |
| 210 | static int __dsos__write_buildid_table(struct list_head *head, pid_t pid, |
| 211 | u16 misc, int fd) |
| 212 | { |
| 213 | struct dso *pos; |
| 214 | |
| 215 | dsos__for_each_with_build_id(pos, head) { |
| 216 | int err; |
| 217 | struct build_id_event b; |
| 218 | size_t len; |
| 219 | |
| 220 | if (!pos->hit) |
| 221 | continue; |
| 222 | len = pos->long_name_len + 1; |
| 223 | len = ALIGN(len, NAME_ALIGN); |
| 224 | memset(&b, 0, sizeof(b)); |
| 225 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); |
| 226 | b.pid = pid; |
| 227 | b.header.misc = misc; |
| 228 | b.header.size = sizeof(b) + len; |
| 229 | err = do_write(fd, &b, sizeof(b)); |
| 230 | if (err < 0) |
| 231 | return err; |
| 232 | err = write_padded(fd, pos->long_name, |
| 233 | pos->long_name_len + 1, len); |
| 234 | if (err < 0) |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int machine__write_buildid_table(struct machine *machine, int fd) |
| 242 | { |
| 243 | int err; |
| 244 | u16 kmisc = PERF_RECORD_MISC_KERNEL, |
| 245 | umisc = PERF_RECORD_MISC_USER; |
| 246 | |
| 247 | if (!machine__is_host(machine)) { |
| 248 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; |
| 249 | umisc = PERF_RECORD_MISC_GUEST_USER; |
| 250 | } |
| 251 | |
| 252 | err = __dsos__write_buildid_table(&machine->kernel_dsos, machine->pid, |
| 253 | kmisc, fd); |
| 254 | if (err == 0) |
| 255 | err = __dsos__write_buildid_table(&machine->user_dsos, |
| 256 | machine->pid, umisc, fd); |
| 257 | return err; |
| 258 | } |
| 259 | |
| 260 | static int dsos__write_buildid_table(struct perf_header *header, int fd) |
| 261 | { |
| 262 | struct perf_session *session = container_of(header, |
| 263 | struct perf_session, header); |
| 264 | struct rb_node *nd; |
| 265 | int err = machine__write_buildid_table(&session->host_machine, fd); |
| 266 | |
| 267 | if (err) |
| 268 | return err; |
| 269 | |
| 270 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
| 271 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
| 272 | err = machine__write_buildid_table(pos, fd); |
| 273 | if (err) |
| 274 | break; |
| 275 | } |
| 276 | return err; |
| 277 | } |
| 278 | |
| 279 | int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, |
| 280 | const char *name, bool is_kallsyms) |
| 281 | { |
| 282 | const size_t size = PATH_MAX; |
| 283 | char *realname, *filename = zalloc(size), |
| 284 | *linkname = zalloc(size), *targetname; |
| 285 | int len, err = -1; |
| 286 | |
| 287 | if (is_kallsyms) { |
| 288 | if (symbol_conf.kptr_restrict) { |
| 289 | pr_debug("Not caching a kptr_restrict'ed /proc/kallsyms\n"); |
| 290 | return 0; |
| 291 | } |
| 292 | realname = (char *)name; |
| 293 | } else |
| 294 | realname = realpath(name, NULL); |
| 295 | |
| 296 | if (realname == NULL || filename == NULL || linkname == NULL) |
| 297 | goto out_free; |
| 298 | |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 299 | len = scnprintf(filename, size, "%s%s%s", |
Robert Richter | 1b54950 | 2011-12-07 10:02:53 +0100 | [diff] [blame] | 300 | debugdir, is_kallsyms ? "/" : "", realname); |
| 301 | if (mkdir_p(filename, 0755)) |
| 302 | goto out_free; |
| 303 | |
Namhyung Kim | afda0f9 | 2012-05-01 23:19:36 +0900 | [diff] [blame] | 304 | snprintf(filename + len, size - len, "/%s", sbuild_id); |
Robert Richter | 1b54950 | 2011-12-07 10:02:53 +0100 | [diff] [blame] | 305 | |
| 306 | if (access(filename, F_OK)) { |
| 307 | if (is_kallsyms) { |
| 308 | if (copyfile("/proc/kallsyms", filename)) |
| 309 | goto out_free; |
| 310 | } else if (link(realname, filename) && copyfile(name, filename)) |
| 311 | goto out_free; |
| 312 | } |
| 313 | |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 314 | len = scnprintf(linkname, size, "%s/.build-id/%.2s", |
Robert Richter | 1b54950 | 2011-12-07 10:02:53 +0100 | [diff] [blame] | 315 | debugdir, sbuild_id); |
| 316 | |
| 317 | if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) |
| 318 | goto out_free; |
| 319 | |
| 320 | snprintf(linkname + len, size - len, "/%s", sbuild_id + 2); |
| 321 | targetname = filename + strlen(debugdir) - 5; |
| 322 | memcpy(targetname, "../..", 5); |
| 323 | |
| 324 | if (symlink(targetname, linkname) == 0) |
| 325 | err = 0; |
| 326 | out_free: |
| 327 | if (!is_kallsyms) |
| 328 | free(realname); |
| 329 | free(filename); |
| 330 | free(linkname); |
| 331 | return err; |
| 332 | } |
| 333 | |
| 334 | static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size, |
| 335 | const char *name, const char *debugdir, |
| 336 | bool is_kallsyms) |
| 337 | { |
| 338 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
| 339 | |
| 340 | build_id__sprintf(build_id, build_id_size, sbuild_id); |
| 341 | |
| 342 | return build_id_cache__add_s(sbuild_id, debugdir, name, is_kallsyms); |
| 343 | } |
| 344 | |
| 345 | int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir) |
| 346 | { |
| 347 | const size_t size = PATH_MAX; |
| 348 | char *filename = zalloc(size), |
| 349 | *linkname = zalloc(size); |
| 350 | int err = -1; |
| 351 | |
| 352 | if (filename == NULL || linkname == NULL) |
| 353 | goto out_free; |
| 354 | |
| 355 | snprintf(linkname, size, "%s/.build-id/%.2s/%s", |
| 356 | debugdir, sbuild_id, sbuild_id + 2); |
| 357 | |
| 358 | if (access(linkname, F_OK)) |
| 359 | goto out_free; |
| 360 | |
| 361 | if (readlink(linkname, filename, size - 1) < 0) |
| 362 | goto out_free; |
| 363 | |
| 364 | if (unlink(linkname)) |
| 365 | goto out_free; |
| 366 | |
| 367 | /* |
| 368 | * Since the link is relative, we must make it absolute: |
| 369 | */ |
| 370 | snprintf(linkname, size, "%s/.build-id/%.2s/%s", |
| 371 | debugdir, sbuild_id, filename); |
| 372 | |
| 373 | if (unlink(linkname)) |
| 374 | goto out_free; |
| 375 | |
| 376 | err = 0; |
| 377 | out_free: |
| 378 | free(filename); |
| 379 | free(linkname); |
| 380 | return err; |
| 381 | } |
| 382 | |
| 383 | static int dso__cache_build_id(struct dso *dso, const char *debugdir) |
| 384 | { |
| 385 | bool is_kallsyms = dso->kernel && dso->long_name[0] != '/'; |
| 386 | |
| 387 | return build_id_cache__add_b(dso->build_id, sizeof(dso->build_id), |
| 388 | dso->long_name, debugdir, is_kallsyms); |
| 389 | } |
| 390 | |
| 391 | static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir) |
| 392 | { |
| 393 | struct dso *pos; |
| 394 | int err = 0; |
| 395 | |
| 396 | dsos__for_each_with_build_id(pos, head) |
| 397 | if (dso__cache_build_id(pos, debugdir)) |
| 398 | err = -1; |
| 399 | |
| 400 | return err; |
| 401 | } |
| 402 | |
| 403 | static int machine__cache_build_ids(struct machine *machine, const char *debugdir) |
| 404 | { |
| 405 | int ret = __dsos__cache_build_ids(&machine->kernel_dsos, debugdir); |
| 406 | ret |= __dsos__cache_build_ids(&machine->user_dsos, debugdir); |
| 407 | return ret; |
| 408 | } |
| 409 | |
| 410 | static int perf_session__cache_build_ids(struct perf_session *session) |
| 411 | { |
| 412 | struct rb_node *nd; |
| 413 | int ret; |
| 414 | char debugdir[PATH_MAX]; |
| 415 | |
| 416 | snprintf(debugdir, sizeof(debugdir), "%s", buildid_dir); |
| 417 | |
| 418 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) |
| 419 | return -1; |
| 420 | |
| 421 | ret = machine__cache_build_ids(&session->host_machine, debugdir); |
| 422 | |
| 423 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
| 424 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
| 425 | ret |= machine__cache_build_ids(pos, debugdir); |
| 426 | } |
| 427 | return ret ? -1 : 0; |
| 428 | } |
| 429 | |
| 430 | static bool machine__read_build_ids(struct machine *machine, bool with_hits) |
| 431 | { |
| 432 | bool ret = __dsos__read_build_ids(&machine->kernel_dsos, with_hits); |
| 433 | ret |= __dsos__read_build_ids(&machine->user_dsos, with_hits); |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | static bool perf_session__read_build_ids(struct perf_session *session, bool with_hits) |
| 438 | { |
| 439 | struct rb_node *nd; |
| 440 | bool ret = machine__read_build_ids(&session->host_machine, with_hits); |
| 441 | |
| 442 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
| 443 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
| 444 | ret |= machine__read_build_ids(pos, with_hits); |
| 445 | } |
| 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 450 | static int write_tracing_data(int fd, struct perf_header *h __used, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 451 | struct perf_evlist *evlist) |
| 452 | { |
| 453 | return read_tracing_data(fd, &evlist->entries); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | static int write_build_id(int fd, struct perf_header *h, |
| 458 | struct perf_evlist *evlist __used) |
| 459 | { |
| 460 | struct perf_session *session; |
| 461 | int err; |
| 462 | |
| 463 | session = container_of(h, struct perf_session, header); |
| 464 | |
Robert Richter | e20960c | 2011-12-07 10:02:55 +0100 | [diff] [blame] | 465 | if (!perf_session__read_build_ids(session, true)) |
| 466 | return -1; |
| 467 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 468 | err = dsos__write_buildid_table(h, fd); |
| 469 | if (err < 0) { |
| 470 | pr_debug("failed to write buildid table\n"); |
| 471 | return err; |
| 472 | } |
| 473 | if (!no_buildid_cache) |
| 474 | perf_session__cache_build_ids(session); |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int write_hostname(int fd, struct perf_header *h __used, |
| 480 | struct perf_evlist *evlist __used) |
| 481 | { |
| 482 | struct utsname uts; |
| 483 | int ret; |
| 484 | |
| 485 | ret = uname(&uts); |
| 486 | if (ret < 0) |
| 487 | return -1; |
| 488 | |
| 489 | return do_write_string(fd, uts.nodename); |
| 490 | } |
| 491 | |
| 492 | static int write_osrelease(int fd, struct perf_header *h __used, |
| 493 | struct perf_evlist *evlist __used) |
| 494 | { |
| 495 | struct utsname uts; |
| 496 | int ret; |
| 497 | |
| 498 | ret = uname(&uts); |
| 499 | if (ret < 0) |
| 500 | return -1; |
| 501 | |
| 502 | return do_write_string(fd, uts.release); |
| 503 | } |
| 504 | |
| 505 | static int write_arch(int fd, struct perf_header *h __used, |
| 506 | struct perf_evlist *evlist __used) |
| 507 | { |
| 508 | struct utsname uts; |
| 509 | int ret; |
| 510 | |
| 511 | ret = uname(&uts); |
| 512 | if (ret < 0) |
| 513 | return -1; |
| 514 | |
| 515 | return do_write_string(fd, uts.machine); |
| 516 | } |
| 517 | |
| 518 | static int write_version(int fd, struct perf_header *h __used, |
| 519 | struct perf_evlist *evlist __used) |
| 520 | { |
| 521 | return do_write_string(fd, perf_version_string); |
| 522 | } |
| 523 | |
| 524 | static int write_cpudesc(int fd, struct perf_header *h __used, |
| 525 | struct perf_evlist *evlist __used) |
| 526 | { |
| 527 | #ifndef CPUINFO_PROC |
| 528 | #define CPUINFO_PROC NULL |
| 529 | #endif |
| 530 | FILE *file; |
| 531 | char *buf = NULL; |
| 532 | char *s, *p; |
| 533 | const char *search = CPUINFO_PROC; |
| 534 | size_t len = 0; |
| 535 | int ret = -1; |
| 536 | |
| 537 | if (!search) |
| 538 | return -1; |
| 539 | |
| 540 | file = fopen("/proc/cpuinfo", "r"); |
| 541 | if (!file) |
| 542 | return -1; |
| 543 | |
| 544 | while (getline(&buf, &len, file) > 0) { |
| 545 | ret = strncmp(buf, search, strlen(search)); |
| 546 | if (!ret) |
| 547 | break; |
| 548 | } |
| 549 | |
| 550 | if (ret) |
| 551 | goto done; |
| 552 | |
| 553 | s = buf; |
| 554 | |
| 555 | p = strchr(buf, ':'); |
| 556 | if (p && *(p+1) == ' ' && *(p+2)) |
| 557 | s = p + 2; |
| 558 | p = strchr(s, '\n'); |
| 559 | if (p) |
| 560 | *p = '\0'; |
| 561 | |
| 562 | /* squash extra space characters (branding string) */ |
| 563 | p = s; |
| 564 | while (*p) { |
| 565 | if (isspace(*p)) { |
| 566 | char *r = p + 1; |
| 567 | char *q = r; |
| 568 | *p = ' '; |
| 569 | while (*q && isspace(*q)) |
| 570 | q++; |
| 571 | if (q != (p+1)) |
| 572 | while ((*r++ = *q++)); |
| 573 | } |
| 574 | p++; |
| 575 | } |
| 576 | ret = do_write_string(fd, s); |
| 577 | done: |
| 578 | free(buf); |
| 579 | fclose(file); |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | static int write_nrcpus(int fd, struct perf_header *h __used, |
| 584 | struct perf_evlist *evlist __used) |
| 585 | { |
| 586 | long nr; |
| 587 | u32 nrc, nra; |
| 588 | int ret; |
| 589 | |
| 590 | nr = sysconf(_SC_NPROCESSORS_CONF); |
| 591 | if (nr < 0) |
| 592 | return -1; |
| 593 | |
| 594 | nrc = (u32)(nr & UINT_MAX); |
| 595 | |
| 596 | nr = sysconf(_SC_NPROCESSORS_ONLN); |
| 597 | if (nr < 0) |
| 598 | return -1; |
| 599 | |
| 600 | nra = (u32)(nr & UINT_MAX); |
| 601 | |
| 602 | ret = do_write(fd, &nrc, sizeof(nrc)); |
| 603 | if (ret < 0) |
| 604 | return ret; |
| 605 | |
| 606 | return do_write(fd, &nra, sizeof(nra)); |
| 607 | } |
| 608 | |
| 609 | static int write_event_desc(int fd, struct perf_header *h __used, |
| 610 | struct perf_evlist *evlist) |
| 611 | { |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 612 | struct perf_evsel *evsel; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 613 | u32 nre = 0, nri, sz; |
| 614 | int ret; |
| 615 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 616 | list_for_each_entry(evsel, &evlist->entries, node) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 617 | nre++; |
| 618 | |
| 619 | /* |
| 620 | * write number of events |
| 621 | */ |
| 622 | ret = do_write(fd, &nre, sizeof(nre)); |
| 623 | if (ret < 0) |
| 624 | return ret; |
| 625 | |
| 626 | /* |
| 627 | * size of perf_event_attr struct |
| 628 | */ |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 629 | sz = (u32)sizeof(evsel->attr); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 630 | ret = do_write(fd, &sz, sizeof(sz)); |
| 631 | if (ret < 0) |
| 632 | return ret; |
| 633 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 634 | list_for_each_entry(evsel, &evlist->entries, node) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 635 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 636 | ret = do_write(fd, &evsel->attr, sz); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 637 | if (ret < 0) |
| 638 | return ret; |
| 639 | /* |
| 640 | * write number of unique id per event |
| 641 | * there is one id per instance of an event |
| 642 | * |
| 643 | * copy into an nri to be independent of the |
| 644 | * type of ids, |
| 645 | */ |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 646 | nri = evsel->ids; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 647 | ret = do_write(fd, &nri, sizeof(nri)); |
| 648 | if (ret < 0) |
| 649 | return ret; |
| 650 | |
| 651 | /* |
| 652 | * write event string as passed on cmdline |
| 653 | */ |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 654 | ret = do_write_string(fd, perf_evsel__name(evsel)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 655 | if (ret < 0) |
| 656 | return ret; |
| 657 | /* |
| 658 | * write unique ids for this event |
| 659 | */ |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 660 | ret = do_write(fd, evsel->id, evsel->ids * sizeof(u64)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 661 | if (ret < 0) |
| 662 | return ret; |
| 663 | } |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int write_cmdline(int fd, struct perf_header *h __used, |
| 668 | struct perf_evlist *evlist __used) |
| 669 | { |
| 670 | char buf[MAXPATHLEN]; |
| 671 | char proc[32]; |
| 672 | u32 i, n; |
| 673 | int ret; |
| 674 | |
| 675 | /* |
| 676 | * actual atual path to perf binary |
| 677 | */ |
| 678 | sprintf(proc, "/proc/%d/exe", getpid()); |
| 679 | ret = readlink(proc, buf, sizeof(buf)); |
| 680 | if (ret <= 0) |
| 681 | return -1; |
| 682 | |
| 683 | /* readlink() does not add null termination */ |
| 684 | buf[ret] = '\0'; |
| 685 | |
| 686 | /* account for binary path */ |
| 687 | n = header_argc + 1; |
| 688 | |
| 689 | ret = do_write(fd, &n, sizeof(n)); |
| 690 | if (ret < 0) |
| 691 | return ret; |
| 692 | |
| 693 | ret = do_write_string(fd, buf); |
| 694 | if (ret < 0) |
| 695 | return ret; |
| 696 | |
| 697 | for (i = 0 ; i < header_argc; i++) { |
| 698 | ret = do_write_string(fd, header_argv[i]); |
| 699 | if (ret < 0) |
| 700 | return ret; |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | #define CORE_SIB_FMT \ |
| 706 | "/sys/devices/system/cpu/cpu%d/topology/core_siblings_list" |
| 707 | #define THRD_SIB_FMT \ |
| 708 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list" |
| 709 | |
| 710 | struct cpu_topo { |
| 711 | u32 core_sib; |
| 712 | u32 thread_sib; |
| 713 | char **core_siblings; |
| 714 | char **thread_siblings; |
| 715 | }; |
| 716 | |
| 717 | static int build_cpu_topo(struct cpu_topo *tp, int cpu) |
| 718 | { |
| 719 | FILE *fp; |
| 720 | char filename[MAXPATHLEN]; |
| 721 | char *buf = NULL, *p; |
| 722 | size_t len = 0; |
| 723 | u32 i = 0; |
| 724 | int ret = -1; |
| 725 | |
| 726 | sprintf(filename, CORE_SIB_FMT, cpu); |
| 727 | fp = fopen(filename, "r"); |
| 728 | if (!fp) |
| 729 | return -1; |
| 730 | |
| 731 | if (getline(&buf, &len, fp) <= 0) |
| 732 | goto done; |
| 733 | |
| 734 | fclose(fp); |
| 735 | |
| 736 | p = strchr(buf, '\n'); |
| 737 | if (p) |
| 738 | *p = '\0'; |
| 739 | |
| 740 | for (i = 0; i < tp->core_sib; i++) { |
| 741 | if (!strcmp(buf, tp->core_siblings[i])) |
| 742 | break; |
| 743 | } |
| 744 | if (i == tp->core_sib) { |
| 745 | tp->core_siblings[i] = buf; |
| 746 | tp->core_sib++; |
| 747 | buf = NULL; |
| 748 | len = 0; |
| 749 | } |
| 750 | |
| 751 | sprintf(filename, THRD_SIB_FMT, cpu); |
| 752 | fp = fopen(filename, "r"); |
| 753 | if (!fp) |
| 754 | goto done; |
| 755 | |
| 756 | if (getline(&buf, &len, fp) <= 0) |
| 757 | goto done; |
| 758 | |
| 759 | p = strchr(buf, '\n'); |
| 760 | if (p) |
| 761 | *p = '\0'; |
| 762 | |
| 763 | for (i = 0; i < tp->thread_sib; i++) { |
| 764 | if (!strcmp(buf, tp->thread_siblings[i])) |
| 765 | break; |
| 766 | } |
| 767 | if (i == tp->thread_sib) { |
| 768 | tp->thread_siblings[i] = buf; |
| 769 | tp->thread_sib++; |
| 770 | buf = NULL; |
| 771 | } |
| 772 | ret = 0; |
| 773 | done: |
| 774 | if(fp) |
| 775 | fclose(fp); |
| 776 | free(buf); |
| 777 | return ret; |
| 778 | } |
| 779 | |
| 780 | static void free_cpu_topo(struct cpu_topo *tp) |
| 781 | { |
| 782 | u32 i; |
| 783 | |
| 784 | if (!tp) |
| 785 | return; |
| 786 | |
| 787 | for (i = 0 ; i < tp->core_sib; i++) |
| 788 | free(tp->core_siblings[i]); |
| 789 | |
| 790 | for (i = 0 ; i < tp->thread_sib; i++) |
| 791 | free(tp->thread_siblings[i]); |
| 792 | |
| 793 | free(tp); |
| 794 | } |
| 795 | |
| 796 | static struct cpu_topo *build_cpu_topology(void) |
| 797 | { |
| 798 | struct cpu_topo *tp; |
| 799 | void *addr; |
| 800 | u32 nr, i; |
| 801 | size_t sz; |
| 802 | long ncpus; |
| 803 | int ret = -1; |
| 804 | |
| 805 | ncpus = sysconf(_SC_NPROCESSORS_CONF); |
| 806 | if (ncpus < 0) |
| 807 | return NULL; |
| 808 | |
| 809 | nr = (u32)(ncpus & UINT_MAX); |
| 810 | |
| 811 | sz = nr * sizeof(char *); |
| 812 | |
| 813 | addr = calloc(1, sizeof(*tp) + 2 * sz); |
| 814 | if (!addr) |
| 815 | return NULL; |
| 816 | |
| 817 | tp = addr; |
| 818 | |
| 819 | addr += sizeof(*tp); |
| 820 | tp->core_siblings = addr; |
| 821 | addr += sz; |
| 822 | tp->thread_siblings = addr; |
| 823 | |
| 824 | for (i = 0; i < nr; i++) { |
| 825 | ret = build_cpu_topo(tp, i); |
| 826 | if (ret < 0) |
| 827 | break; |
| 828 | } |
| 829 | if (ret) { |
| 830 | free_cpu_topo(tp); |
| 831 | tp = NULL; |
| 832 | } |
| 833 | return tp; |
| 834 | } |
| 835 | |
| 836 | static int write_cpu_topology(int fd, struct perf_header *h __used, |
| 837 | struct perf_evlist *evlist __used) |
| 838 | { |
| 839 | struct cpu_topo *tp; |
| 840 | u32 i; |
| 841 | int ret; |
| 842 | |
| 843 | tp = build_cpu_topology(); |
| 844 | if (!tp) |
| 845 | return -1; |
| 846 | |
| 847 | ret = do_write(fd, &tp->core_sib, sizeof(tp->core_sib)); |
| 848 | if (ret < 0) |
| 849 | goto done; |
| 850 | |
| 851 | for (i = 0; i < tp->core_sib; i++) { |
| 852 | ret = do_write_string(fd, tp->core_siblings[i]); |
| 853 | if (ret < 0) |
| 854 | goto done; |
| 855 | } |
| 856 | ret = do_write(fd, &tp->thread_sib, sizeof(tp->thread_sib)); |
| 857 | if (ret < 0) |
| 858 | goto done; |
| 859 | |
| 860 | for (i = 0; i < tp->thread_sib; i++) { |
| 861 | ret = do_write_string(fd, tp->thread_siblings[i]); |
| 862 | if (ret < 0) |
| 863 | break; |
| 864 | } |
| 865 | done: |
| 866 | free_cpu_topo(tp); |
| 867 | return ret; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | |
| 872 | static int write_total_mem(int fd, struct perf_header *h __used, |
| 873 | struct perf_evlist *evlist __used) |
| 874 | { |
| 875 | char *buf = NULL; |
| 876 | FILE *fp; |
| 877 | size_t len = 0; |
| 878 | int ret = -1, n; |
| 879 | uint64_t mem; |
| 880 | |
| 881 | fp = fopen("/proc/meminfo", "r"); |
| 882 | if (!fp) |
| 883 | return -1; |
| 884 | |
| 885 | while (getline(&buf, &len, fp) > 0) { |
| 886 | ret = strncmp(buf, "MemTotal:", 9); |
| 887 | if (!ret) |
| 888 | break; |
| 889 | } |
| 890 | if (!ret) { |
| 891 | n = sscanf(buf, "%*s %"PRIu64, &mem); |
| 892 | if (n == 1) |
| 893 | ret = do_write(fd, &mem, sizeof(mem)); |
| 894 | } |
| 895 | free(buf); |
| 896 | fclose(fp); |
| 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | static int write_topo_node(int fd, int node) |
| 901 | { |
| 902 | char str[MAXPATHLEN]; |
| 903 | char field[32]; |
| 904 | char *buf = NULL, *p; |
| 905 | size_t len = 0; |
| 906 | FILE *fp; |
| 907 | u64 mem_total, mem_free, mem; |
| 908 | int ret = -1; |
| 909 | |
| 910 | sprintf(str, "/sys/devices/system/node/node%d/meminfo", node); |
| 911 | fp = fopen(str, "r"); |
| 912 | if (!fp) |
| 913 | return -1; |
| 914 | |
| 915 | while (getline(&buf, &len, fp) > 0) { |
| 916 | /* skip over invalid lines */ |
| 917 | if (!strchr(buf, ':')) |
| 918 | continue; |
| 919 | if (sscanf(buf, "%*s %*d %s %"PRIu64, field, &mem) != 2) |
| 920 | goto done; |
| 921 | if (!strcmp(field, "MemTotal:")) |
| 922 | mem_total = mem; |
| 923 | if (!strcmp(field, "MemFree:")) |
| 924 | mem_free = mem; |
| 925 | } |
| 926 | |
| 927 | fclose(fp); |
| 928 | |
| 929 | ret = do_write(fd, &mem_total, sizeof(u64)); |
| 930 | if (ret) |
| 931 | goto done; |
| 932 | |
| 933 | ret = do_write(fd, &mem_free, sizeof(u64)); |
| 934 | if (ret) |
| 935 | goto done; |
| 936 | |
| 937 | ret = -1; |
| 938 | sprintf(str, "/sys/devices/system/node/node%d/cpulist", node); |
| 939 | |
| 940 | fp = fopen(str, "r"); |
| 941 | if (!fp) |
| 942 | goto done; |
| 943 | |
| 944 | if (getline(&buf, &len, fp) <= 0) |
| 945 | goto done; |
| 946 | |
| 947 | p = strchr(buf, '\n'); |
| 948 | if (p) |
| 949 | *p = '\0'; |
| 950 | |
| 951 | ret = do_write_string(fd, buf); |
| 952 | done: |
| 953 | free(buf); |
| 954 | fclose(fp); |
| 955 | return ret; |
| 956 | } |
| 957 | |
| 958 | static int write_numa_topology(int fd, struct perf_header *h __used, |
| 959 | struct perf_evlist *evlist __used) |
| 960 | { |
| 961 | char *buf = NULL; |
| 962 | size_t len = 0; |
| 963 | FILE *fp; |
| 964 | struct cpu_map *node_map = NULL; |
| 965 | char *c; |
| 966 | u32 nr, i, j; |
| 967 | int ret = -1; |
| 968 | |
| 969 | fp = fopen("/sys/devices/system/node/online", "r"); |
| 970 | if (!fp) |
| 971 | return -1; |
| 972 | |
| 973 | if (getline(&buf, &len, fp) <= 0) |
| 974 | goto done; |
| 975 | |
| 976 | c = strchr(buf, '\n'); |
| 977 | if (c) |
| 978 | *c = '\0'; |
| 979 | |
| 980 | node_map = cpu_map__new(buf); |
| 981 | if (!node_map) |
| 982 | goto done; |
| 983 | |
| 984 | nr = (u32)node_map->nr; |
| 985 | |
| 986 | ret = do_write(fd, &nr, sizeof(nr)); |
| 987 | if (ret < 0) |
| 988 | goto done; |
| 989 | |
| 990 | for (i = 0; i < nr; i++) { |
| 991 | j = (u32)node_map->map[i]; |
| 992 | ret = do_write(fd, &j, sizeof(j)); |
| 993 | if (ret < 0) |
| 994 | break; |
| 995 | |
| 996 | ret = write_topo_node(fd, i); |
| 997 | if (ret < 0) |
| 998 | break; |
| 999 | } |
| 1000 | done: |
| 1001 | free(buf); |
| 1002 | fclose(fp); |
| 1003 | free(node_map); |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
| 1007 | /* |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame^] | 1008 | * File format: |
| 1009 | * |
| 1010 | * struct pmu_mappings { |
| 1011 | * u32 pmu_num; |
| 1012 | * struct pmu_map { |
| 1013 | * u32 type; |
| 1014 | * char name[]; |
| 1015 | * }[pmu_num]; |
| 1016 | * }; |
| 1017 | */ |
| 1018 | |
| 1019 | static int write_pmu_mappings(int fd, struct perf_header *h __used, |
| 1020 | struct perf_evlist *evlist __used) |
| 1021 | { |
| 1022 | struct perf_pmu *pmu = NULL; |
| 1023 | off_t offset = lseek(fd, 0, SEEK_CUR); |
| 1024 | __u32 pmu_num = 0; |
| 1025 | |
| 1026 | /* write real pmu_num later */ |
| 1027 | do_write(fd, &pmu_num, sizeof(pmu_num)); |
| 1028 | |
| 1029 | while ((pmu = perf_pmu__scan(pmu))) { |
| 1030 | if (!pmu->name) |
| 1031 | continue; |
| 1032 | pmu_num++; |
| 1033 | do_write(fd, &pmu->type, sizeof(pmu->type)); |
| 1034 | do_write_string(fd, pmu->name); |
| 1035 | } |
| 1036 | |
| 1037 | if (pwrite(fd, &pmu_num, sizeof(pmu_num), offset) != sizeof(pmu_num)) { |
| 1038 | /* discard all */ |
| 1039 | lseek(fd, offset, SEEK_SET); |
| 1040 | return -1; |
| 1041 | } |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | /* |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1047 | * default get_cpuid(): nothing gets recorded |
| 1048 | * actual implementation must be in arch/$(ARCH)/util/header.c |
| 1049 | */ |
| 1050 | int __attribute__((weak)) get_cpuid(char *buffer __used, size_t sz __used) |
| 1051 | { |
| 1052 | return -1; |
| 1053 | } |
| 1054 | |
| 1055 | static int write_cpuid(int fd, struct perf_header *h __used, |
| 1056 | struct perf_evlist *evlist __used) |
| 1057 | { |
| 1058 | char buffer[64]; |
| 1059 | int ret; |
| 1060 | |
| 1061 | ret = get_cpuid(buffer, sizeof(buffer)); |
| 1062 | if (!ret) |
| 1063 | goto write_it; |
| 1064 | |
| 1065 | return -1; |
| 1066 | write_it: |
| 1067 | return do_write_string(fd, buffer); |
| 1068 | } |
| 1069 | |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 1070 | static int write_branch_stack(int fd __used, struct perf_header *h __used, |
| 1071 | struct perf_evlist *evlist __used) |
| 1072 | { |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1076 | static void print_hostname(struct perf_header *ph, int fd, FILE *fp) |
| 1077 | { |
| 1078 | char *str = do_read_string(fd, ph); |
| 1079 | fprintf(fp, "# hostname : %s\n", str); |
| 1080 | free(str); |
| 1081 | } |
| 1082 | |
| 1083 | static void print_osrelease(struct perf_header *ph, int fd, FILE *fp) |
| 1084 | { |
| 1085 | char *str = do_read_string(fd, ph); |
| 1086 | fprintf(fp, "# os release : %s\n", str); |
| 1087 | free(str); |
| 1088 | } |
| 1089 | |
| 1090 | static void print_arch(struct perf_header *ph, int fd, FILE *fp) |
| 1091 | { |
| 1092 | char *str = do_read_string(fd, ph); |
| 1093 | fprintf(fp, "# arch : %s\n", str); |
| 1094 | free(str); |
| 1095 | } |
| 1096 | |
| 1097 | static void print_cpudesc(struct perf_header *ph, int fd, FILE *fp) |
| 1098 | { |
| 1099 | char *str = do_read_string(fd, ph); |
| 1100 | fprintf(fp, "# cpudesc : %s\n", str); |
| 1101 | free(str); |
| 1102 | } |
| 1103 | |
| 1104 | static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp) |
| 1105 | { |
| 1106 | ssize_t ret; |
| 1107 | u32 nr; |
| 1108 | |
| 1109 | ret = read(fd, &nr, sizeof(nr)); |
| 1110 | if (ret != (ssize_t)sizeof(nr)) |
| 1111 | nr = -1; /* interpreted as error */ |
| 1112 | |
| 1113 | if (ph->needs_swap) |
| 1114 | nr = bswap_32(nr); |
| 1115 | |
| 1116 | fprintf(fp, "# nrcpus online : %u\n", nr); |
| 1117 | |
| 1118 | ret = read(fd, &nr, sizeof(nr)); |
| 1119 | if (ret != (ssize_t)sizeof(nr)) |
| 1120 | nr = -1; /* interpreted as error */ |
| 1121 | |
| 1122 | if (ph->needs_swap) |
| 1123 | nr = bswap_32(nr); |
| 1124 | |
| 1125 | fprintf(fp, "# nrcpus avail : %u\n", nr); |
| 1126 | } |
| 1127 | |
| 1128 | static void print_version(struct perf_header *ph, int fd, FILE *fp) |
| 1129 | { |
| 1130 | char *str = do_read_string(fd, ph); |
| 1131 | fprintf(fp, "# perf version : %s\n", str); |
| 1132 | free(str); |
| 1133 | } |
| 1134 | |
| 1135 | static void print_cmdline(struct perf_header *ph, int fd, FILE *fp) |
| 1136 | { |
| 1137 | ssize_t ret; |
| 1138 | char *str; |
| 1139 | u32 nr, i; |
| 1140 | |
| 1141 | ret = read(fd, &nr, sizeof(nr)); |
| 1142 | if (ret != (ssize_t)sizeof(nr)) |
| 1143 | return; |
| 1144 | |
| 1145 | if (ph->needs_swap) |
| 1146 | nr = bswap_32(nr); |
| 1147 | |
| 1148 | fprintf(fp, "# cmdline : "); |
| 1149 | |
| 1150 | for (i = 0; i < nr; i++) { |
| 1151 | str = do_read_string(fd, ph); |
| 1152 | fprintf(fp, "%s ", str); |
| 1153 | free(str); |
| 1154 | } |
| 1155 | fputc('\n', fp); |
| 1156 | } |
| 1157 | |
| 1158 | static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp) |
| 1159 | { |
| 1160 | ssize_t ret; |
| 1161 | u32 nr, i; |
| 1162 | char *str; |
| 1163 | |
| 1164 | ret = read(fd, &nr, sizeof(nr)); |
| 1165 | if (ret != (ssize_t)sizeof(nr)) |
| 1166 | return; |
| 1167 | |
| 1168 | if (ph->needs_swap) |
| 1169 | nr = bswap_32(nr); |
| 1170 | |
| 1171 | for (i = 0; i < nr; i++) { |
| 1172 | str = do_read_string(fd, ph); |
| 1173 | fprintf(fp, "# sibling cores : %s\n", str); |
| 1174 | free(str); |
| 1175 | } |
| 1176 | |
| 1177 | ret = read(fd, &nr, sizeof(nr)); |
| 1178 | if (ret != (ssize_t)sizeof(nr)) |
| 1179 | return; |
| 1180 | |
| 1181 | if (ph->needs_swap) |
| 1182 | nr = bswap_32(nr); |
| 1183 | |
| 1184 | for (i = 0; i < nr; i++) { |
| 1185 | str = do_read_string(fd, ph); |
| 1186 | fprintf(fp, "# sibling threads : %s\n", str); |
| 1187 | free(str); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1191 | static void free_event_desc(struct perf_evsel *events) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1192 | { |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1193 | struct perf_evsel *evsel; |
| 1194 | |
| 1195 | if (!events) |
| 1196 | return; |
| 1197 | |
| 1198 | for (evsel = events; evsel->attr.size; evsel++) { |
| 1199 | if (evsel->name) |
| 1200 | free(evsel->name); |
| 1201 | if (evsel->id) |
| 1202 | free(evsel->id); |
| 1203 | } |
| 1204 | |
| 1205 | free(events); |
| 1206 | } |
| 1207 | |
| 1208 | static struct perf_evsel * |
| 1209 | read_event_desc(struct perf_header *ph, int fd) |
| 1210 | { |
| 1211 | struct perf_evsel *evsel, *events = NULL; |
| 1212 | u64 *id; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1213 | void *buf = NULL; |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1214 | u32 nre, sz, nr, i, j; |
| 1215 | ssize_t ret; |
| 1216 | size_t msz; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1217 | |
| 1218 | /* number of events */ |
| 1219 | ret = read(fd, &nre, sizeof(nre)); |
| 1220 | if (ret != (ssize_t)sizeof(nre)) |
| 1221 | goto error; |
| 1222 | |
| 1223 | if (ph->needs_swap) |
| 1224 | nre = bswap_32(nre); |
| 1225 | |
| 1226 | ret = read(fd, &sz, sizeof(sz)); |
| 1227 | if (ret != (ssize_t)sizeof(sz)) |
| 1228 | goto error; |
| 1229 | |
| 1230 | if (ph->needs_swap) |
| 1231 | sz = bswap_32(sz); |
| 1232 | |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1233 | /* buffer to hold on file attr struct */ |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1234 | buf = malloc(sz); |
| 1235 | if (!buf) |
| 1236 | goto error; |
| 1237 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1238 | /* the last event terminates with evsel->attr.size == 0: */ |
| 1239 | events = calloc(nre + 1, sizeof(*events)); |
| 1240 | if (!events) |
| 1241 | goto error; |
| 1242 | |
| 1243 | msz = sizeof(evsel->attr); |
Jiri Olsa | 9fafd98 | 2012-03-20 19:15:39 +0100 | [diff] [blame] | 1244 | if (sz < msz) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1245 | msz = sz; |
| 1246 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1247 | for (i = 0, evsel = events; i < nre; evsel++, i++) { |
| 1248 | evsel->idx = i; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1249 | |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1250 | /* |
| 1251 | * must read entire on-file attr struct to |
| 1252 | * sync up with layout. |
| 1253 | */ |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1254 | ret = read(fd, buf, sz); |
| 1255 | if (ret != (ssize_t)sz) |
| 1256 | goto error; |
| 1257 | |
| 1258 | if (ph->needs_swap) |
| 1259 | perf_event__attr_swap(buf); |
| 1260 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1261 | memcpy(&evsel->attr, buf, msz); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1262 | |
| 1263 | ret = read(fd, &nr, sizeof(nr)); |
| 1264 | if (ret != (ssize_t)sizeof(nr)) |
| 1265 | goto error; |
| 1266 | |
| 1267 | if (ph->needs_swap) |
| 1268 | nr = bswap_32(nr); |
| 1269 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1270 | evsel->name = do_read_string(fd, ph); |
| 1271 | |
| 1272 | if (!nr) |
| 1273 | continue; |
| 1274 | |
| 1275 | id = calloc(nr, sizeof(*id)); |
| 1276 | if (!id) |
| 1277 | goto error; |
| 1278 | evsel->ids = nr; |
| 1279 | evsel->id = id; |
| 1280 | |
| 1281 | for (j = 0 ; j < nr; j++) { |
| 1282 | ret = read(fd, id, sizeof(*id)); |
| 1283 | if (ret != (ssize_t)sizeof(*id)) |
| 1284 | goto error; |
| 1285 | if (ph->needs_swap) |
| 1286 | *id = bswap_64(*id); |
| 1287 | id++; |
| 1288 | } |
| 1289 | } |
| 1290 | out: |
| 1291 | if (buf) |
| 1292 | free(buf); |
| 1293 | return events; |
| 1294 | error: |
| 1295 | if (events) |
| 1296 | free_event_desc(events); |
| 1297 | events = NULL; |
| 1298 | goto out; |
| 1299 | } |
| 1300 | |
| 1301 | static void print_event_desc(struct perf_header *ph, int fd, FILE *fp) |
| 1302 | { |
| 1303 | struct perf_evsel *evsel, *events = read_event_desc(ph, fd); |
| 1304 | u32 j; |
| 1305 | u64 *id; |
| 1306 | |
| 1307 | if (!events) { |
| 1308 | fprintf(fp, "# event desc: not available or unable to read\n"); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | for (evsel = events; evsel->attr.size; evsel++) { |
| 1313 | fprintf(fp, "# event : name = %s, ", evsel->name); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1314 | |
| 1315 | fprintf(fp, "type = %d, config = 0x%"PRIx64 |
| 1316 | ", config1 = 0x%"PRIx64", config2 = 0x%"PRIx64, |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1317 | evsel->attr.type, |
| 1318 | (u64)evsel->attr.config, |
| 1319 | (u64)evsel->attr.config1, |
| 1320 | (u64)evsel->attr.config2); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1321 | |
| 1322 | fprintf(fp, ", excl_usr = %d, excl_kern = %d", |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1323 | evsel->attr.exclude_user, |
| 1324 | evsel->attr.exclude_kernel); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1325 | |
David Ahern | 78b961f | 2012-07-20 17:25:52 -0600 | [diff] [blame] | 1326 | fprintf(fp, ", excl_host = %d, excl_guest = %d", |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1327 | evsel->attr.exclude_host, |
| 1328 | evsel->attr.exclude_guest); |
David Ahern | 78b961f | 2012-07-20 17:25:52 -0600 | [diff] [blame] | 1329 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1330 | fprintf(fp, ", precise_ip = %d", evsel->attr.precise_ip); |
David Ahern | 78b961f | 2012-07-20 17:25:52 -0600 | [diff] [blame] | 1331 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1332 | if (evsel->ids) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1333 | fprintf(fp, ", id = {"); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1334 | for (j = 0, id = evsel->id; j < evsel->ids; j++, id++) { |
| 1335 | if (j) |
| 1336 | fputc(',', fp); |
| 1337 | fprintf(fp, " %"PRIu64, *id); |
| 1338 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1339 | fprintf(fp, " }"); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1342 | fputc('\n', fp); |
| 1343 | } |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1344 | |
| 1345 | free_event_desc(events); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void print_total_mem(struct perf_header *h __used, int fd, FILE *fp) |
| 1349 | { |
| 1350 | uint64_t mem; |
| 1351 | ssize_t ret; |
| 1352 | |
| 1353 | ret = read(fd, &mem, sizeof(mem)); |
| 1354 | if (ret != sizeof(mem)) |
| 1355 | goto error; |
| 1356 | |
| 1357 | if (h->needs_swap) |
| 1358 | mem = bswap_64(mem); |
| 1359 | |
| 1360 | fprintf(fp, "# total memory : %"PRIu64" kB\n", mem); |
| 1361 | return; |
| 1362 | error: |
| 1363 | fprintf(fp, "# total memory : unknown\n"); |
| 1364 | } |
| 1365 | |
| 1366 | static void print_numa_topology(struct perf_header *h __used, int fd, FILE *fp) |
| 1367 | { |
| 1368 | ssize_t ret; |
| 1369 | u32 nr, c, i; |
| 1370 | char *str; |
| 1371 | uint64_t mem_total, mem_free; |
| 1372 | |
| 1373 | /* nr nodes */ |
| 1374 | ret = read(fd, &nr, sizeof(nr)); |
| 1375 | if (ret != (ssize_t)sizeof(nr)) |
| 1376 | goto error; |
| 1377 | |
| 1378 | if (h->needs_swap) |
| 1379 | nr = bswap_32(nr); |
| 1380 | |
| 1381 | for (i = 0; i < nr; i++) { |
| 1382 | |
| 1383 | /* node number */ |
| 1384 | ret = read(fd, &c, sizeof(c)); |
| 1385 | if (ret != (ssize_t)sizeof(c)) |
| 1386 | goto error; |
| 1387 | |
| 1388 | if (h->needs_swap) |
| 1389 | c = bswap_32(c); |
| 1390 | |
| 1391 | ret = read(fd, &mem_total, sizeof(u64)); |
| 1392 | if (ret != sizeof(u64)) |
| 1393 | goto error; |
| 1394 | |
| 1395 | ret = read(fd, &mem_free, sizeof(u64)); |
| 1396 | if (ret != sizeof(u64)) |
| 1397 | goto error; |
| 1398 | |
| 1399 | if (h->needs_swap) { |
| 1400 | mem_total = bswap_64(mem_total); |
| 1401 | mem_free = bswap_64(mem_free); |
| 1402 | } |
| 1403 | |
| 1404 | fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," |
| 1405 | " free = %"PRIu64" kB\n", |
| 1406 | c, |
| 1407 | mem_total, |
| 1408 | mem_free); |
| 1409 | |
| 1410 | str = do_read_string(fd, h); |
| 1411 | fprintf(fp, "# node%u cpu list : %s\n", c, str); |
| 1412 | free(str); |
| 1413 | } |
| 1414 | return; |
| 1415 | error: |
| 1416 | fprintf(fp, "# numa topology : not available\n"); |
| 1417 | } |
| 1418 | |
| 1419 | static void print_cpuid(struct perf_header *ph, int fd, FILE *fp) |
| 1420 | { |
| 1421 | char *str = do_read_string(fd, ph); |
| 1422 | fprintf(fp, "# cpuid : %s\n", str); |
| 1423 | free(str); |
| 1424 | } |
| 1425 | |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 1426 | static void print_branch_stack(struct perf_header *ph __used, int fd __used, |
| 1427 | FILE *fp) |
| 1428 | { |
| 1429 | fprintf(fp, "# contains samples with branch stack\n"); |
| 1430 | } |
| 1431 | |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame^] | 1432 | static void print_pmu_mappings(struct perf_header *ph, int fd, FILE *fp) |
| 1433 | { |
| 1434 | const char *delimiter = "# pmu mappings: "; |
| 1435 | char *name; |
| 1436 | int ret; |
| 1437 | u32 pmu_num; |
| 1438 | u32 type; |
| 1439 | |
| 1440 | ret = read(fd, &pmu_num, sizeof(pmu_num)); |
| 1441 | if (ret != sizeof(pmu_num)) |
| 1442 | goto error; |
| 1443 | |
| 1444 | if (!pmu_num) { |
| 1445 | fprintf(fp, "# pmu mappings: not available\n"); |
| 1446 | return; |
| 1447 | } |
| 1448 | |
| 1449 | while (pmu_num) { |
| 1450 | if (read(fd, &type, sizeof(type)) != sizeof(type)) |
| 1451 | break; |
| 1452 | name = do_read_string(fd, ph); |
| 1453 | if (!name) |
| 1454 | break; |
| 1455 | pmu_num--; |
| 1456 | fprintf(fp, "%s%s = %" PRIu32, delimiter, name, type); |
| 1457 | free(name); |
| 1458 | delimiter = ", "; |
| 1459 | } |
| 1460 | |
| 1461 | fprintf(fp, "\n"); |
| 1462 | |
| 1463 | if (!pmu_num) |
| 1464 | return; |
| 1465 | error: |
| 1466 | fprintf(fp, "# pmu mappings: unable to read\n"); |
| 1467 | } |
| 1468 | |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1469 | static int __event_process_build_id(struct build_id_event *bev, |
| 1470 | char *filename, |
| 1471 | struct perf_session *session) |
| 1472 | { |
| 1473 | int err = -1; |
| 1474 | struct list_head *head; |
| 1475 | struct machine *machine; |
| 1476 | u16 misc; |
| 1477 | struct dso *dso; |
| 1478 | enum dso_kernel_type dso_type; |
| 1479 | |
| 1480 | machine = perf_session__findnew_machine(session, bev->pid); |
| 1481 | if (!machine) |
| 1482 | goto out; |
| 1483 | |
| 1484 | misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 1485 | |
| 1486 | switch (misc) { |
| 1487 | case PERF_RECORD_MISC_KERNEL: |
| 1488 | dso_type = DSO_TYPE_KERNEL; |
| 1489 | head = &machine->kernel_dsos; |
| 1490 | break; |
| 1491 | case PERF_RECORD_MISC_GUEST_KERNEL: |
| 1492 | dso_type = DSO_TYPE_GUEST_KERNEL; |
| 1493 | head = &machine->kernel_dsos; |
| 1494 | break; |
| 1495 | case PERF_RECORD_MISC_USER: |
| 1496 | case PERF_RECORD_MISC_GUEST_USER: |
| 1497 | dso_type = DSO_TYPE_USER; |
| 1498 | head = &machine->user_dsos; |
| 1499 | break; |
| 1500 | default: |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | dso = __dsos__findnew(head, filename); |
| 1505 | if (dso != NULL) { |
| 1506 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
| 1507 | |
| 1508 | dso__set_build_id(dso, &bev->build_id); |
| 1509 | |
| 1510 | if (filename[0] == '[') |
| 1511 | dso->kernel = dso_type; |
| 1512 | |
| 1513 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), |
| 1514 | sbuild_id); |
| 1515 | pr_debug("build id event received for %s: %s\n", |
| 1516 | dso->long_name, sbuild_id); |
| 1517 | } |
| 1518 | |
| 1519 | err = 0; |
| 1520 | out: |
| 1521 | return err; |
| 1522 | } |
| 1523 | |
| 1524 | static int perf_header__read_build_ids_abi_quirk(struct perf_header *header, |
| 1525 | int input, u64 offset, u64 size) |
| 1526 | { |
| 1527 | struct perf_session *session = container_of(header, struct perf_session, header); |
| 1528 | struct { |
| 1529 | struct perf_event_header header; |
| 1530 | u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))]; |
| 1531 | char filename[0]; |
| 1532 | } old_bev; |
| 1533 | struct build_id_event bev; |
| 1534 | char filename[PATH_MAX]; |
| 1535 | u64 limit = offset + size; |
| 1536 | |
| 1537 | while (offset < limit) { |
| 1538 | ssize_t len; |
| 1539 | |
| 1540 | if (read(input, &old_bev, sizeof(old_bev)) != sizeof(old_bev)) |
| 1541 | return -1; |
| 1542 | |
| 1543 | if (header->needs_swap) |
| 1544 | perf_event_header__bswap(&old_bev.header); |
| 1545 | |
| 1546 | len = old_bev.header.size - sizeof(old_bev); |
| 1547 | if (read(input, filename, len) != len) |
| 1548 | return -1; |
| 1549 | |
| 1550 | bev.header = old_bev.header; |
| 1551 | |
| 1552 | /* |
| 1553 | * As the pid is the missing value, we need to fill |
| 1554 | * it properly. The header.misc value give us nice hint. |
| 1555 | */ |
| 1556 | bev.pid = HOST_KERNEL_ID; |
| 1557 | if (bev.header.misc == PERF_RECORD_MISC_GUEST_USER || |
| 1558 | bev.header.misc == PERF_RECORD_MISC_GUEST_KERNEL) |
| 1559 | bev.pid = DEFAULT_GUEST_KERNEL_ID; |
| 1560 | |
| 1561 | memcpy(bev.build_id, old_bev.build_id, sizeof(bev.build_id)); |
| 1562 | __event_process_build_id(&bev, filename, session); |
| 1563 | |
| 1564 | offset += bev.header.size; |
| 1565 | } |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | static int perf_header__read_build_ids(struct perf_header *header, |
| 1571 | int input, u64 offset, u64 size) |
| 1572 | { |
| 1573 | struct perf_session *session = container_of(header, struct perf_session, header); |
| 1574 | struct build_id_event bev; |
| 1575 | char filename[PATH_MAX]; |
| 1576 | u64 limit = offset + size, orig_offset = offset; |
| 1577 | int err = -1; |
| 1578 | |
| 1579 | while (offset < limit) { |
| 1580 | ssize_t len; |
| 1581 | |
| 1582 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) |
| 1583 | goto out; |
| 1584 | |
| 1585 | if (header->needs_swap) |
| 1586 | perf_event_header__bswap(&bev.header); |
| 1587 | |
| 1588 | len = bev.header.size - sizeof(bev); |
| 1589 | if (read(input, filename, len) != len) |
| 1590 | goto out; |
| 1591 | /* |
| 1592 | * The a1645ce1 changeset: |
| 1593 | * |
| 1594 | * "perf: 'perf kvm' tool for monitoring guest performance from host" |
| 1595 | * |
| 1596 | * Added a field to struct build_id_event that broke the file |
| 1597 | * format. |
| 1598 | * |
| 1599 | * Since the kernel build-id is the first entry, process the |
| 1600 | * table using the old format if the well known |
| 1601 | * '[kernel.kallsyms]' string for the kernel build-id has the |
| 1602 | * first 4 characters chopped off (where the pid_t sits). |
| 1603 | */ |
| 1604 | if (memcmp(filename, "nel.kallsyms]", 13) == 0) { |
| 1605 | if (lseek(input, orig_offset, SEEK_SET) == (off_t)-1) |
| 1606 | return -1; |
| 1607 | return perf_header__read_build_ids_abi_quirk(header, input, offset, size); |
| 1608 | } |
| 1609 | |
| 1610 | __event_process_build_id(&bev, filename, session); |
| 1611 | |
| 1612 | offset += bev.header.size; |
| 1613 | } |
| 1614 | err = 0; |
| 1615 | out: |
| 1616 | return err; |
| 1617 | } |
| 1618 | |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 1619 | static int process_tracing_data(struct perf_file_section *section __unused, |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1620 | struct perf_header *ph __unused, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1621 | int feat __unused, int fd, void *data) |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1622 | { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1623 | trace_report(fd, data, false); |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | static int process_build_id(struct perf_file_section *section, |
| 1628 | struct perf_header *ph, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1629 | int feat __unused, int fd, void *data __used) |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1630 | { |
| 1631 | if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) |
| 1632 | pr_debug("Failed to read buildids, continuing...\n"); |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 1636 | static struct perf_evsel * |
| 1637 | perf_evlist__find_by_index(struct perf_evlist *evlist, int idx) |
| 1638 | { |
| 1639 | struct perf_evsel *evsel; |
| 1640 | |
| 1641 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 1642 | if (evsel->idx == idx) |
| 1643 | return evsel; |
| 1644 | } |
| 1645 | |
| 1646 | return NULL; |
| 1647 | } |
| 1648 | |
| 1649 | static void |
| 1650 | perf_evlist__set_event_name(struct perf_evlist *evlist, struct perf_evsel *event) |
| 1651 | { |
| 1652 | struct perf_evsel *evsel; |
| 1653 | |
| 1654 | if (!event->name) |
| 1655 | return; |
| 1656 | |
| 1657 | evsel = perf_evlist__find_by_index(evlist, event->idx); |
| 1658 | if (!evsel) |
| 1659 | return; |
| 1660 | |
| 1661 | if (evsel->name) |
| 1662 | return; |
| 1663 | |
| 1664 | evsel->name = strdup(event->name); |
| 1665 | } |
| 1666 | |
| 1667 | static int |
| 1668 | process_event_desc(struct perf_file_section *section __unused, |
| 1669 | struct perf_header *header, int feat __unused, int fd, |
| 1670 | void *data __used) |
| 1671 | { |
| 1672 | struct perf_session *session = container_of(header, struct perf_session, header); |
| 1673 | struct perf_evsel *evsel, *events = read_event_desc(header, fd); |
| 1674 | |
| 1675 | if (!events) |
| 1676 | return 0; |
| 1677 | |
| 1678 | for (evsel = events; evsel->attr.size; evsel++) |
| 1679 | perf_evlist__set_event_name(session->evlist, evsel); |
| 1680 | |
| 1681 | free_event_desc(events); |
| 1682 | |
| 1683 | return 0; |
| 1684 | } |
| 1685 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1686 | struct feature_ops { |
| 1687 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); |
| 1688 | void (*print)(struct perf_header *h, int fd, FILE *fp); |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1689 | int (*process)(struct perf_file_section *section, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1690 | struct perf_header *h, int feat, int fd, void *data); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1691 | const char *name; |
| 1692 | bool full_only; |
| 1693 | }; |
| 1694 | |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 1695 | #define FEAT_OPA(n, func) \ |
| 1696 | [n] = { .name = #n, .write = write_##func, .print = print_##func } |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1697 | #define FEAT_OPP(n, func) \ |
| 1698 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ |
| 1699 | .process = process_##func } |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 1700 | #define FEAT_OPF(n, func) \ |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1701 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ |
| 1702 | .full_only = true } |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 1703 | |
| 1704 | /* feature_ops not implemented: */ |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 1705 | #define print_tracing_data NULL |
| 1706 | #define print_build_id NULL |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1707 | |
| 1708 | static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 1709 | FEAT_OPP(HEADER_TRACING_DATA, tracing_data), |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 1710 | FEAT_OPP(HEADER_BUILD_ID, build_id), |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 1711 | FEAT_OPA(HEADER_HOSTNAME, hostname), |
| 1712 | FEAT_OPA(HEADER_OSRELEASE, osrelease), |
| 1713 | FEAT_OPA(HEADER_VERSION, version), |
| 1714 | FEAT_OPA(HEADER_ARCH, arch), |
| 1715 | FEAT_OPA(HEADER_NRCPUS, nrcpus), |
| 1716 | FEAT_OPA(HEADER_CPUDESC, cpudesc), |
| 1717 | FEAT_OPA(HEADER_CPUID, cpuid), |
| 1718 | FEAT_OPA(HEADER_TOTAL_MEM, total_mem), |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 1719 | FEAT_OPP(HEADER_EVENT_DESC, event_desc), |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 1720 | FEAT_OPA(HEADER_CMDLINE, cmdline), |
| 1721 | FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology), |
| 1722 | FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology), |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 1723 | FEAT_OPA(HEADER_BRANCH_STACK, branch_stack), |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame^] | 1724 | FEAT_OPA(HEADER_PMU_MAPPINGS, pmu_mappings), |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1725 | }; |
| 1726 | |
| 1727 | struct header_print_data { |
| 1728 | FILE *fp; |
| 1729 | bool full; /* extended list of headers */ |
| 1730 | }; |
| 1731 | |
| 1732 | static int perf_file_section__fprintf_info(struct perf_file_section *section, |
| 1733 | struct perf_header *ph, |
| 1734 | int feat, int fd, void *data) |
| 1735 | { |
| 1736 | struct header_print_data *hd = data; |
| 1737 | |
| 1738 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { |
| 1739 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " |
| 1740 | "%d, continuing...\n", section->offset, feat); |
| 1741 | return 0; |
| 1742 | } |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1743 | if (feat >= HEADER_LAST_FEATURE) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1744 | pr_warning("unknown feature %d\n", feat); |
Robert Richter | f7a8a13 | 2011-12-07 10:02:51 +0100 | [diff] [blame] | 1745 | return 0; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1746 | } |
| 1747 | if (!feat_ops[feat].print) |
| 1748 | return 0; |
| 1749 | |
| 1750 | if (!feat_ops[feat].full_only || hd->full) |
| 1751 | feat_ops[feat].print(ph, fd, hd->fp); |
| 1752 | else |
| 1753 | fprintf(hd->fp, "# %s info available, use -I to display\n", |
| 1754 | feat_ops[feat].name); |
| 1755 | |
| 1756 | return 0; |
| 1757 | } |
| 1758 | |
| 1759 | int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full) |
| 1760 | { |
| 1761 | struct header_print_data hd; |
| 1762 | struct perf_header *header = &session->header; |
| 1763 | int fd = session->fd; |
| 1764 | hd.fp = fp; |
| 1765 | hd.full = full; |
| 1766 | |
| 1767 | perf_header__process_sections(header, fd, &hd, |
| 1768 | perf_file_section__fprintf_info); |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1772 | static int do_write_feat(int fd, struct perf_header *h, int type, |
| 1773 | struct perf_file_section **p, |
| 1774 | struct perf_evlist *evlist) |
| 1775 | { |
| 1776 | int err; |
| 1777 | int ret = 0; |
| 1778 | |
| 1779 | if (perf_header__has_feat(h, type)) { |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1780 | if (!feat_ops[type].write) |
| 1781 | return -1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1782 | |
| 1783 | (*p)->offset = lseek(fd, 0, SEEK_CUR); |
| 1784 | |
| 1785 | err = feat_ops[type].write(fd, h, evlist); |
| 1786 | if (err < 0) { |
| 1787 | pr_debug("failed to write feature %d\n", type); |
| 1788 | |
| 1789 | /* undo anything written */ |
| 1790 | lseek(fd, (*p)->offset, SEEK_SET); |
| 1791 | |
| 1792 | return -1; |
| 1793 | } |
| 1794 | (*p)->size = lseek(fd, 0, SEEK_CUR) - (*p)->offset; |
| 1795 | (*p)++; |
| 1796 | } |
| 1797 | return ret; |
| 1798 | } |
| 1799 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1800 | static int perf_header__adds_write(struct perf_header *header, |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 1801 | struct perf_evlist *evlist, int fd) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 1802 | { |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1803 | int nr_sections; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1804 | struct perf_file_section *feat_sec, *p; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1805 | int sec_size; |
| 1806 | u64 sec_start; |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1807 | int feat; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1808 | int err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1809 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1810 | nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1811 | if (!nr_sections) |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1812 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1813 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1814 | feat_sec = p = calloc(sizeof(*feat_sec), nr_sections); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1815 | if (feat_sec == NULL) |
| 1816 | return -ENOMEM; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1817 | |
| 1818 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 1819 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1820 | sec_start = header->data_offset + header->data_size; |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 1821 | lseek(fd, sec_start + sec_size, SEEK_SET); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 1822 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1823 | for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) { |
| 1824 | if (do_write_feat(fd, header, feat, &p, evlist)) |
| 1825 | perf_header__clear_feat(header, feat); |
| 1826 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1827 | |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 1828 | lseek(fd, sec_start, SEEK_SET); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1829 | /* |
| 1830 | * may write more than needed due to dropped feature, but |
| 1831 | * this is okay, reader will skip the mising entries |
| 1832 | */ |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1833 | err = do_write(fd, feat_sec, sec_size); |
| 1834 | if (err < 0) |
| 1835 | pr_debug("failed to write feature section\n"); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1836 | free(feat_sec); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1837 | return err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1838 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 1839 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1840 | int perf_header__write_pipe(int fd) |
| 1841 | { |
| 1842 | struct perf_pipe_file_header f_header; |
| 1843 | int err; |
| 1844 | |
| 1845 | f_header = (struct perf_pipe_file_header){ |
| 1846 | .magic = PERF_MAGIC, |
| 1847 | .size = sizeof(f_header), |
| 1848 | }; |
| 1849 | |
| 1850 | err = do_write(fd, &f_header, sizeof(f_header)); |
| 1851 | if (err < 0) { |
| 1852 | pr_debug("failed to write perf pipe header\n"); |
| 1853 | return err; |
| 1854 | } |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1859 | int perf_session__write_header(struct perf_session *session, |
| 1860 | struct perf_evlist *evlist, |
| 1861 | int fd, bool at_exit) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1862 | { |
| 1863 | struct perf_file_header f_header; |
| 1864 | struct perf_file_attr f_attr; |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1865 | struct perf_header *header = &session->header; |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1866 | struct perf_evsel *evsel, *pair = NULL; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1867 | int err; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1868 | |
| 1869 | lseek(fd, sizeof(f_header), SEEK_SET); |
| 1870 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1871 | if (session->evlist != evlist) |
Arnaldo Carvalho de Melo | 0c21f73 | 2012-08-14 16:42:15 -0300 | [diff] [blame] | 1872 | pair = perf_evlist__first(session->evlist); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1873 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1874 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 1875 | evsel->id_offset = lseek(fd, 0, SEEK_CUR); |
| 1876 | err = do_write(fd, evsel->id, evsel->ids * sizeof(u64)); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1877 | if (err < 0) { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1878 | out_err_write: |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1879 | pr_debug("failed to write perf header\n"); |
| 1880 | return err; |
| 1881 | } |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1882 | if (session->evlist != evlist) { |
| 1883 | err = do_write(fd, pair->id, pair->ids * sizeof(u64)); |
| 1884 | if (err < 0) |
| 1885 | goto out_err_write; |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1886 | evsel->ids += pair->ids; |
Arnaldo Carvalho de Melo | 0c21f73 | 2012-08-14 16:42:15 -0300 | [diff] [blame] | 1887 | pair = perf_evsel__next(pair); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1888 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1889 | } |
| 1890 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1891 | header->attr_offset = lseek(fd, 0, SEEK_CUR); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1892 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1893 | list_for_each_entry(evsel, &evlist->entries, node) { |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1894 | f_attr = (struct perf_file_attr){ |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1895 | .attr = evsel->attr, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1896 | .ids = { |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 1897 | .offset = evsel->id_offset, |
| 1898 | .size = evsel->ids * sizeof(u64), |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1899 | } |
| 1900 | }; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1901 | err = do_write(fd, &f_attr, sizeof(f_attr)); |
| 1902 | if (err < 0) { |
| 1903 | pr_debug("failed to write perf header attribute\n"); |
| 1904 | return err; |
| 1905 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1906 | } |
| 1907 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1908 | header->event_offset = lseek(fd, 0, SEEK_CUR); |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 1909 | header->event_size = trace_event_count * sizeof(struct perf_trace_event_type); |
| 1910 | if (trace_events) { |
| 1911 | err = do_write(fd, trace_events, header->event_size); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1912 | if (err < 0) { |
| 1913 | pr_debug("failed to write perf header events\n"); |
| 1914 | return err; |
| 1915 | } |
| 1916 | } |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 1917 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1918 | header->data_offset = lseek(fd, 0, SEEK_CUR); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1919 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1920 | if (at_exit) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1921 | err = perf_header__adds_write(header, evlist, fd); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1922 | if (err < 0) |
| 1923 | return err; |
| 1924 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1925 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1926 | f_header = (struct perf_file_header){ |
| 1927 | .magic = PERF_MAGIC, |
| 1928 | .size = sizeof(f_header), |
| 1929 | .attr_size = sizeof(f_attr), |
| 1930 | .attrs = { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1931 | .offset = header->attr_offset, |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 1932 | .size = evlist->nr_entries * sizeof(f_attr), |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1933 | }, |
| 1934 | .data = { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1935 | .offset = header->data_offset, |
| 1936 | .size = header->data_size, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1937 | }, |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 1938 | .event_types = { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1939 | .offset = header->event_offset, |
| 1940 | .size = header->event_size, |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 1941 | }, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1942 | }; |
| 1943 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1944 | memcpy(&f_header.adds_features, &header->adds_features, sizeof(header->adds_features)); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 1945 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1946 | lseek(fd, 0, SEEK_SET); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1947 | err = do_write(fd, &f_header, sizeof(f_header)); |
| 1948 | if (err < 0) { |
| 1949 | pr_debug("failed to write perf header\n"); |
| 1950 | return err; |
| 1951 | } |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1952 | lseek(fd, header->data_offset + header->data_size, SEEK_SET); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1953 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1954 | header->frozen = 1; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 1955 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1958 | static int perf_header__getbuffer64(struct perf_header *header, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1959 | int fd, void *buf, size_t size) |
| 1960 | { |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 1961 | if (readn(fd, buf, size) <= 0) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1962 | return -1; |
| 1963 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1964 | if (header->needs_swap) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1965 | mem_bswap_64(buf, size); |
| 1966 | |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1970 | int perf_header__process_sections(struct perf_header *header, int fd, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1971 | void *data, |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1972 | int (*process)(struct perf_file_section *section, |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1973 | struct perf_header *ph, |
| 1974 | int feat, int fd, void *data)) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 1975 | { |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1976 | struct perf_file_section *feat_sec, *sec; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1977 | int nr_sections; |
| 1978 | int sec_size; |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1979 | int feat; |
| 1980 | int err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1981 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1982 | nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1983 | if (!nr_sections) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 1984 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1985 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1986 | feat_sec = sec = calloc(sizeof(*feat_sec), nr_sections); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1987 | if (!feat_sec) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 1988 | return -1; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1989 | |
| 1990 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 1991 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 1992 | lseek(fd, header->data_offset + header->data_size, SEEK_SET); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1993 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1994 | err = perf_header__getbuffer64(header, fd, feat_sec, sec_size); |
| 1995 | if (err < 0) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 1996 | goto out_free; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 1997 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 1998 | for_each_set_bit(feat, header->adds_features, HEADER_LAST_FEATURE) { |
| 1999 | err = process(sec++, header, feat, fd, data); |
| 2000 | if (err < 0) |
| 2001 | goto out_free; |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 2002 | } |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 2003 | err = 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2004 | out_free: |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 2005 | free(feat_sec); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2006 | return err; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2007 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 2008 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2009 | static const int attr_file_abi_sizes[] = { |
| 2010 | [0] = PERF_ATTR_SIZE_VER0, |
| 2011 | [1] = PERF_ATTR_SIZE_VER1, |
Jiri Olsa | 239cc47 | 2012-08-07 15:20:42 +0200 | [diff] [blame] | 2012 | [2] = PERF_ATTR_SIZE_VER2, |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 2013 | [3] = PERF_ATTR_SIZE_VER3, |
| 2014 | [4] = PERF_ATTR_SIZE_VER4, |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2015 | 0, |
| 2016 | }; |
| 2017 | |
| 2018 | /* |
| 2019 | * In the legacy file format, the magic number is not used to encode endianness. |
| 2020 | * hdr_sz was used to encode endianness. But given that hdr_sz can vary based |
| 2021 | * on ABI revisions, we need to try all combinations for all endianness to |
| 2022 | * detect the endianness. |
| 2023 | */ |
| 2024 | static int try_all_file_abis(uint64_t hdr_sz, struct perf_header *ph) |
| 2025 | { |
| 2026 | uint64_t ref_size, attr_size; |
| 2027 | int i; |
| 2028 | |
| 2029 | for (i = 0 ; attr_file_abi_sizes[i]; i++) { |
| 2030 | ref_size = attr_file_abi_sizes[i] |
| 2031 | + sizeof(struct perf_file_section); |
| 2032 | if (hdr_sz != ref_size) { |
| 2033 | attr_size = bswap_64(hdr_sz); |
| 2034 | if (attr_size != ref_size) |
| 2035 | continue; |
| 2036 | |
| 2037 | ph->needs_swap = true; |
| 2038 | } |
| 2039 | pr_debug("ABI%d perf.data file detected, need_swap=%d\n", |
| 2040 | i, |
| 2041 | ph->needs_swap); |
| 2042 | return 0; |
| 2043 | } |
| 2044 | /* could not determine endianness */ |
| 2045 | return -1; |
| 2046 | } |
| 2047 | |
| 2048 | #define PERF_PIPE_HDR_VER0 16 |
| 2049 | |
| 2050 | static const size_t attr_pipe_abi_sizes[] = { |
| 2051 | [0] = PERF_PIPE_HDR_VER0, |
| 2052 | 0, |
| 2053 | }; |
| 2054 | |
| 2055 | /* |
| 2056 | * In the legacy pipe format, there is an implicit assumption that endiannesss |
| 2057 | * between host recording the samples, and host parsing the samples is the |
| 2058 | * same. This is not always the case given that the pipe output may always be |
| 2059 | * redirected into a file and analyzed on a different machine with possibly a |
| 2060 | * different endianness and perf_event ABI revsions in the perf tool itself. |
| 2061 | */ |
| 2062 | static int try_all_pipe_abis(uint64_t hdr_sz, struct perf_header *ph) |
| 2063 | { |
| 2064 | u64 attr_size; |
| 2065 | int i; |
| 2066 | |
| 2067 | for (i = 0 ; attr_pipe_abi_sizes[i]; i++) { |
| 2068 | if (hdr_sz != attr_pipe_abi_sizes[i]) { |
| 2069 | attr_size = bswap_64(hdr_sz); |
| 2070 | if (attr_size != hdr_sz) |
| 2071 | continue; |
| 2072 | |
| 2073 | ph->needs_swap = true; |
| 2074 | } |
| 2075 | pr_debug("Pipe ABI%d perf.data file detected\n", i); |
| 2076 | return 0; |
| 2077 | } |
| 2078 | return -1; |
| 2079 | } |
| 2080 | |
| 2081 | static int check_magic_endian(u64 magic, uint64_t hdr_sz, |
| 2082 | bool is_pipe, struct perf_header *ph) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2083 | { |
| 2084 | int ret; |
| 2085 | |
| 2086 | /* check for legacy format */ |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2087 | ret = memcmp(&magic, __perf_magic1, sizeof(magic)); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2088 | if (ret == 0) { |
| 2089 | pr_debug("legacy perf.data format\n"); |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2090 | if (is_pipe) |
| 2091 | return try_all_pipe_abis(hdr_sz, ph); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2092 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2093 | return try_all_file_abis(hdr_sz, ph); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2094 | } |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2095 | /* |
| 2096 | * the new magic number serves two purposes: |
| 2097 | * - unique number to identify actual perf.data files |
| 2098 | * - encode endianness of file |
| 2099 | */ |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2100 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2101 | /* check magic number with one endianness */ |
| 2102 | if (magic == __perf_magic2) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2103 | return 0; |
| 2104 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2105 | /* check magic number with opposite endianness */ |
| 2106 | if (magic != __perf_magic2_sw) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2107 | return -1; |
| 2108 | |
| 2109 | ph->needs_swap = true; |
| 2110 | |
| 2111 | return 0; |
| 2112 | } |
| 2113 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2114 | int perf_file_header__read(struct perf_file_header *header, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2115 | struct perf_header *ph, int fd) |
| 2116 | { |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2117 | int ret; |
| 2118 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2119 | lseek(fd, 0, SEEK_SET); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2120 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2121 | ret = readn(fd, header, sizeof(*header)); |
| 2122 | if (ret <= 0) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2123 | return -1; |
| 2124 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2125 | if (check_magic_endian(header->magic, |
| 2126 | header->attr_size, false, ph) < 0) { |
| 2127 | pr_debug("magic/endian check failed\n"); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2128 | return -1; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2129 | } |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2130 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2131 | if (ph->needs_swap) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2132 | mem_bswap_64(header, offsetof(struct perf_file_header, |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2133 | adds_features)); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2134 | } |
| 2135 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2136 | if (header->size != sizeof(*header)) { |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2137 | /* Support the previous format */ |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2138 | if (header->size == offsetof(typeof(*header), adds_features)) |
| 2139 | bitmap_zero(header->adds_features, HEADER_FEAT_BITS); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2140 | else |
| 2141 | return -1; |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 2142 | } else if (ph->needs_swap) { |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 2143 | /* |
| 2144 | * feature bitmap is declared as an array of unsigned longs -- |
| 2145 | * not good since its size can differ between the host that |
| 2146 | * generated the data file and the host analyzing the file. |
| 2147 | * |
| 2148 | * We need to handle endianness, but we don't know the size of |
| 2149 | * the unsigned long where the file was generated. Take a best |
| 2150 | * guess at determining it: try 64-bit swap first (ie., file |
| 2151 | * created on a 64-bit host), and check if the hostname feature |
| 2152 | * bit is set (this feature bit is forced on as of fbe96f2). |
| 2153 | * If the bit is not, undo the 64-bit swap and try a 32-bit |
| 2154 | * swap. If the hostname bit is still not set (e.g., older data |
| 2155 | * file), punt and fallback to the original behavior -- |
| 2156 | * clearing all feature bits and setting buildid. |
| 2157 | */ |
David Ahern | 80c0120 | 2012-06-08 11:47:51 -0300 | [diff] [blame] | 2158 | mem_bswap_64(&header->adds_features, |
| 2159 | BITS_TO_U64(HEADER_FEAT_BITS)); |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 2160 | |
| 2161 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
David Ahern | 80c0120 | 2012-06-08 11:47:51 -0300 | [diff] [blame] | 2162 | /* unswap as u64 */ |
| 2163 | mem_bswap_64(&header->adds_features, |
| 2164 | BITS_TO_U64(HEADER_FEAT_BITS)); |
| 2165 | |
| 2166 | /* unswap as u32 */ |
| 2167 | mem_bswap_32(&header->adds_features, |
| 2168 | BITS_TO_U32(HEADER_FEAT_BITS)); |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
| 2172 | bitmap_zero(header->adds_features, HEADER_FEAT_BITS); |
| 2173 | set_bit(HEADER_BUILD_ID, header->adds_features); |
| 2174 | } |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2175 | } |
| 2176 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2177 | memcpy(&ph->adds_features, &header->adds_features, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2178 | sizeof(ph->adds_features)); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2179 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2180 | ph->event_offset = header->event_types.offset; |
| 2181 | ph->event_size = header->event_types.size; |
| 2182 | ph->data_offset = header->data.offset; |
| 2183 | ph->data_size = header->data.size; |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2184 | return 0; |
| 2185 | } |
| 2186 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2187 | static int perf_file_section__process(struct perf_file_section *section, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2188 | struct perf_header *ph, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2189 | int feat, int fd, void *data) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2190 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2191 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 2192 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2193 | "%d, continuing...\n", section->offset, feat); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2194 | return 0; |
| 2195 | } |
| 2196 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 2197 | if (feat >= HEADER_LAST_FEATURE) { |
| 2198 | pr_debug("unknown feature %d, continuing...\n", feat); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 2202 | if (!feat_ops[feat].process) |
| 2203 | return 0; |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2204 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2205 | return feat_ops[feat].process(section, ph, feat, fd, data); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 2206 | } |
| 2207 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2208 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 2209 | struct perf_header *ph, int fd, |
| 2210 | bool repipe) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2211 | { |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 2212 | int ret; |
| 2213 | |
| 2214 | ret = readn(fd, header, sizeof(*header)); |
| 2215 | if (ret <= 0) |
| 2216 | return -1; |
| 2217 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2218 | if (check_magic_endian(header->magic, header->size, true, ph) < 0) { |
| 2219 | pr_debug("endian/magic failed\n"); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2220 | return -1; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | if (ph->needs_swap) |
| 2224 | header->size = bswap_64(header->size); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2225 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2226 | if (repipe && do_write(STDOUT_FILENO, header, sizeof(*header)) < 0) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 2227 | return -1; |
| 2228 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2229 | return 0; |
| 2230 | } |
| 2231 | |
| 2232 | static int perf_header__read_pipe(struct perf_session *session, int fd) |
| 2233 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2234 | struct perf_header *header = &session->header; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2235 | struct perf_pipe_file_header f_header; |
| 2236 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2237 | if (perf_file_header__read_pipe(&f_header, header, fd, |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 2238 | session->repipe) < 0) { |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2239 | pr_debug("incompatible file format\n"); |
| 2240 | return -EINVAL; |
| 2241 | } |
| 2242 | |
| 2243 | session->fd = fd; |
| 2244 | |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 2248 | static int read_attr(int fd, struct perf_header *ph, |
| 2249 | struct perf_file_attr *f_attr) |
| 2250 | { |
| 2251 | struct perf_event_attr *attr = &f_attr->attr; |
| 2252 | size_t sz, left; |
| 2253 | size_t our_sz = sizeof(f_attr->attr); |
| 2254 | int ret; |
| 2255 | |
| 2256 | memset(f_attr, 0, sizeof(*f_attr)); |
| 2257 | |
| 2258 | /* read minimal guaranteed structure */ |
| 2259 | ret = readn(fd, attr, PERF_ATTR_SIZE_VER0); |
| 2260 | if (ret <= 0) { |
| 2261 | pr_debug("cannot read %d bytes of header attr\n", |
| 2262 | PERF_ATTR_SIZE_VER0); |
| 2263 | return -1; |
| 2264 | } |
| 2265 | |
| 2266 | /* on file perf_event_attr size */ |
| 2267 | sz = attr->size; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 2268 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 2269 | if (ph->needs_swap) |
| 2270 | sz = bswap_32(sz); |
| 2271 | |
| 2272 | if (sz == 0) { |
| 2273 | /* assume ABI0 */ |
| 2274 | sz = PERF_ATTR_SIZE_VER0; |
| 2275 | } else if (sz > our_sz) { |
| 2276 | pr_debug("file uses a more recent and unsupported ABI" |
| 2277 | " (%zu bytes extra)\n", sz - our_sz); |
| 2278 | return -1; |
| 2279 | } |
| 2280 | /* what we have not yet read and that we know about */ |
| 2281 | left = sz - PERF_ATTR_SIZE_VER0; |
| 2282 | if (left) { |
| 2283 | void *ptr = attr; |
| 2284 | ptr += PERF_ATTR_SIZE_VER0; |
| 2285 | |
| 2286 | ret = readn(fd, ptr, left); |
| 2287 | } |
| 2288 | /* read perf_file_section, ids are read in caller */ |
| 2289 | ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids)); |
| 2290 | |
| 2291 | return ret <= 0 ? -1 : 0; |
| 2292 | } |
| 2293 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2294 | static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel, |
| 2295 | struct pevent *pevent) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2296 | { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2297 | struct event_format *event = pevent_find_event(pevent, |
| 2298 | evsel->attr.config); |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2299 | char bf[128]; |
| 2300 | |
| 2301 | if (event == NULL) |
| 2302 | return -1; |
| 2303 | |
| 2304 | snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name); |
| 2305 | evsel->name = strdup(bf); |
| 2306 | if (event->name == NULL) |
| 2307 | return -1; |
| 2308 | |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 2309 | evsel->tp_format = event; |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2310 | return 0; |
| 2311 | } |
| 2312 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2313 | static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist, |
| 2314 | struct pevent *pevent) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2315 | { |
| 2316 | struct perf_evsel *pos; |
| 2317 | |
| 2318 | list_for_each_entry(pos, &evlist->entries, node) { |
| 2319 | if (pos->attr.type == PERF_TYPE_TRACEPOINT && |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2320 | perf_evsel__set_tracepoint_name(pos, pevent)) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2321 | return -1; |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2327 | int perf_session__read_header(struct perf_session *session, int fd) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2328 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2329 | struct perf_header *header = &session->header; |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2330 | struct perf_file_header f_header; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2331 | struct perf_file_attr f_attr; |
| 2332 | u64 f_id; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2333 | int nr_attrs, nr_ids, i, j; |
| 2334 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2335 | session->evlist = perf_evlist__new(NULL, NULL); |
| 2336 | if (session->evlist == NULL) |
| 2337 | return -ENOMEM; |
| 2338 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 2339 | if (session->fd_pipe) |
| 2340 | return perf_header__read_pipe(session, fd); |
| 2341 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 2342 | if (perf_file_header__read(&f_header, header, fd) < 0) |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 2343 | return -EINVAL; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2344 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 2345 | nr_attrs = f_header.attrs.size / f_header.attr_size; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2346 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
| 2347 | |
| 2348 | for (i = 0; i < nr_attrs; i++) { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2349 | struct perf_evsel *evsel; |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 2350 | off_t tmp; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2351 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 2352 | if (read_attr(fd, header, &f_attr) < 0) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2353 | goto out_errno; |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2354 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 2355 | if (header->needs_swap) |
| 2356 | perf_event__attr_swap(&f_attr.attr); |
| 2357 | |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 2358 | tmp = lseek(fd, 0, SEEK_CUR); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2359 | evsel = perf_evsel__new(&f_attr.attr, i); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2360 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2361 | if (evsel == NULL) |
| 2362 | goto out_delete_evlist; |
| 2363 | /* |
| 2364 | * Do it before so that if perf_evsel__alloc_id fails, this |
| 2365 | * entry gets purged too at perf_evlist__delete(). |
| 2366 | */ |
| 2367 | perf_evlist__add(session->evlist, evsel); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2368 | |
| 2369 | nr_ids = f_attr.ids.size / sizeof(u64); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2370 | /* |
| 2371 | * We don't have the cpu and thread maps on the header, so |
| 2372 | * for allocating the perf_sample_id table we fake 1 cpu and |
| 2373 | * hattr->ids threads. |
| 2374 | */ |
| 2375 | if (perf_evsel__alloc_id(evsel, 1, nr_ids)) |
| 2376 | goto out_delete_evlist; |
| 2377 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2378 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
| 2379 | |
| 2380 | for (j = 0; j < nr_ids; j++) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2381 | if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id))) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2382 | goto out_errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2383 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2384 | perf_evlist__id_add(session->evlist, evsel, 0, j, f_id); |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 2385 | } |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 2386 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2387 | lseek(fd, tmp, SEEK_SET); |
| 2388 | } |
| 2389 | |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 2390 | symbol_conf.nr_events = nr_attrs; |
| 2391 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 2392 | if (f_header.event_types.size) { |
| 2393 | lseek(fd, f_header.event_types.offset, SEEK_SET); |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 2394 | trace_events = malloc(f_header.event_types.size); |
| 2395 | if (trace_events == NULL) |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 2396 | return -ENOMEM; |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 2397 | if (perf_header__getbuffer64(header, fd, trace_events, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 2398 | f_header.event_types.size)) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2399 | goto out_errno; |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 2400 | trace_event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 2401 | } |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 2402 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2403 | perf_header__process_sections(header, fd, &session->pevent, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2404 | perf_file_section__process); |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 2405 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2406 | lseek(fd, header->data_offset, SEEK_SET); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2407 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2408 | if (perf_evlist__set_tracepoint_names(session->evlist, session->pevent)) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 2409 | goto out_delete_evlist; |
| 2410 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 2411 | header->frozen = 1; |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 2412 | return 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 2413 | out_errno: |
| 2414 | return -errno; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2415 | |
| 2416 | out_delete_evlist: |
| 2417 | perf_evlist__delete(session->evlist); |
| 2418 | session->evlist = NULL; |
| 2419 | return -ENOMEM; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 2420 | } |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 2421 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2422 | int perf_event__synthesize_attr(struct perf_tool *tool, |
Robert Richter | f4d8343 | 2012-08-16 21:10:17 +0200 | [diff] [blame] | 2423 | struct perf_event_attr *attr, u32 ids, u64 *id, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2424 | perf_event__handler_t process) |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 2425 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2426 | union perf_event *ev; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2427 | size_t size; |
| 2428 | int err; |
| 2429 | |
| 2430 | size = sizeof(struct perf_event_attr); |
| 2431 | size = ALIGN(size, sizeof(u64)); |
| 2432 | size += sizeof(struct perf_event_header); |
| 2433 | size += ids * sizeof(u64); |
| 2434 | |
| 2435 | ev = malloc(size); |
| 2436 | |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 2437 | if (ev == NULL) |
| 2438 | return -ENOMEM; |
| 2439 | |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2440 | ev->attr.attr = *attr; |
| 2441 | memcpy(ev->attr.id, id, ids * sizeof(u64)); |
| 2442 | |
| 2443 | ev->attr.header.type = PERF_RECORD_HEADER_ATTR; |
Robert Richter | f4d8343 | 2012-08-16 21:10:17 +0200 | [diff] [blame] | 2444 | ev->attr.header.size = (u16)size; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2445 | |
Robert Richter | f4d8343 | 2012-08-16 21:10:17 +0200 | [diff] [blame] | 2446 | if (ev->attr.header.size == size) |
| 2447 | err = process(tool, ev, NULL, NULL); |
| 2448 | else |
| 2449 | err = -E2BIG; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2450 | |
| 2451 | free(ev); |
| 2452 | |
| 2453 | return err; |
| 2454 | } |
| 2455 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2456 | int perf_event__synthesize_attrs(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2457 | struct perf_session *session, |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2458 | perf_event__handler_t process) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2459 | { |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 2460 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2461 | int err = 0; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2462 | |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 2463 | list_for_each_entry(evsel, &session->evlist->entries, node) { |
| 2464 | err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids, |
| 2465 | evsel->id, process); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2466 | if (err) { |
| 2467 | pr_debug("failed to create perf header attribute\n"); |
| 2468 | return err; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | return err; |
| 2473 | } |
| 2474 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2475 | int perf_event__process_attr(union perf_event *event, |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2476 | struct perf_evlist **pevlist) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2477 | { |
Robert Richter | f4d8343 | 2012-08-16 21:10:17 +0200 | [diff] [blame] | 2478 | u32 i, ids, n_ids; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2479 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2480 | struct perf_evlist *evlist = *pevlist; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2481 | |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2482 | if (evlist == NULL) { |
| 2483 | *pevlist = evlist = perf_evlist__new(NULL, NULL); |
| 2484 | if (evlist == NULL) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2485 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2486 | } |
| 2487 | |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2488 | evsel = perf_evsel__new(&event->attr.attr, evlist->nr_entries); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2489 | if (evsel == NULL) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2490 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2491 | |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2492 | perf_evlist__add(evlist, evsel); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2493 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2494 | ids = event->header.size; |
| 2495 | ids -= (void *)&event->attr.id - (void *)event; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2496 | n_ids = ids / sizeof(u64); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 2497 | /* |
| 2498 | * We don't have the cpu and thread maps on the header, so |
| 2499 | * for allocating the perf_sample_id table we fake 1 cpu and |
| 2500 | * hattr->ids threads. |
| 2501 | */ |
| 2502 | if (perf_evsel__alloc_id(evsel, 1, n_ids)) |
| 2503 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2504 | |
| 2505 | for (i = 0; i < n_ids; i++) { |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 2506 | perf_evlist__id_add(evlist, evsel, 0, i, event->attr.id[i]); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 2509 | return 0; |
| 2510 | } |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2511 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2512 | int perf_event__synthesize_event_type(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2513 | u64 event_id, char *name, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2514 | perf_event__handler_t process, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2515 | struct machine *machine) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2516 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2517 | union perf_event ev; |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2518 | size_t size = 0; |
| 2519 | int err = 0; |
| 2520 | |
| 2521 | memset(&ev, 0, sizeof(ev)); |
| 2522 | |
| 2523 | ev.event_type.event_type.event_id = event_id; |
| 2524 | memset(ev.event_type.event_type.name, 0, MAX_EVENT_NAME); |
| 2525 | strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1); |
| 2526 | |
| 2527 | ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE; |
Stephane Eranian | f8f4b28 | 2012-01-20 10:49:12 +0100 | [diff] [blame] | 2528 | size = strlen(ev.event_type.event_type.name); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2529 | size = ALIGN(size, sizeof(u64)); |
| 2530 | ev.event_type.header.size = sizeof(ev.event_type) - |
| 2531 | (sizeof(ev.event_type.event_type.name) - size); |
| 2532 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2533 | err = process(tool, &ev, NULL, machine); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2534 | |
| 2535 | return err; |
| 2536 | } |
| 2537 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2538 | int perf_event__synthesize_event_types(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2539 | perf_event__handler_t process, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2540 | struct machine *machine) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2541 | { |
| 2542 | struct perf_trace_event_type *type; |
| 2543 | int i, err = 0; |
| 2544 | |
Robert Richter | db146f0 | 2012-08-16 21:10:20 +0200 | [diff] [blame] | 2545 | for (i = 0; i < trace_event_count; i++) { |
| 2546 | type = &trace_events[i]; |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2547 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2548 | err = perf_event__synthesize_event_type(tool, type->event_id, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2549 | type->name, process, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2550 | machine); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2551 | if (err) { |
| 2552 | pr_debug("failed to create perf header event type\n"); |
| 2553 | return err; |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | return err; |
| 2558 | } |
| 2559 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2560 | int perf_event__process_event_type(struct perf_tool *tool __unused, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2561 | union perf_event *event) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2562 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2563 | if (perf_header__push_event(event->event_type.event_type.event_id, |
| 2564 | event->event_type.event_type.name) < 0) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 2565 | return -ENOMEM; |
| 2566 | |
| 2567 | return 0; |
| 2568 | } |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2569 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2570 | int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2571 | struct perf_evlist *evlist, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2572 | perf_event__handler_t process) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2573 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2574 | union perf_event ev; |
Jiri Olsa | 29208e5 | 2011-10-20 15:59:43 +0200 | [diff] [blame] | 2575 | struct tracing_data *tdata; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2576 | ssize_t size = 0, aligned_size = 0, padding; |
Kyle McMartin | fb7d0b3 | 2011-01-24 11:13:04 -0500 | [diff] [blame] | 2577 | int err __used = 0; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2578 | |
Jiri Olsa | 29208e5 | 2011-10-20 15:59:43 +0200 | [diff] [blame] | 2579 | /* |
| 2580 | * We are going to store the size of the data followed |
| 2581 | * by the data contents. Since the fd descriptor is a pipe, |
| 2582 | * we cannot seek back to store the size of the data once |
| 2583 | * we know it. Instead we: |
| 2584 | * |
| 2585 | * - write the tracing data to the temp file |
| 2586 | * - get/write the data size to pipe |
| 2587 | * - write the tracing data from the temp file |
| 2588 | * to the pipe |
| 2589 | */ |
| 2590 | tdata = tracing_data_get(&evlist->entries, fd, true); |
| 2591 | if (!tdata) |
| 2592 | return -1; |
| 2593 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2594 | memset(&ev, 0, sizeof(ev)); |
| 2595 | |
| 2596 | ev.tracing_data.header.type = PERF_RECORD_HEADER_TRACING_DATA; |
Jiri Olsa | 29208e5 | 2011-10-20 15:59:43 +0200 | [diff] [blame] | 2597 | size = tdata->size; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2598 | aligned_size = ALIGN(size, sizeof(u64)); |
| 2599 | padding = aligned_size - size; |
| 2600 | ev.tracing_data.header.size = sizeof(ev.tracing_data); |
| 2601 | ev.tracing_data.size = aligned_size; |
| 2602 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2603 | process(tool, &ev, NULL, NULL); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2604 | |
Jiri Olsa | 29208e5 | 2011-10-20 15:59:43 +0200 | [diff] [blame] | 2605 | /* |
| 2606 | * The put function will copy all the tracing data |
| 2607 | * stored in temp file to the pipe. |
| 2608 | */ |
| 2609 | tracing_data_put(tdata); |
| 2610 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2611 | write_padded(fd, NULL, 0, padding); |
| 2612 | |
| 2613 | return aligned_size; |
| 2614 | } |
| 2615 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2616 | int perf_event__process_tracing_data(union perf_event *event, |
| 2617 | struct perf_session *session) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2618 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2619 | ssize_t size_read, padding, size = event->tracing_data.size; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2620 | off_t offset = lseek(session->fd, 0, SEEK_CUR); |
| 2621 | char buf[BUFSIZ]; |
| 2622 | |
| 2623 | /* setup for reading amidst mmap */ |
| 2624 | lseek(session->fd, offset + sizeof(struct tracing_data_event), |
| 2625 | SEEK_SET); |
| 2626 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2627 | size_read = trace_report(session->fd, &session->pevent, |
| 2628 | session->repipe); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2629 | padding = ALIGN(size_read, sizeof(u64)) - size_read; |
| 2630 | |
| 2631 | if (read(session->fd, buf, padding) < 0) |
| 2632 | die("reading input file"); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 2633 | if (session->repipe) { |
| 2634 | int retw = write(STDOUT_FILENO, buf, padding); |
| 2635 | if (retw <= 0 || retw != padding) |
| 2636 | die("repiping tracing data padding"); |
| 2637 | } |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2638 | |
| 2639 | if (size_read + padding != size) |
| 2640 | die("tracing data size mismatch"); |
| 2641 | |
Arnaldo Carvalho de Melo | 8b6ee4c | 2012-08-07 23:36:16 -0300 | [diff] [blame] | 2642 | perf_evlist__set_tracepoint_names(session->evlist, session->pevent); |
| 2643 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 2644 | return size_read + padding; |
| 2645 | } |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2646 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2647 | int perf_event__synthesize_build_id(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2648 | struct dso *pos, u16 misc, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2649 | perf_event__handler_t process, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 2650 | struct machine *machine) |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2651 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2652 | union perf_event ev; |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2653 | size_t len; |
| 2654 | int err = 0; |
| 2655 | |
| 2656 | if (!pos->hit) |
| 2657 | return err; |
| 2658 | |
| 2659 | memset(&ev, 0, sizeof(ev)); |
| 2660 | |
| 2661 | len = pos->long_name_len + 1; |
| 2662 | len = ALIGN(len, NAME_ALIGN); |
| 2663 | memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id)); |
| 2664 | ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID; |
| 2665 | ev.build_id.header.misc = misc; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 2666 | ev.build_id.pid = machine->pid; |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2667 | ev.build_id.header.size = sizeof(ev.build_id) + len; |
| 2668 | memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); |
| 2669 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2670 | err = process(tool, &ev, NULL, machine); |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2671 | |
| 2672 | return err; |
| 2673 | } |
| 2674 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 2675 | int perf_event__process_build_id(struct perf_tool *tool __used, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 2676 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2677 | struct perf_session *session) |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2678 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 2679 | __event_process_build_id(&event->build_id, |
| 2680 | event->build_id.filename, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2681 | session); |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 2682 | return 0; |
| 2683 | } |
Stephane Eranian | a1ac1d3 | 2010-06-17 11:39:01 +0200 | [diff] [blame] | 2684 | |
| 2685 | void disable_buildid_cache(void) |
| 2686 | { |
| 2687 | no_buildid_cache = true; |
| 2688 | } |