builtin-buildid-list.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. static char const *input_name = "perf.data";
  17. static int force;
  18. static bool with_hits;
  19. static const char * const buildid_list_usage[] = {
  20. "perf buildid-list [<options>]",
  21. NULL
  22. };
  23. static const struct option options[] = {
  24. OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
  25. OPT_STRING('i', "input", &input_name, "file",
  26. "input file name"),
  27. OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
  28. OPT_BOOLEAN('v', "verbose", &verbose,
  29. "be more verbose"),
  30. OPT_END()
  31. };
  32. static int build_id_list__process_event(event_t *event,
  33. struct perf_session *session)
  34. {
  35. struct addr_location al;
  36. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  37. struct thread *thread = perf_session__findnew(session, event->ip.pid);
  38. if (thread == NULL) {
  39. pr_err("problem processing %d event, skipping it.\n",
  40. event->header.type);
  41. return -1;
  42. }
  43. thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
  44. event->ip.ip, &al);
  45. if (al.map != NULL)
  46. al.map->dso->hit = 1;
  47. return 0;
  48. }
  49. static struct perf_event_ops build_id_list__event_ops = {
  50. .sample = build_id_list__process_event,
  51. .mmap = event__process_mmap,
  52. .fork = event__process_task,
  53. };
  54. static int __cmd_buildid_list(void)
  55. {
  56. int err = -1;
  57. struct perf_session *session;
  58. session = perf_session__new(input_name, O_RDONLY, force);
  59. if (session == NULL)
  60. return -1;
  61. if (with_hits)
  62. perf_session__process_events(session, &build_id_list__event_ops);
  63. dsos__fprintf_buildid(stdout, with_hits);
  64. perf_session__delete(session);
  65. return err;
  66. }
  67. int cmd_buildid_list(int argc, const char **argv, const char *prefix __used)
  68. {
  69. argc = parse_options(argc, argv, options, buildid_list_usage, 0);
  70. setup_pager();
  71. return __cmd_buildid_list();
  72. }