builtin-evlist.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "perf.h"
  9. #include "util/evlist.h"
  10. #include "util/evsel.h"
  11. #include "util/evsel_fprintf.h"
  12. #include "util/parse-events.h"
  13. #include <subcmd/parse-options.h>
  14. #include "util/session.h"
  15. #include "util/data.h"
  16. #include "util/debug.h"
  17. #include <linux/err.h>
  18. #include "util/tool.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. /* only needed for pipe mode */
  36. .attr = perf_event__process_attr,
  37. .feature = process_header_feature,
  38. };
  39. bool has_tracepoint = false;
  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. }
  50. if (has_tracepoint && !details->trace_fields)
  51. printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
  52. perf_session__delete(session);
  53. return 0;
  54. }
  55. int cmd_evlist(int argc, const char **argv)
  56. {
  57. struct perf_attr_details details = { .verbose = false, };
  58. const struct option options[] = {
  59. OPT_STRING('i', "input", &input_name, "file", "Input file name"),
  60. OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
  61. OPT_BOOLEAN('v', "verbose", &details.verbose,
  62. "Show all event attr details"),
  63. OPT_BOOLEAN('g', "group", &details.event_group,
  64. "Show event group information"),
  65. OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
  66. OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
  67. OPT_END()
  68. };
  69. const char * const evlist_usage[] = {
  70. "perf evlist [<options>]",
  71. NULL
  72. };
  73. argc = parse_options(argc, argv, options, evlist_usage, 0);
  74. if (argc)
  75. usage_with_options(evlist_usage, options);
  76. if (details.event_group && (details.verbose || details.freq)) {
  77. usage_with_options_msg(evlist_usage, options,
  78. "--group option is not compatible with other options\n");
  79. }
  80. return __cmd_evlist(input_name, &details);
  81. }