blob: 431f204bde64165be4d159214e7e7693dc97db3e [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;
Arnaldo Carvalho de Melo88d3d9b2010-01-14 23:45:30 -020019static bool with_hits;
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020020
Arnaldo Carvalho de Melo0422a4f2009-12-18 16:35:58 -020021static const char * const buildid_list_usage[] = {
Arnaldo Carvalho de Melob9b1e1c2009-12-06 18:03:10 -020022 "perf buildid-list [<options>]",
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020023 NULL
24};
25
26static const struct option options[] = {
Arnaldo Carvalho de Melo88d3d9b2010-01-14 23:45:30 -020027 OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020028 OPT_STRING('i', "input", &input_name, "file",
29 "input file name"),
30 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
31 OPT_BOOLEAN('v', "verbose", &verbose,
Arnaldo Carvalho de Melo1124ba72009-11-16 21:45:25 -020032 "be more verbose"),
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020033 OPT_END()
34};
35
Arnaldo Carvalho de Melo88d3d9b2010-01-14 23:45:30 -020036static int build_id_list__process_event(event_t *event,
37 struct perf_session *session)
38{
39 struct addr_location al;
40 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
41 struct thread *thread = perf_session__findnew(session, event->ip.pid);
42
43 if (thread == NULL) {
44 pr_err("problem processing %d event, skipping it.\n",
45 event->header.type);
46 return -1;
47 }
48
49 thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
50 event->ip.ip, &al);
51
52 if (al.map != NULL)
53 al.map->dso->hit = 1;
54
55 return 0;
56}
57
58static struct perf_event_ops build_id_list__event_ops = {
59 .sample = build_id_list__process_event,
60 .mmap = event__process_mmap,
61 .fork = event__process_task,
62};
63
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020064static int __cmd_buildid_list(void)
65{
66 int err = -1;
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020067 struct perf_session *session;
68
69 session = perf_session__new(input_name, O_RDONLY, force);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020070 if (session == NULL)
71 return -1;
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020072
Arnaldo Carvalho de Melo88d3d9b2010-01-14 23:45:30 -020073 if (with_hits)
74 perf_session__process_events(session, &build_id_list__event_ops);
75
76 dsos__fprintf_buildid(stdout, with_hits);
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020077
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020078 perf_session__delete(session);
Arnaldo Carvalho de Meloc34984b2009-11-16 16:32:45 -020079 return err;
80}
81
82int cmd_buildid_list(int argc, const char **argv, const char *prefix __used)
83{
84 argc = parse_options(argc, argv, options, buildid_list_usage, 0);
85 setup_pager();
86 return __cmd_buildid_list();
87}