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" |
Arnaldo Carvalho de Melo | 7b2567c | 2010-02-03 16:52:04 -0200 | [diff] [blame] | 11 | #include "util/build-id.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 12 | #include "util/cache.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 13 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 14 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 15 | #include "util/session.h" |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 16 | #include "util/symbol.h" |
| 17 | |
| 18 | static char const *input_name = "perf.data"; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 19 | static bool force; |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame] | 20 | static bool with_hits; |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 21 | |
Arnaldo Carvalho de Melo | 0422a4f | 2009-12-18 16:35:58 -0200 | [diff] [blame] | 22 | static const char * const buildid_list_usage[] = { |
Arnaldo Carvalho de Melo | b9b1e1c | 2009-12-06 18:03:10 -0200 | [diff] [blame] | 23 | "perf buildid-list [<options>]", |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 24 | NULL |
| 25 | }; |
| 26 | |
| 27 | static const struct option options[] = { |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame] | 28 | 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] | 29 | OPT_STRING('i', "input", &input_name, "file", |
| 30 | "input file name"), |
| 31 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 32 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | 1124ba7 | 2009-11-16 21:45:25 -0200 | [diff] [blame] | 33 | "be more verbose"), |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 34 | OPT_END() |
| 35 | }; |
| 36 | |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 37 | static int __cmd_buildid_list(void) |
| 38 | { |
| 39 | int err = -1; |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 40 | struct perf_session *session; |
| 41 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 42 | session = perf_session__new(input_name, O_RDONLY, force, false); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 43 | if (session == NULL) |
| 44 | return -1; |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 45 | |
Arnaldo Carvalho de Melo | b5c874f | 2010-06-01 12:37:05 -0300 | [diff] [blame] | 46 | if (with_hits) { |
| 47 | symbol_conf.full_paths = true; |
Arnaldo Carvalho de Melo | 7b2567c | 2010-02-03 16:52:04 -0200 | [diff] [blame] | 48 | perf_session__process_events(session, &build_id__mark_dso_hit_ops); |
Arnaldo Carvalho de Melo | b5c874f | 2010-06-01 12:37:05 -0300 | [diff] [blame] | 49 | } |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame] | 50 | |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 51 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 52 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 53 | perf_session__delete(session); |
Arnaldo Carvalho de Melo | c34984b | 2009-11-16 16:32:45 -0200 | [diff] [blame] | 54 | return err; |
| 55 | } |
| 56 | |
| 57 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) |
| 58 | { |
| 59 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); |
| 60 | setup_pager(); |
| 61 | return __cmd_buildid_list(); |
| 62 | } |