builtin-list.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * builtin-list.c
  4. *
  5. * Builtin list command: list all event types
  6. *
  7. * Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de>
  8. * Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
  9. * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
  10. */
  11. #include "builtin.h"
  12. #include "perf.h"
  13. #include "util/parse-events.h"
  14. #include "util/cache.h"
  15. #include "util/pmu.h"
  16. #include "util/debug.h"
  17. #include "util/metricgroup.h"
  18. #include <subcmd/parse-options.h>
  19. static bool desc_flag = true;
  20. static bool details_flag;
  21. int cmd_list(int argc, const char **argv)
  22. {
  23. int i;
  24. bool raw_dump = false;
  25. bool long_desc_flag = false;
  26. struct option list_options[] = {
  27. OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
  28. OPT_BOOLEAN('d', "desc", &desc_flag,
  29. "Print extra event descriptions. --no-desc to not print."),
  30. OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
  31. "Print longer event descriptions."),
  32. OPT_BOOLEAN(0, "details", &details_flag,
  33. "Print information on the perf event names and expressions used internally by events."),
  34. OPT_INCR(0, "debug", &verbose,
  35. "Enable debugging output"),
  36. OPT_END()
  37. };
  38. const char * const list_usage[] = {
  39. "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
  40. NULL
  41. };
  42. set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
  43. argc = parse_options(argc, argv, list_options, list_usage,
  44. PARSE_OPT_STOP_AT_NON_OPTION);
  45. setup_pager();
  46. if (!raw_dump && pager_in_use())
  47. printf("\nList of pre-defined events (to be used in -e):\n\n");
  48. if (argc == 0) {
  49. print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
  50. details_flag);
  51. return 0;
  52. }
  53. for (i = 0; i < argc; ++i) {
  54. char *sep, *s;
  55. if (strcmp(argv[i], "tracepoint") == 0)
  56. print_tracepoint_events(NULL, NULL, raw_dump);
  57. else if (strcmp(argv[i], "hw") == 0 ||
  58. strcmp(argv[i], "hardware") == 0)
  59. print_symbol_events(NULL, PERF_TYPE_HARDWARE,
  60. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  61. else if (strcmp(argv[i], "sw") == 0 ||
  62. strcmp(argv[i], "software") == 0)
  63. print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
  64. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  65. else if (strcmp(argv[i], "cache") == 0 ||
  66. strcmp(argv[i], "hwcache") == 0)
  67. print_hwcache_events(NULL, raw_dump);
  68. else if (strcmp(argv[i], "pmu") == 0)
  69. print_pmu_events(NULL, raw_dump, !desc_flag,
  70. long_desc_flag, details_flag);
  71. else if (strcmp(argv[i], "sdt") == 0)
  72. print_sdt_events(NULL, NULL, raw_dump);
  73. else if (strcmp(argv[i], "metric") == 0)
  74. metricgroup__print(true, false, NULL, raw_dump);
  75. else if (strcmp(argv[i], "metricgroup") == 0)
  76. metricgroup__print(false, true, NULL, raw_dump);
  77. else if ((sep = strchr(argv[i], ':')) != NULL) {
  78. int sep_idx;
  79. if (sep == NULL) {
  80. print_events(argv[i], raw_dump, !desc_flag,
  81. long_desc_flag,
  82. details_flag);
  83. continue;
  84. }
  85. sep_idx = sep - argv[i];
  86. s = strdup(argv[i]);
  87. if (s == NULL)
  88. return -1;
  89. s[sep_idx] = '\0';
  90. print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
  91. print_sdt_events(s, s + sep_idx + 1, raw_dump);
  92. metricgroup__print(true, true, s, raw_dump);
  93. free(s);
  94. } else {
  95. if (asprintf(&s, "*%s*", argv[i]) < 0) {
  96. printf("Critical: Not enough memory! Trying to continue...\n");
  97. continue;
  98. }
  99. print_symbol_events(s, PERF_TYPE_HARDWARE,
  100. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  101. print_symbol_events(s, PERF_TYPE_SOFTWARE,
  102. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  103. print_hwcache_events(s, raw_dump);
  104. print_pmu_events(s, raw_dump, !desc_flag,
  105. long_desc_flag,
  106. details_flag);
  107. print_tracepoint_events(NULL, s, raw_dump);
  108. print_sdt_events(NULL, s, raw_dump);
  109. metricgroup__print(true, true, NULL, raw_dump);
  110. free(s);
  111. }
  112. }
  113. return 0;
  114. }