builtin-list.c 3.1 KB

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