1c34984b2SArnaldo Carvalho de Melo /* 2c34984b2SArnaldo Carvalho de Melo * builtin-buildid-list.c 3c34984b2SArnaldo Carvalho de Melo * 4*f2add9cdSArnaldo Carvalho de Melo * Builtin buildid-list command: list buildids in perf.data or in the running 5*f2add9cdSArnaldo Carvalho de Melo * kernel. 6c34984b2SArnaldo Carvalho de Melo * 7c34984b2SArnaldo Carvalho de Melo * Copyright (C) 2009, Red Hat Inc. 8c34984b2SArnaldo Carvalho de Melo * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> 9c34984b2SArnaldo Carvalho de Melo */ 10c34984b2SArnaldo Carvalho de Melo #include "builtin.h" 11c34984b2SArnaldo Carvalho de Melo #include "perf.h" 127b2567c1SArnaldo Carvalho de Melo #include "util/build-id.h" 13c34984b2SArnaldo Carvalho de Melo #include "util/cache.h" 14c34984b2SArnaldo Carvalho de Melo #include "util/debug.h" 15c34984b2SArnaldo Carvalho de Melo #include "util/parse-options.h" 1694c744b6SArnaldo Carvalho de Melo #include "util/session.h" 17c34984b2SArnaldo Carvalho de Melo #include "util/symbol.h" 18c34984b2SArnaldo Carvalho de Melo 19c34984b2SArnaldo Carvalho de Melo static char const *input_name = "perf.data"; 20c0555642SIan Munsie static bool force; 21*f2add9cdSArnaldo Carvalho de Melo static bool show_kernel; 2288d3d9b7SArnaldo Carvalho de Melo static bool with_hits; 23c34984b2SArnaldo Carvalho de Melo 24c34984b2SArnaldo Carvalho de Melo static const char * const buildid_list_usage[] = { 25b9b1e1c7SArnaldo Carvalho de Melo "perf buildid-list [<options>]", 26c34984b2SArnaldo Carvalho de Melo NULL 27c34984b2SArnaldo Carvalho de Melo }; 28c34984b2SArnaldo Carvalho de Melo 29c34984b2SArnaldo Carvalho de Melo static const struct option options[] = { 3088d3d9b7SArnaldo Carvalho de Melo OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"), 31c34984b2SArnaldo Carvalho de Melo OPT_STRING('i', "input", &input_name, "file", 32c34984b2SArnaldo Carvalho de Melo "input file name"), 33c34984b2SArnaldo Carvalho de Melo OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), 34*f2add9cdSArnaldo Carvalho de Melo OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"), 35c0555642SIan Munsie OPT_INCR('v', "verbose", &verbose, 361124ba73SArnaldo Carvalho de Melo "be more verbose"), 37c34984b2SArnaldo Carvalho de Melo OPT_END() 38c34984b2SArnaldo Carvalho de Melo }; 39c34984b2SArnaldo Carvalho de Melo 40*f2add9cdSArnaldo Carvalho de Melo static int perf_session__list_build_ids(void) 41c34984b2SArnaldo Carvalho de Melo { 4275be6cf4SArnaldo Carvalho de Melo struct perf_session *session; 4375be6cf4SArnaldo Carvalho de Melo 4421ef97f0SIan Munsie session = perf_session__new(input_name, O_RDONLY, force, false, 4521ef97f0SIan Munsie &build_id__mark_dso_hit_ops); 4694c744b6SArnaldo Carvalho de Melo if (session == NULL) 4794c744b6SArnaldo Carvalho de Melo return -1; 48c34984b2SArnaldo Carvalho de Melo 4988ca895dSDave Martin if (with_hits) 507b2567c1SArnaldo Carvalho de Melo perf_session__process_events(session, &build_id__mark_dso_hit_ops); 5188d3d9b7SArnaldo Carvalho de Melo 52cbf69680SArnaldo Carvalho de Melo perf_session__fprintf_dsos_buildid(session, stdout, with_hits); 5394c744b6SArnaldo Carvalho de Melo 5494c744b6SArnaldo Carvalho de Melo perf_session__delete(session); 55bbde588bSArnaldo Carvalho de Melo return 0; 56c34984b2SArnaldo Carvalho de Melo } 57c34984b2SArnaldo Carvalho de Melo 58*f2add9cdSArnaldo Carvalho de Melo static int sysfs__fprintf_build_id(FILE *fp) 59*f2add9cdSArnaldo Carvalho de Melo { 60*f2add9cdSArnaldo Carvalho de Melo u8 kallsyms_build_id[BUILD_ID_SIZE]; 61*f2add9cdSArnaldo Carvalho de Melo char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 62*f2add9cdSArnaldo Carvalho de Melo 63*f2add9cdSArnaldo Carvalho de Melo if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, 64*f2add9cdSArnaldo Carvalho de Melo sizeof(kallsyms_build_id)) != 0) 65*f2add9cdSArnaldo Carvalho de Melo return -1; 66*f2add9cdSArnaldo Carvalho de Melo 67*f2add9cdSArnaldo Carvalho de Melo build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id), 68*f2add9cdSArnaldo Carvalho de Melo sbuild_id); 69*f2add9cdSArnaldo Carvalho de Melo fprintf(fp, "%s\n", sbuild_id); 70*f2add9cdSArnaldo Carvalho de Melo return 0; 71*f2add9cdSArnaldo Carvalho de Melo } 72*f2add9cdSArnaldo Carvalho de Melo 73*f2add9cdSArnaldo Carvalho de Melo static int __cmd_buildid_list(void) 74*f2add9cdSArnaldo Carvalho de Melo { 75*f2add9cdSArnaldo Carvalho de Melo 76*f2add9cdSArnaldo Carvalho de Melo if (show_kernel) 77*f2add9cdSArnaldo Carvalho de Melo return sysfs__fprintf_build_id(stdout); 78*f2add9cdSArnaldo Carvalho de Melo 79*f2add9cdSArnaldo Carvalho de Melo return perf_session__list_build_ids(); 80*f2add9cdSArnaldo Carvalho de Melo } 81*f2add9cdSArnaldo Carvalho de Melo 82c34984b2SArnaldo Carvalho de Melo int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) 83c34984b2SArnaldo Carvalho de Melo { 84c34984b2SArnaldo Carvalho de Melo argc = parse_options(argc, argv, options, buildid_list_usage, 0); 85c34984b2SArnaldo Carvalho de Melo setup_pager(); 86c34984b2SArnaldo Carvalho de Melo return __cmd_buildid_list(); 87c34984b2SArnaldo Carvalho de Melo } 88