builtin-list.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <[email protected]>
  8. * Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <[email protected]>
  9. * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]>
  10. */
  11. #include "builtin.h"
  12. #include "util/print-events.h"
  13. #include "util/pmu.h"
  14. #include "util/pmu-hybrid.h"
  15. #include "util/debug.h"
  16. #include "util/metricgroup.h"
  17. #include <subcmd/pager.h>
  18. #include <subcmd/parse-options.h>
  19. #include <stdio.h>
  20. static bool desc_flag = true;
  21. static bool details_flag;
  22. static const char *hybrid_type;
  23. int cmd_list(int argc, const char **argv)
  24. {
  25. int i, ret = 0;
  26. bool raw_dump = false;
  27. bool long_desc_flag = false;
  28. bool deprecated = false;
  29. char *pmu_name = NULL;
  30. struct option list_options[] = {
  31. OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
  32. OPT_BOOLEAN('d', "desc", &desc_flag,
  33. "Print extra event descriptions. --no-desc to not print."),
  34. OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
  35. "Print longer event descriptions."),
  36. OPT_BOOLEAN(0, "details", &details_flag,
  37. "Print information on the perf event names and expressions used internally by events."),
  38. OPT_BOOLEAN(0, "deprecated", &deprecated,
  39. "Print deprecated events."),
  40. OPT_STRING(0, "cputype", &hybrid_type, "hybrid cpu type",
  41. "Print events applying cpu with this type for hybrid platform "
  42. "(e.g. core or atom)"),
  43. OPT_INCR(0, "debug", &verbose,
  44. "Enable debugging output"),
  45. OPT_END()
  46. };
  47. const char * const list_usage[] = {
  48. "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
  49. NULL
  50. };
  51. set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
  52. argc = parse_options(argc, argv, list_options, list_usage,
  53. PARSE_OPT_STOP_AT_NON_OPTION);
  54. setup_pager();
  55. if (!raw_dump && pager_in_use())
  56. printf("\nList of pre-defined events (to be used in -e or -M):\n\n");
  57. if (hybrid_type) {
  58. pmu_name = perf_pmu__hybrid_type_to_pmu(hybrid_type);
  59. if (!pmu_name)
  60. pr_warning("WARNING: hybrid cputype is not supported!\n");
  61. }
  62. if (argc == 0) {
  63. print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
  64. details_flag, deprecated, pmu_name);
  65. goto out;
  66. }
  67. for (i = 0; i < argc; ++i) {
  68. char *sep, *s;
  69. if (strcmp(argv[i], "tracepoint") == 0)
  70. print_tracepoint_events(NULL, NULL, raw_dump);
  71. else if (strcmp(argv[i], "hw") == 0 ||
  72. strcmp(argv[i], "hardware") == 0)
  73. print_symbol_events(NULL, PERF_TYPE_HARDWARE,
  74. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  75. else if (strcmp(argv[i], "sw") == 0 ||
  76. strcmp(argv[i], "software") == 0) {
  77. print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
  78. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  79. print_tool_events(NULL, raw_dump);
  80. } else if (strcmp(argv[i], "cache") == 0 ||
  81. strcmp(argv[i], "hwcache") == 0)
  82. print_hwcache_events(NULL, raw_dump);
  83. else if (strcmp(argv[i], "pmu") == 0)
  84. print_pmu_events(NULL, raw_dump, !desc_flag,
  85. long_desc_flag, details_flag,
  86. deprecated, pmu_name);
  87. else if (strcmp(argv[i], "sdt") == 0)
  88. print_sdt_events(NULL, NULL, raw_dump);
  89. else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0)
  90. metricgroup__print(true, false, NULL, raw_dump, details_flag, pmu_name);
  91. else if (strcmp(argv[i], "metricgroup") == 0 || strcmp(argv[i], "metricgroups") == 0)
  92. metricgroup__print(false, true, NULL, raw_dump, details_flag, pmu_name);
  93. else if ((sep = strchr(argv[i], ':')) != NULL) {
  94. int sep_idx;
  95. sep_idx = sep - argv[i];
  96. s = strdup(argv[i]);
  97. if (s == NULL) {
  98. ret = -1;
  99. goto out;
  100. }
  101. s[sep_idx] = '\0';
  102. print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
  103. print_sdt_events(s, s + sep_idx + 1, raw_dump);
  104. metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name);
  105. free(s);
  106. } else {
  107. if (asprintf(&s, "*%s*", argv[i]) < 0) {
  108. printf("Critical: Not enough memory! Trying to continue...\n");
  109. continue;
  110. }
  111. print_symbol_events(s, PERF_TYPE_HARDWARE,
  112. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  113. print_symbol_events(s, PERF_TYPE_SOFTWARE,
  114. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  115. print_tool_events(s, raw_dump);
  116. print_hwcache_events(s, raw_dump);
  117. print_pmu_events(s, raw_dump, !desc_flag,
  118. long_desc_flag,
  119. details_flag,
  120. deprecated,
  121. pmu_name);
  122. print_tracepoint_events(NULL, s, raw_dump);
  123. print_sdt_events(NULL, s, raw_dump);
  124. metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name);
  125. free(s);
  126. }
  127. }
  128. out:
  129. free(pmu_name);
  130. return ret;
  131. }