blob: b2d755fe88a50614da63ac4c6e674a6045ab6188 [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
27struct perf_evsel {
28 struct list_head node;
29 struct perf_event_attr attr;
30 char *filter;
31 struct xyarray *fd;
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020032 struct perf_counts *counts;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020033 int idx;
34 void *priv;
35};
36
Arnaldo Carvalho de Melo86bd5e82011-01-03 23:09:46 -020037struct cpu_map;
38struct thread_map;
39
Lin Ming23a2f3a2011-01-07 11:11:09 +080040struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020041void perf_evsel__delete(struct perf_evsel *evsel);
42
43int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020044int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020045void perf_evsel__free_fd(struct perf_evsel *evsel);
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020046void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020047
Arnaldo Carvalho de Melo86bd5e82011-01-03 23:09:46 -020048int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus);
49int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads);
50int perf_evsel__open(struct perf_evsel *evsel,
51 struct cpu_map *cpus, struct thread_map *threads);
Arnaldo Carvalho de Melo48290602011-01-03 17:48:12 -020052
Arnaldo Carvalho de Melodaec78a2011-01-03 16:49:44 -020053#define perf_evsel__match(evsel, t, c) \
54 (evsel->attr.type == PERF_TYPE_##t && \
55 evsel->attr.config == PERF_COUNT_##c)
56
Arnaldo Carvalho de Meloc52b12e2011-01-03 17:45:52 -020057int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
58 int cpu, int thread, bool scale);
59
60/**
61 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
62 *
63 * @evsel - event selector to read value
64 * @cpu - CPU of interest
65 * @thread - thread of interest
66 */
67static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
68 int cpu, int thread)
69{
70 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
71}
72
73/**
74 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
75 *
76 * @evsel - event selector to read value
77 * @cpu - CPU of interest
78 * @thread - thread of interest
79 */
80static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
81 int cpu, int thread)
82{
83 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
84}
85
86int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
87 bool scale);
88
89/**
90 * perf_evsel__read - Read the aggregate results on all CPUs
91 *
92 * @evsel - event selector to read value
93 * @ncpus - Number of cpus affected, from zero
94 * @nthreads - Number of threads affected, from zero
95 */
96static inline int perf_evsel__read(struct perf_evsel *evsel,
97 int ncpus, int nthreads)
98{
99 return __perf_evsel__read(evsel, ncpus, nthreads, false);
100}
101
102/**
103 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
104 *
105 * @evsel - event selector to read value
106 * @ncpus - Number of cpus affected, from zero
107 * @nthreads - Number of threads affected, from zero
108 */
109static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
110 int ncpus, int nthreads)
111{
112 return __perf_evsel__read(evsel, ncpus, nthreads, true);
113}
114
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200115#endif /* __PERF_EVSEL_H */