builtin-evlist.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
  19. {
  20. struct perf_session *session;
  21. struct evsel *pos;
  22. struct perf_data data = {
  23. .path = file_name,
  24. .mode = PERF_DATA_MODE_READ,
  25. .force = details->force,
  26. };
  27. bool has_tracepoint = false;
  28. session = perf_session__new(&data, 0, NULL);
  29. if (IS_ERR(session))
  30. return PTR_ERR(session);
  31. evlist__for_each_entry(session->evlist, pos) {
  32. evsel__fprintf(pos, details, stdout);
  33. if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
  34. has_tracepoint = true;
  35. }
  36. if (has_tracepoint && !details->trace_fields)
  37. printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
  38. perf_session__delete(session);
  39. return 0;
  40. }
  41. int cmd_evlist(int argc, const char **argv)
  42. {
  43. struct perf_attr_details details = { .verbose = false, };
  44. const struct option options[] = {
  45. OPT_STRING('i', "input", &input_name, "file", "Input file name"),
  46. OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
  47. OPT_BOOLEAN('v', "verbose", &details.verbose,
  48. "Show all event attr details"),
  49. OPT_BOOLEAN('g', "group", &details.event_group,
  50. "Show event group information"),
  51. OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
  52. OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
  53. OPT_END()
  54. };
  55. const char * const evlist_usage[] = {
  56. "perf evlist [<options>]",
  57. NULL
  58. };
  59. argc = parse_options(argc, argv, options, evlist_usage, 0);
  60. if (argc)
  61. usage_with_options(evlist_usage, options);
  62. if (details.event_group && (details.verbose || details.freq)) {
  63. usage_with_options_msg(evlist_usage, options,
  64. "--group option is not compatible with other options\n");
  65. }
  66. return __cmd_evlist(input_name, &details);
  67. }