builtin-list.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. const struct option list_options[] = {
  20. OPT_END()
  21. };
  22. const char * const list_usage[] = {
  23. "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
  24. NULL
  25. };
  26. argc = parse_options(argc, argv, list_options, list_usage,
  27. PARSE_OPT_STOP_AT_NON_OPTION);
  28. setup_pager();
  29. if (argc == 0) {
  30. print_events(NULL, false);
  31. return 0;
  32. }
  33. for (i = 0; i < argc; ++i) {
  34. if (i)
  35. putchar('\n');
  36. if (strncmp(argv[i], "tracepoint", 10) == 0)
  37. print_tracepoint_events(NULL, NULL, false);
  38. else if (strcmp(argv[i], "hw") == 0 ||
  39. strcmp(argv[i], "hardware") == 0)
  40. print_events_type(PERF_TYPE_HARDWARE);
  41. else if (strcmp(argv[i], "sw") == 0 ||
  42. strcmp(argv[i], "software") == 0)
  43. print_events_type(PERF_TYPE_SOFTWARE);
  44. else if (strcmp(argv[i], "cache") == 0 ||
  45. strcmp(argv[i], "hwcache") == 0)
  46. print_hwcache_events(NULL, false);
  47. else if (strcmp(argv[i], "pmu") == 0)
  48. print_pmu_events(NULL, false);
  49. else if (strcmp(argv[i], "--raw-dump") == 0)
  50. print_events(NULL, true);
  51. else {
  52. char *sep = strchr(argv[i], ':'), *s;
  53. int sep_idx;
  54. if (sep == NULL) {
  55. print_events(argv[i], false);
  56. continue;
  57. }
  58. sep_idx = sep - argv[i];
  59. s = strdup(argv[i]);
  60. if (s == NULL)
  61. return -1;
  62. s[sep_idx] = '\0';
  63. print_tracepoint_events(s, s + sep_idx + 1, false);
  64. free(s);
  65. }
  66. }
  67. return 0;
  68. }