diff options
| -rw-r--r-- | tools/perf/builtin-record.c | 32 | ||||
| -rw-r--r-- | tools/perf/util/header.c | 41 | ||||
| -rw-r--r-- | tools/perf/util/header.h | 2 |
3 files changed, 41 insertions, 34 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 9f98b86e747c..c35e61b30988 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
| @@ -378,39 +378,11 @@ static void open_counters(int cpu, pid_t pid) | |||
| 378 | nr_cpu++; | 378 | nr_cpu++; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | static bool write_buildid_table(void) | ||
| 382 | { | ||
| 383 | struct dso *pos; | ||
| 384 | bool have_buildid = false; | ||
| 385 | |||
| 386 | list_for_each_entry(pos, &dsos, node) { | ||
| 387 | struct build_id_event b; | ||
| 388 | size_t len; | ||
| 389 | |||
| 390 | if (filename__read_build_id(pos->long_name, | ||
| 391 | &b.build_id, | ||
| 392 | sizeof(b.build_id)) < 0) | ||
| 393 | continue; | ||
| 394 | have_buildid = true; | ||
| 395 | memset(&b.header, 0, sizeof(b.header)); | ||
| 396 | len = strlen(pos->long_name) + 1; | ||
| 397 | len = ALIGN(len, 64); | ||
| 398 | b.header.size = sizeof(b) + len; | ||
| 399 | write_output(&b, sizeof(b)); | ||
| 400 | write_output(pos->long_name, len); | ||
| 401 | } | ||
| 402 | |||
| 403 | return have_buildid; | ||
| 404 | } | ||
| 405 | |||
| 406 | static void atexit_header(void) | 381 | static void atexit_header(void) |
| 407 | { | 382 | { |
| 408 | header->data_size += bytes_written; | 383 | header->data_size += bytes_written; |
| 409 | 384 | ||
| 410 | if (write_buildid_table()) | 385 | perf_header__write(header, output, true); |
| 411 | perf_header__set_feat(header, HEADER_BUILD_ID); | ||
| 412 | |||
| 413 | perf_header__write(header, output); | ||
| 414 | } | 386 | } |
| 415 | 387 | ||
| 416 | static int __cmd_record(int argc, const char **argv) | 388 | static int __cmd_record(int argc, const char **argv) |
| @@ -487,7 +459,7 @@ static int __cmd_record(int argc, const char **argv) | |||
| 487 | } | 459 | } |
| 488 | 460 | ||
| 489 | if (file_new) | 461 | if (file_new) |
| 490 | perf_header__write(header, output); | 462 | perf_header__write(header, output, false); |
| 491 | 463 | ||
| 492 | if (!system_wide) | 464 | if (!system_wide) |
| 493 | event__synthesize_thread(pid, process_synthesized_event); | 465 | event__synthesize_thread(pid, process_synthesized_event); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 050f543fd965..a4d0bbef9a43 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -2,11 +2,13 @@ | |||
| 2 | #include <unistd.h> | 2 | #include <unistd.h> |
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| 5 | #include <linux/list.h> | ||
| 5 | 6 | ||
| 6 | #include "util.h" | 7 | #include "util.h" |
| 7 | #include "header.h" | 8 | #include "header.h" |
| 8 | #include "../perf.h" | 9 | #include "../perf.h" |
| 9 | #include "trace-event.h" | 10 | #include "trace-event.h" |
| 11 | #include "symbol.h" | ||
| 10 | 12 | ||
| 11 | /* | 13 | /* |
| 12 | * Create new perf.data header attribute: | 14 | * Create new perf.data header attribute: |
| @@ -172,7 +174,33 @@ static void do_write(int fd, void *buf, size_t size) | |||
| 172 | } | 174 | } |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | static void perf_header__adds_write(struct perf_header *self, int fd) | 177 | static bool write_buildid_table(int fd) |
| 178 | { | ||
| 179 | struct dso *pos; | ||
| 180 | bool have_buildid = false; | ||
| 181 | |||
| 182 | list_for_each_entry(pos, &dsos, node) { | ||
| 183 | struct build_id_event b; | ||
| 184 | size_t len; | ||
| 185 | |||
| 186 | if (filename__read_build_id(pos->long_name, | ||
| 187 | &b.build_id, | ||
| 188 | sizeof(b.build_id)) < 0) | ||
| 189 | continue; | ||
| 190 | have_buildid = true; | ||
| 191 | memset(&b.header, 0, sizeof(b.header)); | ||
| 192 | len = strlen(pos->long_name) + 1; | ||
| 193 | len = ALIGN(len, 64); | ||
| 194 | b.header.size = sizeof(b) + len; | ||
| 195 | do_write(fd, &b, sizeof(b)); | ||
| 196 | do_write(fd, pos->long_name, len); | ||
| 197 | } | ||
| 198 | |||
| 199 | return have_buildid; | ||
| 200 | } | ||
| 201 | |||
| 202 | static void | ||
| 203 | perf_header__adds_write(struct perf_header *self, int fd, bool at_exit) | ||
| 176 | { | 204 | { |
| 177 | struct perf_file_section trace_sec; | 205 | struct perf_file_section trace_sec; |
| 178 | u64 cur_offset = lseek(fd, 0, SEEK_CUR); | 206 | u64 cur_offset = lseek(fd, 0, SEEK_CUR); |
| @@ -196,9 +224,16 @@ static void perf_header__adds_write(struct perf_header *self, int fd) | |||
| 196 | */ | 224 | */ |
| 197 | cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); | 225 | cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); |
| 198 | } | 226 | } |
| 227 | |||
| 228 | if (at_exit) { | ||
| 229 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | ||
| 230 | if (write_buildid_table(fd)) | ||
| 231 | perf_header__set_feat(self, HEADER_BUILD_ID); | ||
| 232 | lseek(fd, cur_offset, SEEK_SET); | ||
| 233 | } | ||
| 199 | }; | 234 | }; |
| 200 | 235 | ||
| 201 | void perf_header__write(struct perf_header *self, int fd) | 236 | void perf_header__write(struct perf_header *self, int fd, bool at_exit) |
| 202 | { | 237 | { |
| 203 | struct perf_file_header f_header; | 238 | struct perf_file_header f_header; |
| 204 | struct perf_file_attr f_attr; | 239 | struct perf_file_attr f_attr; |
| @@ -236,7 +271,7 @@ void perf_header__write(struct perf_header *self, int fd) | |||
| 236 | if (events) | 271 | if (events) |
| 237 | do_write(fd, events, self->event_size); | 272 | do_write(fd, events, self->event_size); |
| 238 | 273 | ||
| 239 | perf_header__adds_write(self, fd); | 274 | perf_header__adds_write(self, fd, at_exit); |
| 240 | 275 | ||
| 241 | self->data_offset = lseek(fd, 0, SEEK_CUR); | 276 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
| 242 | 277 | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 2f233c5db7e9..77186c9e605b 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
| @@ -33,7 +33,7 @@ struct perf_header { | |||
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | struct perf_header *perf_header__read(int fd); | 35 | struct perf_header *perf_header__read(int fd); |
| 36 | void perf_header__write(struct perf_header *self, int fd); | 36 | void perf_header__write(struct perf_header *self, int fd, bool at_exit); |
| 37 | 37 | ||
| 38 | void perf_header__add_attr(struct perf_header *self, | 38 | void perf_header__add_attr(struct perf_header *self, |
| 39 | struct perf_header_attr *attr); | 39 | struct perf_header_attr *attr); |
