6 const char default_parent_pattern[] = "^sys_|^do_page_fault";
7 const char *parent_pattern = default_parent_pattern;
8 const char default_sort_order[] = "comm,dso,symbol";
9 const char *sort_order = default_sort_order;
10 regex_t ignore_callees_regex;
11 int have_ignore_callees = 0;
12 int sort__need_collapse = 0;
13 int sort__has_parent = 0;
14 int sort__has_sym = 0;
15 enum sort_mode sort__mode = SORT_MODE__NORMAL;
17 enum sort_type sort__first_dimension;
19 LIST_HEAD(hist_entry__sort_list);
21 static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
27 n = vsnprintf(bf, size, fmt, ap);
28 if (symbol_conf.field_sep && n > 0) {
32 sep = strchr(sep, *symbol_conf.field_sep);
45 static int64_t cmp_null(void *l, void *r)
58 sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
60 return right->thread->tid - left->thread->tid;
63 static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf,
64 size_t size, unsigned int width)
66 return repsep_snprintf(bf, size, "%*s:%5d", width - 6,
67 self->thread->comm ?: "", self->thread->tid);
70 struct sort_entry sort_thread = {
71 .se_header = "Command: Pid",
72 .se_cmp = sort__thread_cmp,
73 .se_snprintf = hist_entry__thread_snprintf,
74 .se_width_idx = HISTC_THREAD,
80 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
82 return right->thread->tid - left->thread->tid;
86 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
88 char *comm_l = left->thread->comm;
89 char *comm_r = right->thread->comm;
91 if (!comm_l || !comm_r)
92 return cmp_null(comm_l, comm_r);
94 return strcmp(comm_l, comm_r);
97 static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf,
98 size_t size, unsigned int width)
100 return repsep_snprintf(bf, size, "%*s", width, self->thread->comm);
103 struct sort_entry sort_comm = {
104 .se_header = "Command",
105 .se_cmp = sort__comm_cmp,
106 .se_collapse = sort__comm_collapse,
107 .se_snprintf = hist_entry__comm_snprintf,
108 .se_width_idx = HISTC_COMM,
113 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
115 struct dso *dso_l = map_l ? map_l->dso : NULL;
116 struct dso *dso_r = map_r ? map_r->dso : NULL;
117 const char *dso_name_l, *dso_name_r;
119 if (!dso_l || !dso_r)
120 return cmp_null(dso_l, dso_r);
123 dso_name_l = dso_l->long_name;
124 dso_name_r = dso_r->long_name;
126 dso_name_l = dso_l->short_name;
127 dso_name_r = dso_r->short_name;
130 return strcmp(dso_name_l, dso_name_r);
134 sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
136 return _sort__dso_cmp(left->ms.map, right->ms.map);
139 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
140 size_t size, unsigned int width)
142 if (map && map->dso) {
143 const char *dso_name = !verbose ? map->dso->short_name :
145 return repsep_snprintf(bf, size, "%-*s", width, dso_name);
148 return repsep_snprintf(bf, size, "%-*s", width, "[unknown]");
151 static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf,
152 size_t size, unsigned int width)
154 return _hist_entry__dso_snprintf(self->ms.map, bf, size, width);
157 struct sort_entry sort_dso = {
158 .se_header = "Shared Object",
159 .se_cmp = sort__dso_cmp,
160 .se_snprintf = hist_entry__dso_snprintf,
161 .se_width_idx = HISTC_DSO,
166 static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r)
170 if (!sym_l || !sym_r)
171 return cmp_null(sym_l, sym_r);
179 return (int64_t)(ip_r - ip_l);
183 sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
185 if (!left->ms.sym && !right->ms.sym)
186 return right->level - left->level;
188 return _sort__sym_cmp(left->ms.sym, right->ms.sym);
191 static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
192 u64 ip, char level, char *bf, size_t size,
198 char o = map ? dso__symtab_origin(map->dso) : '!';
199 ret += repsep_snprintf(bf, size, "%-#*llx %c ",
200 BITS_PER_LONG / 4 + 2, ip, o);
203 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level);
205 if (map->type == MAP__VARIABLE) {
206 ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
207 ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
208 ip - map->unmap_ip(map, sym->start));
209 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
212 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
217 size_t len = BITS_PER_LONG / 4;
218 ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx",
220 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
227 static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
228 size_t size, unsigned int width)
230 return _hist_entry__sym_snprintf(self->ms.map, self->ms.sym, self->ip,
231 self->level, bf, size, width);
234 struct sort_entry sort_sym = {
235 .se_header = "Symbol",
236 .se_cmp = sort__sym_cmp,
237 .se_snprintf = hist_entry__sym_snprintf,
238 .se_width_idx = HISTC_SYMBOL,
244 sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
246 return (int64_t)(right->ip - left->ip);
249 static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
251 unsigned int width __maybe_unused)
254 char *path = self->srcline;
262 path = get_srcline(self->ms.map->dso, self->ip);
263 self->srcline = path;
268 return repsep_snprintf(bf, size, "%s", path);
272 return repsep_snprintf(bf, size, "%-#*llx", BITS_PER_LONG / 4, self->ip);
275 struct sort_entry sort_srcline = {
276 .se_header = "Source:Line",
277 .se_cmp = sort__srcline_cmp,
278 .se_snprintf = hist_entry__srcline_snprintf,
279 .se_width_idx = HISTC_SRCLINE,
285 sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
287 struct symbol *sym_l = left->parent;
288 struct symbol *sym_r = right->parent;
290 if (!sym_l || !sym_r)
291 return cmp_null(sym_l, sym_r);
293 return strcmp(sym_l->name, sym_r->name);
296 static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf,
297 size_t size, unsigned int width)
299 return repsep_snprintf(bf, size, "%-*s", width,
300 self->parent ? self->parent->name : "[other]");
303 struct sort_entry sort_parent = {
304 .se_header = "Parent symbol",
305 .se_cmp = sort__parent_cmp,
306 .se_snprintf = hist_entry__parent_snprintf,
307 .se_width_idx = HISTC_PARENT,
313 sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right)
315 return right->cpu - left->cpu;
318 static int hist_entry__cpu_snprintf(struct hist_entry *self, char *bf,
319 size_t size, unsigned int width)
321 return repsep_snprintf(bf, size, "%*d", width, self->cpu);
324 struct sort_entry sort_cpu = {
326 .se_cmp = sort__cpu_cmp,
327 .se_snprintf = hist_entry__cpu_snprintf,
328 .se_width_idx = HISTC_CPU,
331 /* sort keys for branch stacks */
334 sort__dso_from_cmp(struct hist_entry *left, struct hist_entry *right)
336 return _sort__dso_cmp(left->branch_info->from.map,
337 right->branch_info->from.map);
340 static int hist_entry__dso_from_snprintf(struct hist_entry *self, char *bf,
341 size_t size, unsigned int width)
343 return _hist_entry__dso_snprintf(self->branch_info->from.map,
348 sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right)
350 return _sort__dso_cmp(left->branch_info->to.map,
351 right->branch_info->to.map);
354 static int hist_entry__dso_to_snprintf(struct hist_entry *self, char *bf,
355 size_t size, unsigned int width)
357 return _hist_entry__dso_snprintf(self->branch_info->to.map,
362 sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right)
364 struct addr_map_symbol *from_l = &left->branch_info->from;
365 struct addr_map_symbol *from_r = &right->branch_info->from;
367 if (!from_l->sym && !from_r->sym)
368 return right->level - left->level;
370 return _sort__sym_cmp(from_l->sym, from_r->sym);
374 sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right)
376 struct addr_map_symbol *to_l = &left->branch_info->to;
377 struct addr_map_symbol *to_r = &right->branch_info->to;
379 if (!to_l->sym && !to_r->sym)
380 return right->level - left->level;
382 return _sort__sym_cmp(to_l->sym, to_r->sym);
385 static int hist_entry__sym_from_snprintf(struct hist_entry *self, char *bf,
386 size_t size, unsigned int width)
388 struct addr_map_symbol *from = &self->branch_info->from;
389 return _hist_entry__sym_snprintf(from->map, from->sym, from->addr,
390 self->level, bf, size, width);
394 static int hist_entry__sym_to_snprintf(struct hist_entry *self, char *bf,
395 size_t size, unsigned int width)
397 struct addr_map_symbol *to = &self->branch_info->to;
398 return _hist_entry__sym_snprintf(to->map, to->sym, to->addr,
399 self->level, bf, size, width);
403 struct sort_entry sort_dso_from = {
404 .se_header = "Source Shared Object",
405 .se_cmp = sort__dso_from_cmp,
406 .se_snprintf = hist_entry__dso_from_snprintf,
407 .se_width_idx = HISTC_DSO_FROM,
410 struct sort_entry sort_dso_to = {
411 .se_header = "Target Shared Object",
412 .se_cmp = sort__dso_to_cmp,
413 .se_snprintf = hist_entry__dso_to_snprintf,
414 .se_width_idx = HISTC_DSO_TO,
417 struct sort_entry sort_sym_from = {
418 .se_header = "Source Symbol",
419 .se_cmp = sort__sym_from_cmp,
420 .se_snprintf = hist_entry__sym_from_snprintf,
421 .se_width_idx = HISTC_SYMBOL_FROM,
424 struct sort_entry sort_sym_to = {
425 .se_header = "Target Symbol",
426 .se_cmp = sort__sym_to_cmp,
427 .se_snprintf = hist_entry__sym_to_snprintf,
428 .se_width_idx = HISTC_SYMBOL_TO,
432 sort__mispredict_cmp(struct hist_entry *left, struct hist_entry *right)
434 const unsigned char mp = left->branch_info->flags.mispred !=
435 right->branch_info->flags.mispred;
436 const unsigned char p = left->branch_info->flags.predicted !=
437 right->branch_info->flags.predicted;
442 static int hist_entry__mispredict_snprintf(struct hist_entry *self, char *bf,
443 size_t size, unsigned int width){
444 static const char *out = "N/A";
446 if (self->branch_info->flags.predicted)
448 else if (self->branch_info->flags.mispred)
451 return repsep_snprintf(bf, size, "%-*s", width, out);
454 /* --sort daddr_sym */
456 sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right)
458 uint64_t l = 0, r = 0;
461 l = left->mem_info->daddr.addr;
463 r = right->mem_info->daddr.addr;
465 return (int64_t)(r - l);
468 static int hist_entry__daddr_snprintf(struct hist_entry *self, char *bf,
469 size_t size, unsigned int width)
472 struct map *map = NULL;
473 struct symbol *sym = NULL;
475 if (self->mem_info) {
476 addr = self->mem_info->daddr.addr;
477 map = self->mem_info->daddr.map;
478 sym = self->mem_info->daddr.sym;
480 return _hist_entry__sym_snprintf(map, sym, addr, self->level, bf, size,
485 sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right)
487 struct map *map_l = NULL;
488 struct map *map_r = NULL;
491 map_l = left->mem_info->daddr.map;
493 map_r = right->mem_info->daddr.map;
495 return _sort__dso_cmp(map_l, map_r);
498 static int hist_entry__dso_daddr_snprintf(struct hist_entry *self, char *bf,
499 size_t size, unsigned int width)
501 struct map *map = NULL;
504 map = self->mem_info->daddr.map;
506 return _hist_entry__dso_snprintf(map, bf, size, width);
510 sort__locked_cmp(struct hist_entry *left, struct hist_entry *right)
512 union perf_mem_data_src data_src_l;
513 union perf_mem_data_src data_src_r;
516 data_src_l = left->mem_info->data_src;
518 data_src_l.mem_lock = PERF_MEM_LOCK_NA;
521 data_src_r = right->mem_info->data_src;
523 data_src_r.mem_lock = PERF_MEM_LOCK_NA;
525 return (int64_t)(data_src_r.mem_lock - data_src_l.mem_lock);
528 static int hist_entry__locked_snprintf(struct hist_entry *self, char *bf,
529 size_t size, unsigned int width)
532 u64 mask = PERF_MEM_LOCK_NA;
535 mask = self->mem_info->data_src.mem_lock;
537 if (mask & PERF_MEM_LOCK_NA)
539 else if (mask & PERF_MEM_LOCK_LOCKED)
544 return repsep_snprintf(bf, size, "%-*s", width, out);
548 sort__tlb_cmp(struct hist_entry *left, struct hist_entry *right)
550 union perf_mem_data_src data_src_l;
551 union perf_mem_data_src data_src_r;
554 data_src_l = left->mem_info->data_src;
556 data_src_l.mem_dtlb = PERF_MEM_TLB_NA;
559 data_src_r = right->mem_info->data_src;
561 data_src_r.mem_dtlb = PERF_MEM_TLB_NA;
563 return (int64_t)(data_src_r.mem_dtlb - data_src_l.mem_dtlb);
566 static const char * const tlb_access[] = {
575 #define NUM_TLB_ACCESS (sizeof(tlb_access)/sizeof(const char *))
577 static int hist_entry__tlb_snprintf(struct hist_entry *self, char *bf,
578 size_t size, unsigned int width)
581 size_t sz = sizeof(out) - 1; /* -1 for null termination */
583 u64 m = PERF_MEM_TLB_NA;
589 m = self->mem_info->data_src.mem_dtlb;
591 hit = m & PERF_MEM_TLB_HIT;
592 miss = m & PERF_MEM_TLB_MISS;
594 /* already taken care of */
595 m &= ~(PERF_MEM_TLB_HIT|PERF_MEM_TLB_MISS);
597 for (i = 0; m && i < NUM_TLB_ACCESS; i++, m >>= 1) {
604 strncat(out, tlb_access[i], sz - l);
605 l += strlen(tlb_access[i]);
610 strncat(out, " hit", sz - l);
612 strncat(out, " miss", sz - l);
614 return repsep_snprintf(bf, size, "%-*s", width, out);
618 sort__lvl_cmp(struct hist_entry *left, struct hist_entry *right)
620 union perf_mem_data_src data_src_l;
621 union perf_mem_data_src data_src_r;
624 data_src_l = left->mem_info->data_src;
626 data_src_l.mem_lvl = PERF_MEM_LVL_NA;
629 data_src_r = right->mem_info->data_src;
631 data_src_r.mem_lvl = PERF_MEM_LVL_NA;
633 return (int64_t)(data_src_r.mem_lvl - data_src_l.mem_lvl);
636 static const char * const mem_lvl[] = {
645 "Remote RAM (1 hop)",
646 "Remote RAM (2 hops)",
647 "Remote Cache (1 hop)",
648 "Remote Cache (2 hops)",
652 #define NUM_MEM_LVL (sizeof(mem_lvl)/sizeof(const char *))
654 static int hist_entry__lvl_snprintf(struct hist_entry *self, char *bf,
655 size_t size, unsigned int width)
658 size_t sz = sizeof(out) - 1; /* -1 for null termination */
660 u64 m = PERF_MEM_LVL_NA;
664 m = self->mem_info->data_src.mem_lvl;
668 hit = m & PERF_MEM_LVL_HIT;
669 miss = m & PERF_MEM_LVL_MISS;
671 /* already taken care of */
672 m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
674 for (i = 0; m && i < NUM_MEM_LVL; i++, m >>= 1) {
681 strncat(out, mem_lvl[i], sz - l);
682 l += strlen(mem_lvl[i]);
687 strncat(out, " hit", sz - l);
689 strncat(out, " miss", sz - l);
691 return repsep_snprintf(bf, size, "%-*s", width, out);
695 sort__snoop_cmp(struct hist_entry *left, struct hist_entry *right)
697 union perf_mem_data_src data_src_l;
698 union perf_mem_data_src data_src_r;
701 data_src_l = left->mem_info->data_src;
703 data_src_l.mem_snoop = PERF_MEM_SNOOP_NA;
706 data_src_r = right->mem_info->data_src;
708 data_src_r.mem_snoop = PERF_MEM_SNOOP_NA;
710 return (int64_t)(data_src_r.mem_snoop - data_src_l.mem_snoop);
713 static const char * const snoop_access[] = {
720 #define NUM_SNOOP_ACCESS (sizeof(snoop_access)/sizeof(const char *))
722 static int hist_entry__snoop_snprintf(struct hist_entry *self, char *bf,
723 size_t size, unsigned int width)
726 size_t sz = sizeof(out) - 1; /* -1 for null termination */
728 u64 m = PERF_MEM_SNOOP_NA;
733 m = self->mem_info->data_src.mem_snoop;
735 for (i = 0; m && i < NUM_SNOOP_ACCESS; i++, m >>= 1) {
742 strncat(out, snoop_access[i], sz - l);
743 l += strlen(snoop_access[i]);
749 return repsep_snprintf(bf, size, "%-*s", width, out);
752 struct sort_entry sort_mispredict = {
753 .se_header = "Branch Mispredicted",
754 .se_cmp = sort__mispredict_cmp,
755 .se_snprintf = hist_entry__mispredict_snprintf,
756 .se_width_idx = HISTC_MISPREDICT,
759 static u64 he_weight(struct hist_entry *he)
761 return he->stat.nr_events ? he->stat.weight / he->stat.nr_events : 0;
765 sort__local_weight_cmp(struct hist_entry *left, struct hist_entry *right)
767 return he_weight(left) - he_weight(right);
770 static int hist_entry__local_weight_snprintf(struct hist_entry *self, char *bf,
771 size_t size, unsigned int width)
773 return repsep_snprintf(bf, size, "%-*llu", width, he_weight(self));
776 struct sort_entry sort_local_weight = {
777 .se_header = "Local Weight",
778 .se_cmp = sort__local_weight_cmp,
779 .se_snprintf = hist_entry__local_weight_snprintf,
780 .se_width_idx = HISTC_LOCAL_WEIGHT,
784 sort__global_weight_cmp(struct hist_entry *left, struct hist_entry *right)
786 return left->stat.weight - right->stat.weight;
789 static int hist_entry__global_weight_snprintf(struct hist_entry *self, char *bf,
790 size_t size, unsigned int width)
792 return repsep_snprintf(bf, size, "%-*llu", width, self->stat.weight);
795 struct sort_entry sort_global_weight = {
796 .se_header = "Weight",
797 .se_cmp = sort__global_weight_cmp,
798 .se_snprintf = hist_entry__global_weight_snprintf,
799 .se_width_idx = HISTC_GLOBAL_WEIGHT,
802 struct sort_entry sort_mem_daddr_sym = {
803 .se_header = "Data Symbol",
804 .se_cmp = sort__daddr_cmp,
805 .se_snprintf = hist_entry__daddr_snprintf,
806 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,
809 struct sort_entry sort_mem_daddr_dso = {
810 .se_header = "Data Object",
811 .se_cmp = sort__dso_daddr_cmp,
812 .se_snprintf = hist_entry__dso_daddr_snprintf,
813 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,
816 struct sort_entry sort_mem_locked = {
817 .se_header = "Locked",
818 .se_cmp = sort__locked_cmp,
819 .se_snprintf = hist_entry__locked_snprintf,
820 .se_width_idx = HISTC_MEM_LOCKED,
823 struct sort_entry sort_mem_tlb = {
824 .se_header = "TLB access",
825 .se_cmp = sort__tlb_cmp,
826 .se_snprintf = hist_entry__tlb_snprintf,
827 .se_width_idx = HISTC_MEM_TLB,
830 struct sort_entry sort_mem_lvl = {
831 .se_header = "Memory access",
832 .se_cmp = sort__lvl_cmp,
833 .se_snprintf = hist_entry__lvl_snprintf,
834 .se_width_idx = HISTC_MEM_LVL,
837 struct sort_entry sort_mem_snoop = {
838 .se_header = "Snoop",
839 .se_cmp = sort__snoop_cmp,
840 .se_snprintf = hist_entry__snoop_snprintf,
841 .se_width_idx = HISTC_MEM_SNOOP,
845 sort__abort_cmp(struct hist_entry *left, struct hist_entry *right)
847 return left->branch_info->flags.abort !=
848 right->branch_info->flags.abort;
851 static int hist_entry__abort_snprintf(struct hist_entry *self, char *bf,
852 size_t size, unsigned int width)
854 static const char *out = ".";
856 if (self->branch_info->flags.abort)
858 return repsep_snprintf(bf, size, "%-*s", width, out);
861 struct sort_entry sort_abort = {
862 .se_header = "Transaction abort",
863 .se_cmp = sort__abort_cmp,
864 .se_snprintf = hist_entry__abort_snprintf,
865 .se_width_idx = HISTC_ABORT,
869 sort__in_tx_cmp(struct hist_entry *left, struct hist_entry *right)
871 return left->branch_info->flags.in_tx !=
872 right->branch_info->flags.in_tx;
875 static int hist_entry__in_tx_snprintf(struct hist_entry *self, char *bf,
876 size_t size, unsigned int width)
878 static const char *out = ".";
880 if (self->branch_info->flags.in_tx)
883 return repsep_snprintf(bf, size, "%-*s", width, out);
886 struct sort_entry sort_in_tx = {
887 .se_header = "Branch in transaction",
888 .se_cmp = sort__in_tx_cmp,
889 .se_snprintf = hist_entry__in_tx_snprintf,
890 .se_width_idx = HISTC_IN_TX,
894 sort__transaction_cmp(struct hist_entry *left, struct hist_entry *right)
896 return left->transaction - right->transaction;
899 static inline char *add_str(char *p, const char *str)
902 return p + strlen(str);
905 static struct txbit {
910 { PERF_TXN_ELISION, "EL ", 0 },
911 { PERF_TXN_TRANSACTION, "TX ", 1 },
912 { PERF_TXN_SYNC, "SYNC ", 1 },
913 { PERF_TXN_ASYNC, "ASYNC ", 0 },
914 { PERF_TXN_RETRY, "RETRY ", 0 },
915 { PERF_TXN_CONFLICT, "CON ", 0 },
916 { PERF_TXN_CAPACITY_WRITE, "CAP-WRITE ", 1 },
917 { PERF_TXN_CAPACITY_READ, "CAP-READ ", 0 },
921 int hist_entry__transaction_len(void)
926 for (i = 0; txbits[i].name; i++) {
927 if (!txbits[i].skip_for_len)
928 len += strlen(txbits[i].name);
930 len += 4; /* :XX<space> */
934 static int hist_entry__transaction_snprintf(struct hist_entry *self, char *bf,
935 size_t size, unsigned int width)
937 u64 t = self->transaction;
943 for (i = 0; txbits[i].name; i++)
944 if (txbits[i].flag & t)
945 p = add_str(p, txbits[i].name);
946 if (t && !(t & (PERF_TXN_SYNC|PERF_TXN_ASYNC)))
947 p = add_str(p, "NEITHER ");
948 if (t & PERF_TXN_ABORT_MASK) {
949 sprintf(p, ":%" PRIx64,
950 (t & PERF_TXN_ABORT_MASK) >>
951 PERF_TXN_ABORT_SHIFT);
955 return repsep_snprintf(bf, size, "%-*s", width, buf);
958 struct sort_entry sort_transaction = {
959 .se_header = "Transaction ",
960 .se_cmp = sort__transaction_cmp,
961 .se_snprintf = hist_entry__transaction_snprintf,
962 .se_width_idx = HISTC_TRANSACTION,
965 struct sort_dimension {
967 struct sort_entry *entry;
971 #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) }
973 static struct sort_dimension common_sort_dimensions[] = {
974 DIM(SORT_PID, "pid", sort_thread),
975 DIM(SORT_COMM, "comm", sort_comm),
976 DIM(SORT_DSO, "dso", sort_dso),
977 DIM(SORT_SYM, "symbol", sort_sym),
978 DIM(SORT_PARENT, "parent", sort_parent),
979 DIM(SORT_CPU, "cpu", sort_cpu),
980 DIM(SORT_SRCLINE, "srcline", sort_srcline),
981 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
982 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
983 DIM(SORT_TRANSACTION, "transaction", sort_transaction),
988 #define DIM(d, n, func) [d - __SORT_BRANCH_STACK] = { .name = n, .entry = &(func) }
990 static struct sort_dimension bstack_sort_dimensions[] = {
991 DIM(SORT_DSO_FROM, "dso_from", sort_dso_from),
992 DIM(SORT_DSO_TO, "dso_to", sort_dso_to),
993 DIM(SORT_SYM_FROM, "symbol_from", sort_sym_from),
994 DIM(SORT_SYM_TO, "symbol_to", sort_sym_to),
995 DIM(SORT_MISPREDICT, "mispredict", sort_mispredict),
996 DIM(SORT_IN_TX, "in_tx", sort_in_tx),
997 DIM(SORT_ABORT, "abort", sort_abort),
1002 #define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) }
1004 static struct sort_dimension memory_sort_dimensions[] = {
1005 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),
1006 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),
1007 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),
1008 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),
1009 DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
1010 DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
1015 static void __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
1020 if (sd->entry->se_collapse)
1021 sort__need_collapse = 1;
1023 if (list_empty(&hist_entry__sort_list))
1024 sort__first_dimension = idx;
1026 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
1030 int sort_dimension__add(const char *tok)
1034 for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) {
1035 struct sort_dimension *sd = &common_sort_dimensions[i];
1037 if (strncasecmp(tok, sd->name, strlen(tok)))
1040 if (sd->entry == &sort_parent) {
1041 int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
1045 regerror(ret, &parent_regex, err, sizeof(err));
1046 pr_err("Invalid regex: %s\n%s", parent_pattern, err);
1049 sort__has_parent = 1;
1050 } else if (sd->entry == &sort_sym) {
1054 __sort_dimension__add(sd, i);
1058 for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) {
1059 struct sort_dimension *sd = &bstack_sort_dimensions[i];
1061 if (strncasecmp(tok, sd->name, strlen(tok)))
1064 if (sort__mode != SORT_MODE__BRANCH)
1067 if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to)
1070 __sort_dimension__add(sd, i + __SORT_BRANCH_STACK);
1074 for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) {
1075 struct sort_dimension *sd = &memory_sort_dimensions[i];
1077 if (strncasecmp(tok, sd->name, strlen(tok)))
1080 if (sort__mode != SORT_MODE__MEMORY)
1083 if (sd->entry == &sort_mem_daddr_sym)
1086 __sort_dimension__add(sd, i + __SORT_MEMORY_MODE);
1093 int setup_sorting(void)
1095 char *tmp, *tok, *str = strdup(sort_order);
1099 error("Not enough memory to setup sort keys");
1103 for (tok = strtok_r(str, ", ", &tmp);
1104 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1105 ret = sort_dimension__add(tok);
1106 if (ret == -EINVAL) {
1107 error("Invalid --sort key: `%s'", tok);
1109 } else if (ret == -ESRCH) {
1110 error("Unknown --sort key: `%s'", tok);
1119 static void sort_entry__setup_elide(struct sort_entry *self,
1120 struct strlist *list,
1121 const char *list_name, FILE *fp)
1123 if (list && strlist__nr_entries(list) == 1) {
1125 fprintf(fp, "# %s: %s\n", list_name,
1126 strlist__entry(list, 0)->s);
1131 void sort__setup_elide(FILE *output)
1133 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1135 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list,
1137 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list,
1140 if (sort__mode == SORT_MODE__BRANCH) {
1141 sort_entry__setup_elide(&sort_dso_from,
1142 symbol_conf.dso_from_list,
1143 "dso_from", output);
1144 sort_entry__setup_elide(&sort_dso_to,
1145 symbol_conf.dso_to_list,
1147 sort_entry__setup_elide(&sort_sym_from,
1148 symbol_conf.sym_from_list,
1149 "sym_from", output);
1150 sort_entry__setup_elide(&sort_sym_to,
1151 symbol_conf.sym_to_list,
1153 } else if (sort__mode == SORT_MODE__MEMORY) {
1154 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1155 "symbol_daddr", output);
1156 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1157 "dso_daddr", output);
1158 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1160 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1161 "local_weight", output);
1162 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1164 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,