builtin-evlist.c 2.1 KB

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