Linux Audio

Check our new training course

Loading...
v4.17
 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
 8struct perf_counts *perf_counts__new(int ncpus, int nthreads)
 9{
10	struct perf_counts *counts = zalloc(sizeof(*counts));
11
12	if (counts) {
13		struct xyarray *values;
14
15		values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
16		if (!values) {
17			free(counts);
18			return NULL;
19		}
20
21		counts->values = values;
 
 
 
 
 
 
 
 
 
22	}
23
24	return counts;
25}
26
27void perf_counts__delete(struct perf_counts *counts)
28{
29	if (counts) {
 
30		xyarray__delete(counts->values);
31		free(counts);
32	}
33}
34
35static void perf_counts__reset(struct perf_counts *counts)
36{
 
37	xyarray__reset(counts->values);
38}
39
40void perf_evsel__reset_counts(struct perf_evsel *evsel)
41{
42	perf_counts__reset(evsel->counts);
43}
44
45int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
46{
47	evsel->counts = perf_counts__new(ncpus, nthreads);
 
 
 
48	return evsel->counts != NULL ? 0 : -ENOMEM;
49}
50
51void perf_evsel__free_counts(struct perf_evsel *evsel)
52{
53	perf_counts__delete(evsel->counts);
54	evsel->counts = NULL;
55}
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2#include <errno.h>
 3#include <stdlib.h>
 4#include <string.h>
 5#include "evsel.h"
 6#include "counts.h"
 7#include <perf/threadmap.h>
 8#include <linux/zalloc.h>
 9
10struct perf_counts *perf_counts__new(int ncpus, int nthreads)
11{
12	struct perf_counts *counts = zalloc(sizeof(*counts));
13
14	if (counts) {
15		struct xyarray *values;
16
17		values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
18		if (!values) {
19			free(counts);
20			return NULL;
21		}
22
23		counts->values = values;
24
25		values = xyarray__new(ncpus, nthreads, sizeof(bool));
26		if (!values) {
27			xyarray__delete(counts->values);
28			free(counts);
29			return NULL;
30		}
31
32		counts->loaded = values;
33	}
34
35	return counts;
36}
37
38void perf_counts__delete(struct perf_counts *counts)
39{
40	if (counts) {
41		xyarray__delete(counts->loaded);
42		xyarray__delete(counts->values);
43		free(counts);
44	}
45}
46
47void perf_counts__reset(struct perf_counts *counts)
48{
49	xyarray__reset(counts->loaded);
50	xyarray__reset(counts->values);
51}
52
53void evsel__reset_counts(struct evsel *evsel)
54{
55	perf_counts__reset(evsel->counts);
56}
57
58int evsel__alloc_counts(struct evsel *evsel)
59{
60	struct perf_cpu_map *cpus = evsel__cpus(evsel);
61	int nthreads = perf_thread_map__nr(evsel->core.threads);
62
63	evsel->counts = perf_counts__new(perf_cpu_map__nr(cpus), nthreads);
64	return evsel->counts != NULL ? 0 : -ENOMEM;
65}
66
67void evsel__free_counts(struct evsel *evsel)
68{
69	perf_counts__delete(evsel->counts);
70	evsel->counts = NULL;
71}