diff options
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r-- | tools/perf/util/evsel.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 57e4ce57bbcc..91d19138f3ec 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "cpumap.h" | 15 | #include "cpumap.h" |
16 | #include "thread_map.h" | 16 | #include "thread_map.h" |
17 | #include "target.h" | 17 | #include "target.h" |
18 | #include "../../include/linux/perf_event.h" | ||
18 | 19 | ||
19 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 20 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
20 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) | 21 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) |
@@ -64,6 +65,95 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) | |||
64 | return evsel; | 65 | return evsel; |
65 | } | 66 | } |
66 | 67 | ||
68 | static const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { | ||
69 | "cycles", | ||
70 | "instructions", | ||
71 | "cache-references", | ||
72 | "cache-misses", | ||
73 | "branches", | ||
74 | "branch-misses", | ||
75 | "bus-cycles", | ||
76 | "stalled-cycles-frontend", | ||
77 | "stalled-cycles-backend", | ||
78 | "ref-cycles", | ||
79 | }; | ||
80 | |||
81 | const char *__perf_evsel__hw_name(u64 config) | ||
82 | { | ||
83 | if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config]) | ||
84 | return perf_evsel__hw_names[config]; | ||
85 | |||
86 | return "unknown-hardware"; | ||
87 | } | ||
88 | |||
89 | static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) | ||
90 | { | ||
91 | int colon = 0; | ||
92 | struct perf_event_attr *attr = &evsel->attr; | ||
93 | int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(attr->config)); | ||
94 | bool exclude_guest_default = false; | ||
95 | |||
96 | #define MOD_PRINT(context, mod) do { \ | ||
97 | if (!attr->exclude_##context) { \ | ||
98 | if (!colon) colon = r++; \ | ||
99 | r += scnprintf(bf + r, size - r, "%c", mod); \ | ||
100 | } } while(0) | ||
101 | |||
102 | if (attr->exclude_kernel || attr->exclude_user || attr->exclude_hv) { | ||
103 | MOD_PRINT(kernel, 'k'); | ||
104 | MOD_PRINT(user, 'u'); | ||
105 | MOD_PRINT(hv, 'h'); | ||
106 | exclude_guest_default = true; | ||
107 | } | ||
108 | |||
109 | if (attr->precise_ip) { | ||
110 | if (!colon) | ||
111 | colon = r++; | ||
112 | r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); | ||
113 | exclude_guest_default = true; | ||
114 | } | ||
115 | |||
116 | if (attr->exclude_host || attr->exclude_guest == exclude_guest_default) { | ||
117 | MOD_PRINT(host, 'H'); | ||
118 | MOD_PRINT(guest, 'G'); | ||
119 | } | ||
120 | #undef MOD_PRINT | ||
121 | if (colon) | ||
122 | bf[colon] = ':'; | ||
123 | return r; | ||
124 | } | ||
125 | |||
126 | int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size) | ||
127 | { | ||
128 | int ret; | ||
129 | |||
130 | switch (evsel->attr.type) { | ||
131 | case PERF_TYPE_RAW: | ||
132 | ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config); | ||
133 | break; | ||
134 | |||
135 | case PERF_TYPE_HARDWARE: | ||
136 | ret = perf_evsel__hw_name(evsel, bf, size); | ||
137 | break; | ||
138 | default: | ||
139 | /* | ||
140 | * FIXME | ||
141 | * | ||
142 | * This is the minimal perf_evsel__name so that we can | ||
143 | * reconstruct event names taking into account event modifiers. | ||
144 | * | ||
145 | * The old event_name uses it now for raw anr hw events, so that | ||
146 | * we don't drag all the parsing stuff into the python binding. | ||
147 | * | ||
148 | * On the next devel cycle the rest of the event naming will be | ||
149 | * brought here. | ||
150 | */ | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | return ret; | ||
155 | } | ||
156 | |||
67 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | 157 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, |
68 | struct perf_evsel *first) | 158 | struct perf_evsel *first) |
69 | { | 159 | { |