blob: 1e99ac806913679d963ae8043f6035f844ea2bc2 [file] [log] [blame]
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -02001/*
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"
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020012#include "util/debug.h"
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020013#include "util/parse-options.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020014#include "util/session.h"
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020015#include "util/symbol.h"
16
17static char const *input_name = "perf.data";
18static int force;
19
Arnaldo Carvalho de Melo0422a4f2009-12-18 16:35:58 -020020static const char * const buildid_list_usage[] = {
Arnaldo Carvalho de Melob9b1e1c2009-12-06 18:03:10 -020021 "perf buildid-list [<options>]",
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020022 NULL
23};
24
25static const struct option options[] = {
26 OPT_STRING('i', "input", &input_name, "file",
27 "input file name"),
28 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
29 OPT_BOOLEAN('v', "verbose", &verbose,
Arnaldo Carvalho de Melo1124ba72009-11-16 21:45:25 -020030 "be more verbose"),
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020031 OPT_END()
32};
33
34static int perf_file_section__process_buildids(struct perf_file_section *self,
35 int feat, int fd)
36{
37 if (feat != HEADER_BUILD_ID)
38 return 0;
39
40 if (lseek(fd, self->offset, SEEK_SET) < 0) {
41 pr_warning("Failed to lseek to %Ld offset for buildids!\n",
42 self->offset);
43 return -1;
44 }
45
46 if (perf_header__read_build_ids(fd, self->offset, self->size)) {
47 pr_warning("Failed to read buildids!\n");
48 return -1;
49 }
50
51 return 0;
52}
53
54static int __cmd_buildid_list(void)
55{
56 int err = -1;
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020057 struct perf_session *session;
58
59 session = perf_session__new(input_name, O_RDONLY, force);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020060 if (session == NULL)
61 return -1;
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020062
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020063 err = perf_header__process_sections(&session->header, session->fd,
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020064 perf_file_section__process_buildids);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020065 if (err >= 0)
66 dsos__fprintf_buildid(stdout);
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020067
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020068 perf_session__delete(session);
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020069 return err;
70}
71
72int 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}