counts.c 1.0 KB

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