diff options
| -rw-r--r-- | tools/perf/Documentation/perf-buildid-list.txt | 34 | ||||
| -rw-r--r-- | tools/perf/Makefile | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-buildid-list.c | 116 | ||||
| -rw-r--r-- | tools/perf/builtin.h | 1 | ||||
| -rw-r--r-- | tools/perf/command-list.txt | 1 | ||||
| -rw-r--r-- | tools/perf/perf.c | 1 |
6 files changed, 154 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-buildid-list.txt b/tools/perf/Documentation/perf-buildid-list.txt new file mode 100644 index 000000000000..abab34e05576 --- /dev/null +++ b/tools/perf/Documentation/perf-buildid-list.txt | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | perf-buildid-list(1) | ||
| 2 | ==================== | ||
| 3 | |||
| 4 | NAME | ||
| 5 | ---- | ||
| 6 | perf-buildid-list - List the buildids in a perf.data file | ||
| 7 | |||
| 8 | SYNOPSIS | ||
| 9 | -------- | ||
| 10 | [verse] | ||
| 11 | 'perf buildid-list <options>' | ||
| 12 | |||
| 13 | DESCRIPTION | ||
| 14 | ----------- | ||
| 15 | This command displays the buildids found in a perf.data file, so that other | ||
| 16 | tools can be used to fetch packages with matching symbol tables for use by | ||
| 17 | perf report. | ||
| 18 | |||
| 19 | OPTIONS | ||
| 20 | ------- | ||
| 21 | -i:: | ||
| 22 | --input=:: | ||
| 23 | Input file name. (default: perf.data) | ||
| 24 | -f:: | ||
| 25 | --force:: | ||
| 26 | Don't do ownership validation. | ||
| 27 | -v:: | ||
| 28 | --verbose:: | ||
| 29 | Be more verbose, showing the name of the DSOs after the buildids. | ||
| 30 | |||
| 31 | SEE ALSO | ||
| 32 | -------- | ||
| 33 | linkperf:perf-record[1], linkperf:perf-top[1], | ||
| 34 | linkperf:perf-report[1] | ||
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index f7cd89622cf4..46a58a81c9ad 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
| @@ -430,6 +430,7 @@ BUILTIN_OBJS += bench/sched-pipe.o | |||
| 430 | 430 | ||
| 431 | BUILTIN_OBJS += builtin-help.o | 431 | BUILTIN_OBJS += builtin-help.o |
| 432 | BUILTIN_OBJS += builtin-sched.o | 432 | BUILTIN_OBJS += builtin-sched.o |
| 433 | BUILTIN_OBJS += builtin-buildid-list.o | ||
| 433 | BUILTIN_OBJS += builtin-list.o | 434 | BUILTIN_OBJS += builtin-list.o |
| 434 | BUILTIN_OBJS += builtin-record.o | 435 | BUILTIN_OBJS += builtin-record.o |
| 435 | BUILTIN_OBJS += builtin-report.o | 436 | BUILTIN_OBJS += builtin-report.o |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c new file mode 100644 index 000000000000..2e377e1be435 --- /dev/null +++ b/tools/perf/builtin-buildid-list.c | |||
| @@ -0,0 +1,116 @@ | |||
| 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" | ||
| 14 | #include "util/header.h" | ||
| 15 | #include "util/parse-options.h" | ||
| 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[] = { | ||
| 22 | "perf report [<options>]", | ||
| 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, | ||
| 31 | "be more verbose (show counter open errors, etc)"), | ||
| 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; | ||
| 58 | struct perf_header *header; | ||
| 59 | struct perf_file_header f_header; | ||
| 60 | struct stat input_stat; | ||
| 61 | int input = open(input_name, O_RDONLY); | ||
| 62 | |||
| 63 | if (input < 0) { | ||
| 64 | pr_err("failed to open file: %s", input_name); | ||
| 65 | if (!strcmp(input_name, "perf.data")) | ||
| 66 | pr_err(" (try 'perf record' first)"); | ||
| 67 | pr_err("\n"); | ||
| 68 | goto out; | ||
| 69 | } | ||
| 70 | |||
| 71 | err = fstat(input, &input_stat); | ||
| 72 | if (err < 0) { | ||
| 73 | perror("failed to stat file"); | ||
| 74 | goto out_close; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { | ||
| 78 | pr_err("file %s not owned by current user or root\n", | ||
| 79 | input_name); | ||
| 80 | goto out_close; | ||
| 81 | } | ||
| 82 | |||
| 83 | if (!input_stat.st_size) { | ||
| 84 | pr_info("zero-sized file, nothing to do!\n"); | ||
| 85 | goto out_close; | ||
| 86 | } | ||
| 87 | |||
| 88 | err = -1; | ||
| 89 | header = perf_header__new(); | ||
| 90 | if (header == NULL) | ||
| 91 | goto out_close; | ||
| 92 | |||
| 93 | if (perf_file_header__read(&f_header, header, input) < 0) { | ||
| 94 | pr_warning("incompatible file format"); | ||
| 95 | goto out_close; | ||
| 96 | } | ||
| 97 | |||
| 98 | err = perf_header__process_sections(header, input, | ||
| 99 | perf_file_section__process_buildids); | ||
| 100 | |||
| 101 | if (err < 0) | ||
| 102 | goto out_close; | ||
| 103 | |||
| 104 | dsos__fprintf_buildid(stdout); | ||
| 105 | out_close: | ||
| 106 | close(input); | ||
| 107 | out: | ||
| 108 | return err; | ||
| 109 | } | ||
| 110 | |||
| 111 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) | ||
| 112 | { | ||
| 113 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); | ||
| 114 | setup_pager(); | ||
| 115 | return __cmd_buildid_list(); | ||
| 116 | } | ||
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index f0cd5b139b7c..e97954a0a3d2 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h | |||
| @@ -16,6 +16,7 @@ extern int check_pager_config(const char *cmd); | |||
| 16 | 16 | ||
| 17 | extern int cmd_annotate(int argc, const char **argv, const char *prefix); | 17 | extern int cmd_annotate(int argc, const char **argv, const char *prefix); |
| 18 | extern int cmd_bench(int argc, const char **argv, const char *prefix); | 18 | extern int cmd_bench(int argc, const char **argv, const char *prefix); |
| 19 | extern int cmd_buildid_list(int argc, const char **argv, const char *prefix); | ||
| 19 | extern int cmd_help(int argc, const char **argv, const char *prefix); | 20 | extern int cmd_help(int argc, const char **argv, const char *prefix); |
| 20 | extern int cmd_sched(int argc, const char **argv, const char *prefix); | 21 | extern int cmd_sched(int argc, const char **argv, const char *prefix); |
| 21 | extern int cmd_list(int argc, const char **argv, const char *prefix); | 22 | extern int cmd_list(int argc, const char **argv, const char *prefix); |
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt index 981c40b9a5e2..d37b16cf18ff 100644 --- a/tools/perf/command-list.txt +++ b/tools/perf/command-list.txt | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | # | 4 | # |
| 5 | perf-annotate mainporcelain common | 5 | perf-annotate mainporcelain common |
| 6 | perf-bench mainporcelain common | 6 | perf-bench mainporcelain common |
| 7 | perf-buildid-list mainporcelain common | ||
| 7 | perf-list mainporcelain common | 8 | perf-list mainporcelain common |
| 8 | perf-sched mainporcelain common | 9 | perf-sched mainporcelain common |
| 9 | perf-record mainporcelain common | 10 | perf-record mainporcelain common |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 8936786b42ea..53359ebb369a 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
| @@ -287,6 +287,7 @@ static void handle_internal_command(int argc, const char **argv) | |||
| 287 | static struct cmd_struct commands[] = { | 287 | static struct cmd_struct commands[] = { |
| 288 | { "help", cmd_help, 0 }, | 288 | { "help", cmd_help, 0 }, |
| 289 | { "list", cmd_list, 0 }, | 289 | { "list", cmd_list, 0 }, |
| 290 | { "buildid-list", cmd_buildid_list, 0 }, | ||
| 290 | { "record", cmd_record, 0 }, | 291 | { "record", cmd_record, 0 }, |
| 291 | { "report", cmd_report, 0 }, | 292 | { "report", cmd_report, 0 }, |
| 292 | { "bench", cmd_bench, 0 }, | 293 | { "bench", cmd_bench, 0 }, |
