builtin-evlist.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Builtin evlist command: Show the list of event selectors present
  4. * in a perf.data file.
  5. */
  6. #include "builtin.h"
  7. #include <linux/list.h>
  8. #include "util/evlist.h"
  9. #include "util/evsel.h"
  10. #include "util/evsel_fprintf.h"
  11. #include "util/parse-events.h"
  12. #include <subcmd/parse-options.h>
  13. #include "util/session.h"
  14. #include "util/data.h"
  15. #include "util/debug.h"
  16. #include <linux/err.h>
  17. #include "util/tool.h"
  18. #include "util/util.h"
  19. static int process_header_feature(struct perf_session *session __maybe_unused,
  20. union perf_event *event __maybe_unused)
  21. {
  22. session_done = 1;
  23. return 0;
  24. }
  25. static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
  26. {
  27. struct perf_session *session;
  28. struct evsel *pos;
  29. struct perf_data data = {
  30. .path = file_name,
  31. .mode = PERF_DATA_MODE_READ,
  32. .force = details->force,
  33. };
  34. struct perf_tool tool;
  35. bool has_tracepoint = false, has_group = false;
  36. perf_tool__init(&tool, /*ordered_events=*/false);
  37. /* only needed for pipe mode */
  38. tool.attr = perf_event__process_attr;
  39. tool.feature = process_header_feature;
  40. session = perf_session__new(&data, &tool);
  41. if (IS_ERR(session))
  42. return PTR_ERR(session);
  43. if (data.is_pipe)
  44. perf_session__process_events(session);
  45. evlist__for_each_entry(session->evlist, pos) {
  46. evsel__fprintf(pos, details, stdout);
  47. if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
  48. has_tracepoint = true;
  49. if (!evsel__is_group_leader(pos))
  50. has_group = true;
  51. }
  52. if (has_tracepoint && !details->trace_fields)
  53. printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
  54. if (has_group && !details->event_group)
  55. printf("# Tip: use 'perf evlist -g' to show group information\n");
  56. perf_session__delete(session);
  57. return 0;
  58. }
  59. int cmd_evlist(int argc, const char **argv)
  60. {
  61. struct perf_attr_details details = { .verbose = false, };
  62. const struct option options[] = {
  63. OPT_STRING('i', "input", &input_name, "file", "Input file name"),
  64. OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
  65. OPT_BOOLEAN('v', "verbose", &details.verbose,
  66. "Show all event attr details"),
  67. OPT_BOOLEAN('g', "group", &details.event_group,
  68. "Show event group information"),
  69. OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
  70. OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
  71. OPT_END()
  72. };
  73. const char * const evlist_usage[] = {
  74. "perf evlist [<options>]",
  75. NULL
  76. };
  77. argc = parse_options(argc, argv, options, evlist_usage, 0);
  78. if (argc)
  79. usage_with_options(evlist_usage, options);
  80. if (details.event_group && (details.verbose || details.freq)) {
  81. usage_with_options_msg(evlist_usage, options,
  82. "--group option is not compatible with other options\n");
  83. }
  84. return __cmd_evlist(input_name, &details);
  85. }