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