Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-buildid-list.c |
| 3 | * |
| 4 | * Builtin buildid-list command: list buildids in perf.data |
| 5 | * |
| 6 | * Copyright (C) 2009, Red Hat Inc. |
| 7 | * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 8 | */ |
| 9 | #include "builtin.h" |
| 10 | #include "perf.h" |
| 11 | #include "util/cache.h" |
| 12 | #include "util/data_map.h" |
| 13 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 14 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 15 | #include "util/session.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 16 | #include "util/symbol.h" |
| 17 | |
| 18 | static char const *input_name = "perf.data"; |
| 19 | static int force; |
| 20 | |
| 21 | static const char *const buildid_list_usage[] = { |
Arnaldo Carvalho de Melo | b9b1e1c | 2009-12-06 18:03:10 -0200 | [diff] [blame] | 22 | "perf buildid-list [<options>]", |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 23 | NULL |
| 24 | }; |
| 25 | |
| 26 | static const struct option options[] = { |
| 27 | OPT_STRING('i', "input", &input_name, "file", |
| 28 | "input file name"), |
| 29 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
| 30 | OPT_BOOLEAN('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | 1124ba7 | 2009-11-16 21:45:25 -0200 | [diff] [blame] | 31 | "be more verbose"), |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 32 | OPT_END() |
| 33 | }; |
| 34 | |
| 35 | static int perf_file_section__process_buildids(struct perf_file_section *self, |
| 36 | int feat, int fd) |
| 37 | { |
| 38 | if (feat != HEADER_BUILD_ID) |
| 39 | return 0; |
| 40 | |
| 41 | if (lseek(fd, self->offset, SEEK_SET) < 0) { |
| 42 | pr_warning("Failed to lseek to %Ld offset for buildids!\n", |
| 43 | self->offset); |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | if (perf_header__read_build_ids(fd, self->offset, self->size)) { |
| 48 | pr_warning("Failed to read buildids!\n"); |
| 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static int __cmd_buildid_list(void) |
| 56 | { |
| 57 | int err = -1; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 58 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, force); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 59 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 60 | if (session == NULL) |
| 61 | return -1; |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 62 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 63 | err = perf_header__process_sections(&session->header, session->fd, |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 64 | perf_file_section__process_buildids); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 65 | if (err >= 0) |
| 66 | dsos__fprintf_buildid(stdout); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 67 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 68 | perf_session__delete(session); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 69 | return err; |
| 70 | } |
| 71 | |
| 72 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) |
| 73 | { |
| 74 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); |
| 75 | setup_pager(); |
| 76 | return __cmd_buildid_list(); |
| 77 | } |