builtin-list.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "util/parse-events.h"
  13. #include "util/pmu.h"
  14. #include "util/debug.h"
  15. #include "util/metricgroup.h"
  16. #include <subcmd/pager.h>
  17. #include <subcmd/parse-options.h>
  18. #include <stdio.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. print_tool_events(NULL, raw_dump);
  66. } else if (strcmp(argv[i], "cache") == 0 ||
  67. strcmp(argv[i], "hwcache") == 0)
  68. print_hwcache_events(NULL, raw_dump);
  69. else if (strcmp(argv[i], "pmu") == 0)
  70. print_pmu_events(NULL, raw_dump, !desc_flag,
  71. long_desc_flag, details_flag);
  72. else if (strcmp(argv[i], "sdt") == 0)
  73. print_sdt_events(NULL, NULL, raw_dump);
  74. else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0)
  75. metricgroup__print(true, false, NULL, raw_dump, details_flag);
  76. else if (strcmp(argv[i], "metricgroup") == 0 || strcmp(argv[i], "metricgroups") == 0)
  77. metricgroup__print(false, true, NULL, raw_dump, details_flag);
  78. else if ((sep = strchr(argv[i], ':')) != NULL) {
  79. int sep_idx;
  80. if (sep == NULL) {
  81. print_events(argv[i], raw_dump, !desc_flag,
  82. long_desc_flag,
  83. details_flag);
  84. continue;
  85. }
  86. sep_idx = sep - argv[i];
  87. s = strdup(argv[i]);
  88. if (s == NULL)
  89. return -1;
  90. s[sep_idx] = '\0';
  91. print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
  92. print_sdt_events(s, s + sep_idx + 1, raw_dump);
  93. metricgroup__print(true, true, s, raw_dump, details_flag);
  94. free(s);
  95. } else {
  96. if (asprintf(&s, "*%s*", argv[i]) < 0) {
  97. printf("Critical: Not enough memory! Trying to continue...\n");
  98. continue;
  99. }
  100. print_symbol_events(s, PERF_TYPE_HARDWARE,
  101. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  102. print_symbol_events(s, PERF_TYPE_SOFTWARE,
  103. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  104. print_tool_events(s, raw_dump);
  105. print_hwcache_events(s, raw_dump);
  106. print_pmu_events(s, raw_dump, !desc_flag,
  107. long_desc_flag,
  108. details_flag);
  109. print_tracepoint_events(NULL, s, raw_dump);
  110. print_sdt_events(NULL, s, raw_dump);
  111. metricgroup__print(true, true, s, raw_dump, details_flag);
  112. free(s);
  113. }
  114. }
  115. return 0;
  116. }