builtin-list.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "util/parse-options.h"
  16. int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
  17. {
  18. int i;
  19. bool raw_dump = false;
  20. struct option list_options[] = {
  21. OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
  22. OPT_END()
  23. };
  24. const char * const list_usage[] = {
  25. "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
  26. NULL
  27. };
  28. set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
  29. argc = parse_options(argc, argv, list_options, list_usage,
  30. PARSE_OPT_STOP_AT_NON_OPTION);
  31. setup_pager();
  32. if (!raw_dump && pager_in_use())
  33. printf("\nList of pre-defined events (to be used in -e):\n\n");
  34. if (argc == 0) {
  35. print_events(NULL, raw_dump);
  36. return 0;
  37. }
  38. for (i = 0; i < argc; ++i) {
  39. char *sep, *s;
  40. if (strcmp(argv[i], "tracepoint") == 0)
  41. print_tracepoint_events(NULL, NULL, raw_dump);
  42. else if (strcmp(argv[i], "hw") == 0 ||
  43. strcmp(argv[i], "hardware") == 0)
  44. print_symbol_events(NULL, PERF_TYPE_HARDWARE,
  45. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  46. else if (strcmp(argv[i], "sw") == 0 ||
  47. strcmp(argv[i], "software") == 0)
  48. print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
  49. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  50. else if (strcmp(argv[i], "cache") == 0 ||
  51. strcmp(argv[i], "hwcache") == 0)
  52. print_hwcache_events(NULL, raw_dump);
  53. else if (strcmp(argv[i], "pmu") == 0)
  54. print_pmu_events(NULL, raw_dump);
  55. else if ((sep = strchr(argv[i], ':')) != NULL) {
  56. int sep_idx;
  57. if (sep == NULL) {
  58. print_events(argv[i], raw_dump);
  59. continue;
  60. }
  61. sep_idx = sep - argv[i];
  62. s = strdup(argv[i]);
  63. if (s == NULL)
  64. return -1;
  65. s[sep_idx] = '\0';
  66. print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
  67. free(s);
  68. } else {
  69. if (asprintf(&s, "*%s*", argv[i]) < 0) {
  70. printf("Critical: Not enough memory! Trying to continue...\n");
  71. continue;
  72. }
  73. print_symbol_events(s, PERF_TYPE_HARDWARE,
  74. event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
  75. print_symbol_events(s, PERF_TYPE_SOFTWARE,
  76. event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
  77. print_hwcache_events(s, raw_dump);
  78. print_pmu_events(s, raw_dump);
  79. print_tracepoint_events(NULL, s, raw_dump);
  80. free(s);
  81. }
  82. }
  83. return 0;
  84. }