builtin-list.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. int cmd_list(int argc, const char **argv, const char *prefix __used)
  15. {
  16. setup_pager();
  17. if (argc == 1)
  18. print_events(NULL);
  19. else {
  20. int i;
  21. for (i = 1; i < argc; ++i) {
  22. if (i > 1)
  23. putchar('\n');
  24. if (strncmp(argv[i], "tracepoint", 10) == 0)
  25. print_tracepoint_events(NULL, NULL);
  26. else if (strcmp(argv[i], "hw") == 0 ||
  27. strcmp(argv[i], "hardware") == 0)
  28. print_events_type(PERF_TYPE_HARDWARE);
  29. else if (strcmp(argv[i], "sw") == 0 ||
  30. strcmp(argv[i], "software") == 0)
  31. print_events_type(PERF_TYPE_SOFTWARE);
  32. else if (strcmp(argv[i], "cache") == 0 ||
  33. strcmp(argv[i], "hwcache") == 0)
  34. print_hwcache_events(NULL);
  35. else {
  36. char *sep = strchr(argv[i], ':'), *s;
  37. int sep_idx;
  38. if (sep == NULL) {
  39. print_events(argv[i]);
  40. continue;
  41. }
  42. sep_idx = sep - argv[i];
  43. s = strdup(argv[i]);
  44. if (s == NULL)
  45. return -1;
  46. s[sep_idx] = '\0';
  47. print_tracepoint_events(s, s + sep_idx + 1);
  48. free(s);
  49. }
  50. }
  51. }
  52. return 0;
  53. }