builtin-list.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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) {
  33. print_events(NULL, true);
  34. return 0;
  35. }
  36. if (argc == 0) {
  37. print_events(NULL, false);
  38. return 0;
  39. }
  40. for (i = 0; i < argc; ++i) {
  41. if (i)
  42. putchar('\n');
  43. if (strncmp(argv[i], "tracepoint", 10) == 0)
  44. print_tracepoint_events(NULL, NULL, false);
  45. else if (strcmp(argv[i], "hw") == 0 ||
  46. strcmp(argv[i], "hardware") == 0)
  47. print_events_type(PERF_TYPE_HARDWARE);
  48. else if (strcmp(argv[i], "sw") == 0 ||
  49. strcmp(argv[i], "software") == 0)
  50. print_events_type(PERF_TYPE_SOFTWARE);
  51. else if (strcmp(argv[i], "cache") == 0 ||
  52. strcmp(argv[i], "hwcache") == 0)
  53. print_hwcache_events(NULL, false);
  54. else if (strcmp(argv[i], "pmu") == 0)
  55. print_pmu_events(NULL, false);
  56. else {
  57. char *sep = strchr(argv[i], ':'), *s;
  58. int sep_idx;
  59. if (sep == NULL) {
  60. print_events(argv[i], false);
  61. continue;
  62. }
  63. sep_idx = sep - argv[i];
  64. s = strdup(argv[i]);
  65. if (s == NULL)
  66. return -1;
  67. s[sep_idx] = '\0';
  68. print_tracepoint_events(s, s + sep_idx + 1, false);
  69. free(s);
  70. }
  71. }
  72. return 0;
  73. }