counts.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include "evsel.h"
  5. #include "counts.h"
  6. #include "util.h"
  7. struct perf_counts *perf_counts__new(int ncpus, int nthreads)
  8. {
  9. struct perf_counts *counts = zalloc(sizeof(*counts));
  10. if (counts) {
  11. struct xyarray *values;
  12. values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
  13. if (!values) {
  14. free(counts);
  15. return NULL;
  16. }
  17. counts->values = values;
  18. }
  19. return counts;
  20. }
  21. void perf_counts__delete(struct perf_counts *counts)
  22. {
  23. if (counts) {
  24. xyarray__delete(counts->values);
  25. free(counts);
  26. }
  27. }
  28. static void perf_counts__reset(struct perf_counts *counts)
  29. {
  30. xyarray__reset(counts->values);
  31. }
  32. void perf_evsel__reset_counts(struct perf_evsel *evsel)
  33. {
  34. perf_counts__reset(evsel->counts);
  35. }
  36. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
  37. {
  38. evsel->counts = perf_counts__new(ncpus, nthreads);
  39. return evsel->counts != NULL ? 0 : -ENOMEM;
  40. }
  41. void perf_evsel__free_counts(struct perf_evsel *evsel)
  42. {
  43. perf_counts__delete(evsel->counts);
  44. evsel->counts = NULL;
  45. }