Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 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" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 12 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 13 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 14 | #include "util/session.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 15 | #include "util/symbol.h" |
| 16 | |
| 17 | static char const *input_name = "perf.data"; |
| 18 | static int force; |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame^] | 19 | static bool with_hits; |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 20 | |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 21 | static const char * const buildid_list_usage[] = { |
Arnaldo Carvalho de Melo | b9b1e1c | 2009-12-06 18:03:10 -0200 | [diff] [blame] | 22 | "perf buildid-list [<options>]", |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 23 | NULL |
| 24 | }; |
| 25 | |
| 26 | static const struct option options[] = { |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame^] | 27 | OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"), |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 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, |
Arnaldo Carvalho de Melo | 1124ba7 | 2009-11-16 21:45:25 -0200 | [diff] [blame] | 32 | "be more verbose"), |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 33 | OPT_END() |
| 34 | }; |
| 35 | |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame^] | 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 | |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 64 | static int __cmd_buildid_list(void) |
| 65 | { |
| 66 | int err = -1; |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 67 | struct perf_session *session; |
| 68 | |
| 69 | session = perf_session__new(input_name, O_RDONLY, force); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 70 | if (session == NULL) |
| 71 | return -1; |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 72 | |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame^] | 73 | 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 Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 77 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 78 | perf_session__delete(session); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 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 | } |