Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1 | #ifndef __PERF_EVSEL_H |
| 2 | #define __PERF_EVSEL_H 1 |
| 3 | |
| 4 | #include <linux/list.h> |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 5 | #include <stdbool.h> |
Stephane Eranian | d030260 | 2011-01-04 16:30:01 +0200 | [diff] [blame] | 6 | #include "../../../include/linux/perf_event.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 7 | #include "types.h" |
| 8 | #include "xyarray.h" |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 9 | |
| 10 | struct perf_counts_values { |
| 11 | union { |
| 12 | struct { |
| 13 | u64 val; |
| 14 | u64 ena; |
| 15 | u64 run; |
| 16 | }; |
| 17 | u64 values[3]; |
| 18 | }; |
| 19 | }; |
| 20 | |
| 21 | struct perf_counts { |
| 22 | s8 scaled; |
| 23 | struct perf_counts_values aggr; |
| 24 | struct perf_counts_values cpu[]; |
| 25 | }; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 26 | |
| 27 | struct perf_evsel { |
| 28 | struct list_head node; |
| 29 | struct perf_event_attr attr; |
| 30 | char *filter; |
| 31 | struct xyarray *fd; |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 32 | struct perf_counts *counts; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 33 | int idx; |
| 34 | void *priv; |
| 35 | }; |
| 36 | |
Arnaldo Carvalho de Melo | 86bd5e8 | 2011-01-03 23:09:46 -0200 | [diff] [blame] | 37 | struct cpu_map; |
| 38 | struct thread_map; |
| 39 | |
Lin Ming | 23a2f3a | 2011-01-07 11:11:09 +0800 | [diff] [blame] | 40 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 41 | void perf_evsel__delete(struct perf_evsel *evsel); |
| 42 | |
| 43 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 44 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 45 | void perf_evsel__free_fd(struct perf_evsel *evsel); |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 46 | void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 47 | |
Arnaldo Carvalho de Melo | 86bd5e8 | 2011-01-03 23:09:46 -0200 | [diff] [blame] | 48 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus); |
| 49 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads); |
| 50 | int perf_evsel__open(struct perf_evsel *evsel, |
| 51 | struct cpu_map *cpus, struct thread_map *threads); |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 52 | |
Arnaldo Carvalho de Melo | daec78a | 2011-01-03 16:49:44 -0200 | [diff] [blame] | 53 | #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 Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 57 | int __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 | */ |
| 67 | static 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 | */ |
| 80 | static 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 | |
| 86 | int __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 | */ |
| 96 | static 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 | */ |
| 109 | static 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 Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 115 | #endif /* __PERF_EVSEL_H */ |