blob: eecdc3aabc147062300730589ffbd41d37c201ce [file] [log] [blame]
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -02001#ifndef __PERF_EVSEL_H
2#define __PERF_EVSEL_H 1
3
4#include <linux/list.h>
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -02005#include <stdbool.h>
Stephane Eraniand0302602011-01-04 16:30:01 +02006#include "../../../include/linux/perf_event.h"
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -02007#include "types.h"
8#include "xyarray.h"
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -02009
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};
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020026
Arnaldo Carvalho de Melo70db7532011-01-12 22:39:13 -020027struct 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
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020039struct perf_evsel {
40 struct list_head node;
41 struct perf_event_attr attr;
42 char *filter;
43 struct xyarray *fd;
Arnaldo Carvalho de Melo70db7532011-01-12 22:39:13 -020044 struct xyarray *id;
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020045 struct perf_counts *counts;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020046 int idx;
47 void *priv;
48};
49
Arnaldo Carvalho de Melo86bd5e82011-01-03 23:09:46 -020050struct cpu_map;
51struct thread_map;
Arnaldo Carvalho de Melo70082dd2011-01-12 17:03:24 -020052struct perf_evlist;
Arnaldo Carvalho de Melo86bd5e82011-01-03 23:09:46 -020053
Lin Ming23a2f3a2011-01-07 11:11:09 +080054struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
Arnaldo Carvalho de Meloef1d1af2011-01-18 21:41:45 -020055void perf_evsel__init(struct perf_evsel *evsel,
56 struct perf_event_attr *attr, int idx);
57void perf_evsel__exit(struct perf_evsel *evsel);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020058void perf_evsel__delete(struct perf_evsel *evsel);
59
60int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
Arnaldo Carvalho de Melo70db7532011-01-12 22:39:13 -020061int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020062int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020063void perf_evsel__free_fd(struct perf_evsel *evsel);
Arnaldo Carvalho de Melo70db7532011-01-12 22:39:13 -020064void perf_evsel__free_id(struct perf_evsel *evsel);
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020065void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020066
Arnaldo Carvalho de Melof08199d2011-01-11 23:42:19 -020067int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
Arnaldo Carvalho de Melo9d04f172011-01-12 00:08:18 -020068 struct cpu_map *cpus, bool group, bool inherit);
Arnaldo Carvalho de Melof08199d2011-01-11 23:42:19 -020069int perf_evsel__open_per_thread(struct perf_evsel *evsel,
Arnaldo Carvalho de Melo9d04f172011-01-12 00:08:18 -020070 struct thread_map *threads, bool group, bool inherit);
Arnaldo Carvalho de Melof08199d2011-01-11 23:42:19 -020071int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
Arnaldo Carvalho de Melo9d04f172011-01-12 00:08:18 -020072 struct thread_map *threads, bool group, bool inherit);
Arnaldo Carvalho de Melo48290602011-01-03 17:48:12 -020073
Arnaldo Carvalho de Melodaec78a2011-01-03 16:49:44 -020074#define perf_evsel__match(evsel, t, c) \
75 (evsel->attr.type == PERF_TYPE_##t && \
76 evsel->attr.config == PERF_COUNT_##c)
77
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020078int __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
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200136#endif /* __PERF_EVSEL_H */