9 const char default_parent_pattern
[] = "^sys_|^do_page_fault";
10 const char *parent_pattern
= default_parent_pattern
;
11 const char default_sort_order
[] = "comm,dso,symbol";
12 const char default_branch_sort_order
[] = "comm,dso_from,symbol_from,dso_to,symbol_to";
13 const char default_mem_sort_order
[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked";
14 const char default_top_sort_order
[] = "dso,symbol";
15 const char default_diff_sort_order
[] = "dso,symbol";
16 const char *sort_order
;
17 const char *field_order
;
18 regex_t ignore_callees_regex
;
19 int have_ignore_callees
= 0;
20 int sort__need_collapse
= 0;
21 int sort__has_parent
= 0;
22 int sort__has_sym
= 0;
23 int sort__has_dso
= 0;
24 enum sort_mode sort__mode
= SORT_MODE__NORMAL
;
27 static int repsep_snprintf(char *bf
, size_t size
, const char *fmt
, ...)
33 n
= vsnprintf(bf
, size
, fmt
, ap
);
34 if (symbol_conf
.field_sep
&& n
> 0) {
38 sep
= strchr(sep
, *symbol_conf
.field_sep
);
51 static int64_t cmp_null(const void *l
, const void *r
)
64 sort__thread_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
66 return right
->thread
->tid
- left
->thread
->tid
;
69 static int hist_entry__thread_snprintf(struct hist_entry
*he
, char *bf
,
70 size_t size
, unsigned int width
)
72 const char *comm
= thread__comm_str(he
->thread
);
74 width
= max(7U, width
) - 6;
75 return repsep_snprintf(bf
, size
, "%5d:%-*.*s", he
->thread
->tid
,
76 width
, width
, comm
?: "");
79 struct sort_entry sort_thread
= {
80 .se_header
= " Pid:Command",
81 .se_cmp
= sort__thread_cmp
,
82 .se_snprintf
= hist_entry__thread_snprintf
,
83 .se_width_idx
= HISTC_THREAD
,
89 sort__comm_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
91 /* Compare the addr that should be unique among comm */
92 return strcmp(comm__str(right
->comm
), comm__str(left
->comm
));
96 sort__comm_collapse(struct hist_entry
*left
, struct hist_entry
*right
)
98 /* Compare the addr that should be unique among comm */
99 return strcmp(comm__str(right
->comm
), comm__str(left
->comm
));
103 sort__comm_sort(struct hist_entry
*left
, struct hist_entry
*right
)
105 return strcmp(comm__str(right
->comm
), comm__str(left
->comm
));
108 static int hist_entry__comm_snprintf(struct hist_entry
*he
, char *bf
,
109 size_t size
, unsigned int width
)
111 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, comm__str(he
->comm
));
114 struct sort_entry sort_comm
= {
115 .se_header
= "Command",
116 .se_cmp
= sort__comm_cmp
,
117 .se_collapse
= sort__comm_collapse
,
118 .se_sort
= sort__comm_sort
,
119 .se_snprintf
= hist_entry__comm_snprintf
,
120 .se_width_idx
= HISTC_COMM
,
125 static int64_t _sort__dso_cmp(struct map
*map_l
, struct map
*map_r
)
127 struct dso
*dso_l
= map_l
? map_l
->dso
: NULL
;
128 struct dso
*dso_r
= map_r
? map_r
->dso
: NULL
;
129 const char *dso_name_l
, *dso_name_r
;
131 if (!dso_l
|| !dso_r
)
132 return cmp_null(dso_r
, dso_l
);
135 dso_name_l
= dso_l
->long_name
;
136 dso_name_r
= dso_r
->long_name
;
138 dso_name_l
= dso_l
->short_name
;
139 dso_name_r
= dso_r
->short_name
;
142 return strcmp(dso_name_l
, dso_name_r
);
146 sort__dso_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
148 return _sort__dso_cmp(right
->ms
.map
, left
->ms
.map
);
151 static int _hist_entry__dso_snprintf(struct map
*map
, char *bf
,
152 size_t size
, unsigned int width
)
154 if (map
&& map
->dso
) {
155 const char *dso_name
= !verbose
? map
->dso
->short_name
:
157 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, dso_name
);
160 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, "[unknown]");
163 static int hist_entry__dso_snprintf(struct hist_entry
*he
, char *bf
,
164 size_t size
, unsigned int width
)
166 return _hist_entry__dso_snprintf(he
->ms
.map
, bf
, size
, width
);
169 struct sort_entry sort_dso
= {
170 .se_header
= "Shared Object",
171 .se_cmp
= sort__dso_cmp
,
172 .se_snprintf
= hist_entry__dso_snprintf
,
173 .se_width_idx
= HISTC_DSO
,
178 static int64_t _sort__addr_cmp(u64 left_ip
, u64 right_ip
)
180 return (int64_t)(right_ip
- left_ip
);
183 static int64_t _sort__sym_cmp(struct symbol
*sym_l
, struct symbol
*sym_r
)
185 if (!sym_l
|| !sym_r
)
186 return cmp_null(sym_l
, sym_r
);
191 if (sym_l
->start
!= sym_r
->start
)
192 return (int64_t)(sym_r
->start
- sym_l
->start
);
194 return (int64_t)(sym_r
->end
- sym_l
->end
);
198 sort__sym_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
202 if (!left
->ms
.sym
&& !right
->ms
.sym
)
203 return _sort__addr_cmp(left
->ip
, right
->ip
);
206 * comparing symbol address alone is not enough since it's a
207 * relative address within a dso.
209 if (!sort__has_dso
) {
210 ret
= sort__dso_cmp(left
, right
);
215 return _sort__sym_cmp(left
->ms
.sym
, right
->ms
.sym
);
219 sort__sym_sort(struct hist_entry
*left
, struct hist_entry
*right
)
221 if (!left
->ms
.sym
|| !right
->ms
.sym
)
222 return cmp_null(left
->ms
.sym
, right
->ms
.sym
);
224 return strcmp(right
->ms
.sym
->name
, left
->ms
.sym
->name
);
227 static int _hist_entry__sym_snprintf(struct map
*map
, struct symbol
*sym
,
228 u64 ip
, char level
, char *bf
, size_t size
,
234 char o
= map
? dso__symtab_origin(map
->dso
) : '!';
235 ret
+= repsep_snprintf(bf
, size
, "%-#*llx %c ",
236 BITS_PER_LONG
/ 4 + 2, ip
, o
);
239 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "[%c] ", level
);
241 if (map
->type
== MAP__VARIABLE
) {
242 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "%s", sym
->name
);
243 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "+0x%llx",
244 ip
- map
->unmap_ip(map
, sym
->start
));
245 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "%-*s",
248 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "%-*s",
253 size_t len
= BITS_PER_LONG
/ 4;
254 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "%-#.*llx",
256 ret
+= repsep_snprintf(bf
+ ret
, size
- ret
, "%-*s",
266 static int hist_entry__sym_snprintf(struct hist_entry
*he
, char *bf
,
267 size_t size
, unsigned int width
)
269 return _hist_entry__sym_snprintf(he
->ms
.map
, he
->ms
.sym
, he
->ip
,
270 he
->level
, bf
, size
, width
);
273 struct sort_entry sort_sym
= {
274 .se_header
= "Symbol",
275 .se_cmp
= sort__sym_cmp
,
276 .se_sort
= sort__sym_sort
,
277 .se_snprintf
= hist_entry__sym_snprintf
,
278 .se_width_idx
= HISTC_SYMBOL
,
284 sort__srcline_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
286 if (!left
->srcline
) {
288 left
->srcline
= SRCLINE_UNKNOWN
;
290 struct map
*map
= left
->ms
.map
;
291 left
->srcline
= get_srcline(map
->dso
,
292 map__rip_2objdump(map
, left
->ip
),
296 if (!right
->srcline
) {
298 right
->srcline
= SRCLINE_UNKNOWN
;
300 struct map
*map
= right
->ms
.map
;
301 right
->srcline
= get_srcline(map
->dso
,
302 map__rip_2objdump(map
, right
->ip
),
303 right
->ms
.sym
, true);
306 return strcmp(right
->srcline
, left
->srcline
);
309 static int hist_entry__srcline_snprintf(struct hist_entry
*he
, char *bf
,
310 size_t size
, unsigned int width
)
312 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, he
->srcline
);
315 struct sort_entry sort_srcline
= {
316 .se_header
= "Source:Line",
317 .se_cmp
= sort__srcline_cmp
,
318 .se_snprintf
= hist_entry__srcline_snprintf
,
319 .se_width_idx
= HISTC_SRCLINE
,
325 sort__parent_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
327 struct symbol
*sym_l
= left
->parent
;
328 struct symbol
*sym_r
= right
->parent
;
330 if (!sym_l
|| !sym_r
)
331 return cmp_null(sym_l
, sym_r
);
333 return strcmp(sym_r
->name
, sym_l
->name
);
336 static int hist_entry__parent_snprintf(struct hist_entry
*he
, char *bf
,
337 size_t size
, unsigned int width
)
339 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
,
340 he
->parent
? he
->parent
->name
: "[other]");
343 struct sort_entry sort_parent
= {
344 .se_header
= "Parent symbol",
345 .se_cmp
= sort__parent_cmp
,
346 .se_snprintf
= hist_entry__parent_snprintf
,
347 .se_width_idx
= HISTC_PARENT
,
353 sort__cpu_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
355 return right
->cpu
- left
->cpu
;
358 static int hist_entry__cpu_snprintf(struct hist_entry
*he
, char *bf
,
359 size_t size
, unsigned int width
)
361 return repsep_snprintf(bf
, size
, "%*.*d", width
, width
, he
->cpu
);
364 struct sort_entry sort_cpu
= {
366 .se_cmp
= sort__cpu_cmp
,
367 .se_snprintf
= hist_entry__cpu_snprintf
,
368 .se_width_idx
= HISTC_CPU
,
371 /* sort keys for branch stacks */
374 sort__dso_from_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
376 if (!left
->branch_info
|| !right
->branch_info
)
377 return cmp_null(left
->branch_info
, right
->branch_info
);
379 return _sort__dso_cmp(left
->branch_info
->from
.map
,
380 right
->branch_info
->from
.map
);
383 static int hist_entry__dso_from_snprintf(struct hist_entry
*he
, char *bf
,
384 size_t size
, unsigned int width
)
387 return _hist_entry__dso_snprintf(he
->branch_info
->from
.map
,
390 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, "N/A");
394 sort__dso_to_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
396 if (!left
->branch_info
|| !right
->branch_info
)
397 return cmp_null(left
->branch_info
, right
->branch_info
);
399 return _sort__dso_cmp(left
->branch_info
->to
.map
,
400 right
->branch_info
->to
.map
);
403 static int hist_entry__dso_to_snprintf(struct hist_entry
*he
, char *bf
,
404 size_t size
, unsigned int width
)
407 return _hist_entry__dso_snprintf(he
->branch_info
->to
.map
,
410 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, "N/A");
414 sort__sym_from_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
416 struct addr_map_symbol
*from_l
= &left
->branch_info
->from
;
417 struct addr_map_symbol
*from_r
= &right
->branch_info
->from
;
419 if (!left
->branch_info
|| !right
->branch_info
)
420 return cmp_null(left
->branch_info
, right
->branch_info
);
422 from_l
= &left
->branch_info
->from
;
423 from_r
= &right
->branch_info
->from
;
425 if (!from_l
->sym
&& !from_r
->sym
)
426 return _sort__addr_cmp(from_l
->addr
, from_r
->addr
);
428 return _sort__sym_cmp(from_l
->sym
, from_r
->sym
);
432 sort__sym_to_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
434 struct addr_map_symbol
*to_l
, *to_r
;
436 if (!left
->branch_info
|| !right
->branch_info
)
437 return cmp_null(left
->branch_info
, right
->branch_info
);
439 to_l
= &left
->branch_info
->to
;
440 to_r
= &right
->branch_info
->to
;
442 if (!to_l
->sym
&& !to_r
->sym
)
443 return _sort__addr_cmp(to_l
->addr
, to_r
->addr
);
445 return _sort__sym_cmp(to_l
->sym
, to_r
->sym
);
448 static int hist_entry__sym_from_snprintf(struct hist_entry
*he
, char *bf
,
449 size_t size
, unsigned int width
)
451 if (he
->branch_info
) {
452 struct addr_map_symbol
*from
= &he
->branch_info
->from
;
454 return _hist_entry__sym_snprintf(from
->map
, from
->sym
, from
->addr
,
455 he
->level
, bf
, size
, width
);
458 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, "N/A");
461 static int hist_entry__sym_to_snprintf(struct hist_entry
*he
, char *bf
,
462 size_t size
, unsigned int width
)
464 if (he
->branch_info
) {
465 struct addr_map_symbol
*to
= &he
->branch_info
->to
;
467 return _hist_entry__sym_snprintf(to
->map
, to
->sym
, to
->addr
,
468 he
->level
, bf
, size
, width
);
471 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, "N/A");
474 struct sort_entry sort_dso_from
= {
475 .se_header
= "Source Shared Object",
476 .se_cmp
= sort__dso_from_cmp
,
477 .se_snprintf
= hist_entry__dso_from_snprintf
,
478 .se_width_idx
= HISTC_DSO_FROM
,
481 struct sort_entry sort_dso_to
= {
482 .se_header
= "Target Shared Object",
483 .se_cmp
= sort__dso_to_cmp
,
484 .se_snprintf
= hist_entry__dso_to_snprintf
,
485 .se_width_idx
= HISTC_DSO_TO
,
488 struct sort_entry sort_sym_from
= {
489 .se_header
= "Source Symbol",
490 .se_cmp
= sort__sym_from_cmp
,
491 .se_snprintf
= hist_entry__sym_from_snprintf
,
492 .se_width_idx
= HISTC_SYMBOL_FROM
,
495 struct sort_entry sort_sym_to
= {
496 .se_header
= "Target Symbol",
497 .se_cmp
= sort__sym_to_cmp
,
498 .se_snprintf
= hist_entry__sym_to_snprintf
,
499 .se_width_idx
= HISTC_SYMBOL_TO
,
503 sort__mispredict_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
507 if (!left
->branch_info
|| !right
->branch_info
)
508 return cmp_null(left
->branch_info
, right
->branch_info
);
510 mp
= left
->branch_info
->flags
.mispred
!= right
->branch_info
->flags
.mispred
;
511 p
= left
->branch_info
->flags
.predicted
!= right
->branch_info
->flags
.predicted
;
515 static int hist_entry__mispredict_snprintf(struct hist_entry
*he
, char *bf
,
516 size_t size
, unsigned int width
){
517 static const char *out
= "N/A";
519 if (he
->branch_info
) {
520 if (he
->branch_info
->flags
.predicted
)
522 else if (he
->branch_info
->flags
.mispred
)
526 return repsep_snprintf(bf
, size
, "%-*.*s", width
, width
, out
);
529 /* --sort daddr_sym */
531 sort__daddr_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
533 uint64_t l
= 0, r
= 0;
536 l
= left
->mem_info
->daddr
.addr
;
538 r
= right
->mem_info
->daddr
.addr
;
540 return (int64_t)(r
- l
);
543 static int hist_entry__daddr_snprintf(struct hist_entry
*he
, char *bf
,
544 size_t size
, unsigned int width
)
547 struct map
*map
= NULL
;
548 struct symbol
*sym
= NULL
;
551 addr
= he
->mem_info
->daddr
.addr
;
552 map
= he
->mem_info
->daddr
.map
;
553 sym
= he
->mem_info
->daddr
.sym
;
555 return _hist_entry__sym_snprintf(map
, sym
, addr
, he
->level
, bf
, size
,
560 sort__dso_daddr_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
562 struct map
*map_l
= NULL
;
563 struct map
*map_r
= NULL
;
566 map_l
= left
->mem_info
->daddr
.map
;
568 map_r
= right
->mem_info
->daddr
.map
;
570 return _sort__dso_cmp(map_l
, map_r
);
573 static int hist_entry__dso_daddr_snprintf(struct hist_entry
*he
, char *bf
,
574 size_t size
, unsigned int width
)
576 struct map
*map
= NULL
;
579 map
= he
->mem_info
->daddr
.map
;
581 return _hist_entry__dso_snprintf(map
, bf
, size
, width
);
585 sort__locked_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
587 union perf_mem_data_src data_src_l
;
588 union perf_mem_data_src data_src_r
;
591 data_src_l
= left
->mem_info
->data_src
;
593 data_src_l
.mem_lock
= PERF_MEM_LOCK_NA
;
596 data_src_r
= right
->mem_info
->data_src
;
598 data_src_r
.mem_lock
= PERF_MEM_LOCK_NA
;
600 return (int64_t)(data_src_r
.mem_lock
- data_src_l
.mem_lock
);
603 static int hist_entry__locked_snprintf(struct hist_entry
*he
, char *bf
,
604 size_t size
, unsigned int width
)
607 u64 mask
= PERF_MEM_LOCK_NA
;
610 mask
= he
->mem_info
->data_src
.mem_lock
;
612 if (mask
& PERF_MEM_LOCK_NA
)
614 else if (mask
& PERF_MEM_LOCK_LOCKED
)
619 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
623 sort__tlb_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
625 union perf_mem_data_src data_src_l
;
626 union perf_mem_data_src data_src_r
;
629 data_src_l
= left
->mem_info
->data_src
;
631 data_src_l
.mem_dtlb
= PERF_MEM_TLB_NA
;
634 data_src_r
= right
->mem_info
->data_src
;
636 data_src_r
.mem_dtlb
= PERF_MEM_TLB_NA
;
638 return (int64_t)(data_src_r
.mem_dtlb
- data_src_l
.mem_dtlb
);
641 static const char * const tlb_access
[] = {
650 #define NUM_TLB_ACCESS (sizeof(tlb_access)/sizeof(const char *))
652 static int hist_entry__tlb_snprintf(struct hist_entry
*he
, char *bf
,
653 size_t size
, unsigned int width
)
656 size_t sz
= sizeof(out
) - 1; /* -1 for null termination */
658 u64 m
= PERF_MEM_TLB_NA
;
664 m
= he
->mem_info
->data_src
.mem_dtlb
;
666 hit
= m
& PERF_MEM_TLB_HIT
;
667 miss
= m
& PERF_MEM_TLB_MISS
;
669 /* already taken care of */
670 m
&= ~(PERF_MEM_TLB_HIT
|PERF_MEM_TLB_MISS
);
672 for (i
= 0; m
&& i
< NUM_TLB_ACCESS
; i
++, m
>>= 1) {
679 strncat(out
, tlb_access
[i
], sz
- l
);
680 l
+= strlen(tlb_access
[i
]);
685 strncat(out
, " hit", sz
- l
);
687 strncat(out
, " miss", sz
- l
);
689 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
693 sort__lvl_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
695 union perf_mem_data_src data_src_l
;
696 union perf_mem_data_src data_src_r
;
699 data_src_l
= left
->mem_info
->data_src
;
701 data_src_l
.mem_lvl
= PERF_MEM_LVL_NA
;
704 data_src_r
= right
->mem_info
->data_src
;
706 data_src_r
.mem_lvl
= PERF_MEM_LVL_NA
;
708 return (int64_t)(data_src_r
.mem_lvl
- data_src_l
.mem_lvl
);
711 static const char * const mem_lvl
[] = {
720 "Remote RAM (1 hop)",
721 "Remote RAM (2 hops)",
722 "Remote Cache (1 hop)",
723 "Remote Cache (2 hops)",
727 #define NUM_MEM_LVL (sizeof(mem_lvl)/sizeof(const char *))
729 static int hist_entry__lvl_snprintf(struct hist_entry
*he
, char *bf
,
730 size_t size
, unsigned int width
)
733 size_t sz
= sizeof(out
) - 1; /* -1 for null termination */
735 u64 m
= PERF_MEM_LVL_NA
;
739 m
= he
->mem_info
->data_src
.mem_lvl
;
743 hit
= m
& PERF_MEM_LVL_HIT
;
744 miss
= m
& PERF_MEM_LVL_MISS
;
746 /* already taken care of */
747 m
&= ~(PERF_MEM_LVL_HIT
|PERF_MEM_LVL_MISS
);
749 for (i
= 0; m
&& i
< NUM_MEM_LVL
; i
++, m
>>= 1) {
756 strncat(out
, mem_lvl
[i
], sz
- l
);
757 l
+= strlen(mem_lvl
[i
]);
762 strncat(out
, " hit", sz
- l
);
764 strncat(out
, " miss", sz
- l
);
766 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
770 sort__snoop_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
772 union perf_mem_data_src data_src_l
;
773 union perf_mem_data_src data_src_r
;
776 data_src_l
= left
->mem_info
->data_src
;
778 data_src_l
.mem_snoop
= PERF_MEM_SNOOP_NA
;
781 data_src_r
= right
->mem_info
->data_src
;
783 data_src_r
.mem_snoop
= PERF_MEM_SNOOP_NA
;
785 return (int64_t)(data_src_r
.mem_snoop
- data_src_l
.mem_snoop
);
788 static const char * const snoop_access
[] = {
795 #define NUM_SNOOP_ACCESS (sizeof(snoop_access)/sizeof(const char *))
797 static int hist_entry__snoop_snprintf(struct hist_entry
*he
, char *bf
,
798 size_t size
, unsigned int width
)
801 size_t sz
= sizeof(out
) - 1; /* -1 for null termination */
803 u64 m
= PERF_MEM_SNOOP_NA
;
808 m
= he
->mem_info
->data_src
.mem_snoop
;
810 for (i
= 0; m
&& i
< NUM_SNOOP_ACCESS
; i
++, m
>>= 1) {
817 strncat(out
, snoop_access
[i
], sz
- l
);
818 l
+= strlen(snoop_access
[i
]);
824 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
827 static inline u64
cl_address(u64 address
)
829 /* return the cacheline of the address */
830 return (address
& ~(cacheline_size
- 1));
834 sort__dcacheline_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
837 struct map
*l_map
, *r_map
;
839 if (!left
->mem_info
) return -1;
840 if (!right
->mem_info
) return 1;
842 /* group event types together */
843 if (left
->cpumode
> right
->cpumode
) return -1;
844 if (left
->cpumode
< right
->cpumode
) return 1;
846 l_map
= left
->mem_info
->daddr
.map
;
847 r_map
= right
->mem_info
->daddr
.map
;
849 /* if both are NULL, jump to sort on al_addr instead */
850 if (!l_map
&& !r_map
)
853 if (!l_map
) return -1;
854 if (!r_map
) return 1;
856 if (l_map
->maj
> r_map
->maj
) return -1;
857 if (l_map
->maj
< r_map
->maj
) return 1;
859 if (l_map
->min
> r_map
->min
) return -1;
860 if (l_map
->min
< r_map
->min
) return 1;
862 if (l_map
->ino
> r_map
->ino
) return -1;
863 if (l_map
->ino
< r_map
->ino
) return 1;
865 if (l_map
->ino_generation
> r_map
->ino_generation
) return -1;
866 if (l_map
->ino_generation
< r_map
->ino_generation
) return 1;
869 * Addresses with no major/minor numbers are assumed to be
870 * anonymous in userspace. Sort those on pid then address.
872 * The kernel and non-zero major/minor mapped areas are
873 * assumed to be unity mapped. Sort those on address.
876 if ((left
->cpumode
!= PERF_RECORD_MISC_KERNEL
) &&
877 (!(l_map
->flags
& MAP_SHARED
)) &&
878 !l_map
->maj
&& !l_map
->min
&& !l_map
->ino
&&
879 !l_map
->ino_generation
) {
880 /* userspace anonymous */
882 if (left
->thread
->pid_
> right
->thread
->pid_
) return -1;
883 if (left
->thread
->pid_
< right
->thread
->pid_
) return 1;
887 /* al_addr does all the right addr - start + offset calculations */
888 l
= cl_address(left
->mem_info
->daddr
.al_addr
);
889 r
= cl_address(right
->mem_info
->daddr
.al_addr
);
891 if (l
> r
) return -1;
897 static int hist_entry__dcacheline_snprintf(struct hist_entry
*he
, char *bf
,
898 size_t size
, unsigned int width
)
902 struct map
*map
= NULL
;
903 struct symbol
*sym
= NULL
;
904 char level
= he
->level
;
907 addr
= cl_address(he
->mem_info
->daddr
.al_addr
);
908 map
= he
->mem_info
->daddr
.map
;
909 sym
= he
->mem_info
->daddr
.sym
;
911 /* print [s] for shared data mmaps */
912 if ((he
->cpumode
!= PERF_RECORD_MISC_KERNEL
) &&
913 map
&& (map
->type
== MAP__VARIABLE
) &&
914 (map
->flags
& MAP_SHARED
) &&
915 (map
->maj
|| map
->min
|| map
->ino
||
916 map
->ino_generation
))
921 return _hist_entry__sym_snprintf(map
, sym
, addr
, level
, bf
, size
,
925 struct sort_entry sort_mispredict
= {
926 .se_header
= "Branch Mispredicted",
927 .se_cmp
= sort__mispredict_cmp
,
928 .se_snprintf
= hist_entry__mispredict_snprintf
,
929 .se_width_idx
= HISTC_MISPREDICT
,
932 static u64
he_weight(struct hist_entry
*he
)
934 return he
->stat
.nr_events
? he
->stat
.weight
/ he
->stat
.nr_events
: 0;
938 sort__local_weight_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
940 return he_weight(left
) - he_weight(right
);
943 static int hist_entry__local_weight_snprintf(struct hist_entry
*he
, char *bf
,
944 size_t size
, unsigned int width
)
946 return repsep_snprintf(bf
, size
, "%-*llu", width
, he_weight(he
));
949 struct sort_entry sort_local_weight
= {
950 .se_header
= "Local Weight",
951 .se_cmp
= sort__local_weight_cmp
,
952 .se_snprintf
= hist_entry__local_weight_snprintf
,
953 .se_width_idx
= HISTC_LOCAL_WEIGHT
,
957 sort__global_weight_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
959 return left
->stat
.weight
- right
->stat
.weight
;
962 static int hist_entry__global_weight_snprintf(struct hist_entry
*he
, char *bf
,
963 size_t size
, unsigned int width
)
965 return repsep_snprintf(bf
, size
, "%-*llu", width
, he
->stat
.weight
);
968 struct sort_entry sort_global_weight
= {
969 .se_header
= "Weight",
970 .se_cmp
= sort__global_weight_cmp
,
971 .se_snprintf
= hist_entry__global_weight_snprintf
,
972 .se_width_idx
= HISTC_GLOBAL_WEIGHT
,
975 struct sort_entry sort_mem_daddr_sym
= {
976 .se_header
= "Data Symbol",
977 .se_cmp
= sort__daddr_cmp
,
978 .se_snprintf
= hist_entry__daddr_snprintf
,
979 .se_width_idx
= HISTC_MEM_DADDR_SYMBOL
,
982 struct sort_entry sort_mem_daddr_dso
= {
983 .se_header
= "Data Object",
984 .se_cmp
= sort__dso_daddr_cmp
,
985 .se_snprintf
= hist_entry__dso_daddr_snprintf
,
986 .se_width_idx
= HISTC_MEM_DADDR_SYMBOL
,
989 struct sort_entry sort_mem_locked
= {
990 .se_header
= "Locked",
991 .se_cmp
= sort__locked_cmp
,
992 .se_snprintf
= hist_entry__locked_snprintf
,
993 .se_width_idx
= HISTC_MEM_LOCKED
,
996 struct sort_entry sort_mem_tlb
= {
997 .se_header
= "TLB access",
998 .se_cmp
= sort__tlb_cmp
,
999 .se_snprintf
= hist_entry__tlb_snprintf
,
1000 .se_width_idx
= HISTC_MEM_TLB
,
1003 struct sort_entry sort_mem_lvl
= {
1004 .se_header
= "Memory access",
1005 .se_cmp
= sort__lvl_cmp
,
1006 .se_snprintf
= hist_entry__lvl_snprintf
,
1007 .se_width_idx
= HISTC_MEM_LVL
,
1010 struct sort_entry sort_mem_snoop
= {
1011 .se_header
= "Snoop",
1012 .se_cmp
= sort__snoop_cmp
,
1013 .se_snprintf
= hist_entry__snoop_snprintf
,
1014 .se_width_idx
= HISTC_MEM_SNOOP
,
1017 struct sort_entry sort_mem_dcacheline
= {
1018 .se_header
= "Data Cacheline",
1019 .se_cmp
= sort__dcacheline_cmp
,
1020 .se_snprintf
= hist_entry__dcacheline_snprintf
,
1021 .se_width_idx
= HISTC_MEM_DCACHELINE
,
1025 sort__abort_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
1027 if (!left
->branch_info
|| !right
->branch_info
)
1028 return cmp_null(left
->branch_info
, right
->branch_info
);
1030 return left
->branch_info
->flags
.abort
!=
1031 right
->branch_info
->flags
.abort
;
1034 static int hist_entry__abort_snprintf(struct hist_entry
*he
, char *bf
,
1035 size_t size
, unsigned int width
)
1037 static const char *out
= "N/A";
1039 if (he
->branch_info
) {
1040 if (he
->branch_info
->flags
.abort
)
1046 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
1049 struct sort_entry sort_abort
= {
1050 .se_header
= "Transaction abort",
1051 .se_cmp
= sort__abort_cmp
,
1052 .se_snprintf
= hist_entry__abort_snprintf
,
1053 .se_width_idx
= HISTC_ABORT
,
1057 sort__in_tx_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
1059 if (!left
->branch_info
|| !right
->branch_info
)
1060 return cmp_null(left
->branch_info
, right
->branch_info
);
1062 return left
->branch_info
->flags
.in_tx
!=
1063 right
->branch_info
->flags
.in_tx
;
1066 static int hist_entry__in_tx_snprintf(struct hist_entry
*he
, char *bf
,
1067 size_t size
, unsigned int width
)
1069 static const char *out
= "N/A";
1071 if (he
->branch_info
) {
1072 if (he
->branch_info
->flags
.in_tx
)
1078 return repsep_snprintf(bf
, size
, "%-*s", width
, out
);
1081 struct sort_entry sort_in_tx
= {
1082 .se_header
= "Branch in transaction",
1083 .se_cmp
= sort__in_tx_cmp
,
1084 .se_snprintf
= hist_entry__in_tx_snprintf
,
1085 .se_width_idx
= HISTC_IN_TX
,
1089 sort__transaction_cmp(struct hist_entry
*left
, struct hist_entry
*right
)
1091 return left
->transaction
- right
->transaction
;
1094 static inline char *add_str(char *p
, const char *str
)
1097 return p
+ strlen(str
);
1100 static struct txbit
{
1105 { PERF_TXN_ELISION
, "EL ", 0 },
1106 { PERF_TXN_TRANSACTION
, "TX ", 1 },
1107 { PERF_TXN_SYNC
, "SYNC ", 1 },
1108 { PERF_TXN_ASYNC
, "ASYNC ", 0 },
1109 { PERF_TXN_RETRY
, "RETRY ", 0 },
1110 { PERF_TXN_CONFLICT
, "CON ", 0 },
1111 { PERF_TXN_CAPACITY_WRITE
, "CAP-WRITE ", 1 },
1112 { PERF_TXN_CAPACITY_READ
, "CAP-READ ", 0 },
1116 int hist_entry__transaction_len(void)
1121 for (i
= 0; txbits
[i
].name
; i
++) {
1122 if (!txbits
[i
].skip_for_len
)
1123 len
+= strlen(txbits
[i
].name
);
1125 len
+= 4; /* :XX<space> */
1129 static int hist_entry__transaction_snprintf(struct hist_entry
*he
, char *bf
,
1130 size_t size
, unsigned int width
)
1132 u64 t
= he
->transaction
;
1138 for (i
= 0; txbits
[i
].name
; i
++)
1139 if (txbits
[i
].flag
& t
)
1140 p
= add_str(p
, txbits
[i
].name
);
1141 if (t
&& !(t
& (PERF_TXN_SYNC
|PERF_TXN_ASYNC
)))
1142 p
= add_str(p
, "NEITHER ");
1143 if (t
& PERF_TXN_ABORT_MASK
) {
1144 sprintf(p
, ":%" PRIx64
,
1145 (t
& PERF_TXN_ABORT_MASK
) >>
1146 PERF_TXN_ABORT_SHIFT
);
1150 return repsep_snprintf(bf
, size
, "%-*s", width
, buf
);
1153 struct sort_entry sort_transaction
= {
1154 .se_header
= "Transaction ",
1155 .se_cmp
= sort__transaction_cmp
,
1156 .se_snprintf
= hist_entry__transaction_snprintf
,
1157 .se_width_idx
= HISTC_TRANSACTION
,
1160 struct sort_dimension
{
1162 struct sort_entry
*entry
;
1166 #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) }
1168 static struct sort_dimension common_sort_dimensions
[] = {
1169 DIM(SORT_PID
, "pid", sort_thread
),
1170 DIM(SORT_COMM
, "comm", sort_comm
),
1171 DIM(SORT_DSO
, "dso", sort_dso
),
1172 DIM(SORT_SYM
, "symbol", sort_sym
),
1173 DIM(SORT_PARENT
, "parent", sort_parent
),
1174 DIM(SORT_CPU
, "cpu", sort_cpu
),
1175 DIM(SORT_SRCLINE
, "srcline", sort_srcline
),
1176 DIM(SORT_LOCAL_WEIGHT
, "local_weight", sort_local_weight
),
1177 DIM(SORT_GLOBAL_WEIGHT
, "weight", sort_global_weight
),
1178 DIM(SORT_TRANSACTION
, "transaction", sort_transaction
),
1183 #define DIM(d, n, func) [d - __SORT_BRANCH_STACK] = { .name = n, .entry = &(func) }
1185 static struct sort_dimension bstack_sort_dimensions
[] = {
1186 DIM(SORT_DSO_FROM
, "dso_from", sort_dso_from
),
1187 DIM(SORT_DSO_TO
, "dso_to", sort_dso_to
),
1188 DIM(SORT_SYM_FROM
, "symbol_from", sort_sym_from
),
1189 DIM(SORT_SYM_TO
, "symbol_to", sort_sym_to
),
1190 DIM(SORT_MISPREDICT
, "mispredict", sort_mispredict
),
1191 DIM(SORT_IN_TX
, "in_tx", sort_in_tx
),
1192 DIM(SORT_ABORT
, "abort", sort_abort
),
1197 #define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) }
1199 static struct sort_dimension memory_sort_dimensions
[] = {
1200 DIM(SORT_MEM_DADDR_SYMBOL
, "symbol_daddr", sort_mem_daddr_sym
),
1201 DIM(SORT_MEM_DADDR_DSO
, "dso_daddr", sort_mem_daddr_dso
),
1202 DIM(SORT_MEM_LOCKED
, "locked", sort_mem_locked
),
1203 DIM(SORT_MEM_TLB
, "tlb", sort_mem_tlb
),
1204 DIM(SORT_MEM_LVL
, "mem", sort_mem_lvl
),
1205 DIM(SORT_MEM_SNOOP
, "snoop", sort_mem_snoop
),
1206 DIM(SORT_MEM_DCACHELINE
, "dcacheline", sort_mem_dcacheline
),
1211 struct hpp_dimension
{
1213 struct perf_hpp_fmt
*fmt
;
1217 #define DIM(d, n) { .name = n, .fmt = &perf_hpp__format[d], }
1219 static struct hpp_dimension hpp_sort_dimensions
[] = {
1220 DIM(PERF_HPP__OVERHEAD
, "overhead"),
1221 DIM(PERF_HPP__OVERHEAD_SYS
, "overhead_sys"),
1222 DIM(PERF_HPP__OVERHEAD_US
, "overhead_us"),
1223 DIM(PERF_HPP__OVERHEAD_GUEST_SYS
, "overhead_guest_sys"),
1224 DIM(PERF_HPP__OVERHEAD_GUEST_US
, "overhead_guest_us"),
1225 DIM(PERF_HPP__OVERHEAD_ACC
, "overhead_children"),
1226 DIM(PERF_HPP__SAMPLES
, "sample"),
1227 DIM(PERF_HPP__PERIOD
, "period"),
1232 struct hpp_sort_entry
{
1233 struct perf_hpp_fmt hpp
;
1234 struct sort_entry
*se
;
1237 bool perf_hpp__same_sort_entry(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1239 struct hpp_sort_entry
*hse_a
;
1240 struct hpp_sort_entry
*hse_b
;
1242 if (!perf_hpp__is_sort_entry(a
) || !perf_hpp__is_sort_entry(b
))
1245 hse_a
= container_of(a
, struct hpp_sort_entry
, hpp
);
1246 hse_b
= container_of(b
, struct hpp_sort_entry
, hpp
);
1248 return hse_a
->se
== hse_b
->se
;
1251 void perf_hpp__reset_sort_width(struct perf_hpp_fmt
*fmt
, struct hists
*hists
)
1253 struct hpp_sort_entry
*hse
;
1255 if (!perf_hpp__is_sort_entry(fmt
))
1258 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1259 hists__new_col_len(hists
, hse
->se
->se_width_idx
, strlen(fmt
->name
));
1262 static int __sort__hpp_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1263 struct perf_evsel
*evsel
)
1265 struct hpp_sort_entry
*hse
;
1266 size_t len
= fmt
->user_len
;
1268 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1271 len
= hists__col_len(evsel__hists(evsel
), hse
->se
->se_width_idx
);
1273 return scnprintf(hpp
->buf
, hpp
->size
, "%-*.*s", len
, len
, fmt
->name
);
1276 static int __sort__hpp_width(struct perf_hpp_fmt
*fmt
,
1277 struct perf_hpp
*hpp __maybe_unused
,
1278 struct perf_evsel
*evsel
)
1280 struct hpp_sort_entry
*hse
;
1281 size_t len
= fmt
->user_len
;
1283 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1286 len
= hists__col_len(evsel__hists(evsel
), hse
->se
->se_width_idx
);
1291 static int __sort__hpp_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1292 struct hist_entry
*he
)
1294 struct hpp_sort_entry
*hse
;
1295 size_t len
= fmt
->user_len
;
1297 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1300 len
= hists__col_len(he
->hists
, hse
->se
->se_width_idx
);
1302 return hse
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1305 static int64_t __sort__hpp_cmp(struct perf_hpp_fmt
*fmt
,
1306 struct hist_entry
*a
, struct hist_entry
*b
)
1308 struct hpp_sort_entry
*hse
;
1310 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1311 return hse
->se
->se_cmp(a
, b
);
1314 static int64_t __sort__hpp_collapse(struct perf_hpp_fmt
*fmt
,
1315 struct hist_entry
*a
, struct hist_entry
*b
)
1317 struct hpp_sort_entry
*hse
;
1318 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1320 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1321 collapse_fn
= hse
->se
->se_collapse
?: hse
->se
->se_cmp
;
1322 return collapse_fn(a
, b
);
1325 static int64_t __sort__hpp_sort(struct perf_hpp_fmt
*fmt
,
1326 struct hist_entry
*a
, struct hist_entry
*b
)
1328 struct hpp_sort_entry
*hse
;
1329 int64_t (*sort_fn
)(struct hist_entry
*, struct hist_entry
*);
1331 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1332 sort_fn
= hse
->se
->se_sort
?: hse
->se
->se_cmp
;
1333 return sort_fn(a
, b
);
1336 static struct hpp_sort_entry
*
1337 __sort_dimension__alloc_hpp(struct sort_dimension
*sd
)
1339 struct hpp_sort_entry
*hse
;
1341 hse
= malloc(sizeof(*hse
));
1343 pr_err("Memory allocation failed\n");
1347 hse
->se
= sd
->entry
;
1348 hse
->hpp
.name
= sd
->entry
->se_header
;
1349 hse
->hpp
.header
= __sort__hpp_header
;
1350 hse
->hpp
.width
= __sort__hpp_width
;
1351 hse
->hpp
.entry
= __sort__hpp_entry
;
1352 hse
->hpp
.color
= NULL
;
1354 hse
->hpp
.cmp
= __sort__hpp_cmp
;
1355 hse
->hpp
.collapse
= __sort__hpp_collapse
;
1356 hse
->hpp
.sort
= __sort__hpp_sort
;
1358 INIT_LIST_HEAD(&hse
->hpp
.list
);
1359 INIT_LIST_HEAD(&hse
->hpp
.sort_list
);
1360 hse
->hpp
.elide
= false;
1362 hse
->hpp
.user_len
= 0;
1367 bool perf_hpp__is_sort_entry(struct perf_hpp_fmt
*format
)
1369 return format
->header
== __sort__hpp_header
;
1372 static int __sort_dimension__add_hpp_sort(struct sort_dimension
*sd
)
1374 struct hpp_sort_entry
*hse
= __sort_dimension__alloc_hpp(sd
);
1379 perf_hpp__register_sort_field(&hse
->hpp
);
1383 static int __sort_dimension__add_hpp_output(struct sort_dimension
*sd
)
1385 struct hpp_sort_entry
*hse
= __sort_dimension__alloc_hpp(sd
);
1390 perf_hpp__column_register(&hse
->hpp
);
1394 static int __sort_dimension__add(struct sort_dimension
*sd
)
1399 if (__sort_dimension__add_hpp_sort(sd
) < 0)
1402 if (sd
->entry
->se_collapse
)
1403 sort__need_collapse
= 1;
1410 static int __hpp_dimension__add(struct hpp_dimension
*hd
)
1415 perf_hpp__register_sort_field(hd
->fmt
);
1420 static int __sort_dimension__add_output(struct sort_dimension
*sd
)
1425 if (__sort_dimension__add_hpp_output(sd
) < 0)
1432 static int __hpp_dimension__add_output(struct hpp_dimension
*hd
)
1437 perf_hpp__column_register(hd
->fmt
);
1442 int sort_dimension__add(const char *tok
)
1446 for (i
= 0; i
< ARRAY_SIZE(common_sort_dimensions
); i
++) {
1447 struct sort_dimension
*sd
= &common_sort_dimensions
[i
];
1449 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1452 if (sd
->entry
== &sort_parent
) {
1453 int ret
= regcomp(&parent_regex
, parent_pattern
, REG_EXTENDED
);
1457 regerror(ret
, &parent_regex
, err
, sizeof(err
));
1458 pr_err("Invalid regex: %s\n%s", parent_pattern
, err
);
1461 sort__has_parent
= 1;
1462 } else if (sd
->entry
== &sort_sym
) {
1465 * perf diff displays the performance difference amongst
1466 * two or more perf.data files. Those files could come
1467 * from different binaries. So we should not compare
1468 * their ips, but the name of symbol.
1470 if (sort__mode
== SORT_MODE__DIFF
)
1471 sd
->entry
->se_collapse
= sort__sym_sort
;
1473 } else if (sd
->entry
== &sort_dso
) {
1477 return __sort_dimension__add(sd
);
1480 for (i
= 0; i
< ARRAY_SIZE(hpp_sort_dimensions
); i
++) {
1481 struct hpp_dimension
*hd
= &hpp_sort_dimensions
[i
];
1483 if (strncasecmp(tok
, hd
->name
, strlen(tok
)))
1486 return __hpp_dimension__add(hd
);
1489 for (i
= 0; i
< ARRAY_SIZE(bstack_sort_dimensions
); i
++) {
1490 struct sort_dimension
*sd
= &bstack_sort_dimensions
[i
];
1492 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1495 if (sort__mode
!= SORT_MODE__BRANCH
)
1498 if (sd
->entry
== &sort_sym_from
|| sd
->entry
== &sort_sym_to
)
1501 __sort_dimension__add(sd
);
1505 for (i
= 0; i
< ARRAY_SIZE(memory_sort_dimensions
); i
++) {
1506 struct sort_dimension
*sd
= &memory_sort_dimensions
[i
];
1508 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1511 if (sort__mode
!= SORT_MODE__MEMORY
)
1514 if (sd
->entry
== &sort_mem_daddr_sym
)
1517 __sort_dimension__add(sd
);
1524 static const char *get_default_sort_order(void)
1526 const char *default_sort_orders
[] = {
1528 default_branch_sort_order
,
1529 default_mem_sort_order
,
1530 default_top_sort_order
,
1531 default_diff_sort_order
,
1534 BUG_ON(sort__mode
>= ARRAY_SIZE(default_sort_orders
));
1536 return default_sort_orders
[sort__mode
];
1539 static int setup_sort_order(void)
1541 char *new_sort_order
;
1544 * Append '+'-prefixed sort order to the default sort
1547 if (!sort_order
|| is_strict_order(sort_order
))
1550 if (sort_order
[1] == '\0') {
1551 error("Invalid --sort key: `+'");
1556 * We allocate new sort_order string, but we never free it,
1557 * because it's checked over the rest of the code.
1559 if (asprintf(&new_sort_order
, "%s,%s",
1560 get_default_sort_order(), sort_order
+ 1) < 0) {
1561 error("Not enough memory to set up --sort");
1565 sort_order
= new_sort_order
;
1569 static int __setup_sorting(void)
1571 char *tmp
, *tok
, *str
;
1572 const char *sort_keys
;
1575 ret
= setup_sort_order();
1579 sort_keys
= sort_order
;
1580 if (sort_keys
== NULL
) {
1581 if (is_strict_order(field_order
)) {
1583 * If user specified field order but no sort order,
1584 * we'll honor it and not add default sort orders.
1589 sort_keys
= get_default_sort_order();
1592 str
= strdup(sort_keys
);
1594 error("Not enough memory to setup sort keys");
1598 for (tok
= strtok_r(str
, ", ", &tmp
);
1599 tok
; tok
= strtok_r(NULL
, ", ", &tmp
)) {
1600 ret
= sort_dimension__add(tok
);
1601 if (ret
== -EINVAL
) {
1602 error("Invalid --sort key: `%s'", tok
);
1604 } else if (ret
== -ESRCH
) {
1605 error("Unknown --sort key: `%s'", tok
);
1614 void perf_hpp__set_elide(int idx
, bool elide
)
1616 struct perf_hpp_fmt
*fmt
;
1617 struct hpp_sort_entry
*hse
;
1619 perf_hpp__for_each_format(fmt
) {
1620 if (!perf_hpp__is_sort_entry(fmt
))
1623 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1624 if (hse
->se
->se_width_idx
== idx
) {
1631 static bool __get_elide(struct strlist
*list
, const char *list_name
, FILE *fp
)
1633 if (list
&& strlist__nr_entries(list
) == 1) {
1635 fprintf(fp
, "# %s: %s\n", list_name
,
1636 strlist__entry(list
, 0)->s
);
1642 static bool get_elide(int idx
, FILE *output
)
1646 return __get_elide(symbol_conf
.sym_list
, "symbol", output
);
1648 return __get_elide(symbol_conf
.dso_list
, "dso", output
);
1650 return __get_elide(symbol_conf
.comm_list
, "comm", output
);
1655 if (sort__mode
!= SORT_MODE__BRANCH
)
1659 case HISTC_SYMBOL_FROM
:
1660 return __get_elide(symbol_conf
.sym_from_list
, "sym_from", output
);
1661 case HISTC_SYMBOL_TO
:
1662 return __get_elide(symbol_conf
.sym_to_list
, "sym_to", output
);
1663 case HISTC_DSO_FROM
:
1664 return __get_elide(symbol_conf
.dso_from_list
, "dso_from", output
);
1666 return __get_elide(symbol_conf
.dso_to_list
, "dso_to", output
);
1674 void sort__setup_elide(FILE *output
)
1676 struct perf_hpp_fmt
*fmt
;
1677 struct hpp_sort_entry
*hse
;
1679 perf_hpp__for_each_format(fmt
) {
1680 if (!perf_hpp__is_sort_entry(fmt
))
1683 hse
= container_of(fmt
, struct hpp_sort_entry
, hpp
);
1684 fmt
->elide
= get_elide(hse
->se
->se_width_idx
, output
);
1688 * It makes no sense to elide all of sort entries.
1689 * Just revert them to show up again.
1691 perf_hpp__for_each_format(fmt
) {
1692 if (!perf_hpp__is_sort_entry(fmt
))
1699 perf_hpp__for_each_format(fmt
) {
1700 if (!perf_hpp__is_sort_entry(fmt
))
1707 static int output_field_add(char *tok
)
1711 for (i
= 0; i
< ARRAY_SIZE(common_sort_dimensions
); i
++) {
1712 struct sort_dimension
*sd
= &common_sort_dimensions
[i
];
1714 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1717 return __sort_dimension__add_output(sd
);
1720 for (i
= 0; i
< ARRAY_SIZE(hpp_sort_dimensions
); i
++) {
1721 struct hpp_dimension
*hd
= &hpp_sort_dimensions
[i
];
1723 if (strncasecmp(tok
, hd
->name
, strlen(tok
)))
1726 return __hpp_dimension__add_output(hd
);
1729 for (i
= 0; i
< ARRAY_SIZE(bstack_sort_dimensions
); i
++) {
1730 struct sort_dimension
*sd
= &bstack_sort_dimensions
[i
];
1732 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1735 return __sort_dimension__add_output(sd
);
1738 for (i
= 0; i
< ARRAY_SIZE(memory_sort_dimensions
); i
++) {
1739 struct sort_dimension
*sd
= &memory_sort_dimensions
[i
];
1741 if (strncasecmp(tok
, sd
->name
, strlen(tok
)))
1744 return __sort_dimension__add_output(sd
);
1750 static void reset_dimensions(void)
1754 for (i
= 0; i
< ARRAY_SIZE(common_sort_dimensions
); i
++)
1755 common_sort_dimensions
[i
].taken
= 0;
1757 for (i
= 0; i
< ARRAY_SIZE(hpp_sort_dimensions
); i
++)
1758 hpp_sort_dimensions
[i
].taken
= 0;
1760 for (i
= 0; i
< ARRAY_SIZE(bstack_sort_dimensions
); i
++)
1761 bstack_sort_dimensions
[i
].taken
= 0;
1763 for (i
= 0; i
< ARRAY_SIZE(memory_sort_dimensions
); i
++)
1764 memory_sort_dimensions
[i
].taken
= 0;
1767 bool is_strict_order(const char *order
)
1769 return order
&& (*order
!= '+');
1772 static int __setup_output_field(void)
1774 char *tmp
, *tok
, *str
, *strp
;
1777 if (field_order
== NULL
)
1782 strp
= str
= strdup(field_order
);
1784 error("Not enough memory to setup output fields");
1788 if (!is_strict_order(field_order
))
1791 if (!strlen(strp
)) {
1792 error("Invalid --fields key: `+'");
1796 for (tok
= strtok_r(strp
, ", ", &tmp
);
1797 tok
; tok
= strtok_r(NULL
, ", ", &tmp
)) {
1798 ret
= output_field_add(tok
);
1799 if (ret
== -EINVAL
) {
1800 error("Invalid --fields key: `%s'", tok
);
1802 } else if (ret
== -ESRCH
) {
1803 error("Unknown --fields key: `%s'", tok
);
1813 int setup_sorting(void)
1817 err
= __setup_sorting();
1821 if (parent_pattern
!= default_parent_pattern
) {
1822 err
= sort_dimension__add("parent");
1830 * perf diff doesn't use default hpp output fields.
1832 if (sort__mode
!= SORT_MODE__DIFF
)
1835 err
= __setup_output_field();
1839 /* copy sort keys to output fields */
1840 perf_hpp__setup_output_field();
1841 /* and then copy output fields to sort keys */
1842 perf_hpp__append_sort_keys();
1847 void reset_output_field(void)
1849 sort__need_collapse
= 0;
1850 sort__has_parent
= 0;
1858 perf_hpp__reset_output_field();