diff options
Diffstat (limited to 'tools/perf/builtin-buildid-list.c')
-rw-r--r-- | tools/perf/builtin-buildid-list.c | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 5af32ae9031e..cb690a65bf02 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * builtin-buildid-list.c | 2 | * builtin-buildid-list.c |
3 | * | 3 | * |
4 | * Builtin buildid-list command: list buildids in perf.data | 4 | * Builtin buildid-list command: list buildids in perf.data, in the running |
5 | * kernel and in ELF files. | ||
5 | * | 6 | * |
6 | * Copyright (C) 2009, Red Hat Inc. | 7 | * Copyright (C) 2009, Red Hat Inc. |
7 | * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> | 8 | * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> |
@@ -15,8 +16,11 @@ | |||
15 | #include "util/session.h" | 16 | #include "util/session.h" |
16 | #include "util/symbol.h" | 17 | #include "util/symbol.h" |
17 | 18 | ||
19 | #include <libelf.h> | ||
20 | |||
18 | static char const *input_name = "perf.data"; | 21 | static char const *input_name = "perf.data"; |
19 | static bool force; | 22 | static bool force; |
23 | static bool show_kernel; | ||
20 | static bool with_hits; | 24 | static bool with_hits; |
21 | 25 | ||
22 | static const char * const buildid_list_usage[] = { | 26 | static const char * const buildid_list_usage[] = { |
@@ -29,12 +33,13 @@ static const struct option options[] = { | |||
29 | OPT_STRING('i', "input", &input_name, "file", | 33 | OPT_STRING('i', "input", &input_name, "file", |
30 | "input file name"), | 34 | "input file name"), |
31 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 35 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
36 | OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"), | ||
32 | OPT_INCR('v', "verbose", &verbose, | 37 | OPT_INCR('v', "verbose", &verbose, |
33 | "be more verbose"), | 38 | "be more verbose"), |
34 | OPT_END() | 39 | OPT_END() |
35 | }; | 40 | }; |
36 | 41 | ||
37 | static int __cmd_buildid_list(void) | 42 | static int perf_session__list_build_ids(void) |
38 | { | 43 | { |
39 | struct perf_session *session; | 44 | struct perf_session *session; |
40 | 45 | ||
@@ -52,6 +57,49 @@ static int __cmd_buildid_list(void) | |||
52 | return 0; | 57 | return 0; |
53 | } | 58 | } |
54 | 59 | ||
60 | static int sysfs__fprintf_build_id(FILE *fp) | ||
61 | { | ||
62 | u8 kallsyms_build_id[BUILD_ID_SIZE]; | ||
63 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
64 | |||
65 | if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, | ||
66 | sizeof(kallsyms_build_id)) != 0) | ||
67 | return -1; | ||
68 | |||
69 | build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id), | ||
70 | sbuild_id); | ||
71 | fprintf(fp, "%s\n", sbuild_id); | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static int filename__fprintf_build_id(const char *name, FILE *fp) | ||
76 | { | ||
77 | u8 build_id[BUILD_ID_SIZE]; | ||
78 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
79 | |||
80 | if (filename__read_build_id(name, build_id, | ||
81 | sizeof(build_id)) != sizeof(build_id)) | ||
82 | return 0; | ||
83 | |||
84 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); | ||
85 | return fprintf(fp, "%s\n", sbuild_id); | ||
86 | } | ||
87 | |||
88 | static int __cmd_buildid_list(void) | ||
89 | { | ||
90 | if (show_kernel) | ||
91 | return sysfs__fprintf_build_id(stdout); | ||
92 | |||
93 | elf_version(EV_CURRENT); | ||
94 | /* | ||
95 | * See if this is an ELF file first: | ||
96 | */ | ||
97 | if (filename__fprintf_build_id(input_name, stdout)) | ||
98 | return 0; | ||
99 | |||
100 | return perf_session__list_build_ids(); | ||
101 | } | ||
102 | |||
55 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) | 103 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) |
56 | { | 104 | { |
57 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); | 105 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); |