builtin-evlist.c 2.1 KB

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