Blame view
tools/perf/builtin-buildid-list.c
2.99 KB
c34984b2b perf buildid-list... |
1 2 3 |
/* * builtin-buildid-list.c * |
7a6f205d6 perf buildid-list... |
4 5 |
* Builtin buildid-list command: list buildids in perf.data, in the running * kernel and in ELF files. |
c34984b2b perf buildid-list... |
6 7 8 9 10 11 |
* * Copyright (C) 2009, Red Hat Inc. * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> */ #include "builtin.h" #include "perf.h" |
7b2567c1f perf build-id: Mo... |
12 |
#include "util/build-id.h" |
c34984b2b perf buildid-list... |
13 |
#include "util/debug.h" |
4a3cec849 perf dsos: Move t... |
14 |
#include "util/dso.h" |
fa0d98462 perf tools: Remov... |
15 |
#include <subcmd/pager.h> |
4b6ab94ea perf subcmd: Crea... |
16 |
#include <subcmd/parse-options.h> |
94c744b6c perf tools: Intro... |
17 |
#include "util/session.h" |
c34984b2b perf buildid-list... |
18 |
#include "util/symbol.h" |
f5fc14124 perf tools: Add d... |
19 |
#include "util/data.h" |
a43783aee perf tools: Inclu... |
20 |
#include <errno.h> |
6ef81c55a perf session: Ret... |
21 |
#include <linux/err.h> |
c34984b2b perf buildid-list... |
22 |
|
f2add9cd6 perf buildid-list... |
23 24 |
static int sysfs__fprintf_build_id(FILE *fp) { |
d77fac7f9 perf buildid: Use... |
25 |
char sbuild_id[SBUILD_ID_SIZE]; |
0b5a7935f perf buildid: Int... |
26 |
int ret; |
f2add9cd6 perf buildid-list... |
27 |
|
0b5a7935f perf buildid: Int... |
28 29 30 |
ret = sysfs__sprintf_build_id("/", sbuild_id); if (ret != sizeof(sbuild_id)) return ret < 0 ? ret : -EINVAL; |
f2add9cd6 perf buildid-list... |
31 |
|
0b5a7935f perf buildid: Int... |
32 33 |
return fprintf(fp, "%s ", sbuild_id); |
f2add9cd6 perf buildid-list... |
34 |
} |
7a6f205d6 perf buildid-list... |
35 |
static int filename__fprintf_build_id(const char *name, FILE *fp) |
f2add9cd6 perf buildid-list... |
36 |
{ |
d77fac7f9 perf buildid: Use... |
37 |
char sbuild_id[SBUILD_ID_SIZE]; |
0b5a7935f perf buildid: Int... |
38 |
int ret; |
f2add9cd6 perf buildid-list... |
39 |
|
0b5a7935f perf buildid: Int... |
40 41 42 |
ret = filename__sprintf_build_id(name, sbuild_id); if (ret != sizeof(sbuild_id)) return ret < 0 ? ret : -EINVAL; |
7a6f205d6 perf buildid-list... |
43 |
|
7a6f205d6 perf buildid-list... |
44 45 46 |
return fprintf(fp, "%s ", sbuild_id); } |
417c2ff68 perf symbols: Gen... |
47 48 49 50 |
static bool dso__skip_buildid(struct dso *dso, int with_hits) { return with_hits && !dso->hit; } |
70cb4e963 perf tools: Add a... |
51 |
static int perf_session__list_build_ids(bool force, bool with_hits) |
1b5495043 perf tools: Movin... |
52 53 |
{ struct perf_session *session; |
8ceb41d7e perf tools: Renam... |
54 |
struct perf_data data = { |
2d4f27999 perf data: Add gl... |
55 56 57 |
.path = input_name, .mode = PERF_DATA_MODE_READ, .force = force, |
f5fc14124 perf tools: Add d... |
58 |
}; |
1b5495043 perf tools: Movin... |
59 |
|
166ccc9c2 perf symbols: Int... |
60 |
symbol__elf_init(); |
efad14150 perf report: Acce... |
61 62 63 |
/* * See if this is an ELF file first: */ |
0b5a7935f perf buildid: Int... |
64 |
if (filename__fprintf_build_id(input_name, stdout) > 0) |
efad14150 perf report: Acce... |
65 |
goto out; |
8ceb41d7e perf tools: Renam... |
66 |
session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops); |
6ef81c55a perf session: Ret... |
67 68 |
if (IS_ERR(session)) return PTR_ERR(session); |
cd10b2895 perf tools: Hit a... |
69 70 71 72 73 |
/* * We take all buildids when the file contains AUX area tracing data * because we do not decode the trace because it would take too long. */ |
8ceb41d7e perf tools: Renam... |
74 |
if (!perf_data__is_pipe(&data) && |
cd10b2895 perf tools: Hit a... |
75 76 |
perf_header__has_feat(&session->header, HEADER_AUXTRACE)) with_hits = false; |
299c34520 perf buildid-list... |
77 78 79 80 |
/* * in pipe-mode, the only way to get the buildids is to parse * the record stream. Buildids are stored as RECORD_HEADER_BUILD_ID */ |
8ceb41d7e perf tools: Renam... |
81 |
if (with_hits || perf_data__is_pipe(&data)) |
b7b61cbeb perf ordered_even... |
82 |
perf_session__process_events(session); |
1b5495043 perf tools: Movin... |
83 |
|
417c2ff68 perf symbols: Gen... |
84 |
perf_session__fprintf_dsos_buildid(session, stdout, dso__skip_buildid, with_hits); |
1b5495043 perf tools: Movin... |
85 |
perf_session__delete(session); |
f0bf91076 perf buildid-list... |
86 |
out: |
1b5495043 perf tools: Movin... |
87 88 |
return 0; } |
b0ad8ea66 perf tools: Remov... |
89 |
int cmd_buildid_list(int argc, const char **argv) |
c34984b2b perf buildid-list... |
90 |
{ |
6ee414973 perf buildid-list... |
91 92 93 |
bool show_kernel = false; bool with_hits = false; bool force = false; |
6ee414973 perf buildid-list... |
94 95 96 97 98 99 100 101 102 103 104 105 |
const struct option options[] = { OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"), OPT_STRING('i', "input", &input_name, "file", "input file name"), OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"), OPT_INCR('v', "verbose", &verbose, "be more verbose"), OPT_END() }; const char * const buildid_list_usage[] = { "perf buildid-list [<options>]", NULL }; |
c34984b2b perf buildid-list... |
106 107 |
argc = parse_options(argc, argv, options, buildid_list_usage, 0); setup_pager(); |
6ee414973 perf buildid-list... |
108 109 |
if (show_kernel) |
c8319c9d0 perf buildid-list... |
110 |
return !(sysfs__fprintf_build_id(stdout) > 0); |
6ee414973 perf buildid-list... |
111 |
|
70cb4e963 perf tools: Add a... |
112 |
return perf_session__list_build_ids(force, with_hits); |
c34984b2b perf buildid-list... |
113 |
} |