topdown.c 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include "pmu.h"
  4. #include "topdown.h"
  5. int topdown_filter_events(const char **attr, char **str, bool use_group)
  6. {
  7. int off = 0;
  8. int i;
  9. int len = 0;
  10. char *s;
  11. for (i = 0; attr[i]; i++) {
  12. if (pmu_have_event("cpu", attr[i])) {
  13. len += strlen(attr[i]) + 1;
  14. attr[i - off] = attr[i];
  15. } else
  16. off++;
  17. }
  18. attr[i - off] = NULL;
  19. *str = malloc(len + 1 + 2);
  20. if (!*str)
  21. return -1;
  22. s = *str;
  23. if (i - off == 0) {
  24. *s = 0;
  25. return 0;
  26. }
  27. if (use_group)
  28. *s++ = '{';
  29. for (i = 0; attr[i]; i++) {
  30. strcpy(s, attr[i]);
  31. s += strlen(s);
  32. *s++ = ',';
  33. }
  34. if (use_group) {
  35. s[-1] = '}';
  36. *s = 0;
  37. } else
  38. s[-1] = 0;
  39. return 0;
  40. }
  41. __weak bool arch_topdown_check_group(bool *warn)
  42. {
  43. *warn = false;
  44. return false;
  45. }
  46. __weak void arch_topdown_group_warn(void)
  47. {
  48. }
  49. __weak bool arch_topdown_sample_read(struct evsel *leader __maybe_unused)
  50. {
  51. return false;
  52. }