Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
a43783ae | 2 | #include <errno.h> |
fd20e811 | 3 | #include <inttypes.h> |
1eae20c1 | 4 | #include <regex.h> |
6769e98d | 5 | #include <linux/mman.h> |
3723908d | 6 | #include <linux/time64.h> |
dd68ada2 | 7 | #include "sort.h" |
8a6c5b26 | 8 | #include "hist.h" |
4dfced35 | 9 | #include "comm.h" |
1101f69a | 10 | #include "map.h" |
08e71542 | 11 | #include "symbol.h" |
e7ff8920 | 12 | #include "thread.h" |
8b536999 | 13 | #include "evsel.h" |
40184c46 | 14 | #include "evlist.h" |
8ec20b17 | 15 | #include "strlist.h" |
40184c46 | 16 | #include <traceevent/event-parse.h> |
0c877d75 | 17 | #include "mem-events.h" |
ec6ae74f | 18 | #include "annotate.h" |
3723908d | 19 | #include "time-utils.h" |
877a7a11 | 20 | #include <linux/kernel.h> |
dd68ada2 JK |
21 | |
22 | regex_t parent_regex; | |
edb7c60e ACM |
23 | const char default_parent_pattern[] = "^sys_|^do_page_fault"; |
24 | const char *parent_pattern = default_parent_pattern; | |
fa1f4565 | 25 | const char *default_sort_order = "comm,dso,symbol"; |
40997d6c | 26 | const char default_branch_sort_order[] = "comm,dso_from,symbol_from,symbol_to,cycles"; |
512ae1bd NK |
27 | const char default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked"; |
28 | const char default_top_sort_order[] = "dso,symbol"; | |
29 | const char default_diff_sort_order[] = "dso,symbol"; | |
d49dadea | 30 | const char default_tracepoint_sort_order[] = "trace"; |
512ae1bd | 31 | const char *sort_order; |
a7d945bc | 32 | const char *field_order; |
b21484f1 GP |
33 | regex_t ignore_callees_regex; |
34 | int have_ignore_callees = 0; | |
55369fc1 | 35 | enum sort_mode sort__mode = SORT_MODE__NORMAL; |
a4fb581b | 36 | |
37d9bb58 ACM |
37 | /* |
38 | * Replaces all occurrences of a char used with the: | |
39 | * | |
40 | * -t, --field-separator | |
41 | * | |
42 | * option, that uses a special separator character and don't pad with spaces, | |
adba1634 | 43 | * replacing all occurrences of this separator in symbol names (and other |
37d9bb58 ACM |
44 | * output) with a '.' character, that thus it's the only non valid separator. |
45 | */ | |
a4e3b956 | 46 | static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) |
dd68ada2 JK |
47 | { |
48 | int n; | |
49 | va_list ap; | |
50 | ||
51 | va_start(ap, fmt); | |
a4e3b956 | 52 | n = vsnprintf(bf, size, fmt, ap); |
0ca0c130 | 53 | if (symbol_conf.field_sep && n > 0) { |
a4e3b956 ACM |
54 | char *sep = bf; |
55 | ||
56 | while (1) { | |
0ca0c130 | 57 | sep = strchr(sep, *symbol_conf.field_sep); |
a4e3b956 ACM |
58 | if (sep == NULL) |
59 | break; | |
60 | *sep = '.'; | |
dd68ada2 | 61 | } |
dd68ada2 JK |
62 | } |
63 | va_end(ap); | |
b832796c AB |
64 | |
65 | if (n >= (int)size) | |
66 | return size - 1; | |
dd68ada2 JK |
67 | return n; |
68 | } | |
69 | ||
b9c5143a | 70 | static int64_t cmp_null(const void *l, const void *r) |
872a878f FW |
71 | { |
72 | if (!l && !r) | |
73 | return 0; | |
74 | else if (!l) | |
75 | return -1; | |
76 | else | |
77 | return 1; | |
78 | } | |
79 | ||
80 | /* --sort pid */ | |
81 | ||
82 | static int64_t | |
83 | sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) | |
84 | { | |
38051234 | 85 | return right->thread->tid - left->thread->tid; |
872a878f FW |
86 | } |
87 | ||
c824c433 | 88 | static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, |
a4e3b956 | 89 | size_t size, unsigned int width) |
dd68ada2 | 90 | { |
b9c5143a | 91 | const char *comm = thread__comm_str(he->thread); |
5b591669 | 92 | |
89c7cb2c JO |
93 | width = max(7U, width) - 8; |
94 | return repsep_snprintf(bf, size, "%7d:%-*.*s", he->thread->tid, | |
5b591669 | 95 | width, width, comm ?: ""); |
dd68ada2 JK |
96 | } |
97 | ||
54430101 NK |
98 | static int hist_entry__thread_filter(struct hist_entry *he, int type, const void *arg) |
99 | { | |
100 | const struct thread *th = arg; | |
101 | ||
102 | if (type != HIST_FILTER__THREAD) | |
103 | return -1; | |
104 | ||
105 | return th && he->thread != th; | |
106 | } | |
107 | ||
872a878f | 108 | struct sort_entry sort_thread = { |
89c7cb2c | 109 | .se_header = " Pid:Command", |
872a878f FW |
110 | .se_cmp = sort__thread_cmp, |
111 | .se_snprintf = hist_entry__thread_snprintf, | |
54430101 | 112 | .se_filter = hist_entry__thread_filter, |
872a878f FW |
113 | .se_width_idx = HISTC_THREAD, |
114 | }; | |
115 | ||
116 | /* --sort comm */ | |
117 | ||
a7402c94 JO |
118 | /* |
119 | * We can't use pointer comparison in functions below, | |
120 | * because it gives different results based on pointer | |
121 | * values, which could break some sorting assumptions. | |
122 | */ | |
872a878f FW |
123 | static int64_t |
124 | sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) | |
125 | { | |
2f15bd8c | 126 | return strcmp(comm__str(right->comm), comm__str(left->comm)); |
872a878f FW |
127 | } |
128 | ||
129 | static int64_t | |
130 | sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) | |
131 | { | |
2f15bd8c | 132 | return strcmp(comm__str(right->comm), comm__str(left->comm)); |
872a878f FW |
133 | } |
134 | ||
202e7a6d NK |
135 | static int64_t |
136 | sort__comm_sort(struct hist_entry *left, struct hist_entry *right) | |
137 | { | |
138 | return strcmp(comm__str(right->comm), comm__str(left->comm)); | |
139 | } | |
140 | ||
c824c433 | 141 | static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, |
a4e3b956 | 142 | size_t size, unsigned int width) |
dd68ada2 | 143 | { |
5b591669 | 144 | return repsep_snprintf(bf, size, "%-*.*s", width, width, comm__str(he->comm)); |
dd68ada2 JK |
145 | } |
146 | ||
14d1ac74 NK |
147 | struct sort_entry sort_comm = { |
148 | .se_header = "Command", | |
149 | .se_cmp = sort__comm_cmp, | |
150 | .se_collapse = sort__comm_collapse, | |
202e7a6d | 151 | .se_sort = sort__comm_sort, |
14d1ac74 | 152 | .se_snprintf = hist_entry__comm_snprintf, |
54430101 | 153 | .se_filter = hist_entry__thread_filter, |
14d1ac74 NK |
154 | .se_width_idx = HISTC_COMM, |
155 | }; | |
156 | ||
157 | /* --sort dso */ | |
158 | ||
b5387528 RAV |
159 | static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r) |
160 | { | |
161 | struct dso *dso_l = map_l ? map_l->dso : NULL; | |
162 | struct dso *dso_r = map_r ? map_r->dso : NULL; | |
163 | const char *dso_name_l, *dso_name_r; | |
164 | ||
165 | if (!dso_l || !dso_r) | |
202e7a6d | 166 | return cmp_null(dso_r, dso_l); |
b5387528 | 167 | |
bb963e16 | 168 | if (verbose > 0) { |
b5387528 RAV |
169 | dso_name_l = dso_l->long_name; |
170 | dso_name_r = dso_r->long_name; | |
171 | } else { | |
172 | dso_name_l = dso_l->short_name; | |
173 | dso_name_r = dso_r->short_name; | |
174 | } | |
175 | ||
176 | return strcmp(dso_name_l, dso_name_r); | |
177 | } | |
178 | ||
872a878f | 179 | static int64_t |
dd68ada2 JK |
180 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
181 | { | |
202e7a6d | 182 | return _sort__dso_cmp(right->ms.map, left->ms.map); |
b5387528 | 183 | } |
dd68ada2 | 184 | |
14d1ac74 NK |
185 | static int _hist_entry__dso_snprintf(struct map *map, char *bf, |
186 | size_t size, unsigned int width) | |
187 | { | |
188 | if (map && map->dso) { | |
bb963e16 NK |
189 | const char *dso_name = verbose > 0 ? map->dso->long_name : |
190 | map->dso->short_name; | |
5b591669 | 191 | return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); |
14d1ac74 NK |
192 | } |
193 | ||
5b591669 | 194 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "[unknown]"); |
14d1ac74 NK |
195 | } |
196 | ||
c824c433 | 197 | static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf, |
14d1ac74 NK |
198 | size_t size, unsigned int width) |
199 | { | |
c824c433 | 200 | return _hist_entry__dso_snprintf(he->ms.map, bf, size, width); |
14d1ac74 NK |
201 | } |
202 | ||
54430101 NK |
203 | static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *arg) |
204 | { | |
205 | const struct dso *dso = arg; | |
206 | ||
207 | if (type != HIST_FILTER__DSO) | |
208 | return -1; | |
209 | ||
210 | return dso && (!he->ms.map || he->ms.map->dso != dso); | |
211 | } | |
212 | ||
14d1ac74 NK |
213 | struct sort_entry sort_dso = { |
214 | .se_header = "Shared Object", | |
215 | .se_cmp = sort__dso_cmp, | |
216 | .se_snprintf = hist_entry__dso_snprintf, | |
54430101 | 217 | .se_filter = hist_entry__dso_filter, |
14d1ac74 NK |
218 | .se_width_idx = HISTC_DSO, |
219 | }; | |
220 | ||
221 | /* --sort symbol */ | |
dd68ada2 | 222 | |
2037be53 NK |
223 | static int64_t _sort__addr_cmp(u64 left_ip, u64 right_ip) |
224 | { | |
225 | return (int64_t)(right_ip - left_ip); | |
226 | } | |
227 | ||
51f27d14 | 228 | static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r) |
b5387528 RAV |
229 | { |
230 | if (!sym_l || !sym_r) | |
231 | return cmp_null(sym_l, sym_r); | |
232 | ||
233 | if (sym_l == sym_r) | |
234 | return 0; | |
235 | ||
7346195e HK |
236 | if (sym_l->inlined || sym_r->inlined) { |
237 | int ret = strcmp(sym_l->name, sym_r->name); | |
238 | ||
239 | if (ret) | |
240 | return ret; | |
241 | if ((sym_l->start <= sym_r->end) && (sym_l->end >= sym_r->start)) | |
242 | return 0; | |
243 | } | |
aa441895 | 244 | |
c05676c0 YB |
245 | if (sym_l->start != sym_r->start) |
246 | return (int64_t)(sym_r->start - sym_l->start); | |
b5387528 | 247 | |
c05676c0 | 248 | return (int64_t)(sym_r->end - sym_l->end); |
b5387528 RAV |
249 | } |
250 | ||
14d1ac74 NK |
251 | static int64_t |
252 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | |
b5387528 | 253 | { |
09600e0f NK |
254 | int64_t ret; |
255 | ||
14d1ac74 | 256 | if (!left->ms.sym && !right->ms.sym) |
2037be53 | 257 | return _sort__addr_cmp(left->ip, right->ip); |
dd68ada2 | 258 | |
09600e0f NK |
259 | /* |
260 | * comparing symbol address alone is not enough since it's a | |
261 | * relative address within a dso. | |
262 | */ | |
69849fc5 | 263 | if (!hists__has(left->hists, dso) || hists__has(right->hists, dso)) { |
68f6d022 NK |
264 | ret = sort__dso_cmp(left, right); |
265 | if (ret != 0) | |
266 | return ret; | |
267 | } | |
09600e0f | 268 | |
51f27d14 | 269 | return _sort__sym_cmp(left->ms.sym, right->ms.sym); |
b5387528 RAV |
270 | } |
271 | ||
202e7a6d NK |
272 | static int64_t |
273 | sort__sym_sort(struct hist_entry *left, struct hist_entry *right) | |
274 | { | |
275 | if (!left->ms.sym || !right->ms.sym) | |
276 | return cmp_null(left->ms.sym, right->ms.sym); | |
277 | ||
278 | return strcmp(right->ms.sym->name, left->ms.sym->name); | |
279 | } | |
280 | ||
b5387528 RAV |
281 | static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, |
282 | u64 ip, char level, char *bf, size_t size, | |
43355522 | 283 | unsigned int width) |
b5387528 RAV |
284 | { |
285 | size_t ret = 0; | |
286 | ||
bb963e16 | 287 | if (verbose > 0) { |
b5387528 RAV |
288 | char o = map ? dso__symtab_origin(map->dso) : '!'; |
289 | ret += repsep_snprintf(bf, size, "%-#*llx %c ", | |
ded19d57 | 290 | BITS_PER_LONG / 4 + 2, ip, o); |
439d473b | 291 | } |
dd68ada2 | 292 | |
b5387528 | 293 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level); |
98a3b32c | 294 | if (sym && map) { |
d1fd8d9e | 295 | if (sym->type == STT_OBJECT) { |
98a3b32c SE |
296 | ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name); |
297 | ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx", | |
62667746 | 298 | ip - map->unmap_ip(map, sym->start)); |
98a3b32c | 299 | } else { |
89fee709 | 300 | ret += repsep_snprintf(bf + ret, size - ret, "%.*s", |
98a3b32c SE |
301 | width - ret, |
302 | sym->name); | |
8932f807 MW |
303 | if (sym->inlined) |
304 | ret += repsep_snprintf(bf + ret, size - ret, | |
305 | " (inlined)"); | |
98a3b32c SE |
306 | } |
307 | } else { | |
b5387528 RAV |
308 | size_t len = BITS_PER_LONG / 4; |
309 | ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", | |
310 | len, ip); | |
b5387528 RAV |
311 | } |
312 | ||
89fee709 | 313 | return ret; |
dd68ada2 JK |
314 | } |
315 | ||
c824c433 | 316 | static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, |
43355522 | 317 | size_t size, unsigned int width) |
b5387528 | 318 | { |
c824c433 ACM |
319 | return _hist_entry__sym_snprintf(he->ms.map, he->ms.sym, he->ip, |
320 | he->level, bf, size, width); | |
b5387528 | 321 | } |
dd68ada2 | 322 | |
54430101 NK |
323 | static int hist_entry__sym_filter(struct hist_entry *he, int type, const void *arg) |
324 | { | |
325 | const char *sym = arg; | |
326 | ||
327 | if (type != HIST_FILTER__SYMBOL) | |
328 | return -1; | |
329 | ||
330 | return sym && (!he->ms.sym || !strstr(he->ms.sym->name, sym)); | |
331 | } | |
332 | ||
872a878f FW |
333 | struct sort_entry sort_sym = { |
334 | .se_header = "Symbol", | |
335 | .se_cmp = sort__sym_cmp, | |
202e7a6d | 336 | .se_sort = sort__sym_sort, |
872a878f | 337 | .se_snprintf = hist_entry__sym_snprintf, |
54430101 | 338 | .se_filter = hist_entry__sym_filter, |
872a878f FW |
339 | .se_width_idx = HISTC_SYMBOL, |
340 | }; | |
dd68ada2 | 341 | |
409a8be6 ACM |
342 | /* --sort srcline */ |
343 | ||
6a53da05 | 344 | char *hist_entry__srcline(struct hist_entry *he) |
cecaec63 | 345 | { |
e2d88aaa | 346 | return map__srcline(he->ms.map, he->ip, he->ms.sym); |
cecaec63 NK |
347 | } |
348 | ||
409a8be6 ACM |
349 | static int64_t |
350 | sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) | |
351 | { | |
cecaec63 | 352 | if (!left->srcline) |
6a53da05 | 353 | left->srcline = hist_entry__srcline(left); |
cecaec63 | 354 | if (!right->srcline) |
6a53da05 | 355 | right->srcline = hist_entry__srcline(right); |
cecaec63 | 356 | |
202e7a6d | 357 | return strcmp(right->srcline, left->srcline); |
409a8be6 ACM |
358 | } |
359 | ||
c824c433 | 360 | static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, |
5b591669 | 361 | size_t size, unsigned int width) |
409a8be6 | 362 | { |
cecaec63 | 363 | if (!he->srcline) |
6a53da05 | 364 | he->srcline = hist_entry__srcline(he); |
cecaec63 | 365 | |
2960ed6f | 366 | return repsep_snprintf(bf, size, "%-.*s", width, he->srcline); |
409a8be6 ACM |
367 | } |
368 | ||
369 | struct sort_entry sort_srcline = { | |
370 | .se_header = "Source:Line", | |
371 | .se_cmp = sort__srcline_cmp, | |
372 | .se_snprintf = hist_entry__srcline_snprintf, | |
373 | .se_width_idx = HISTC_SRCLINE, | |
374 | }; | |
375 | ||
508be0df AK |
376 | /* --sort srcline_from */ |
377 | ||
bfa63519 ACM |
378 | static char *addr_map_symbol__srcline(struct addr_map_symbol *ams) |
379 | { | |
380 | return map__srcline(ams->map, ams->al_addr, ams->sym); | |
381 | } | |
382 | ||
508be0df AK |
383 | static int64_t |
384 | sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) | |
385 | { | |
bfa63519 ACM |
386 | if (!left->branch_info->srcline_from) |
387 | left->branch_info->srcline_from = addr_map_symbol__srcline(&left->branch_info->from); | |
388 | ||
389 | if (!right->branch_info->srcline_from) | |
390 | right->branch_info->srcline_from = addr_map_symbol__srcline(&right->branch_info->from); | |
391 | ||
508be0df AK |
392 | return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); |
393 | } | |
394 | ||
395 | static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf, | |
396 | size_t size, unsigned int width) | |
397 | { | |
398 | return repsep_snprintf(bf, size, "%-*.*s", width, width, he->branch_info->srcline_from); | |
399 | } | |
400 | ||
401 | struct sort_entry sort_srcline_from = { | |
402 | .se_header = "From Source:Line", | |
403 | .se_cmp = sort__srcline_from_cmp, | |
404 | .se_snprintf = hist_entry__srcline_from_snprintf, | |
405 | .se_width_idx = HISTC_SRCLINE_FROM, | |
406 | }; | |
407 | ||
408 | /* --sort srcline_to */ | |
409 | ||
410 | static int64_t | |
411 | sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) | |
412 | { | |
bfa63519 ACM |
413 | if (!left->branch_info->srcline_to) |
414 | left->branch_info->srcline_to = addr_map_symbol__srcline(&left->branch_info->to); | |
415 | ||
416 | if (!right->branch_info->srcline_to) | |
417 | right->branch_info->srcline_to = addr_map_symbol__srcline(&right->branch_info->to); | |
418 | ||
508be0df AK |
419 | return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); |
420 | } | |
421 | ||
422 | static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf, | |
423 | size_t size, unsigned int width) | |
424 | { | |
425 | return repsep_snprintf(bf, size, "%-*.*s", width, width, he->branch_info->srcline_to); | |
426 | } | |
427 | ||
428 | struct sort_entry sort_srcline_to = { | |
429 | .se_header = "To Source:Line", | |
430 | .se_cmp = sort__srcline_to_cmp, | |
431 | .se_snprintf = hist_entry__srcline_to_snprintf, | |
432 | .se_width_idx = HISTC_SRCLINE_TO, | |
433 | }; | |
434 | ||
ec6ae74f JY |
435 | static int hist_entry__sym_ipc_snprintf(struct hist_entry *he, char *bf, |
436 | size_t size, unsigned int width) | |
437 | { | |
438 | ||
439 | struct symbol *sym = he->ms.sym; | |
ec6ae74f JY |
440 | struct annotation *notes; |
441 | double ipc = 0.0, coverage = 0.0; | |
442 | char tmp[64]; | |
443 | ||
444 | if (!sym) | |
445 | return repsep_snprintf(bf, size, "%-*s", width, "-"); | |
446 | ||
ec6ae74f JY |
447 | notes = symbol__annotation(sym); |
448 | ||
449 | if (notes->hit_cycles) | |
450 | ipc = notes->hit_insn / ((double)notes->hit_cycles); | |
451 | ||
452 | if (notes->total_insn) { | |
453 | coverage = notes->cover_insn * 100.0 / | |
454 | ((double)notes->total_insn); | |
455 | } | |
456 | ||
457 | snprintf(tmp, sizeof(tmp), "%-5.2f [%5.1f%%]", ipc, coverage); | |
458 | return repsep_snprintf(bf, size, "%-*s", width, tmp); | |
459 | } | |
460 | ||
461 | struct sort_entry sort_sym_ipc = { | |
462 | .se_header = "IPC [IPC Coverage]", | |
463 | .se_cmp = sort__sym_cmp, | |
464 | .se_snprintf = hist_entry__sym_ipc_snprintf, | |
465 | .se_width_idx = HISTC_SYMBOL_IPC, | |
466 | }; | |
467 | ||
468 | static int hist_entry__sym_ipc_null_snprintf(struct hist_entry *he | |
469 | __maybe_unused, | |
470 | char *bf, size_t size, | |
471 | unsigned int width) | |
472 | { | |
473 | char tmp[64]; | |
474 | ||
475 | snprintf(tmp, sizeof(tmp), "%-5s %2s", "-", "-"); | |
476 | return repsep_snprintf(bf, size, "%-*s", width, tmp); | |
477 | } | |
478 | ||
479 | struct sort_entry sort_sym_ipc_null = { | |
480 | .se_header = "IPC [IPC Coverage]", | |
481 | .se_cmp = sort__sym_cmp, | |
482 | .se_snprintf = hist_entry__sym_ipc_null_snprintf, | |
483 | .se_width_idx = HISTC_SYMBOL_IPC, | |
484 | }; | |
485 | ||
31191a85 AK |
486 | /* --sort srcfile */ |
487 | ||
488 | static char no_srcfile[1]; | |
489 | ||
cecaec63 | 490 | static char *hist_entry__get_srcfile(struct hist_entry *e) |
31191a85 AK |
491 | { |
492 | char *sf, *p; | |
493 | struct map *map = e->ms.map; | |
494 | ||
cecaec63 NK |
495 | if (!map) |
496 | return no_srcfile; | |
497 | ||
2f84b42b | 498 | sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip), |
935f5a9d | 499 | e->ms.sym, false, true, true, e->ip); |
76b10655 AK |
500 | if (!strcmp(sf, SRCLINE_UNKNOWN)) |
501 | return no_srcfile; | |
31191a85 AK |
502 | p = strchr(sf, ':'); |
503 | if (p && *sf) { | |
504 | *p = 0; | |
505 | return sf; | |
506 | } | |
507 | free(sf); | |
508 | return no_srcfile; | |
509 | } | |
510 | ||
511 | static int64_t | |
512 | sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right) | |
513 | { | |
cecaec63 NK |
514 | if (!left->srcfile) |
515 | left->srcfile = hist_entry__get_srcfile(left); | |
516 | if (!right->srcfile) | |
517 | right->srcfile = hist_entry__get_srcfile(right); | |
518 | ||
31191a85 AK |
519 | return strcmp(right->srcfile, left->srcfile); |
520 | } | |
521 | ||
522 | static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf, | |
523 | size_t size, unsigned int width) | |
524 | { | |
cecaec63 NK |
525 | if (!he->srcfile) |
526 | he->srcfile = hist_entry__get_srcfile(he); | |
527 | ||
2960ed6f | 528 | return repsep_snprintf(bf, size, "%-.*s", width, he->srcfile); |
31191a85 AK |
529 | } |
530 | ||
531 | struct sort_entry sort_srcfile = { | |
532 | .se_header = "Source File", | |
533 | .se_cmp = sort__srcfile_cmp, | |
534 | .se_snprintf = hist_entry__srcfile_snprintf, | |
535 | .se_width_idx = HISTC_SRCFILE, | |
536 | }; | |
537 | ||
dd68ada2 JK |
538 | /* --sort parent */ |
539 | ||
872a878f | 540 | static int64_t |
dd68ada2 JK |
541 | sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) |
542 | { | |
543 | struct symbol *sym_l = left->parent; | |
544 | struct symbol *sym_r = right->parent; | |
545 | ||
546 | if (!sym_l || !sym_r) | |
547 | return cmp_null(sym_l, sym_r); | |
548 | ||
202e7a6d | 549 | return strcmp(sym_r->name, sym_l->name); |
dd68ada2 JK |
550 | } |
551 | ||
c824c433 | 552 | static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, |
a4e3b956 | 553 | size_t size, unsigned int width) |
dd68ada2 | 554 | { |
5b591669 | 555 | return repsep_snprintf(bf, size, "%-*.*s", width, width, |
c824c433 | 556 | he->parent ? he->parent->name : "[other]"); |
dd68ada2 JK |
557 | } |
558 | ||
872a878f FW |
559 | struct sort_entry sort_parent = { |
560 | .se_header = "Parent symbol", | |
561 | .se_cmp = sort__parent_cmp, | |
562 | .se_snprintf = hist_entry__parent_snprintf, | |
563 | .se_width_idx = HISTC_PARENT, | |
564 | }; | |
565 | ||
f60f3593 AS |
566 | /* --sort cpu */ |
567 | ||
872a878f | 568 | static int64_t |
f60f3593 AS |
569 | sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right) |
570 | { | |
571 | return right->cpu - left->cpu; | |
572 | } | |
573 | ||
c824c433 ACM |
574 | static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf, |
575 | size_t size, unsigned int width) | |
f60f3593 | 576 | { |
5b591669 | 577 | return repsep_snprintf(bf, size, "%*.*d", width, width, he->cpu); |
f60f3593 AS |
578 | } |
579 | ||
872a878f FW |
580 | struct sort_entry sort_cpu = { |
581 | .se_header = "CPU", | |
582 | .se_cmp = sort__cpu_cmp, | |
583 | .se_snprintf = hist_entry__cpu_snprintf, | |
584 | .se_width_idx = HISTC_CPU, | |
585 | }; | |
586 | ||
d890a98c HB |
587 | /* --sort cgroup_id */ |
588 | ||
589 | static int64_t _sort__cgroup_dev_cmp(u64 left_dev, u64 right_dev) | |
590 | { | |
591 | return (int64_t)(right_dev - left_dev); | |
592 | } | |
593 | ||
594 | static int64_t _sort__cgroup_inode_cmp(u64 left_ino, u64 right_ino) | |
595 | { | |
596 | return (int64_t)(right_ino - left_ino); | |
597 | } | |
598 | ||
599 | static int64_t | |
600 | sort__cgroup_id_cmp(struct hist_entry *left, struct hist_entry *right) | |
601 | { | |
602 | int64_t ret; | |
603 | ||
604 | ret = _sort__cgroup_dev_cmp(right->cgroup_id.dev, left->cgroup_id.dev); | |
605 | if (ret != 0) | |
606 | return ret; | |
607 | ||
608 | return _sort__cgroup_inode_cmp(right->cgroup_id.ino, | |
609 | left->cgroup_id.ino); | |
610 | } | |
611 | ||
612 | static int hist_entry__cgroup_id_snprintf(struct hist_entry *he, | |
613 | char *bf, size_t size, | |
614 | unsigned int width __maybe_unused) | |
615 | { | |
616 | return repsep_snprintf(bf, size, "%lu/0x%lx", he->cgroup_id.dev, | |
617 | he->cgroup_id.ino); | |
618 | } | |
619 | ||
620 | struct sort_entry sort_cgroup_id = { | |
621 | .se_header = "cgroup id (dev/inode)", | |
622 | .se_cmp = sort__cgroup_id_cmp, | |
623 | .se_snprintf = hist_entry__cgroup_id_snprintf, | |
624 | .se_width_idx = HISTC_CGROUP_ID, | |
625 | }; | |
626 | ||
2e7ea3ab KL |
627 | /* --sort socket */ |
628 | ||
629 | static int64_t | |
630 | sort__socket_cmp(struct hist_entry *left, struct hist_entry *right) | |
631 | { | |
632 | return right->socket - left->socket; | |
633 | } | |
634 | ||
635 | static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf, | |
636 | size_t size, unsigned int width) | |
637 | { | |
638 | return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket); | |
639 | } | |
640 | ||
54430101 NK |
641 | static int hist_entry__socket_filter(struct hist_entry *he, int type, const void *arg) |
642 | { | |
643 | int sk = *(const int *)arg; | |
644 | ||
645 | if (type != HIST_FILTER__SOCKET) | |
646 | return -1; | |
647 | ||
648 | return sk >= 0 && he->socket != sk; | |
649 | } | |
650 | ||
2e7ea3ab KL |
651 | struct sort_entry sort_socket = { |
652 | .se_header = "Socket", | |
653 | .se_cmp = sort__socket_cmp, | |
654 | .se_snprintf = hist_entry__socket_snprintf, | |
54430101 | 655 | .se_filter = hist_entry__socket_filter, |
2e7ea3ab KL |
656 | .se_width_idx = HISTC_SOCKET, |
657 | }; | |
658 | ||
3723908d AK |
659 | /* --sort time */ |
660 | ||
661 | static int64_t | |
662 | sort__time_cmp(struct hist_entry *left, struct hist_entry *right) | |
663 | { | |
664 | return right->time - left->time; | |
665 | } | |
666 | ||
667 | static int hist_entry__time_snprintf(struct hist_entry *he, char *bf, | |
668 | size_t size, unsigned int width) | |
669 | { | |
670 | unsigned long secs; | |
671 | unsigned long long nsecs; | |
672 | char he_time[32]; | |
673 | ||
674 | nsecs = he->time; | |
675 | secs = nsecs / NSEC_PER_SEC; | |
676 | nsecs -= secs * NSEC_PER_SEC; | |
677 | ||
678 | if (symbol_conf.nanosecs) | |
679 | snprintf(he_time, sizeof he_time, "%5lu.%09llu: ", | |
680 | secs, nsecs); | |
681 | else | |
682 | timestamp__scnprintf_usec(he->time, he_time, | |
683 | sizeof(he_time)); | |
684 | ||
685 | return repsep_snprintf(bf, size, "%-.*s", width, he_time); | |
686 | } | |
687 | ||
688 | struct sort_entry sort_time = { | |
689 | .se_header = "Time", | |
690 | .se_cmp = sort__time_cmp, | |
691 | .se_snprintf = hist_entry__time_snprintf, | |
692 | .se_width_idx = HISTC_TIME, | |
693 | }; | |
694 | ||
a34bb6a0 NK |
695 | /* --sort trace */ |
696 | ||
697 | static char *get_trace_output(struct hist_entry *he) | |
698 | { | |
699 | struct trace_seq seq; | |
700 | struct perf_evsel *evsel; | |
cbc49b25 | 701 | struct tep_record rec = { |
a34bb6a0 NK |
702 | .data = he->raw_data, |
703 | .size = he->raw_size, | |
704 | }; | |
705 | ||
706 | evsel = hists_to_evsel(he->hists); | |
707 | ||
708 | trace_seq_init(&seq); | |
053a3989 | 709 | if (symbol_conf.raw_trace) { |
6a48dc29 TSV |
710 | tep_print_fields(&seq, he->raw_data, he->raw_size, |
711 | evsel->tp_format); | |
053a3989 | 712 | } else { |
4d5c58b1 | 713 | tep_event_info(&seq, evsel->tp_format, &rec); |
053a3989 | 714 | } |
887fa86d ACM |
715 | /* |
716 | * Trim the buffer, it starts at 4KB and we're not going to | |
717 | * add anything more to this buffer. | |
718 | */ | |
719 | return realloc(seq.buffer, seq.len + 1); | |
a34bb6a0 NK |
720 | } |
721 | ||
722 | static int64_t | |
723 | sort__trace_cmp(struct hist_entry *left, struct hist_entry *right) | |
724 | { | |
725 | struct perf_evsel *evsel; | |
726 | ||
727 | evsel = hists_to_evsel(left->hists); | |
728 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | |
729 | return 0; | |
730 | ||
731 | if (left->trace_output == NULL) | |
732 | left->trace_output = get_trace_output(left); | |
733 | if (right->trace_output == NULL) | |
734 | right->trace_output = get_trace_output(right); | |
735 | ||
a34bb6a0 NK |
736 | return strcmp(right->trace_output, left->trace_output); |
737 | } | |
738 | ||
739 | static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf, | |
740 | size_t size, unsigned int width) | |
741 | { | |
742 | struct perf_evsel *evsel; | |
743 | ||
744 | evsel = hists_to_evsel(he->hists); | |
745 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | |
2960ed6f | 746 | return scnprintf(bf, size, "%-.*s", width, "N/A"); |
a34bb6a0 NK |
747 | |
748 | if (he->trace_output == NULL) | |
749 | he->trace_output = get_trace_output(he); | |
2960ed6f | 750 | return repsep_snprintf(bf, size, "%-.*s", width, he->trace_output); |
a34bb6a0 NK |
751 | } |
752 | ||
753 | struct sort_entry sort_trace = { | |
754 | .se_header = "Trace output", | |
755 | .se_cmp = sort__trace_cmp, | |
756 | .se_snprintf = hist_entry__trace_snprintf, | |
757 | .se_width_idx = HISTC_TRACE, | |
758 | }; | |
759 | ||
14d1ac74 NK |
760 | /* sort keys for branch stacks */ |
761 | ||
b5387528 RAV |
762 | static int64_t |
763 | sort__dso_from_cmp(struct hist_entry *left, struct hist_entry *right) | |
764 | { | |
288a4b91 JO |
765 | if (!left->branch_info || !right->branch_info) |
766 | return cmp_null(left->branch_info, right->branch_info); | |
767 | ||
b5387528 RAV |
768 | return _sort__dso_cmp(left->branch_info->from.map, |
769 | right->branch_info->from.map); | |
770 | } | |
771 | ||
c824c433 | 772 | static int hist_entry__dso_from_snprintf(struct hist_entry *he, char *bf, |
b5387528 RAV |
773 | size_t size, unsigned int width) |
774 | { | |
288a4b91 JO |
775 | if (he->branch_info) |
776 | return _hist_entry__dso_snprintf(he->branch_info->from.map, | |
777 | bf, size, width); | |
778 | else | |
779 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); | |
b5387528 RAV |
780 | } |
781 | ||
54430101 NK |
782 | static int hist_entry__dso_from_filter(struct hist_entry *he, int type, |
783 | const void *arg) | |
784 | { | |
785 | const struct dso *dso = arg; | |
786 | ||
787 | if (type != HIST_FILTER__DSO) | |
788 | return -1; | |
789 | ||
790 | return dso && (!he->branch_info || !he->branch_info->from.map || | |
791 | he->branch_info->from.map->dso != dso); | |
792 | } | |
793 | ||
b5387528 RAV |
794 | static int64_t |
795 | sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right) | |
796 | { | |
8b62fa59 JO |
797 | if (!left->branch_info || !right->branch_info) |
798 | return cmp_null(left->branch_info, right->branch_info); | |
799 | ||
b5387528 RAV |
800 | return _sort__dso_cmp(left->branch_info->to.map, |
801 | right->branch_info->to.map); | |
802 | } | |
803 | ||
c824c433 | 804 | static int hist_entry__dso_to_snprintf(struct hist_entry *he, char *bf, |
b5387528 RAV |
805 | size_t size, unsigned int width) |
806 | { | |
8b62fa59 JO |
807 | if (he->branch_info) |
808 | return _hist_entry__dso_snprintf(he->branch_info->to.map, | |
809 | bf, size, width); | |
810 | else | |
811 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); | |
b5387528 RAV |
812 | } |
813 | ||
54430101 NK |
814 | static int hist_entry__dso_to_filter(struct hist_entry *he, int type, |
815 | const void *arg) | |
816 | { | |
817 | const struct dso *dso = arg; | |
818 | ||
819 | if (type != HIST_FILTER__DSO) | |
820 | return -1; | |
821 | ||
822 | return dso && (!he->branch_info || !he->branch_info->to.map || | |
823 | he->branch_info->to.map->dso != dso); | |
824 | } | |
825 | ||
b5387528 RAV |
826 | static int64_t |
827 | sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right) | |
828 | { | |
829 | struct addr_map_symbol *from_l = &left->branch_info->from; | |
830 | struct addr_map_symbol *from_r = &right->branch_info->from; | |
831 | ||
1b9e97a2 JO |
832 | if (!left->branch_info || !right->branch_info) |
833 | return cmp_null(left->branch_info, right->branch_info); | |
834 | ||
835 | from_l = &left->branch_info->from; | |
836 | from_r = &right->branch_info->from; | |
837 | ||
b5387528 | 838 | if (!from_l->sym && !from_r->sym) |
2037be53 | 839 | return _sort__addr_cmp(from_l->addr, from_r->addr); |
b5387528 | 840 | |
51f27d14 | 841 | return _sort__sym_cmp(from_l->sym, from_r->sym); |
b5387528 RAV |
842 | } |
843 | ||
844 | static int64_t | |
845 | sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right) | |
846 | { | |
38cdbd39 JO |
847 | struct addr_map_symbol *to_l, *to_r; |
848 | ||
849 | if (!left->branch_info || !right->branch_info) | |
850 | return cmp_null(left->branch_info, right->branch_info); | |
851 | ||
852 | to_l = &left->branch_info->to; | |
853 | to_r = &right->branch_info->to; | |
b5387528 RAV |
854 | |
855 | if (!to_l->sym && !to_r->sym) | |
2037be53 | 856 | return _sort__addr_cmp(to_l->addr, to_r->addr); |
b5387528 | 857 | |
51f27d14 | 858 | return _sort__sym_cmp(to_l->sym, to_r->sym); |
b5387528 RAV |
859 | } |
860 | ||
c824c433 | 861 | static int hist_entry__sym_from_snprintf(struct hist_entry *he, char *bf, |
43355522 | 862 | size_t size, unsigned int width) |
b5387528 | 863 | { |
1b9e97a2 JO |
864 | if (he->branch_info) { |
865 | struct addr_map_symbol *from = &he->branch_info->from; | |
b5387528 | 866 | |
1b9e97a2 JO |
867 | return _hist_entry__sym_snprintf(from->map, from->sym, from->addr, |
868 | he->level, bf, size, width); | |
869 | } | |
870 | ||
871 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); | |
b5387528 RAV |
872 | } |
873 | ||
c824c433 | 874 | static int hist_entry__sym_to_snprintf(struct hist_entry *he, char *bf, |
43355522 | 875 | size_t size, unsigned int width) |
b5387528 | 876 | { |
38cdbd39 JO |
877 | if (he->branch_info) { |
878 | struct addr_map_symbol *to = &he->branch_info->to; | |
879 | ||
880 | return _hist_entry__sym_snprintf(to->map, to->sym, to->addr, | |
881 | he->level, bf, size, width); | |
882 | } | |
b5387528 | 883 | |
38cdbd39 | 884 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); |
b5387528 RAV |
885 | } |
886 | ||
54430101 NK |
887 | static int hist_entry__sym_from_filter(struct hist_entry *he, int type, |
888 | const void *arg) | |
889 | { | |
890 | const char *sym = arg; | |
891 | ||
892 | if (type != HIST_FILTER__SYMBOL) | |
893 | return -1; | |
894 | ||
895 | return sym && !(he->branch_info && he->branch_info->from.sym && | |
896 | strstr(he->branch_info->from.sym->name, sym)); | |
897 | } | |
898 | ||
899 | static int hist_entry__sym_to_filter(struct hist_entry *he, int type, | |
900 | const void *arg) | |
901 | { | |
902 | const char *sym = arg; | |
903 | ||
904 | if (type != HIST_FILTER__SYMBOL) | |
905 | return -1; | |
906 | ||
907 | return sym && !(he->branch_info && he->branch_info->to.sym && | |
908 | strstr(he->branch_info->to.sym->name, sym)); | |
909 | } | |
910 | ||
14d1ac74 NK |
911 | struct sort_entry sort_dso_from = { |
912 | .se_header = "Source Shared Object", | |
913 | .se_cmp = sort__dso_from_cmp, | |
914 | .se_snprintf = hist_entry__dso_from_snprintf, | |
54430101 | 915 | .se_filter = hist_entry__dso_from_filter, |
14d1ac74 NK |
916 | .se_width_idx = HISTC_DSO_FROM, |
917 | }; | |
918 | ||
b5387528 RAV |
919 | struct sort_entry sort_dso_to = { |
920 | .se_header = "Target Shared Object", | |
921 | .se_cmp = sort__dso_to_cmp, | |
922 | .se_snprintf = hist_entry__dso_to_snprintf, | |
54430101 | 923 | .se_filter = hist_entry__dso_to_filter, |
b5387528 RAV |
924 | .se_width_idx = HISTC_DSO_TO, |
925 | }; | |
926 | ||
927 | struct sort_entry sort_sym_from = { | |
928 | .se_header = "Source Symbol", | |
929 | .se_cmp = sort__sym_from_cmp, | |
930 | .se_snprintf = hist_entry__sym_from_snprintf, | |
54430101 | 931 | .se_filter = hist_entry__sym_from_filter, |
b5387528 RAV |
932 | .se_width_idx = HISTC_SYMBOL_FROM, |
933 | }; | |
934 | ||
935 | struct sort_entry sort_sym_to = { | |
936 | .se_header = "Target Symbol", | |
937 | .se_cmp = sort__sym_to_cmp, | |
938 | .se_snprintf = hist_entry__sym_to_snprintf, | |
54430101 | 939 | .se_filter = hist_entry__sym_to_filter, |
b5387528 RAV |
940 | .se_width_idx = HISTC_SYMBOL_TO, |
941 | }; | |
942 | ||
943 | static int64_t | |
944 | sort__mispredict_cmp(struct hist_entry *left, struct hist_entry *right) | |
945 | { | |
428560e7 | 946 | unsigned char mp, p; |
b5387528 | 947 | |
428560e7 JO |
948 | if (!left->branch_info || !right->branch_info) |
949 | return cmp_null(left->branch_info, right->branch_info); | |
950 | ||
951 | mp = left->branch_info->flags.mispred != right->branch_info->flags.mispred; | |
952 | p = left->branch_info->flags.predicted != right->branch_info->flags.predicted; | |
b5387528 RAV |
953 | return mp || p; |
954 | } | |
955 | ||
c824c433 | 956 | static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf, |
b5387528 RAV |
957 | size_t size, unsigned int width){ |
958 | static const char *out = "N/A"; | |
959 | ||
428560e7 JO |
960 | if (he->branch_info) { |
961 | if (he->branch_info->flags.predicted) | |
962 | out = "N"; | |
963 | else if (he->branch_info->flags.mispred) | |
964 | out = "Y"; | |
965 | } | |
b5387528 | 966 | |
5b591669 | 967 | return repsep_snprintf(bf, size, "%-*.*s", width, width, out); |
b5387528 RAV |
968 | } |
969 | ||
0e332f03 AK |
970 | static int64_t |
971 | sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right) | |
972 | { | |
4b0b3aa6 CD |
973 | if (!left->branch_info || !right->branch_info) |
974 | return cmp_null(left->branch_info, right->branch_info); | |
975 | ||
0e332f03 AK |
976 | return left->branch_info->flags.cycles - |
977 | right->branch_info->flags.cycles; | |
978 | } | |
979 | ||
980 | static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf, | |
981 | size_t size, unsigned int width) | |
982 | { | |
4b0b3aa6 CD |
983 | if (!he->branch_info) |
984 | return scnprintf(bf, size, "%-.*s", width, "N/A"); | |
0e332f03 AK |
985 | if (he->branch_info->flags.cycles == 0) |
986 | return repsep_snprintf(bf, size, "%-*s", width, "-"); | |
987 | return repsep_snprintf(bf, size, "%-*hd", width, | |
988 | he->branch_info->flags.cycles); | |
989 | } | |
990 | ||
991 | struct sort_entry sort_cycles = { | |
992 | .se_header = "Basic Block Cycles", | |
993 | .se_cmp = sort__cycles_cmp, | |
994 | .se_snprintf = hist_entry__cycles_snprintf, | |
995 | .se_width_idx = HISTC_CYCLES, | |
996 | }; | |
997 | ||
98a3b32c | 998 | /* --sort daddr_sym */ |
5fe7b9b4 | 999 | int64_t |
98a3b32c SE |
1000 | sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right) |
1001 | { | |
1002 | uint64_t l = 0, r = 0; | |
1003 | ||
1004 | if (left->mem_info) | |
1005 | l = left->mem_info->daddr.addr; | |
1006 | if (right->mem_info) | |
1007 | r = right->mem_info->daddr.addr; | |
1008 | ||
1009 | return (int64_t)(r - l); | |
1010 | } | |
1011 | ||
c824c433 | 1012 | static int hist_entry__daddr_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1013 | size_t size, unsigned int width) |
1014 | { | |
1015 | uint64_t addr = 0; | |
1016 | struct map *map = NULL; | |
1017 | struct symbol *sym = NULL; | |
1018 | ||
c824c433 ACM |
1019 | if (he->mem_info) { |
1020 | addr = he->mem_info->daddr.addr; | |
1021 | map = he->mem_info->daddr.map; | |
1022 | sym = he->mem_info->daddr.sym; | |
98a3b32c | 1023 | } |
c824c433 | 1024 | return _hist_entry__sym_snprintf(map, sym, addr, he->level, bf, size, |
98a3b32c SE |
1025 | width); |
1026 | } | |
1027 | ||
5fe7b9b4 | 1028 | int64_t |
28e6db20 DZ |
1029 | sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right) |
1030 | { | |
1031 | uint64_t l = 0, r = 0; | |
1032 | ||
1033 | if (left->mem_info) | |
1034 | l = left->mem_info->iaddr.addr; | |
1035 | if (right->mem_info) | |
1036 | r = right->mem_info->iaddr.addr; | |
1037 | ||
1038 | return (int64_t)(r - l); | |
1039 | } | |
1040 | ||
1041 | static int hist_entry__iaddr_snprintf(struct hist_entry *he, char *bf, | |
1042 | size_t size, unsigned int width) | |
1043 | { | |
1044 | uint64_t addr = 0; | |
1045 | struct map *map = NULL; | |
1046 | struct symbol *sym = NULL; | |
1047 | ||
1048 | if (he->mem_info) { | |
1049 | addr = he->mem_info->iaddr.addr; | |
1050 | map = he->mem_info->iaddr.map; | |
1051 | sym = he->mem_info->iaddr.sym; | |
1052 | } | |
1053 | return _hist_entry__sym_snprintf(map, sym, addr, he->level, bf, size, | |
1054 | width); | |
1055 | } | |
1056 | ||
98a3b32c SE |
1057 | static int64_t |
1058 | sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right) | |
1059 | { | |
1060 | struct map *map_l = NULL; | |
1061 | struct map *map_r = NULL; | |
1062 | ||
1063 | if (left->mem_info) | |
1064 | map_l = left->mem_info->daddr.map; | |
1065 | if (right->mem_info) | |
1066 | map_r = right->mem_info->daddr.map; | |
1067 | ||
1068 | return _sort__dso_cmp(map_l, map_r); | |
1069 | } | |
1070 | ||
c824c433 | 1071 | static int hist_entry__dso_daddr_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1072 | size_t size, unsigned int width) |
1073 | { | |
1074 | struct map *map = NULL; | |
1075 | ||
c824c433 ACM |
1076 | if (he->mem_info) |
1077 | map = he->mem_info->daddr.map; | |
98a3b32c SE |
1078 | |
1079 | return _hist_entry__dso_snprintf(map, bf, size, width); | |
1080 | } | |
1081 | ||
1082 | static int64_t | |
1083 | sort__locked_cmp(struct hist_entry *left, struct hist_entry *right) | |
1084 | { | |
1085 | union perf_mem_data_src data_src_l; | |
1086 | union perf_mem_data_src data_src_r; | |
1087 | ||
1088 | if (left->mem_info) | |
1089 | data_src_l = left->mem_info->data_src; | |
1090 | else | |
1091 | data_src_l.mem_lock = PERF_MEM_LOCK_NA; | |
1092 | ||
1093 | if (right->mem_info) | |
1094 | data_src_r = right->mem_info->data_src; | |
1095 | else | |
1096 | data_src_r.mem_lock = PERF_MEM_LOCK_NA; | |
1097 | ||
1098 | return (int64_t)(data_src_r.mem_lock - data_src_l.mem_lock); | |
1099 | } | |
1100 | ||
c824c433 | 1101 | static int hist_entry__locked_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1102 | size_t size, unsigned int width) |
1103 | { | |
69a77275 | 1104 | char out[10]; |
98a3b32c | 1105 | |
69a77275 | 1106 | perf_mem__lck_scnprintf(out, sizeof(out), he->mem_info); |
89fee709 | 1107 | return repsep_snprintf(bf, size, "%.*s", width, out); |
98a3b32c SE |
1108 | } |
1109 | ||
1110 | static int64_t | |
1111 | sort__tlb_cmp(struct hist_entry *left, struct hist_entry *right) | |
1112 | { | |
1113 | union perf_mem_data_src data_src_l; | |
1114 | union perf_mem_data_src data_src_r; | |
1115 | ||
1116 | if (left->mem_info) | |
1117 | data_src_l = left->mem_info->data_src; | |
1118 | else | |
1119 | data_src_l.mem_dtlb = PERF_MEM_TLB_NA; | |
1120 | ||
1121 | if (right->mem_info) | |
1122 | data_src_r = right->mem_info->data_src; | |
1123 | else | |
1124 | data_src_r.mem_dtlb = PERF_MEM_TLB_NA; | |
1125 | ||
1126 | return (int64_t)(data_src_r.mem_dtlb - data_src_l.mem_dtlb); | |
1127 | } | |
1128 | ||
c824c433 | 1129 | static int hist_entry__tlb_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1130 | size_t size, unsigned int width) |
1131 | { | |
1132 | char out[64]; | |
98a3b32c | 1133 | |
0c877d75 | 1134 | perf_mem__tlb_scnprintf(out, sizeof(out), he->mem_info); |
98a3b32c SE |
1135 | return repsep_snprintf(bf, size, "%-*s", width, out); |
1136 | } | |
1137 | ||
1138 | static int64_t | |
1139 | sort__lvl_cmp(struct hist_entry *left, struct hist_entry *right) | |
1140 | { | |
1141 | union perf_mem_data_src data_src_l; | |
1142 | union perf_mem_data_src data_src_r; | |
1143 | ||
1144 | if (left->mem_info) | |
1145 | data_src_l = left->mem_info->data_src; | |
1146 | else | |
1147 | data_src_l.mem_lvl = PERF_MEM_LVL_NA; | |
1148 | ||
1149 | if (right->mem_info) | |
1150 | data_src_r = right->mem_info->data_src; | |
1151 | else | |
1152 | data_src_r.mem_lvl = PERF_MEM_LVL_NA; | |
1153 | ||
1154 | return (int64_t)(data_src_r.mem_lvl - data_src_l.mem_lvl); | |
1155 | } | |
1156 | ||
c824c433 | 1157 | static int hist_entry__lvl_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1158 | size_t size, unsigned int width) |
1159 | { | |
1160 | char out[64]; | |
98a3b32c | 1161 | |
071e9a1e | 1162 | perf_mem__lvl_scnprintf(out, sizeof(out), he->mem_info); |
98a3b32c SE |
1163 | return repsep_snprintf(bf, size, "%-*s", width, out); |
1164 | } | |
1165 | ||
1166 | static int64_t | |
1167 | sort__snoop_cmp(struct hist_entry *left, struct hist_entry *right) | |
1168 | { | |
1169 | union perf_mem_data_src data_src_l; | |
1170 | union perf_mem_data_src data_src_r; | |
1171 | ||
1172 | if (left->mem_info) | |
1173 | data_src_l = left->mem_info->data_src; | |
1174 | else | |
1175 | data_src_l.mem_snoop = PERF_MEM_SNOOP_NA; | |
1176 | ||
1177 | if (right->mem_info) | |
1178 | data_src_r = right->mem_info->data_src; | |
1179 | else | |
1180 | data_src_r.mem_snoop = PERF_MEM_SNOOP_NA; | |
1181 | ||
1182 | return (int64_t)(data_src_r.mem_snoop - data_src_l.mem_snoop); | |
1183 | } | |
1184 | ||
c824c433 | 1185 | static int hist_entry__snoop_snprintf(struct hist_entry *he, char *bf, |
98a3b32c SE |
1186 | size_t size, unsigned int width) |
1187 | { | |
1188 | char out[64]; | |
98a3b32c | 1189 | |
2c07af13 | 1190 | perf_mem__snp_scnprintf(out, sizeof(out), he->mem_info); |
98a3b32c SE |
1191 | return repsep_snprintf(bf, size, "%-*s", width, out); |
1192 | } | |
1193 | ||
5fe7b9b4 | 1194 | int64_t |
9b32ba71 DZ |
1195 | sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right) |
1196 | { | |
1197 | u64 l, r; | |
1198 | struct map *l_map, *r_map; | |
1199 | ||
1200 | if (!left->mem_info) return -1; | |
1201 | if (!right->mem_info) return 1; | |
1202 | ||
1203 | /* group event types together */ | |
1204 | if (left->cpumode > right->cpumode) return -1; | |
1205 | if (left->cpumode < right->cpumode) return 1; | |
1206 | ||
1207 | l_map = left->mem_info->daddr.map; | |
1208 | r_map = right->mem_info->daddr.map; | |
1209 | ||
1210 | /* if both are NULL, jump to sort on al_addr instead */ | |
1211 | if (!l_map && !r_map) | |
1212 | goto addr; | |
1213 | ||
1214 | if (!l_map) return -1; | |
1215 | if (!r_map) return 1; | |
1216 | ||
1217 | if (l_map->maj > r_map->maj) return -1; | |
1218 | if (l_map->maj < r_map->maj) return 1; | |
1219 | ||
1220 | if (l_map->min > r_map->min) return -1; | |
1221 | if (l_map->min < r_map->min) return 1; | |
1222 | ||
1223 | if (l_map->ino > r_map->ino) return -1; | |
1224 | if (l_map->ino < r_map->ino) return 1; | |
1225 | ||
1226 | if (l_map->ino_generation > r_map->ino_generation) return -1; | |
1227 | if (l_map->ino_generation < r_map->ino_generation) return 1; | |
1228 | ||
1229 | /* | |
1230 | * Addresses with no major/minor numbers are assumed to be | |
1231 | * anonymous in userspace. Sort those on pid then address. | |
1232 | * | |
1233 | * The kernel and non-zero major/minor mapped areas are | |
1234 | * assumed to be unity mapped. Sort those on address. | |
1235 | */ | |
1236 | ||
1237 | if ((left->cpumode != PERF_RECORD_MISC_KERNEL) && | |
1238 | (!(l_map->flags & MAP_SHARED)) && | |
1239 | !l_map->maj && !l_map->min && !l_map->ino && | |
1240 | !l_map->ino_generation) { | |
1241 | /* userspace anonymous */ | |
1242 | ||
1243 | if (left->thread->pid_ > right->thread->pid_) return -1; | |
1244 | if (left->thread->pid_ < right->thread->pid_) return 1; | |
1245 | } | |
1246 | ||
1247 | addr: | |
1248 | /* al_addr does all the right addr - start + offset calculations */ | |
1249 | l = cl_address(left->mem_info->daddr.al_addr); | |
1250 | r = cl_address(right->mem_info->daddr.al_addr); | |
1251 | ||
1252 | if (l > r) return -1; | |
1253 | if (l < r) return 1; | |
1254 | ||
1255 | return 0; | |
1256 | } | |
1257 | ||
1258 | static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf, | |
1259 | size_t size, unsigned int width) | |
1260 | { | |
1261 | ||
1262 | uint64_t addr = 0; | |
1263 | struct map *map = NULL; | |
1264 | struct symbol *sym = NULL; | |
1265 | char level = he->level; | |
1266 | ||
1267 | if (he->mem_info) { | |
1268 | addr = cl_address(he->mem_info->daddr.al_addr); | |
1269 | map = he->mem_info->daddr.map; | |
1270 | sym = he->mem_info->daddr.sym; | |
1271 | ||
1272 | /* print [s] for shared data mmaps */ | |
1273 | if ((he->cpumode != PERF_RECORD_MISC_KERNEL) && | |
6769e98d | 1274 | map && !(map->prot & PROT_EXEC) && |
9b32ba71 DZ |
1275 | (map->flags & MAP_SHARED) && |
1276 | (map->maj || map->min || map->ino || | |
1277 | map->ino_generation)) | |
1278 | level = 's'; | |
1279 | else if (!map) | |
1280 | level = 'X'; | |
1281 | } | |
1282 | return _hist_entry__sym_snprintf(map, sym, addr, level, bf, size, | |
1283 | width); | |
1284 | } | |
1285 | ||
b5387528 RAV |
1286 | struct sort_entry sort_mispredict = { |
1287 | .se_header = "Branch Mispredicted", | |
1288 | .se_cmp = sort__mispredict_cmp, | |
1289 | .se_snprintf = hist_entry__mispredict_snprintf, | |
1290 | .se_width_idx = HISTC_MISPREDICT, | |
1291 | }; | |
1292 | ||
05484298 AK |
1293 | static u64 he_weight(struct hist_entry *he) |
1294 | { | |
1295 | return he->stat.nr_events ? he->stat.weight / he->stat.nr_events : 0; | |
1296 | } | |
1297 | ||
1298 | static int64_t | |
1299 | sort__local_weight_cmp(struct hist_entry *left, struct hist_entry *right) | |
1300 | { | |
1301 | return he_weight(left) - he_weight(right); | |
1302 | } | |
1303 | ||
c824c433 | 1304 | static int hist_entry__local_weight_snprintf(struct hist_entry *he, char *bf, |
05484298 AK |
1305 | size_t size, unsigned int width) |
1306 | { | |
c824c433 | 1307 | return repsep_snprintf(bf, size, "%-*llu", width, he_weight(he)); |
05484298 AK |
1308 | } |
1309 | ||
1310 | struct sort_entry sort_local_weight = { | |
1311 | .se_header = "Local Weight", | |
1312 | .se_cmp = sort__local_weight_cmp, | |
1313 | .se_snprintf = hist_entry__local_weight_snprintf, | |
1314 | .se_width_idx = HISTC_LOCAL_WEIGHT, | |
1315 | }; | |
1316 | ||
1317 | static int64_t | |
1318 | sort__global_weight_cmp(struct hist_entry *left, struct hist_entry *right) | |
1319 | { | |
1320 | return left->stat.weight - right->stat.weight; | |
1321 | } | |
1322 | ||
c824c433 | 1323 | static int hist_entry__global_weight_snprintf(struct hist_entry *he, char *bf, |
05484298 AK |
1324 | size_t size, unsigned int width) |
1325 | { | |
c824c433 | 1326 | return repsep_snprintf(bf, size, "%-*llu", width, he->stat.weight); |
05484298 AK |
1327 | } |
1328 | ||
1329 | struct sort_entry sort_global_weight = { | |
1330 | .se_header = "Weight", | |
1331 | .se_cmp = sort__global_weight_cmp, | |
1332 | .se_snprintf = hist_entry__global_weight_snprintf, | |
1333 | .se_width_idx = HISTC_GLOBAL_WEIGHT, | |
1334 | }; | |
1335 | ||
98a3b32c SE |
1336 | struct sort_entry sort_mem_daddr_sym = { |
1337 | .se_header = "Data Symbol", | |
1338 | .se_cmp = sort__daddr_cmp, | |
1339 | .se_snprintf = hist_entry__daddr_snprintf, | |
1340 | .se_width_idx = HISTC_MEM_DADDR_SYMBOL, | |
1341 | }; | |
1342 | ||
28e6db20 DZ |
1343 | struct sort_entry sort_mem_iaddr_sym = { |
1344 | .se_header = "Code Symbol", | |
1345 | .se_cmp = sort__iaddr_cmp, | |
1346 | .se_snprintf = hist_entry__iaddr_snprintf, | |
1347 | .se_width_idx = HISTC_MEM_IADDR_SYMBOL, | |
1348 | }; | |
1349 | ||
98a3b32c SE |
1350 | struct sort_entry sort_mem_daddr_dso = { |
1351 | .se_header = "Data Object", | |
1352 | .se_cmp = sort__dso_daddr_cmp, | |
1353 | .se_snprintf = hist_entry__dso_daddr_snprintf, | |
94c39988 | 1354 | .se_width_idx = HISTC_MEM_DADDR_DSO, |
98a3b32c SE |
1355 | }; |
1356 | ||
1357 | struct sort_entry sort_mem_locked = { | |
1358 | .se_header = "Locked", | |
1359 | .se_cmp = sort__locked_cmp, | |
1360 | .se_snprintf = hist_entry__locked_snprintf, | |
1361 | .se_width_idx = HISTC_MEM_LOCKED, | |
1362 | }; | |
1363 | ||
1364 | struct sort_entry sort_mem_tlb = { | |
1365 | .se_header = "TLB access", | |
1366 | .se_cmp = sort__tlb_cmp, | |
1367 | .se_snprintf = hist_entry__tlb_snprintf, | |
1368 | .se_width_idx = HISTC_MEM_TLB, | |
1369 | }; | |
1370 | ||
1371 | struct sort_entry sort_mem_lvl = { | |
1372 | .se_header = "Memory access", | |
1373 | .se_cmp = sort__lvl_cmp, | |
1374 | .se_snprintf = hist_entry__lvl_snprintf, | |
1375 | .se_width_idx = HISTC_MEM_LVL, | |
1376 | }; | |
1377 | ||
1378 | struct sort_entry sort_mem_snoop = { | |
1379 | .se_header = "Snoop", | |
1380 | .se_cmp = sort__snoop_cmp, | |
1381 | .se_snprintf = hist_entry__snoop_snprintf, | |
1382 | .se_width_idx = HISTC_MEM_SNOOP, | |
1383 | }; | |
1384 | ||
9b32ba71 DZ |
1385 | struct sort_entry sort_mem_dcacheline = { |
1386 | .se_header = "Data Cacheline", | |
1387 | .se_cmp = sort__dcacheline_cmp, | |
1388 | .se_snprintf = hist_entry__dcacheline_snprintf, | |
1389 | .se_width_idx = HISTC_MEM_DCACHELINE, | |
1390 | }; | |
1391 | ||
8780fb25 KL |
1392 | static int64_t |
1393 | sort__phys_daddr_cmp(struct hist_entry *left, struct hist_entry *right) | |
1394 | { | |
1395 | uint64_t l = 0, r = 0; | |
1396 | ||
1397 | if (left->mem_info) | |
1398 | l = left->mem_info->daddr.phys_addr; | |
1399 | if (right->mem_info) | |
1400 | r = right->mem_info->daddr.phys_addr; | |
1401 | ||
1402 | return (int64_t)(r - l); | |
1403 | } | |
1404 | ||
1405 | static int hist_entry__phys_daddr_snprintf(struct hist_entry *he, char *bf, | |
1406 | size_t size, unsigned int width) | |
1407 | { | |
1408 | uint64_t addr = 0; | |
1409 | size_t ret = 0; | |
1410 | size_t len = BITS_PER_LONG / 4; | |
1411 | ||
1412 | addr = he->mem_info->daddr.phys_addr; | |
1413 | ||
1414 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", he->level); | |
1415 | ||
1416 | ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", len, addr); | |
1417 | ||
1418 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", width - ret, ""); | |
1419 | ||
1420 | if (ret > width) | |
1421 | bf[width] = '\0'; | |
1422 | ||
1423 | return width; | |
1424 | } | |
1425 | ||
1426 | struct sort_entry sort_mem_phys_daddr = { | |
1427 | .se_header = "Data Physical Address", | |
1428 | .se_cmp = sort__phys_daddr_cmp, | |
1429 | .se_snprintf = hist_entry__phys_daddr_snprintf, | |
1430 | .se_width_idx = HISTC_MEM_PHYS_DADDR, | |
1431 | }; | |
1432 | ||
f5d05bce AK |
1433 | static int64_t |
1434 | sort__abort_cmp(struct hist_entry *left, struct hist_entry *right) | |
1435 | { | |
49f47443 JO |
1436 | if (!left->branch_info || !right->branch_info) |
1437 | return cmp_null(left->branch_info, right->branch_info); | |
1438 | ||
f5d05bce AK |
1439 | return left->branch_info->flags.abort != |
1440 | right->branch_info->flags.abort; | |
1441 | } | |
1442 | ||
c824c433 | 1443 | static int hist_entry__abort_snprintf(struct hist_entry *he, char *bf, |
f5d05bce AK |
1444 | size_t size, unsigned int width) |
1445 | { | |
49f47443 JO |
1446 | static const char *out = "N/A"; |
1447 | ||
1448 | if (he->branch_info) { | |
1449 | if (he->branch_info->flags.abort) | |
1450 | out = "A"; | |
1451 | else | |
1452 | out = "."; | |
1453 | } | |
f5d05bce | 1454 | |
f5d05bce AK |
1455 | return repsep_snprintf(bf, size, "%-*s", width, out); |
1456 | } | |
1457 | ||
1458 | struct sort_entry sort_abort = { | |
1459 | .se_header = "Transaction abort", | |
1460 | .se_cmp = sort__abort_cmp, | |
1461 | .se_snprintf = hist_entry__abort_snprintf, | |
1462 | .se_width_idx = HISTC_ABORT, | |
1463 | }; | |
1464 | ||
1465 | static int64_t | |
1466 | sort__in_tx_cmp(struct hist_entry *left, struct hist_entry *right) | |
1467 | { | |
0199d244 JO |
1468 | if (!left->branch_info || !right->branch_info) |
1469 | return cmp_null(left->branch_info, right->branch_info); | |
1470 | ||
f5d05bce AK |
1471 | return left->branch_info->flags.in_tx != |
1472 | right->branch_info->flags.in_tx; | |
1473 | } | |
1474 | ||
c824c433 | 1475 | static int hist_entry__in_tx_snprintf(struct hist_entry *he, char *bf, |
f5d05bce AK |
1476 | size_t size, unsigned int width) |
1477 | { | |
0199d244 | 1478 | static const char *out = "N/A"; |
f5d05bce | 1479 | |
0199d244 JO |
1480 | if (he->branch_info) { |
1481 | if (he->branch_info->flags.in_tx) | |
1482 | out = "T"; | |
1483 | else | |
1484 | out = "."; | |
1485 | } | |
f5d05bce AK |
1486 | |
1487 | return repsep_snprintf(bf, size, "%-*s", width, out); | |
1488 | } | |
1489 | ||
1490 | struct sort_entry sort_in_tx = { | |
1491 | .se_header = "Branch in transaction", | |
1492 | .se_cmp = sort__in_tx_cmp, | |
1493 | .se_snprintf = hist_entry__in_tx_snprintf, | |
1494 | .se_width_idx = HISTC_IN_TX, | |
1495 | }; | |
1496 | ||
475eeab9 AK |
1497 | static int64_t |
1498 | sort__transaction_cmp(struct hist_entry *left, struct hist_entry *right) | |
1499 | { | |
1500 | return left->transaction - right->transaction; | |
1501 | } | |
1502 | ||
1503 | static inline char *add_str(char *p, const char *str) | |
1504 | { | |
1505 | strcpy(p, str); | |
1506 | return p + strlen(str); | |
1507 | } | |
1508 | ||
1509 | static struct txbit { | |
1510 | unsigned flag; | |
1511 | const char *name; | |
1512 | int skip_for_len; | |
1513 | } txbits[] = { | |
1514 | { PERF_TXN_ELISION, "EL ", 0 }, | |
1515 | { PERF_TXN_TRANSACTION, "TX ", 1 }, | |
1516 | { PERF_TXN_SYNC, "SYNC ", 1 }, | |
1517 | { PERF_TXN_ASYNC, "ASYNC ", 0 }, | |
1518 | { PERF_TXN_RETRY, "RETRY ", 0 }, | |
1519 | { PERF_TXN_CONFLICT, "CON ", 0 }, | |
1520 | { PERF_TXN_CAPACITY_WRITE, "CAP-WRITE ", 1 }, | |
1521 | { PERF_TXN_CAPACITY_READ, "CAP-READ ", 0 }, | |
1522 | { 0, NULL, 0 } | |
1523 | }; | |
1524 | ||
1525 | int hist_entry__transaction_len(void) | |
1526 | { | |
1527 | int i; | |
1528 | int len = 0; | |
1529 | ||
1530 | for (i = 0; txbits[i].name; i++) { | |
1531 | if (!txbits[i].skip_for_len) | |
1532 | len += strlen(txbits[i].name); | |
1533 | } | |
1534 | len += 4; /* :XX<space> */ | |
1535 | return len; | |
1536 | } | |
1537 | ||
c824c433 | 1538 | static int hist_entry__transaction_snprintf(struct hist_entry *he, char *bf, |
475eeab9 AK |
1539 | size_t size, unsigned int width) |
1540 | { | |
c824c433 | 1541 | u64 t = he->transaction; |
475eeab9 AK |
1542 | char buf[128]; |
1543 | char *p = buf; | |
1544 | int i; | |
1545 | ||
1546 | buf[0] = 0; | |
1547 | for (i = 0; txbits[i].name; i++) | |
1548 | if (txbits[i].flag & t) | |
1549 | p = add_str(p, txbits[i].name); | |
1550 | if (t && !(t & (PERF_TXN_SYNC|PERF_TXN_ASYNC))) | |
1551 | p = add_str(p, "NEITHER "); | |
1552 | if (t & PERF_TXN_ABORT_MASK) { | |
1553 | sprintf(p, ":%" PRIx64, | |
1554 | (t & PERF_TXN_ABORT_MASK) >> | |
1555 | PERF_TXN_ABORT_SHIFT); | |
1556 | p += strlen(p); | |
1557 | } | |
1558 | ||
1559 | return repsep_snprintf(bf, size, "%-*s", width, buf); | |
1560 | } | |
1561 | ||
1562 | struct sort_entry sort_transaction = { | |
1563 | .se_header = "Transaction ", | |
1564 | .se_cmp = sort__transaction_cmp, | |
1565 | .se_snprintf = hist_entry__transaction_snprintf, | |
1566 | .se_width_idx = HISTC_TRANSACTION, | |
1567 | }; | |
1568 | ||
7768f8da CB |
1569 | /* --sort symbol_size */ |
1570 | ||
1571 | static int64_t _sort__sym_size_cmp(struct symbol *sym_l, struct symbol *sym_r) | |
1572 | { | |
1573 | int64_t size_l = sym_l != NULL ? symbol__size(sym_l) : 0; | |
1574 | int64_t size_r = sym_r != NULL ? symbol__size(sym_r) : 0; | |
1575 | ||
1576 | return size_l < size_r ? -1 : | |
1577 | size_l == size_r ? 0 : 1; | |
1578 | } | |
1579 | ||
1580 | static int64_t | |
1581 | sort__sym_size_cmp(struct hist_entry *left, struct hist_entry *right) | |
1582 | { | |
1583 | return _sort__sym_size_cmp(right->ms.sym, left->ms.sym); | |
1584 | } | |
1585 | ||
1586 | static int _hist_entry__sym_size_snprintf(struct symbol *sym, char *bf, | |
1587 | size_t bf_size, unsigned int width) | |
1588 | { | |
1589 | if (sym) | |
1590 | return repsep_snprintf(bf, bf_size, "%*d", width, symbol__size(sym)); | |
1591 | ||
1592 | return repsep_snprintf(bf, bf_size, "%*s", width, "unknown"); | |
1593 | } | |
1594 | ||
1595 | static int hist_entry__sym_size_snprintf(struct hist_entry *he, char *bf, | |
1596 | size_t size, unsigned int width) | |
1597 | { | |
1598 | return _hist_entry__sym_size_snprintf(he->ms.sym, bf, size, width); | |
1599 | } | |
1600 | ||
1601 | struct sort_entry sort_sym_size = { | |
1602 | .se_header = "Symbol size", | |
1603 | .se_cmp = sort__sym_size_cmp, | |
1604 | .se_snprintf = hist_entry__sym_size_snprintf, | |
1605 | .se_width_idx = HISTC_SYM_SIZE, | |
1606 | }; | |
1607 | ||
b74d12d5 KP |
1608 | /* --sort dso_size */ |
1609 | ||
1610 | static int64_t _sort__dso_size_cmp(struct map *map_l, struct map *map_r) | |
1611 | { | |
1612 | int64_t size_l = map_l != NULL ? map__size(map_l) : 0; | |
1613 | int64_t size_r = map_r != NULL ? map__size(map_r) : 0; | |
1614 | ||
1615 | return size_l < size_r ? -1 : | |
1616 | size_l == size_r ? 0 : 1; | |
1617 | } | |
1618 | ||
1619 | static int64_t | |
1620 | sort__dso_size_cmp(struct hist_entry *left, struct hist_entry *right) | |
1621 | { | |
1622 | return _sort__dso_size_cmp(right->ms.map, left->ms.map); | |
1623 | } | |
1624 | ||
1625 | static int _hist_entry__dso_size_snprintf(struct map *map, char *bf, | |
1626 | size_t bf_size, unsigned int width) | |
1627 | { | |
1628 | if (map && map->dso) | |
1629 | return repsep_snprintf(bf, bf_size, "%*d", width, | |
1630 | map__size(map)); | |
1631 | ||
1632 | return repsep_snprintf(bf, bf_size, "%*s", width, "unknown"); | |
1633 | } | |
1634 | ||
1635 | static int hist_entry__dso_size_snprintf(struct hist_entry *he, char *bf, | |
1636 | size_t size, unsigned int width) | |
1637 | { | |
1638 | return _hist_entry__dso_size_snprintf(he->ms.map, bf, size, width); | |
1639 | } | |
1640 | ||
1641 | struct sort_entry sort_dso_size = { | |
1642 | .se_header = "DSO size", | |
1643 | .se_cmp = sort__dso_size_cmp, | |
1644 | .se_snprintf = hist_entry__dso_size_snprintf, | |
1645 | .se_width_idx = HISTC_DSO_SIZE, | |
1646 | }; | |
1647 | ||
7768f8da | 1648 | |
872a878f FW |
1649 | struct sort_dimension { |
1650 | const char *name; | |
1651 | struct sort_entry *entry; | |
1652 | int taken; | |
1653 | }; | |
1654 | ||
b5387528 RAV |
1655 | #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) } |
1656 | ||
fc5871ed | 1657 | static struct sort_dimension common_sort_dimensions[] = { |
b5387528 RAV |
1658 | DIM(SORT_PID, "pid", sort_thread), |
1659 | DIM(SORT_COMM, "comm", sort_comm), | |
1660 | DIM(SORT_DSO, "dso", sort_dso), | |
b5387528 | 1661 | DIM(SORT_SYM, "symbol", sort_sym), |
b5387528 RAV |
1662 | DIM(SORT_PARENT, "parent", sort_parent), |
1663 | DIM(SORT_CPU, "cpu", sort_cpu), | |
2e7ea3ab | 1664 | DIM(SORT_SOCKET, "socket", sort_socket), |
409a8be6 | 1665 | DIM(SORT_SRCLINE, "srcline", sort_srcline), |
31191a85 | 1666 | DIM(SORT_SRCFILE, "srcfile", sort_srcfile), |
f9ea55d0 AK |
1667 | DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight), |
1668 | DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), | |
475eeab9 | 1669 | DIM(SORT_TRANSACTION, "transaction", sort_transaction), |
a34bb6a0 | 1670 | DIM(SORT_TRACE, "trace", sort_trace), |
7768f8da | 1671 | DIM(SORT_SYM_SIZE, "symbol_size", sort_sym_size), |
b74d12d5 | 1672 | DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size), |
d890a98c | 1673 | DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id), |
ec6ae74f | 1674 | DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null), |
3723908d | 1675 | DIM(SORT_TIME, "time", sort_time), |
872a878f FW |
1676 | }; |
1677 | ||
fc5871ed NK |
1678 | #undef DIM |
1679 | ||
1680 | #define DIM(d, n, func) [d - __SORT_BRANCH_STACK] = { .name = n, .entry = &(func) } | |
1681 | ||
1682 | static struct sort_dimension bstack_sort_dimensions[] = { | |
1683 | DIM(SORT_DSO_FROM, "dso_from", sort_dso_from), | |
1684 | DIM(SORT_DSO_TO, "dso_to", sort_dso_to), | |
1685 | DIM(SORT_SYM_FROM, "symbol_from", sort_sym_from), | |
1686 | DIM(SORT_SYM_TO, "symbol_to", sort_sym_to), | |
1687 | DIM(SORT_MISPREDICT, "mispredict", sort_mispredict), | |
f5d05bce AK |
1688 | DIM(SORT_IN_TX, "in_tx", sort_in_tx), |
1689 | DIM(SORT_ABORT, "abort", sort_abort), | |
0e332f03 | 1690 | DIM(SORT_CYCLES, "cycles", sort_cycles), |
508be0df AK |
1691 | DIM(SORT_SRCLINE_FROM, "srcline_from", sort_srcline_from), |
1692 | DIM(SORT_SRCLINE_TO, "srcline_to", sort_srcline_to), | |
ec6ae74f | 1693 | DIM(SORT_SYM_IPC, "ipc_lbr", sort_sym_ipc), |
fc5871ed NK |
1694 | }; |
1695 | ||
1696 | #undef DIM | |
1697 | ||
afab87b9 NK |
1698 | #define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) } |
1699 | ||
1700 | static struct sort_dimension memory_sort_dimensions[] = { | |
afab87b9 | 1701 | DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym), |
28e6db20 | 1702 | DIM(SORT_MEM_IADDR_SYMBOL, "symbol_iaddr", sort_mem_iaddr_sym), |
afab87b9 NK |
1703 | DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso), |
1704 | DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked), | |
1705 | DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb), | |
1706 | DIM(SORT_MEM_LVL, "mem", sort_mem_lvl), | |
1707 | DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop), | |
9b32ba71 | 1708 | DIM(SORT_MEM_DCACHELINE, "dcacheline", sort_mem_dcacheline), |
8780fb25 | 1709 | DIM(SORT_MEM_PHYS_DADDR, "phys_daddr", sort_mem_phys_daddr), |
afab87b9 NK |
1710 | }; |
1711 | ||
1712 | #undef DIM | |
1713 | ||
a2ce067e NK |
1714 | struct hpp_dimension { |
1715 | const char *name; | |
1716 | struct perf_hpp_fmt *fmt; | |
1717 | int taken; | |
1718 | }; | |
1719 | ||
1720 | #define DIM(d, n) { .name = n, .fmt = &perf_hpp__format[d], } | |
1721 | ||
1722 | static struct hpp_dimension hpp_sort_dimensions[] = { | |
1723 | DIM(PERF_HPP__OVERHEAD, "overhead"), | |
1724 | DIM(PERF_HPP__OVERHEAD_SYS, "overhead_sys"), | |
1725 | DIM(PERF_HPP__OVERHEAD_US, "overhead_us"), | |
1726 | DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"), | |
1727 | DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"), | |
594dcbf3 | 1728 | DIM(PERF_HPP__OVERHEAD_ACC, "overhead_children"), |
a2ce067e NK |
1729 | DIM(PERF_HPP__SAMPLES, "sample"), |
1730 | DIM(PERF_HPP__PERIOD, "period"), | |
1731 | }; | |
1732 | ||
1733 | #undef DIM | |
1734 | ||
8b536999 NK |
1735 | struct hpp_sort_entry { |
1736 | struct perf_hpp_fmt hpp; | |
1737 | struct sort_entry *se; | |
1738 | }; | |
1739 | ||
e0d66c74 | 1740 | void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists) |
678a500d NK |
1741 | { |
1742 | struct hpp_sort_entry *hse; | |
1743 | ||
1744 | if (!perf_hpp__is_sort_entry(fmt)) | |
1745 | return; | |
1746 | ||
1747 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1ecd4453 | 1748 | hists__new_col_len(hists, hse->se->se_width_idx, strlen(fmt->name)); |
678a500d NK |
1749 | } |
1750 | ||
8b536999 | 1751 | static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
29659ab4 JO |
1752 | struct hists *hists, int line __maybe_unused, |
1753 | int *span __maybe_unused) | |
8b536999 NK |
1754 | { |
1755 | struct hpp_sort_entry *hse; | |
5b591669 | 1756 | size_t len = fmt->user_len; |
8b536999 NK |
1757 | |
1758 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
8b536999 | 1759 | |
5b591669 | 1760 | if (!len) |
05372173 | 1761 | len = hists__col_len(hists, hse->se->se_width_idx); |
5b591669 | 1762 | |
1ecd4453 | 1763 | return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, fmt->name); |
8b536999 NK |
1764 | } |
1765 | ||
1766 | static int __sort__hpp_width(struct perf_hpp_fmt *fmt, | |
1767 | struct perf_hpp *hpp __maybe_unused, | |
da1b0407 | 1768 | struct hists *hists) |
8b536999 NK |
1769 | { |
1770 | struct hpp_sort_entry *hse; | |
5b591669 | 1771 | size_t len = fmt->user_len; |
8b536999 NK |
1772 | |
1773 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1774 | ||
5b591669 | 1775 | if (!len) |
da1b0407 | 1776 | len = hists__col_len(hists, hse->se->se_width_idx); |
5b591669 NK |
1777 | |
1778 | return len; | |
8b536999 NK |
1779 | } |
1780 | ||
1781 | static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | |
1782 | struct hist_entry *he) | |
1783 | { | |
1784 | struct hpp_sort_entry *hse; | |
5b591669 | 1785 | size_t len = fmt->user_len; |
8b536999 NK |
1786 | |
1787 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
5b591669 NK |
1788 | |
1789 | if (!len) | |
1790 | len = hists__col_len(he->hists, hse->se->se_width_idx); | |
8b536999 NK |
1791 | |
1792 | return hse->se->se_snprintf(he, hpp->buf, hpp->size, len); | |
1793 | } | |
1794 | ||
87bbdf76 NK |
1795 | static int64_t __sort__hpp_cmp(struct perf_hpp_fmt *fmt, |
1796 | struct hist_entry *a, struct hist_entry *b) | |
1797 | { | |
1798 | struct hpp_sort_entry *hse; | |
1799 | ||
1800 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1801 | return hse->se->se_cmp(a, b); | |
1802 | } | |
1803 | ||
1804 | static int64_t __sort__hpp_collapse(struct perf_hpp_fmt *fmt, | |
1805 | struct hist_entry *a, struct hist_entry *b) | |
1806 | { | |
1807 | struct hpp_sort_entry *hse; | |
1808 | int64_t (*collapse_fn)(struct hist_entry *, struct hist_entry *); | |
1809 | ||
1810 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1811 | collapse_fn = hse->se->se_collapse ?: hse->se->se_cmp; | |
1812 | return collapse_fn(a, b); | |
1813 | } | |
1814 | ||
1815 | static int64_t __sort__hpp_sort(struct perf_hpp_fmt *fmt, | |
1816 | struct hist_entry *a, struct hist_entry *b) | |
1817 | { | |
1818 | struct hpp_sort_entry *hse; | |
1819 | int64_t (*sort_fn)(struct hist_entry *, struct hist_entry *); | |
1820 | ||
1821 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1822 | sort_fn = hse->se->se_sort ?: hse->se->se_cmp; | |
1823 | return sort_fn(a, b); | |
1824 | } | |
1825 | ||
97358084 JO |
1826 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format) |
1827 | { | |
1828 | return format->header == __sort__hpp_header; | |
1829 | } | |
1830 | ||
4945cf2a NK |
1831 | #define MK_SORT_ENTRY_CHK(key) \ |
1832 | bool perf_hpp__is_ ## key ## _entry(struct perf_hpp_fmt *fmt) \ | |
1833 | { \ | |
1834 | struct hpp_sort_entry *hse; \ | |
1835 | \ | |
1836 | if (!perf_hpp__is_sort_entry(fmt)) \ | |
1837 | return false; \ | |
1838 | \ | |
1839 | hse = container_of(fmt, struct hpp_sort_entry, hpp); \ | |
1840 | return hse->se == &sort_ ## key ; \ | |
1841 | } | |
1842 | ||
1843 | MK_SORT_ENTRY_CHK(trace) | |
1844 | MK_SORT_ENTRY_CHK(srcline) | |
1845 | MK_SORT_ENTRY_CHK(srcfile) | |
1846 | MK_SORT_ENTRY_CHK(thread) | |
1847 | MK_SORT_ENTRY_CHK(comm) | |
1848 | MK_SORT_ENTRY_CHK(dso) | |
1849 | MK_SORT_ENTRY_CHK(sym) | |
a9c6e46c | 1850 | |
a9c6e46c | 1851 | |
97358084 JO |
1852 | static bool __sort__hpp_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) |
1853 | { | |
1854 | struct hpp_sort_entry *hse_a; | |
1855 | struct hpp_sort_entry *hse_b; | |
1856 | ||
1857 | if (!perf_hpp__is_sort_entry(a) || !perf_hpp__is_sort_entry(b)) | |
1858 | return false; | |
1859 | ||
1860 | hse_a = container_of(a, struct hpp_sort_entry, hpp); | |
1861 | hse_b = container_of(b, struct hpp_sort_entry, hpp); | |
1862 | ||
1863 | return hse_a->se == hse_b->se; | |
1864 | } | |
1865 | ||
564132f3 JO |
1866 | static void hse_free(struct perf_hpp_fmt *fmt) |
1867 | { | |
1868 | struct hpp_sort_entry *hse; | |
1869 | ||
1870 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1871 | free(hse); | |
1872 | } | |
1873 | ||
a7d945bc | 1874 | static struct hpp_sort_entry * |
4b633eba | 1875 | __sort_dimension__alloc_hpp(struct sort_dimension *sd, int level) |
8b536999 NK |
1876 | { |
1877 | struct hpp_sort_entry *hse; | |
1878 | ||
1879 | hse = malloc(sizeof(*hse)); | |
1880 | if (hse == NULL) { | |
1881 | pr_err("Memory allocation failed\n"); | |
a7d945bc | 1882 | return NULL; |
8b536999 NK |
1883 | } |
1884 | ||
1885 | hse->se = sd->entry; | |
1ecd4453 | 1886 | hse->hpp.name = sd->entry->se_header; |
8b536999 NK |
1887 | hse->hpp.header = __sort__hpp_header; |
1888 | hse->hpp.width = __sort__hpp_width; | |
1889 | hse->hpp.entry = __sort__hpp_entry; | |
1890 | hse->hpp.color = NULL; | |
1891 | ||
87bbdf76 NK |
1892 | hse->hpp.cmp = __sort__hpp_cmp; |
1893 | hse->hpp.collapse = __sort__hpp_collapse; | |
1894 | hse->hpp.sort = __sort__hpp_sort; | |
97358084 | 1895 | hse->hpp.equal = __sort__hpp_equal; |
564132f3 | 1896 | hse->hpp.free = hse_free; |
8b536999 NK |
1897 | |
1898 | INIT_LIST_HEAD(&hse->hpp.list); | |
1899 | INIT_LIST_HEAD(&hse->hpp.sort_list); | |
f2998422 | 1900 | hse->hpp.elide = false; |
e0d66c74 | 1901 | hse->hpp.len = 0; |
5b591669 | 1902 | hse->hpp.user_len = 0; |
4b633eba | 1903 | hse->hpp.level = level; |
8b536999 | 1904 | |
a7d945bc NK |
1905 | return hse; |
1906 | } | |
1907 | ||
564132f3 JO |
1908 | static void hpp_free(struct perf_hpp_fmt *fmt) |
1909 | { | |
1910 | free(fmt); | |
1911 | } | |
1912 | ||
4b633eba NK |
1913 | static struct perf_hpp_fmt *__hpp_dimension__alloc_hpp(struct hpp_dimension *hd, |
1914 | int level) | |
1945c3e7 JO |
1915 | { |
1916 | struct perf_hpp_fmt *fmt; | |
1917 | ||
1918 | fmt = memdup(hd->fmt, sizeof(*fmt)); | |
1919 | if (fmt) { | |
1920 | INIT_LIST_HEAD(&fmt->list); | |
1921 | INIT_LIST_HEAD(&fmt->sort_list); | |
564132f3 | 1922 | fmt->free = hpp_free; |
4b633eba | 1923 | fmt->level = level; |
1945c3e7 JO |
1924 | } |
1925 | ||
1926 | return fmt; | |
1927 | } | |
1928 | ||
54430101 NK |
1929 | int hist_entry__filter(struct hist_entry *he, int type, const void *arg) |
1930 | { | |
1931 | struct perf_hpp_fmt *fmt; | |
1932 | struct hpp_sort_entry *hse; | |
f4954cfb NK |
1933 | int ret = -1; |
1934 | int r; | |
1935 | ||
1936 | perf_hpp_list__for_each_format(he->hpp_list, fmt) { | |
1937 | if (!perf_hpp__is_sort_entry(fmt)) | |
1938 | continue; | |
1939 | ||
1940 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
1941 | if (hse->se->se_filter == NULL) | |
1942 | continue; | |
1943 | ||
1944 | /* | |
1945 | * hist entry is filtered if any of sort key in the hpp list | |
1946 | * is applied. But it should skip non-matched filter types. | |
1947 | */ | |
1948 | r = hse->se->se_filter(he, type, arg); | |
1949 | if (r >= 0) { | |
1950 | if (ret < 0) | |
1951 | ret = 0; | |
1952 | ret |= r; | |
1953 | } | |
1954 | } | |
54430101 | 1955 | |
f4954cfb | 1956 | return ret; |
54430101 NK |
1957 | } |
1958 | ||
d7b617f5 JO |
1959 | static int __sort_dimension__add_hpp_sort(struct sort_dimension *sd, |
1960 | struct perf_hpp_list *list, | |
1961 | int level) | |
a7d945bc | 1962 | { |
4b633eba | 1963 | struct hpp_sort_entry *hse = __sort_dimension__alloc_hpp(sd, level); |
a7d945bc NK |
1964 | |
1965 | if (hse == NULL) | |
1966 | return -1; | |
1967 | ||
d7b617f5 | 1968 | perf_hpp_list__register_sort_field(list, &hse->hpp); |
8b536999 NK |
1969 | return 0; |
1970 | } | |
1971 | ||
d7b617f5 JO |
1972 | static int __sort_dimension__add_hpp_output(struct sort_dimension *sd, |
1973 | struct perf_hpp_list *list) | |
a7d945bc | 1974 | { |
4b633eba | 1975 | struct hpp_sort_entry *hse = __sort_dimension__alloc_hpp(sd, 0); |
a7d945bc NK |
1976 | |
1977 | if (hse == NULL) | |
1978 | return -1; | |
1979 | ||
07600027 | 1980 | perf_hpp_list__column_register(list, &hse->hpp); |
a7d945bc NK |
1981 | return 0; |
1982 | } | |
1983 | ||
c7c2a5e4 NK |
1984 | struct hpp_dynamic_entry { |
1985 | struct perf_hpp_fmt hpp; | |
1986 | struct perf_evsel *evsel; | |
2c92f982 | 1987 | struct tep_format_field *field; |
c7c2a5e4 | 1988 | unsigned dynamic_len; |
053a3989 | 1989 | bool raw_trace; |
c7c2a5e4 NK |
1990 | }; |
1991 | ||
1992 | static int hde_width(struct hpp_dynamic_entry *hde) | |
1993 | { | |
1994 | if (!hde->hpp.len) { | |
1995 | int len = hde->dynamic_len; | |
1996 | int namelen = strlen(hde->field->name); | |
1997 | int fieldlen = hde->field->size; | |
1998 | ||
1999 | if (namelen > len) | |
2000 | len = namelen; | |
2001 | ||
bb39ccb2 | 2002 | if (!(hde->field->flags & TEP_FIELD_IS_STRING)) { |
c7c2a5e4 NK |
2003 | /* length for print hex numbers */ |
2004 | fieldlen = hde->field->size * 2 + 2; | |
2005 | } | |
2006 | if (fieldlen > len) | |
2007 | len = fieldlen; | |
2008 | ||
2009 | hde->hpp.len = len; | |
2010 | } | |
2011 | return hde->hpp.len; | |
2012 | } | |
2013 | ||
60517d28 NK |
2014 | static void update_dynamic_len(struct hpp_dynamic_entry *hde, |
2015 | struct hist_entry *he) | |
2016 | { | |
2017 | char *str, *pos; | |
2c92f982 | 2018 | struct tep_format_field *field = hde->field; |
60517d28 NK |
2019 | size_t namelen; |
2020 | bool last = false; | |
2021 | ||
053a3989 NK |
2022 | if (hde->raw_trace) |
2023 | return; | |
2024 | ||
60517d28 NK |
2025 | /* parse pretty print result and update max length */ |
2026 | if (!he->trace_output) | |
2027 | he->trace_output = get_trace_output(he); | |
2028 | ||
2029 | namelen = strlen(field->name); | |
2030 | str = he->trace_output; | |
2031 | ||
2032 | while (str) { | |
2033 | pos = strchr(str, ' '); | |
2034 | if (pos == NULL) { | |
2035 | last = true; | |
2036 | pos = str + strlen(str); | |
2037 | } | |
2038 | ||
2039 | if (!strncmp(str, field->name, namelen)) { | |
2040 | size_t len; | |
2041 | ||
2042 | str += namelen + 1; | |
2043 | len = pos - str; | |
2044 | ||
2045 | if (len > hde->dynamic_len) | |
2046 | hde->dynamic_len = len; | |
2047 | break; | |
2048 | } | |
2049 | ||
2050 | if (last) | |
2051 | str = NULL; | |
2052 | else | |
2053 | str = pos + 1; | |
2054 | } | |
2055 | } | |
2056 | ||
c7c2a5e4 | 2057 | static int __sort__hde_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
74bb43f2 | 2058 | struct hists *hists __maybe_unused, |
29659ab4 JO |
2059 | int line __maybe_unused, |
2060 | int *span __maybe_unused) | |
c7c2a5e4 NK |
2061 | { |
2062 | struct hpp_dynamic_entry *hde; | |
2063 | size_t len = fmt->user_len; | |
2064 | ||
2065 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2066 | ||
2067 | if (!len) | |
2068 | len = hde_width(hde); | |
2069 | ||
2070 | return scnprintf(hpp->buf, hpp->size, "%*.*s", len, len, hde->field->name); | |
2071 | } | |
2072 | ||
2073 | static int __sort__hde_width(struct perf_hpp_fmt *fmt, | |
2074 | struct perf_hpp *hpp __maybe_unused, | |
da1b0407 | 2075 | struct hists *hists __maybe_unused) |
c7c2a5e4 NK |
2076 | { |
2077 | struct hpp_dynamic_entry *hde; | |
2078 | size_t len = fmt->user_len; | |
2079 | ||
2080 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2081 | ||
2082 | if (!len) | |
2083 | len = hde_width(hde); | |
2084 | ||
2085 | return len; | |
2086 | } | |
2087 | ||
361459f1 NK |
2088 | bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists) |
2089 | { | |
2090 | struct hpp_dynamic_entry *hde; | |
2091 | ||
2092 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2093 | ||
2094 | return hists_to_evsel(hists) == hde->evsel; | |
2095 | } | |
2096 | ||
c7c2a5e4 NK |
2097 | static int __sort__hde_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
2098 | struct hist_entry *he) | |
2099 | { | |
2100 | struct hpp_dynamic_entry *hde; | |
2101 | size_t len = fmt->user_len; | |
60517d28 | 2102 | char *str, *pos; |
2c92f982 | 2103 | struct tep_format_field *field; |
60517d28 NK |
2104 | size_t namelen; |
2105 | bool last = false; | |
c7c2a5e4 NK |
2106 | int ret; |
2107 | ||
2108 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2109 | ||
2110 | if (!len) | |
2111 | len = hde_width(hde); | |
2112 | ||
053a3989 NK |
2113 | if (hde->raw_trace) |
2114 | goto raw_field; | |
60517d28 | 2115 | |
e049d4a3 NK |
2116 | if (!he->trace_output) |
2117 | he->trace_output = get_trace_output(he); | |
2118 | ||
053a3989 | 2119 | field = hde->field; |
60517d28 NK |
2120 | namelen = strlen(field->name); |
2121 | str = he->trace_output; | |
2122 | ||
2123 | while (str) { | |
2124 | pos = strchr(str, ' '); | |
2125 | if (pos == NULL) { | |
2126 | last = true; | |
2127 | pos = str + strlen(str); | |
2128 | } | |
2129 | ||
2130 | if (!strncmp(str, field->name, namelen)) { | |
2131 | str += namelen + 1; | |
2132 | str = strndup(str, pos - str); | |
2133 | ||
2134 | if (str == NULL) | |
2135 | return scnprintf(hpp->buf, hpp->size, | |
2136 | "%*.*s", len, len, "ERROR"); | |
2137 | break; | |
2138 | } | |
2139 | ||
2140 | if (last) | |
2141 | str = NULL; | |
2142 | else | |
2143 | str = pos + 1; | |
2144 | } | |
2145 | ||
2146 | if (str == NULL) { | |
2147 | struct trace_seq seq; | |
053a3989 | 2148 | raw_field: |
60517d28 | 2149 | trace_seq_init(&seq); |
6a48dc29 | 2150 | tep_print_field(&seq, he->raw_data, hde->field); |
60517d28 NK |
2151 | str = seq.buffer; |
2152 | } | |
2153 | ||
2154 | ret = scnprintf(hpp->buf, hpp->size, "%*.*s", len, len, str); | |
2155 | free(str); | |
c7c2a5e4 NK |
2156 | return ret; |
2157 | } | |
2158 | ||
2159 | static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt, | |
2160 | struct hist_entry *a, struct hist_entry *b) | |
2161 | { | |
2162 | struct hpp_dynamic_entry *hde; | |
2c92f982 | 2163 | struct tep_format_field *field; |
c7c2a5e4 NK |
2164 | unsigned offset, size; |
2165 | ||
2166 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2167 | ||
abab5e7f NK |
2168 | if (b == NULL) { |
2169 | update_dynamic_len(hde, a); | |
2170 | return 0; | |
2171 | } | |
2172 | ||
c7c2a5e4 | 2173 | field = hde->field; |
bb39ccb2 | 2174 | if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
c7c2a5e4 NK |
2175 | unsigned long long dyn; |
2176 | ||
59c1baee | 2177 | tep_read_number_field(field, a->raw_data, &dyn); |
c7c2a5e4 NK |
2178 | offset = dyn & 0xffff; |
2179 | size = (dyn >> 16) & 0xffff; | |
2180 | ||
2181 | /* record max width for output */ | |
2182 | if (size > hde->dynamic_len) | |
2183 | hde->dynamic_len = size; | |
2184 | } else { | |
2185 | offset = field->offset; | |
2186 | size = field->size; | |
2187 | } | |
2188 | ||
2189 | return memcmp(a->raw_data + offset, b->raw_data + offset, size); | |
2190 | } | |
2191 | ||
361459f1 NK |
2192 | bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *fmt) |
2193 | { | |
2194 | return fmt->cmp == __sort__hde_cmp; | |
2195 | } | |
2196 | ||
665aa757 NK |
2197 | static bool __sort__hde_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) |
2198 | { | |
2199 | struct hpp_dynamic_entry *hde_a; | |
2200 | struct hpp_dynamic_entry *hde_b; | |
2201 | ||
2202 | if (!perf_hpp__is_dynamic_entry(a) || !perf_hpp__is_dynamic_entry(b)) | |
2203 | return false; | |
2204 | ||
2205 | hde_a = container_of(a, struct hpp_dynamic_entry, hpp); | |
2206 | hde_b = container_of(b, struct hpp_dynamic_entry, hpp); | |
2207 | ||
2208 | return hde_a->field == hde_b->field; | |
2209 | } | |
2210 | ||
564132f3 JO |
2211 | static void hde_free(struct perf_hpp_fmt *fmt) |
2212 | { | |
2213 | struct hpp_dynamic_entry *hde; | |
2214 | ||
2215 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2216 | free(hde); | |
2217 | } | |
2218 | ||
c7c2a5e4 | 2219 | static struct hpp_dynamic_entry * |
2c92f982 | 2220 | __alloc_dynamic_entry(struct perf_evsel *evsel, struct tep_format_field *field, |
4b633eba | 2221 | int level) |
c7c2a5e4 NK |
2222 | { |
2223 | struct hpp_dynamic_entry *hde; | |
2224 | ||
2225 | hde = malloc(sizeof(*hde)); | |
2226 | if (hde == NULL) { | |
2227 | pr_debug("Memory allocation failed\n"); | |
2228 | return NULL; | |
2229 | } | |
2230 | ||
2231 | hde->evsel = evsel; | |
2232 | hde->field = field; | |
2233 | hde->dynamic_len = 0; | |
2234 | ||
2235 | hde->hpp.name = field->name; | |
2236 | hde->hpp.header = __sort__hde_header; | |
2237 | hde->hpp.width = __sort__hde_width; | |
2238 | hde->hpp.entry = __sort__hde_entry; | |
2239 | hde->hpp.color = NULL; | |
2240 | ||
2241 | hde->hpp.cmp = __sort__hde_cmp; | |
2242 | hde->hpp.collapse = __sort__hde_cmp; | |
2243 | hde->hpp.sort = __sort__hde_cmp; | |
665aa757 | 2244 | hde->hpp.equal = __sort__hde_equal; |
564132f3 | 2245 | hde->hpp.free = hde_free; |
c7c2a5e4 NK |
2246 | |
2247 | INIT_LIST_HEAD(&hde->hpp.list); | |
2248 | INIT_LIST_HEAD(&hde->hpp.sort_list); | |
2249 | hde->hpp.elide = false; | |
2250 | hde->hpp.len = 0; | |
2251 | hde->hpp.user_len = 0; | |
4b633eba | 2252 | hde->hpp.level = level; |
c7c2a5e4 NK |
2253 | |
2254 | return hde; | |
2255 | } | |
2256 | ||
c3bc0c43 NK |
2257 | struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt) |
2258 | { | |
2259 | struct perf_hpp_fmt *new_fmt = NULL; | |
2260 | ||
2261 | if (perf_hpp__is_sort_entry(fmt)) { | |
2262 | struct hpp_sort_entry *hse, *new_hse; | |
2263 | ||
2264 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
2265 | new_hse = memdup(hse, sizeof(*hse)); | |
2266 | if (new_hse) | |
2267 | new_fmt = &new_hse->hpp; | |
2268 | } else if (perf_hpp__is_dynamic_entry(fmt)) { | |
2269 | struct hpp_dynamic_entry *hde, *new_hde; | |
2270 | ||
2271 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | |
2272 | new_hde = memdup(hde, sizeof(*hde)); | |
2273 | if (new_hde) | |
2274 | new_fmt = &new_hde->hpp; | |
2275 | } else { | |
2276 | new_fmt = memdup(fmt, sizeof(*fmt)); | |
2277 | } | |
2278 | ||
2279 | INIT_LIST_HEAD(&new_fmt->list); | |
2280 | INIT_LIST_HEAD(&new_fmt->sort_list); | |
2281 | ||
2282 | return new_fmt; | |
2283 | } | |
2284 | ||
5d0cff93 NK |
2285 | static int parse_field_name(char *str, char **event, char **field, char **opt) |
2286 | { | |
2287 | char *event_name, *field_name, *opt_name; | |
2288 | ||
2289 | event_name = str; | |
2290 | field_name = strchr(str, '.'); | |
2291 | ||
2292 | if (field_name) { | |
2293 | *field_name++ = '\0'; | |
2294 | } else { | |
2295 | event_name = NULL; | |
2296 | field_name = str; | |
2297 | } | |
2298 | ||
2299 | opt_name = strchr(field_name, '/'); | |
2300 | if (opt_name) | |
2301 | *opt_name++ = '\0'; | |
2302 | ||
2303 | *event = event_name; | |
2304 | *field = field_name; | |
2305 | *opt = opt_name; | |
2306 | ||
2307 | return 0; | |
2308 | } | |
2309 | ||
2310 | /* find match evsel using a given event name. The event name can be: | |
9735be24 NK |
2311 | * 1. '%' + event index (e.g. '%1' for first event) |
2312 | * 2. full event name (e.g. sched:sched_switch) | |
2313 | * 3. partial event name (should not contain ':') | |
5d0cff93 NK |
2314 | */ |
2315 | static struct perf_evsel *find_evsel(struct perf_evlist *evlist, char *event_name) | |
2316 | { | |
2317 | struct perf_evsel *evsel = NULL; | |
2318 | struct perf_evsel *pos; | |
2319 | bool full_name; | |
2320 | ||
2321 | /* case 1 */ | |
5d0cff93 NK |
2322 | if (event_name[0] == '%') { |
2323 | int nr = strtol(event_name+1, NULL, 0); | |
2324 | ||
2325 | if (nr > evlist->nr_entries) | |
2326 | return NULL; | |
2327 | ||
2328 | evsel = perf_evlist__first(evlist); | |
2329 | while (--nr > 0) | |
2330 | evsel = perf_evsel__next(evsel); | |
2331 | ||
2332 | return evsel; | |
2333 | } | |
2334 | ||
2335 | full_name = !!strchr(event_name, ':'); | |
e5cadb93 | 2336 | evlist__for_each_entry(evlist, pos) { |
9735be24 | 2337 | /* case 2 */ |
5d0cff93 NK |
2338 | if (full_name && !strcmp(pos->name, event_name)) |
2339 | return pos; | |
9735be24 | 2340 | /* case 3 */ |
5d0cff93 NK |
2341 | if (!full_name && strstr(pos->name, event_name)) { |
2342 | if (evsel) { | |
2343 | pr_debug("'%s' event is ambiguous: it can be %s or %s\n", | |
2344 | event_name, evsel->name, pos->name); | |
2345 | return NULL; | |
2346 | } | |
2347 | evsel = pos; | |
2348 | } | |
2349 | } | |
2350 | ||
2351 | return evsel; | |
2352 | } | |
2353 | ||
3b099bf5 | 2354 | static int __dynamic_dimension__add(struct perf_evsel *evsel, |
2c92f982 | 2355 | struct tep_format_field *field, |
4b633eba | 2356 | bool raw_trace, int level) |
3b099bf5 NK |
2357 | { |
2358 | struct hpp_dynamic_entry *hde; | |
2359 | ||
4b633eba | 2360 | hde = __alloc_dynamic_entry(evsel, field, level); |
3b099bf5 NK |
2361 | if (hde == NULL) |
2362 | return -ENOMEM; | |
2363 | ||
2364 | hde->raw_trace = raw_trace; | |
2365 | ||
2366 | perf_hpp__register_sort_field(&hde->hpp); | |
2367 | return 0; | |
2368 | } | |
2369 | ||
4b633eba | 2370 | static int add_evsel_fields(struct perf_evsel *evsel, bool raw_trace, int level) |
2e422fd1 NK |
2371 | { |
2372 | int ret; | |
2c92f982 | 2373 | struct tep_format_field *field; |
2e422fd1 NK |
2374 | |
2375 | field = evsel->tp_format->format.fields; | |
2376 | while (field) { | |
4b633eba | 2377 | ret = __dynamic_dimension__add(evsel, field, raw_trace, level); |
2e422fd1 NK |
2378 | if (ret < 0) |
2379 | return ret; | |
2380 | ||
2381 | field = field->next; | |
2382 | } | |
2383 | return 0; | |
2384 | } | |
2385 | ||
4b633eba NK |
2386 | static int add_all_dynamic_fields(struct perf_evlist *evlist, bool raw_trace, |
2387 | int level) | |
2e422fd1 NK |
2388 | { |
2389 | int ret; | |
2390 | struct perf_evsel *evsel; | |
2391 | ||
e5cadb93 | 2392 | evlist__for_each_entry(evlist, evsel) { |
2e422fd1 NK |
2393 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) |
2394 | continue; | |
2395 | ||
4b633eba | 2396 | ret = add_evsel_fields(evsel, raw_trace, level); |
2e422fd1 NK |
2397 | if (ret < 0) |
2398 | return ret; | |
2399 | } | |
2400 | return 0; | |
2401 | } | |
2402 | ||
9735be24 | 2403 | static int add_all_matching_fields(struct perf_evlist *evlist, |
4b633eba | 2404 | char *field_name, bool raw_trace, int level) |
9735be24 NK |
2405 | { |
2406 | int ret = -ESRCH; | |
2407 | struct perf_evsel *evsel; | |
2c92f982 | 2408 | struct tep_format_field *field; |
9735be24 | 2409 | |
e5cadb93 | 2410 | evlist__for_each_entry(evlist, evsel) { |
9735be24 NK |
2411 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) |
2412 | continue; | |
2413 | ||
af85cd19 | 2414 | field = tep_find_any_field(evsel->tp_format, field_name); |
9735be24 NK |
2415 | if (field == NULL) |
2416 | continue; | |
2417 | ||
4b633eba | 2418 | ret = __dynamic_dimension__add(evsel, field, raw_trace, level); |
9735be24 NK |
2419 | if (ret < 0) |
2420 | break; | |
2421 | } | |
2422 | return ret; | |
2423 | } | |
2424 | ||
4b633eba NK |
2425 | static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok, |
2426 | int level) | |
c7c2a5e4 | 2427 | { |
5d0cff93 NK |
2428 | char *str, *event_name, *field_name, *opt_name; |
2429 | struct perf_evsel *evsel; | |
2c92f982 | 2430 | struct tep_format_field *field; |
053a3989 | 2431 | bool raw_trace = symbol_conf.raw_trace; |
c7c2a5e4 NK |
2432 | int ret = 0; |
2433 | ||
2434 | if (evlist == NULL) | |
2435 | return -ENOENT; | |
2436 | ||
2437 | str = strdup(tok); | |
2438 | if (str == NULL) | |
2439 | return -ENOMEM; | |
2440 | ||
5d0cff93 | 2441 | if (parse_field_name(str, &event_name, &field_name, &opt_name) < 0) { |
c7c2a5e4 NK |
2442 | ret = -EINVAL; |
2443 | goto out; | |
2444 | } | |
c7c2a5e4 | 2445 | |
5d0cff93 NK |
2446 | if (opt_name) { |
2447 | if (strcmp(opt_name, "raw")) { | |
2448 | pr_debug("unsupported field option %s\n", opt_name); | |
053a3989 NK |
2449 | ret = -EINVAL; |
2450 | goto out; | |
2451 | } | |
2452 | raw_trace = true; | |
2453 | } | |
2454 | ||
2e422fd1 | 2455 | if (!strcmp(field_name, "trace_fields")) { |
4b633eba | 2456 | ret = add_all_dynamic_fields(evlist, raw_trace, level); |
2e422fd1 NK |
2457 | goto out; |
2458 | } | |
2459 | ||
9735be24 | 2460 | if (event_name == NULL) { |
4b633eba | 2461 | ret = add_all_matching_fields(evlist, field_name, raw_trace, level); |
9735be24 NK |
2462 | goto out; |
2463 | } | |
2464 | ||
5d0cff93 | 2465 | evsel = find_evsel(evlist, event_name); |
c7c2a5e4 NK |
2466 | if (evsel == NULL) { |
2467 | pr_debug("Cannot find event: %s\n", event_name); | |
2468 | ret = -ENOENT; | |
2469 | goto out; | |
2470 | } | |
2471 | ||
2472 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { | |
2473 | pr_debug("%s is not a tracepoint event\n", event_name); | |
2474 | ret = -EINVAL; | |
2475 | goto out; | |
2476 | } | |
2477 | ||
3b099bf5 | 2478 | if (!strcmp(field_name, "*")) { |
4b633eba | 2479 | ret = add_evsel_fields(evsel, raw_trace, level); |
3b099bf5 | 2480 | } else { |
af85cd19 | 2481 | field = tep_find_any_field(evsel->tp_format, field_name); |
3b099bf5 NK |
2482 | if (field == NULL) { |
2483 | pr_debug("Cannot find event field for %s.%s\n", | |
2484 | event_name, field_name); | |
2485 | return -ENOENT; | |
2486 | } | |
2487 | ||
4b633eba | 2488 | ret = __dynamic_dimension__add(evsel, field, raw_trace, level); |
3b099bf5 | 2489 | } |
c7c2a5e4 NK |
2490 | |
2491 | out: | |
2492 | free(str); | |
2493 | return ret; | |
2494 | } | |
2495 | ||
d7b617f5 JO |
2496 | static int __sort_dimension__add(struct sort_dimension *sd, |
2497 | struct perf_hpp_list *list, | |
2498 | int level) | |
2f532d09 NK |
2499 | { |
2500 | if (sd->taken) | |
8b536999 NK |
2501 | return 0; |
2502 | ||
d7b617f5 | 2503 | if (__sort_dimension__add_hpp_sort(sd, list, level) < 0) |
8b536999 | 2504 | return -1; |
2f532d09 NK |
2505 | |
2506 | if (sd->entry->se_collapse) | |
52225036 | 2507 | list->need_collapse = 1; |
2f532d09 | 2508 | |
2f532d09 | 2509 | sd->taken = 1; |
8b536999 NK |
2510 | |
2511 | return 0; | |
2f532d09 NK |
2512 | } |
2513 | ||
d7b617f5 JO |
2514 | static int __hpp_dimension__add(struct hpp_dimension *hd, |
2515 | struct perf_hpp_list *list, | |
2516 | int level) | |
a2ce067e | 2517 | { |
1945c3e7 | 2518 | struct perf_hpp_fmt *fmt; |
a2ce067e | 2519 | |
1945c3e7 JO |
2520 | if (hd->taken) |
2521 | return 0; | |
2522 | ||
4b633eba | 2523 | fmt = __hpp_dimension__alloc_hpp(hd, level); |
1945c3e7 JO |
2524 | if (!fmt) |
2525 | return -1; | |
2526 | ||
2527 | hd->taken = 1; | |
d7b617f5 | 2528 | perf_hpp_list__register_sort_field(list, fmt); |
a2ce067e NK |
2529 | return 0; |
2530 | } | |
2531 | ||
07600027 JO |
2532 | static int __sort_dimension__add_output(struct perf_hpp_list *list, |
2533 | struct sort_dimension *sd) | |
a7d945bc NK |
2534 | { |
2535 | if (sd->taken) | |
2536 | return 0; | |
2537 | ||
d7b617f5 | 2538 | if (__sort_dimension__add_hpp_output(sd, list) < 0) |
a7d945bc NK |
2539 | return -1; |
2540 | ||
2541 | sd->taken = 1; | |
2542 | return 0; | |
2543 | } | |
2544 | ||
07600027 JO |
2545 | static int __hpp_dimension__add_output(struct perf_hpp_list *list, |
2546 | struct hpp_dimension *hd) | |
a7d945bc | 2547 | { |
1945c3e7 | 2548 | struct perf_hpp_fmt *fmt; |
a7d945bc | 2549 | |
1945c3e7 JO |
2550 | if (hd->taken) |
2551 | return 0; | |
2552 | ||
4b633eba | 2553 | fmt = __hpp_dimension__alloc_hpp(hd, 0); |
1945c3e7 JO |
2554 | if (!fmt) |
2555 | return -1; | |
2556 | ||
2557 | hd->taken = 1; | |
07600027 | 2558 | perf_hpp_list__column_register(list, fmt); |
a7d945bc NK |
2559 | return 0; |
2560 | } | |
2561 | ||
beeaaeb3 JO |
2562 | int hpp_dimension__add_output(unsigned col) |
2563 | { | |
2564 | BUG_ON(col >= PERF_HPP__MAX_INDEX); | |
07600027 | 2565 | return __hpp_dimension__add_output(&perf_hpp_list, &hpp_sort_dimensions[col]); |
beeaaeb3 JO |
2566 | } |
2567 | ||
a76490e4 JO |
2568 | int sort_dimension__add(struct perf_hpp_list *list, const char *tok, |
2569 | struct perf_evlist *evlist, | |
2570 | int level) | |
dd68ada2 JK |
2571 | { |
2572 | unsigned int i; | |
2573 | ||
fc5871ed NK |
2574 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) { |
2575 | struct sort_dimension *sd = &common_sort_dimensions[i]; | |
dd68ada2 | 2576 | |
dd68ada2 JK |
2577 | if (strncasecmp(tok, sd->name, strlen(tok))) |
2578 | continue; | |
fc5871ed | 2579 | |
dd68ada2 JK |
2580 | if (sd->entry == &sort_parent) { |
2581 | int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED); | |
2582 | if (ret) { | |
2583 | char err[BUFSIZ]; | |
2584 | ||
2585 | regerror(ret, &parent_regex, err, sizeof(err)); | |
2aefa4f7 ACM |
2586 | pr_err("Invalid regex: %s\n%s", parent_pattern, err); |
2587 | return -EINVAL; | |
dd68ada2 | 2588 | } |
de7e6a7c | 2589 | list->parent = 1; |
930477bd | 2590 | } else if (sd->entry == &sort_sym) { |
2e0453af | 2591 | list->sym = 1; |
94ba462d KL |
2592 | /* |
2593 | * perf diff displays the performance difference amongst | |
2594 | * two or more perf.data files. Those files could come | |
2595 | * from different binaries. So we should not compare | |
2596 | * their ips, but the name of symbol. | |
2597 | */ | |
2598 | if (sort__mode == SORT_MODE__DIFF) | |
2599 | sd->entry->se_collapse = sort__sym_sort; | |
2600 | ||
68f6d022 | 2601 | } else if (sd->entry == &sort_dso) { |
69849fc5 | 2602 | list->dso = 1; |
2e7ea3ab | 2603 | } else if (sd->entry == &sort_socket) { |
35a634f7 | 2604 | list->socket = 1; |
cfd92dad | 2605 | } else if (sd->entry == &sort_thread) { |
fa82911a | 2606 | list->thread = 1; |
078b8d4a | 2607 | } else if (sd->entry == &sort_comm) { |
7cecb7fe | 2608 | list->comm = 1; |
dd68ada2 JK |
2609 | } |
2610 | ||
d7b617f5 | 2611 | return __sort_dimension__add(sd, list, level); |
dd68ada2 | 2612 | } |
fc5871ed | 2613 | |
a2ce067e NK |
2614 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) { |
2615 | struct hpp_dimension *hd = &hpp_sort_dimensions[i]; | |
2616 | ||
2617 | if (strncasecmp(tok, hd->name, strlen(tok))) | |
2618 | continue; | |
2619 | ||
d7b617f5 | 2620 | return __hpp_dimension__add(hd, list, level); |
a2ce067e NK |
2621 | } |
2622 | ||
fc5871ed NK |
2623 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) { |
2624 | struct sort_dimension *sd = &bstack_sort_dimensions[i]; | |
2625 | ||
2626 | if (strncasecmp(tok, sd->name, strlen(tok))) | |
2627 | continue; | |
2628 | ||
55369fc1 | 2629 | if (sort__mode != SORT_MODE__BRANCH) |
fc5871ed NK |
2630 | return -EINVAL; |
2631 | ||
2632 | if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) | |
2e0453af | 2633 | list->sym = 1; |
fc5871ed | 2634 | |
d7b617f5 | 2635 | __sort_dimension__add(sd, list, level); |
fc5871ed NK |
2636 | return 0; |
2637 | } | |
2638 | ||
afab87b9 NK |
2639 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) { |
2640 | struct sort_dimension *sd = &memory_sort_dimensions[i]; | |
2641 | ||
2642 | if (strncasecmp(tok, sd->name, strlen(tok))) | |
2643 | continue; | |
2644 | ||
2645 | if (sort__mode != SORT_MODE__MEMORY) | |
2646 | return -EINVAL; | |
2647 | ||
9ac94e31 | 2648 | if (sd->entry == &sort_mem_dcacheline && cacheline_size() == 0) |
0d203166 ACM |
2649 | return -EINVAL; |
2650 | ||
afab87b9 | 2651 | if (sd->entry == &sort_mem_daddr_sym) |
2e0453af | 2652 | list->sym = 1; |
afab87b9 | 2653 | |
d7b617f5 | 2654 | __sort_dimension__add(sd, list, level); |
afab87b9 NK |
2655 | return 0; |
2656 | } | |
2657 | ||
4b633eba | 2658 | if (!add_dynamic_entry(evlist, tok, level)) |
c7c2a5e4 NK |
2659 | return 0; |
2660 | ||
dd68ada2 JK |
2661 | return -ESRCH; |
2662 | } | |
c8829c7a | 2663 | |
d7b617f5 JO |
2664 | static int setup_sort_list(struct perf_hpp_list *list, char *str, |
2665 | struct perf_evlist *evlist) | |
2fbaa390 JO |
2666 | { |
2667 | char *tmp, *tok; | |
2668 | int ret = 0; | |
4b633eba | 2669 | int level = 0; |
a23f37e8 NK |
2670 | int next_level = 1; |
2671 | bool in_group = false; | |
2672 | ||
2673 | do { | |
2674 | tok = str; | |
2675 | tmp = strpbrk(str, "{}, "); | |
2676 | if (tmp) { | |
2677 | if (in_group) | |
2678 | next_level = level; | |
2679 | else | |
2680 | next_level = level + 1; | |
2681 | ||
2682 | if (*tmp == '{') | |
2683 | in_group = true; | |
2684 | else if (*tmp == '}') | |
2685 | in_group = false; | |
2686 | ||
2687 | *tmp = '\0'; | |
2688 | str = tmp + 1; | |
2689 | } | |
2fbaa390 | 2690 | |
a23f37e8 | 2691 | if (*tok) { |
d7b617f5 | 2692 | ret = sort_dimension__add(list, tok, evlist, level); |
a23f37e8 | 2693 | if (ret == -EINVAL) { |
9ac94e31 | 2694 | if (!cacheline_size() && !strncasecmp(tok, "dcacheline", strlen(tok))) |
62d94b00 | 2695 | pr_err("The \"dcacheline\" --sort key needs to know the cacheline size and it couldn't be determined on this system"); |
0d203166 | 2696 | else |
62d94b00 | 2697 | pr_err("Invalid --sort key: `%s'", tok); |
a23f37e8 NK |
2698 | break; |
2699 | } else if (ret == -ESRCH) { | |
62d94b00 | 2700 | pr_err("Unknown --sort key: `%s'", tok); |
a23f37e8 NK |
2701 | break; |
2702 | } | |
2fbaa390 | 2703 | } |
a23f37e8 NK |
2704 | |
2705 | level = next_level; | |
2706 | } while (tmp); | |
2fbaa390 JO |
2707 | |
2708 | return ret; | |
2709 | } | |
2710 | ||
d49dadea | 2711 | static const char *get_default_sort_order(struct perf_evlist *evlist) |
512ae1bd NK |
2712 | { |
2713 | const char *default_sort_orders[] = { | |
2714 | default_sort_order, | |
2715 | default_branch_sort_order, | |
2716 | default_mem_sort_order, | |
2717 | default_top_sort_order, | |
2718 | default_diff_sort_order, | |
d49dadea | 2719 | default_tracepoint_sort_order, |
512ae1bd | 2720 | }; |
d49dadea NK |
2721 | bool use_trace = true; |
2722 | struct perf_evsel *evsel; | |
512ae1bd NK |
2723 | |
2724 | BUG_ON(sort__mode >= ARRAY_SIZE(default_sort_orders)); | |
2725 | ||
64831a21 | 2726 | if (evlist == NULL || perf_evlist__empty(evlist)) |
d49dadea NK |
2727 | goto out_no_evlist; |
2728 | ||
e5cadb93 | 2729 | evlist__for_each_entry(evlist, evsel) { |
d49dadea NK |
2730 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { |
2731 | use_trace = false; | |
2732 | break; | |
2733 | } | |
2734 | } | |
2735 | ||
2736 | if (use_trace) { | |
2737 | sort__mode = SORT_MODE__TRACEPOINT; | |
2738 | if (symbol_conf.raw_trace) | |
2739 | return "trace_fields"; | |
2740 | } | |
2741 | out_no_evlist: | |
512ae1bd NK |
2742 | return default_sort_orders[sort__mode]; |
2743 | } | |
2744 | ||
d49dadea | 2745 | static int setup_sort_order(struct perf_evlist *evlist) |
1a1c0ffb JO |
2746 | { |
2747 | char *new_sort_order; | |
2748 | ||
2749 | /* | |
2750 | * Append '+'-prefixed sort order to the default sort | |
2751 | * order string. | |
2752 | */ | |
2753 | if (!sort_order || is_strict_order(sort_order)) | |
2754 | return 0; | |
2755 | ||
2756 | if (sort_order[1] == '\0') { | |
62d94b00 | 2757 | pr_err("Invalid --sort key: `+'"); |
1a1c0ffb JO |
2758 | return -EINVAL; |
2759 | } | |
2760 | ||
2761 | /* | |
2762 | * We allocate new sort_order string, but we never free it, | |
2763 | * because it's checked over the rest of the code. | |
2764 | */ | |
2765 | if (asprintf(&new_sort_order, "%s,%s", | |
d49dadea | 2766 | get_default_sort_order(evlist), sort_order + 1) < 0) { |
62d94b00 | 2767 | pr_err("Not enough memory to set up --sort"); |
1a1c0ffb JO |
2768 | return -ENOMEM; |
2769 | } | |
2770 | ||
2771 | sort_order = new_sort_order; | |
2772 | return 0; | |
2773 | } | |
2774 | ||
b97511c5 JO |
2775 | /* |
2776 | * Adds 'pre,' prefix into 'str' is 'pre' is | |
2777 | * not already part of 'str'. | |
2778 | */ | |
2779 | static char *prefix_if_not_in(const char *pre, char *str) | |
2780 | { | |
2781 | char *n; | |
2782 | ||
2783 | if (!str || strstr(str, pre)) | |
2784 | return str; | |
2785 | ||
2786 | if (asprintf(&n, "%s,%s", pre, str) < 0) | |
2787 | return NULL; | |
2788 | ||
2789 | free(str); | |
2790 | return n; | |
2791 | } | |
2792 | ||
2793 | static char *setup_overhead(char *keys) | |
2794 | { | |
e9d848cb NK |
2795 | if (sort__mode == SORT_MODE__DIFF) |
2796 | return keys; | |
2797 | ||
b97511c5 JO |
2798 | keys = prefix_if_not_in("overhead", keys); |
2799 | ||
2800 | if (symbol_conf.cumulate_callchain) | |
2801 | keys = prefix_if_not_in("overhead_children", keys); | |
2802 | ||
2803 | return keys; | |
2804 | } | |
2805 | ||
40184c46 | 2806 | static int __setup_sorting(struct perf_evlist *evlist) |
c8829c7a | 2807 | { |
2fbaa390 | 2808 | char *str; |
1a1c0ffb | 2809 | const char *sort_keys; |
55309985 | 2810 | int ret = 0; |
c8829c7a | 2811 | |
d49dadea | 2812 | ret = setup_sort_order(evlist); |
1a1c0ffb JO |
2813 | if (ret) |
2814 | return ret; | |
2815 | ||
2816 | sort_keys = sort_order; | |
a7d945bc | 2817 | if (sort_keys == NULL) { |
2f3f9bcf | 2818 | if (is_strict_order(field_order)) { |
a7d945bc NK |
2819 | /* |
2820 | * If user specified field order but no sort order, | |
2821 | * we'll honor it and not add default sort orders. | |
2822 | */ | |
2823 | return 0; | |
2824 | } | |
2825 | ||
d49dadea | 2826 | sort_keys = get_default_sort_order(evlist); |
a7d945bc | 2827 | } |
512ae1bd NK |
2828 | |
2829 | str = strdup(sort_keys); | |
5936f54d | 2830 | if (str == NULL) { |
62d94b00 | 2831 | pr_err("Not enough memory to setup sort keys"); |
5936f54d NK |
2832 | return -ENOMEM; |
2833 | } | |
2834 | ||
b97511c5 JO |
2835 | /* |
2836 | * Prepend overhead fields for backward compatibility. | |
2837 | */ | |
2838 | if (!is_strict_order(field_order)) { | |
2839 | str = setup_overhead(str); | |
2840 | if (str == NULL) { | |
62d94b00 | 2841 | pr_err("Not enough memory to setup overhead keys"); |
b97511c5 JO |
2842 | return -ENOMEM; |
2843 | } | |
2844 | } | |
2845 | ||
d7b617f5 | 2846 | ret = setup_sort_list(&perf_hpp_list, str, evlist); |
c8829c7a ACM |
2847 | |
2848 | free(str); | |
55309985 | 2849 | return ret; |
c8829c7a | 2850 | } |
c351c281 | 2851 | |
f2998422 | 2852 | void perf_hpp__set_elide(int idx, bool elide) |
e67d49a7 | 2853 | { |
f2998422 JO |
2854 | struct perf_hpp_fmt *fmt; |
2855 | struct hpp_sort_entry *hse; | |
e67d49a7 | 2856 | |
cf094045 | 2857 | perf_hpp_list__for_each_format(&perf_hpp_list, fmt) { |
f2998422 JO |
2858 | if (!perf_hpp__is_sort_entry(fmt)) |
2859 | continue; | |
2860 | ||
2861 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
2862 | if (hse->se->se_width_idx == idx) { | |
2863 | fmt->elide = elide; | |
2864 | break; | |
2865 | } | |
e67d49a7 | 2866 | } |
e67d49a7 NK |
2867 | } |
2868 | ||
f2998422 | 2869 | static bool __get_elide(struct strlist *list, const char *list_name, FILE *fp) |
c351c281 ACM |
2870 | { |
2871 | if (list && strlist__nr_entries(list) == 1) { | |
2872 | if (fp != NULL) | |
2873 | fprintf(fp, "# %s: %s\n", list_name, | |
2874 | strlist__entry(list, 0)->s); | |
f2998422 JO |
2875 | return true; |
2876 | } | |
2877 | return false; | |
2878 | } | |
2879 | ||
2880 | static bool get_elide(int idx, FILE *output) | |
2881 | { | |
2882 | switch (idx) { | |
2883 | case HISTC_SYMBOL: | |
2884 | return __get_elide(symbol_conf.sym_list, "symbol", output); | |
2885 | case HISTC_DSO: | |
2886 | return __get_elide(symbol_conf.dso_list, "dso", output); | |
2887 | case HISTC_COMM: | |
2888 | return __get_elide(symbol_conf.comm_list, "comm", output); | |
2889 | default: | |
2890 | break; | |
c351c281 | 2891 | } |
f2998422 JO |
2892 | |
2893 | if (sort__mode != SORT_MODE__BRANCH) | |
2894 | return false; | |
2895 | ||
2896 | switch (idx) { | |
2897 | case HISTC_SYMBOL_FROM: | |
2898 | return __get_elide(symbol_conf.sym_from_list, "sym_from", output); | |
2899 | case HISTC_SYMBOL_TO: | |
2900 | return __get_elide(symbol_conf.sym_to_list, "sym_to", output); | |
2901 | case HISTC_DSO_FROM: | |
2902 | return __get_elide(symbol_conf.dso_from_list, "dso_from", output); | |
2903 | case HISTC_DSO_TO: | |
2904 | return __get_elide(symbol_conf.dso_to_list, "dso_to", output); | |
2905 | default: | |
2906 | break; | |
2907 | } | |
2908 | ||
2909 | return false; | |
c351c281 | 2910 | } |
08e71542 NK |
2911 | |
2912 | void sort__setup_elide(FILE *output) | |
2913 | { | |
cfaa154b NK |
2914 | struct perf_hpp_fmt *fmt; |
2915 | struct hpp_sort_entry *hse; | |
7524f63b | 2916 | |
cf094045 | 2917 | perf_hpp_list__for_each_format(&perf_hpp_list, fmt) { |
f2998422 JO |
2918 | if (!perf_hpp__is_sort_entry(fmt)) |
2919 | continue; | |
2920 | ||
2921 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | |
2922 | fmt->elide = get_elide(hse->se->se_width_idx, output); | |
08e71542 NK |
2923 | } |
2924 | ||
7524f63b NK |
2925 | /* |
2926 | * It makes no sense to elide all of sort entries. | |
2927 | * Just revert them to show up again. | |
2928 | */ | |
cf094045 | 2929 | perf_hpp_list__for_each_format(&perf_hpp_list, fmt) { |
cfaa154b NK |
2930 | if (!perf_hpp__is_sort_entry(fmt)) |
2931 | continue; | |
2932 | ||
f2998422 | 2933 | if (!fmt->elide) |
7524f63b NK |
2934 | return; |
2935 | } | |
2936 | ||
cf094045 | 2937 | perf_hpp_list__for_each_format(&perf_hpp_list, fmt) { |
cfaa154b NK |
2938 | if (!perf_hpp__is_sort_entry(fmt)) |
2939 | continue; | |
2940 | ||
f2998422 | 2941 | fmt->elide = false; |
cfaa154b | 2942 | } |
08e71542 | 2943 | } |
a7d945bc | 2944 | |
a76490e4 | 2945 | int output_field_add(struct perf_hpp_list *list, char *tok) |
a7d945bc NK |
2946 | { |
2947 | unsigned int i; | |
2948 | ||
2949 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) { | |
2950 | struct sort_dimension *sd = &common_sort_dimensions[i]; | |
2951 | ||
2952 | if (strncasecmp(tok, sd->name, strlen(tok))) | |
2953 | continue; | |
2954 | ||
07600027 | 2955 | return __sort_dimension__add_output(list, sd); |
a7d945bc NK |
2956 | } |
2957 | ||
2958 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) { | |
2959 | struct hpp_dimension *hd = &hpp_sort_dimensions[i]; | |
2960 | ||
2961 | if (strncasecmp(tok, hd->name, strlen(tok))) | |
2962 | continue; | |
2963 | ||
07600027 | 2964 | return __hpp_dimension__add_output(list, hd); |
a7d945bc NK |
2965 | } |
2966 | ||
2967 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) { | |
2968 | struct sort_dimension *sd = &bstack_sort_dimensions[i]; | |
2969 | ||
2970 | if (strncasecmp(tok, sd->name, strlen(tok))) | |
2971 | continue; | |
2972 | ||
07600027 | 2973 | return __sort_dimension__add_output(list, sd); |
a7d945bc NK |
2974 | } |
2975 | ||
2976 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) { | |
2977 | struct sort_dimension *sd = &memory_sort_dimensions[i]; | |
2978 | ||
2979 | if (strncasecmp(tok, sd->name, strlen(tok))) | |
2980 | continue; | |
2981 | ||
07600027 | 2982 | return __sort_dimension__add_output(list, sd); |
a7d945bc NK |
2983 | } |
2984 | ||
2985 | return -ESRCH; | |
2986 | } | |
2987 | ||
07600027 | 2988 | static int setup_output_list(struct perf_hpp_list *list, char *str) |
6d3375ef JO |
2989 | { |
2990 | char *tmp, *tok; | |
2991 | int ret = 0; | |
2992 | ||
2993 | for (tok = strtok_r(str, ", ", &tmp); | |
2994 | tok; tok = strtok_r(NULL, ", ", &tmp)) { | |
07600027 | 2995 | ret = output_field_add(list, tok); |
6d3375ef | 2996 | if (ret == -EINVAL) { |
56271170 | 2997 | ui__error("Invalid --fields key: `%s'", tok); |
6d3375ef JO |
2998 | break; |
2999 | } else if (ret == -ESRCH) { | |
56271170 | 3000 | ui__error("Unknown --fields key: `%s'", tok); |
6d3375ef JO |
3001 | break; |
3002 | } | |
3003 | } | |
3004 | ||
3005 | return ret; | |
3006 | } | |
3007 | ||
bcf98740 | 3008 | void reset_dimensions(void) |
a7d945bc NK |
3009 | { |
3010 | unsigned int i; | |
3011 | ||
3012 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) | |
3013 | common_sort_dimensions[i].taken = 0; | |
3014 | ||
3015 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) | |
3016 | hpp_sort_dimensions[i].taken = 0; | |
3017 | ||
3018 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) | |
3019 | bstack_sort_dimensions[i].taken = 0; | |
3020 | ||
3021 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) | |
3022 | memory_sort_dimensions[i].taken = 0; | |
3023 | } | |
3024 | ||
2f3f9bcf JO |
3025 | bool is_strict_order(const char *order) |
3026 | { | |
3027 | return order && (*order != '+'); | |
3028 | } | |
3029 | ||
a7d945bc NK |
3030 | static int __setup_output_field(void) |
3031 | { | |
6d3375ef | 3032 | char *str, *strp; |
2f3f9bcf | 3033 | int ret = -EINVAL; |
a7d945bc NK |
3034 | |
3035 | if (field_order == NULL) | |
3036 | return 0; | |
3037 | ||
2f3f9bcf | 3038 | strp = str = strdup(field_order); |
a7d945bc | 3039 | if (str == NULL) { |
62d94b00 | 3040 | pr_err("Not enough memory to setup output fields"); |
a7d945bc NK |
3041 | return -ENOMEM; |
3042 | } | |
3043 | ||
2f3f9bcf JO |
3044 | if (!is_strict_order(field_order)) |
3045 | strp++; | |
3046 | ||
3047 | if (!strlen(strp)) { | |
62d94b00 | 3048 | pr_err("Invalid --fields key: `+'"); |
2f3f9bcf JO |
3049 | goto out; |
3050 | } | |
3051 | ||
07600027 | 3052 | ret = setup_output_list(&perf_hpp_list, strp); |
a7d945bc | 3053 | |
2f3f9bcf | 3054 | out: |
a7d945bc NK |
3055 | free(str); |
3056 | return ret; | |
3057 | } | |
3058 | ||
9b240637 ACM |
3059 | int setup_sorting(struct perf_evlist *evlist) |
3060 | { | |
3061 | int err; | |
3062 | ||
3063 | err = __setup_sorting(evlist); | |
3064 | if (err < 0) | |
3065 | return err; | |
3066 | ||
3067 | if (parent_pattern != default_parent_pattern) { | |
d7b617f5 | 3068 | err = sort_dimension__add(&perf_hpp_list, "parent", evlist, -1); |
9b240637 ACM |
3069 | if (err < 0) |
3070 | return err; | |
3071 | } | |
3072 | ||
a7d945bc NK |
3073 | reset_dimensions(); |
3074 | ||
3075 | /* | |
3076 | * perf diff doesn't use default hpp output fields. | |
3077 | */ | |
3078 | if (sort__mode != SORT_MODE__DIFF) | |
3079 | perf_hpp__init(); | |
3080 | ||
3081 | err = __setup_output_field(); | |
3082 | if (err < 0) | |
3083 | return err; | |
3084 | ||
3085 | /* copy sort keys to output fields */ | |
43e0a68f | 3086 | perf_hpp__setup_output_field(&perf_hpp_list); |
a7d945bc | 3087 | /* and then copy output fields to sort keys */ |
43e0a68f | 3088 | perf_hpp__append_sort_keys(&perf_hpp_list); |
a7d945bc | 3089 | |
c3bc0c43 NK |
3090 | /* setup hists-specific output fields */ |
3091 | if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) | |
3092 | return -1; | |
3093 | ||
a7d945bc NK |
3094 | return 0; |
3095 | } | |
1c89fe9b NK |
3096 | |
3097 | void reset_output_field(void) | |
3098 | { | |
52225036 | 3099 | perf_hpp_list.need_collapse = 0; |
de7e6a7c | 3100 | perf_hpp_list.parent = 0; |
2e0453af | 3101 | perf_hpp_list.sym = 0; |
69849fc5 | 3102 | perf_hpp_list.dso = 0; |
1c89fe9b | 3103 | |
d69b2962 NK |
3104 | field_order = NULL; |
3105 | sort_order = NULL; | |
3106 | ||
1c89fe9b | 3107 | reset_dimensions(); |
43e0a68f | 3108 | perf_hpp__reset_output_field(&perf_hpp_list); |
1c89fe9b | 3109 | } |