builtin-evlist.c 2.2 KB

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