builtin-evlist.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Builtin evlist command: Show the list of event selectors present
  3. * in a perf.data file.
  4. */
  5. #include "builtin.h"
  6. #include "util/util.h"
  7. #include <linux/list.h>
  8. #include "perf.h"
  9. #include "util/evlist.h"
  10. #include "util/evsel.h"
  11. #include "util/parse-events.h"
  12. #include "util/parse-options.h"
  13. #include "util/session.h"
  14. #include "util/data.h"
  15. #include "util/debug.h"
  16. static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
  17. {
  18. struct perf_session *session;
  19. struct perf_evsel *pos;
  20. struct perf_data_file file = {
  21. .path = file_name,
  22. .mode = PERF_DATA_MODE_READ,
  23. .force = details->force,
  24. };
  25. session = perf_session__new(&file, 0, NULL);
  26. if (session == NULL)
  27. return -1;
  28. evlist__for_each(session->evlist, pos)
  29. perf_evsel__fprintf(pos, details, stdout);
  30. perf_session__delete(session);
  31. return 0;
  32. }
  33. int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
  34. {
  35. struct perf_attr_details details = { .verbose = false, };
  36. const struct option options[] = {
  37. OPT_STRING('i', "input", &input_name, "file", "Input file name"),
  38. OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
  39. OPT_BOOLEAN('v', "verbose", &details.verbose,
  40. "Show all event attr details"),
  41. OPT_BOOLEAN('g', "group", &details.event_group,
  42. "Show event group information"),
  43. OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
  44. OPT_END()
  45. };
  46. const char * const evlist_usage[] = {
  47. "perf evlist [<options>]",
  48. NULL
  49. };
  50. argc = parse_options(argc, argv, options, evlist_usage, 0);
  51. if (argc)
  52. usage_with_options(evlist_usage, options);
  53. if (details.event_group && (details.verbose || details.freq)) {
  54. usage_with_options_msg(evlist_usage, options,
  55. "--group option is not compatible with other options\n");
  56. }
  57. return __cmd_evlist(input_name, &details);
  58. }