builtin-list.c 2.0 KB

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