perf buildid-list: Introduce --with-hits option
[deliverable/linux.git] / tools / perf / builtin-buildid-list.c
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/debug.h"
13 #include "util/parse-options.h"
14 #include "util/session.h"
15 #include "util/symbol.h"
16
17 static char const *input_name = "perf.data";
18 static int force;
19 static bool with_hits;
20
21 static const char * const buildid_list_usage[] = {
22 "perf buildid-list [<options>]",
23 NULL
24 };
25
26 static const struct option options[] = {
27 OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
28 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,
32 "be more verbose"),
33 OPT_END()
34 };
35
36 static 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
58 static 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
64 static int __cmd_buildid_list(void)
65 {
66 int err = -1;
67 struct perf_session *session;
68
69 session = perf_session__new(input_name, O_RDONLY, force);
70 if (session == NULL)
71 return -1;
72
73 if (with_hits)
74 perf_session__process_events(session, &build_id_list__event_ops);
75
76 dsos__fprintf_buildid(stdout, with_hits);
77
78 perf_session__delete(session);
79 return err;
80 }
81
82 int 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 }
This page took 0.032644 seconds and 5 git commands to generate.