perf: Add cgroup support
[deliverable/linux.git] / tools / perf / util / evsel.h
CommitLineData
69aad6f1
ACM
1#ifndef __PERF_EVSEL_H
2#define __PERF_EVSEL_H 1
3
4#include <linux/list.h>
c52b12ed 5#include <stdbool.h>
d030260a 6#include "../../../include/linux/perf_event.h"
69aad6f1
ACM
7#include "types.h"
8#include "xyarray.h"
c52b12ed
ACM
9
10struct perf_counts_values {
11 union {
12 struct {
13 u64 val;
14 u64 ena;
15 u64 run;
16 };
17 u64 values[3];
18 };
19};
20
21struct perf_counts {
22 s8 scaled;
23 struct perf_counts_values aggr;
24 struct perf_counts_values cpu[];
25};
69aad6f1 26
70db7533
ACM
27struct perf_evsel;
28
29/*
30 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
31 * more than one entry in the evlist.
32 */
33struct perf_sample_id {
34 struct hlist_node node;
35 u64 id;
36 struct perf_evsel *evsel;
37};
38
69aad6f1
ACM
39struct perf_evsel {
40 struct list_head node;
41 struct perf_event_attr attr;
42 char *filter;
43 struct xyarray *fd;
70db7533 44 struct xyarray *id;
c52b12ed 45 struct perf_counts *counts;
69aad6f1
ACM
46 int idx;
47 void *priv;
48};
49
86bd5e86
ACM
50struct cpu_map;
51struct thread_map;
70082dd9 52struct perf_evlist;
86bd5e86 53
23a2f3ab 54struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
ef1d1af2
ACM
55void perf_evsel__init(struct perf_evsel *evsel,
56 struct perf_event_attr *attr, int idx);
57void perf_evsel__exit(struct perf_evsel *evsel);
69aad6f1
ACM
58void perf_evsel__delete(struct perf_evsel *evsel);
59
60int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
70db7533 61int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
c52b12ed 62int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
69aad6f1 63void perf_evsel__free_fd(struct perf_evsel *evsel);
70db7533 64void perf_evsel__free_id(struct perf_evsel *evsel);
c52b12ed 65void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
69aad6f1 66
f08199d3 67int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
9d04f178 68 struct cpu_map *cpus, bool group, bool inherit);
f08199d3 69int perf_evsel__open_per_thread(struct perf_evsel *evsel,
9d04f178 70 struct thread_map *threads, bool group, bool inherit);
f08199d3 71int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
9d04f178 72 struct thread_map *threads, bool group, bool inherit);
48290609 73
daec78a0
ACM
74#define perf_evsel__match(evsel, t, c) \
75 (evsel->attr.type == PERF_TYPE_##t && \
76 evsel->attr.config == PERF_COUNT_##c)
77
c52b12ed
ACM
78int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
79 int cpu, int thread, bool scale);
80
81/**
82 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
83 *
84 * @evsel - event selector to read value
85 * @cpu - CPU of interest
86 * @thread - thread of interest
87 */
88static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
89 int cpu, int thread)
90{
91 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
92}
93
94/**
95 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
96 *
97 * @evsel - event selector to read value
98 * @cpu - CPU of interest
99 * @thread - thread of interest
100 */
101static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
102 int cpu, int thread)
103{
104 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
105}
106
107int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
108 bool scale);
109
110/**
111 * perf_evsel__read - Read the aggregate results on all CPUs
112 *
113 * @evsel - event selector to read value
114 * @ncpus - Number of cpus affected, from zero
115 * @nthreads - Number of threads affected, from zero
116 */
117static inline int perf_evsel__read(struct perf_evsel *evsel,
118 int ncpus, int nthreads)
119{
120 return __perf_evsel__read(evsel, ncpus, nthreads, false);
121}
122
123/**
124 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
125 *
126 * @evsel - event selector to read value
127 * @ncpus - Number of cpus affected, from zero
128 * @nthreads - Number of threads affected, from zero
129 */
130static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
131 int ncpus, int nthreads)
132{
133 return __perf_evsel__read(evsel, ncpus, nthreads, true);
134}
135
69aad6f1 136#endif /* __PERF_EVSEL_H */
This page took 0.054718 seconds and 5 git commands to generate.