7 const char default_parent_pattern[] = "^sys_|^do_page_fault";
8 const char *parent_pattern = default_parent_pattern;
9 const char default_sort_order[] = "comm,dso,symbol";
10 const char *sort_order = default_sort_order;
11 regex_t ignore_callees_regex;
12 int have_ignore_callees = 0;
13 int sort__need_collapse = 0;
14 int sort__has_parent = 0;
15 int sort__has_sym = 0;
16 enum sort_mode sort__mode = SORT_MODE__NORMAL;
18 enum sort_type sort__first_dimension;
20 LIST_HEAD(hist_entry__sort_list);
22 static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
28 n = vsnprintf(bf, size, fmt, ap);
29 if (symbol_conf.field_sep && n > 0) {
33 sep = strchr(sep, *symbol_conf.field_sep);
46 static int64_t cmp_null(const void *l, const void *r)
59 sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
61 return right->thread->tid - left->thread->tid;
64 static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf,
65 size_t size, unsigned int width)
67 const char *comm = thread__comm_str(he->thread);
68 return repsep_snprintf(bf, size, "%*s:%5d", width - 6,
69 comm ?: "", he->thread->tid);
72 struct sort_entry sort_thread = {
73 .se_header = "Command: Pid",
74 .se_cmp = sort__thread_cmp,
75 .se_snprintf = hist_entry__thread_snprintf,
76 .se_width_idx = HISTC_THREAD,
82 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
84 /* Compare the addr that should be unique among comm */
85 return comm__str(right->comm) - comm__str(left->comm);
89 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
91 /* Compare the addr that should be unique among comm */
92 return comm__str(right->comm) - comm__str(left->comm);
95 static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf,
96 size_t size, unsigned int width)
98 return repsep_snprintf(bf, size, "%*s", width, comm__str(he->comm));
101 struct sort_entry sort_comm = {
102 .se_header = "Command",
103 .se_cmp = sort__comm_cmp,
104 .se_collapse = sort__comm_collapse,
105 .se_snprintf = hist_entry__comm_snprintf,
106 .se_width_idx = HISTC_COMM,
111 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
113 struct dso *dso_l = map_l ? map_l->dso : NULL;
114 struct dso *dso_r = map_r ? map_r->dso : NULL;
115 const char *dso_name_l, *dso_name_r;
117 if (!dso_l || !dso_r)
118 return cmp_null(dso_l, dso_r);
121 dso_name_l = dso_l->long_name;
122 dso_name_r = dso_r->long_name;
124 dso_name_l = dso_l->short_name;
125 dso_name_r = dso_r->short_name;
128 return strcmp(dso_name_l, dso_name_r);
132 sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
134 return _sort__dso_cmp(left->ms.map, right->ms.map);
137 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
138 size_t size, unsigned int width)
140 if (map && map->dso) {
141 const char *dso_name = !verbose ? map->dso->short_name :
143 return repsep_snprintf(bf, size, "%-*s", width, dso_name);
146 return repsep_snprintf(bf, size, "%-*s", width, "[unknown]");
149 static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf,
150 size_t size, unsigned int width)
152 return _hist_entry__dso_snprintf(he->ms.map, bf, size, width);
155 struct sort_entry sort_dso = {
156 .se_header = "Shared Object",
157 .se_cmp = sort__dso_cmp,
158 .se_snprintf = hist_entry__dso_snprintf,
159 .se_width_idx = HISTC_DSO,
164 static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r)
168 if (!sym_l || !sym_r)
169 return cmp_null(sym_l, sym_r);
177 return (int64_t)(ip_r - ip_l);
181 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;
189 * comparing symbol address alone is not enough since it's a
190 * relative address within a dso.
192 ret = sort__dso_cmp(left, right);
196 return _sort__sym_cmp(left->ms.sym, right->ms.sym);
199 static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
200 u64 ip, char level, char *bf, size_t size,
206 char o = map ? dso__symtab_origin(map->dso) : '!';
207 ret += repsep_snprintf(bf, size, "%-#*llx %c ",
208 BITS_PER_LONG / 4 + 2, ip, o);
211 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level);
213 if (map->type == MAP__VARIABLE) {
214 ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
215 ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
216 ip - map->unmap_ip(map, sym->start));
217 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
220 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
225 size_t len = BITS_PER_LONG / 4;
226 ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx",
228 ret += repsep_snprintf(bf + ret, size - ret, "%-*s",
235 static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf,
236 size_t size, unsigned int width)
238 return _hist_entry__sym_snprintf(he->ms.map, he->ms.sym, he->ip,
239 he->level, bf, size, width);
242 struct sort_entry sort_sym = {
243 .se_header = "Symbol",
244 .se_cmp = sort__sym_cmp,
245 .se_snprintf = hist_entry__sym_snprintf,
246 .se_width_idx = HISTC_SYMBOL,
252 sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
254 if (!left->srcline) {
256 left->srcline = SRCLINE_UNKNOWN;
258 struct map *map = left->ms.map;
259 left->srcline = get_srcline(map->dso,
260 map__rip_2objdump(map, left->ip));
263 if (!right->srcline) {
265 right->srcline = SRCLINE_UNKNOWN;
267 struct map *map = right->ms.map;
268 right->srcline = get_srcline(map->dso,
269 map__rip_2objdump(map, right->ip));
272 return strcmp(left->srcline, right->srcline);
275 static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf,
277 unsigned int width __maybe_unused)
279 return repsep_snprintf(bf, size, "%s", he->srcline);
282 struct sort_entry sort_srcline = {
283 .se_header = "Source:Line",
284 .se_cmp = sort__srcline_cmp,
285 .se_snprintf = hist_entry__srcline_snprintf,
286 .se_width_idx = HISTC_SRCLINE,
292 sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
294 struct symbol *sym_l = left->parent;
295 struct symbol *sym_r = right->parent;
297 if (!sym_l || !sym_r)
298 return cmp_null(sym_l, sym_r);
300 return strcmp(sym_l->name, sym_r->name);
303 static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf,
304 size_t size, unsigned int width)
306 return repsep_snprintf(bf, size, "%-*s", width,
307 he->parent ? he->parent->name : "[other]");
310 struct sort_entry sort_parent = {
311 .se_header = "Parent symbol",
312 .se_cmp = sort__parent_cmp,
313 .se_snprintf = hist_entry__parent_snprintf,
314 .se_width_idx = HISTC_PARENT,
320 sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right)
322 return right->cpu - left->cpu;
325 static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf,
326 size_t size, unsigned int width)
328 return repsep_snprintf(bf, size, "%*d", width, he->cpu);
331 struct sort_entry sort_cpu = {
333 .se_cmp = sort__cpu_cmp,
334 .se_snprintf = hist_entry__cpu_snprintf,
335 .se_width_idx = HISTC_CPU,
338 /* sort keys for branch stacks */
341 sort__dso_from_cmp(struct hist_entry *left, struct hist_entry *right)
343 return _sort__dso_cmp(left->branch_info->from.map,
344 right->branch_info->from.map);
347 static int hist_entry__dso_from_snprintf(struct hist_entry *he, char *bf,
348 size_t size, unsigned int width)
350 return _hist_entry__dso_snprintf(he->branch_info->from.map,
355 sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right)
357 return _sort__dso_cmp(left->branch_info->to.map,
358 right->branch_info->to.map);
361 static int hist_entry__dso_to_snprintf(struct hist_entry *he, char *bf,
362 size_t size, unsigned int width)
364 return _hist_entry__dso_snprintf(he->branch_info->to.map,
369 sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right)
371 struct addr_map_symbol *from_l = &left->branch_info->from;
372 struct addr_map_symbol *from_r = &right->branch_info->from;
374 if (!from_l->sym && !from_r->sym)
375 return right->level - left->level;
377 return _sort__sym_cmp(from_l->sym, from_r->sym);
381 sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right)
383 struct addr_map_symbol *to_l = &left->branch_info->to;
384 struct addr_map_symbol *to_r = &right->branch_info->to;
386 if (!to_l->sym && !to_r->sym)
387 return right->level - left->level;
389 return _sort__sym_cmp(to_l->sym, to_r->sym);
392 static int hist_entry__sym_from_snprintf(struct hist_entry *he, char *bf,
393 size_t size, unsigned int width)
395 struct addr_map_symbol *from = &he->branch_info->from;
396 return _hist_entry__sym_snprintf(from->map, from->sym, from->addr,
397 he->level, bf, size, width);
401 static int hist_entry__sym_to_snprintf(struct hist_entry *he, char *bf,
402 size_t size, unsigned int width)
404 struct addr_map_symbol *to = &he->branch_info->to;
405 return _hist_entry__sym_snprintf(to->map, to->sym, to->addr,
406 he->level, bf, size, width);
410 struct sort_entry sort_dso_from = {
411 .se_header = "Source Shared Object",
412 .se_cmp = sort__dso_from_cmp,
413 .se_snprintf = hist_entry__dso_from_snprintf,
414 .se_width_idx = HISTC_DSO_FROM,
417 struct sort_entry sort_dso_to = {
418 .se_header = "Target Shared Object",
419 .se_cmp = sort__dso_to_cmp,
420 .se_snprintf = hist_entry__dso_to_snprintf,
421 .se_width_idx = HISTC_DSO_TO,
424 struct sort_entry sort_sym_from = {
425 .se_header = "Source Symbol",
426 .se_cmp = sort__sym_from_cmp,
427 .se_snprintf = hist_entry__sym_from_snprintf,
428 .se_width_idx = HISTC_SYMBOL_FROM,
431 struct sort_entry sort_sym_to = {
432 .se_header = "Target Symbol",
433 .se_cmp = sort__sym_to_cmp,
434 .se_snprintf = hist_entry__sym_to_snprintf,
435 .se_width_idx = HISTC_SYMBOL_TO,
439 sort__mispredict_cmp(struct hist_entry *left, struct hist_entry *right)
441 const unsigned char mp = left->branch_info->flags.mispred !=
442 right->branch_info->flags.mispred;
443 const unsigned char p = left->branch_info->flags.predicted !=
444 right->branch_info->flags.predicted;
449 static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
450 size_t size, unsigned int width){
451 static const char *out = "N/A";
453 if (he->branch_info->flags.predicted)
455 else if (he->branch_info->flags.mispred)
458 return repsep_snprintf(bf, size, "%-*s", width, out);
461 /* --sort daddr_sym */
463 sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right)
465 uint64_t l = 0, r = 0;
468 l = left->mem_info->daddr.addr;
470 r = right->mem_info->daddr.addr;
472 return (int64_t)(r - l);
475 static int hist_entry__daddr_snprintf(struct hist_entry *he, char *bf,
476 size_t size, unsigned int width)
479 struct map *map = NULL;
480 struct symbol *sym = NULL;
483 addr = he->mem_info->daddr.addr;
484 map = he->mem_info->daddr.map;
485 sym = he->mem_info->daddr.sym;
487 return _hist_entry__sym_snprintf(map, sym, addr, he->level, bf, size,
492 sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right)
494 struct map *map_l = NULL;
495 struct map *map_r = NULL;
498 map_l = left->mem_info->daddr.map;
500 map_r = right->mem_info->daddr.map;
502 return _sort__dso_cmp(map_l, map_r);
505 static int hist_entry__dso_daddr_snprintf(struct hist_entry *he, char *bf,
506 size_t size, unsigned int width)
508 struct map *map = NULL;
511 map = he->mem_info->daddr.map;
513 return _hist_entry__dso_snprintf(map, bf, size, width);
517 sort__locked_cmp(struct hist_entry *left, struct hist_entry *right)
519 union perf_mem_data_src data_src_l;
520 union perf_mem_data_src data_src_r;
523 data_src_l = left->mem_info->data_src;
525 data_src_l.mem_lock = PERF_MEM_LOCK_NA;
528 data_src_r = right->mem_info->data_src;
530 data_src_r.mem_lock = PERF_MEM_LOCK_NA;
532 return (int64_t)(data_src_r.mem_lock - data_src_l.mem_lock);
535 static int hist_entry__locked_snprintf(struct hist_entry *he, char *bf,
536 size_t size, unsigned int width)
539 u64 mask = PERF_MEM_LOCK_NA;
542 mask = he->mem_info->data_src.mem_lock;
544 if (mask & PERF_MEM_LOCK_NA)
546 else if (mask & PERF_MEM_LOCK_LOCKED)
551 return repsep_snprintf(bf, size, "%-*s", width, out);
555 sort__tlb_cmp(struct hist_entry *left, struct hist_entry *right)
557 union perf_mem_data_src data_src_l;
558 union perf_mem_data_src data_src_r;
561 data_src_l = left->mem_info->data_src;
563 data_src_l.mem_dtlb = PERF_MEM_TLB_NA;
566 data_src_r = right->mem_info->data_src;
568 data_src_r.mem_dtlb = PERF_MEM_TLB_NA;
570 return (int64_t)(data_src_r.mem_dtlb - data_src_l.mem_dtlb);
573 static const char * const tlb_access[] = {
582 #define NUM_TLB_ACCESS (sizeof(tlb_access)/sizeof(const char *))
584 static int hist_entry__tlb_snprintf(struct hist_entry *he, char *bf,
585 size_t size, unsigned int width)
588 size_t sz = sizeof(out) - 1; /* -1 for null termination */
590 u64 m = PERF_MEM_TLB_NA;
596 m = he->mem_info->data_src.mem_dtlb;
598 hit = m & PERF_MEM_TLB_HIT;
599 miss = m & PERF_MEM_TLB_MISS;
601 /* already taken care of */
602 m &= ~(PERF_MEM_TLB_HIT|PERF_MEM_TLB_MISS);
604 for (i = 0; m && i < NUM_TLB_ACCESS; i++, m >>= 1) {
611 strncat(out, tlb_access[i], sz - l);
612 l += strlen(tlb_access[i]);
617 strncat(out, " hit", sz - l);
619 strncat(out, " miss", sz - l);
621 return repsep_snprintf(bf, size, "%-*s", width, out);
625 sort__lvl_cmp(struct hist_entry *left, struct hist_entry *right)
627 union perf_mem_data_src data_src_l;
628 union perf_mem_data_src data_src_r;
631 data_src_l = left->mem_info->data_src;
633 data_src_l.mem_lvl = PERF_MEM_LVL_NA;
636 data_src_r = right->mem_info->data_src;
638 data_src_r.mem_lvl = PERF_MEM_LVL_NA;
640 return (int64_t)(data_src_r.mem_lvl - data_src_l.mem_lvl);
643 static const char * const mem_lvl[] = {
652 "Remote RAM (1 hop)",
653 "Remote RAM (2 hops)",
654 "Remote Cache (1 hop)",
655 "Remote Cache (2 hops)",
659 #define NUM_MEM_LVL (sizeof(mem_lvl)/sizeof(const char *))
661 static int hist_entry__lvl_snprintf(struct hist_entry *he, char *bf,
662 size_t size, unsigned int width)
665 size_t sz = sizeof(out) - 1; /* -1 for null termination */
667 u64 m = PERF_MEM_LVL_NA;
671 m = he->mem_info->data_src.mem_lvl;
675 hit = m & PERF_MEM_LVL_HIT;
676 miss = m & PERF_MEM_LVL_MISS;
678 /* already taken care of */
679 m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
681 for (i = 0; m && i < NUM_MEM_LVL; i++, m >>= 1) {
688 strncat(out, mem_lvl[i], sz - l);
689 l += strlen(mem_lvl[i]);
694 strncat(out, " hit", sz - l);
696 strncat(out, " miss", sz - l);
698 return repsep_snprintf(bf, size, "%-*s", width, out);
702 sort__snoop_cmp(struct hist_entry *left, struct hist_entry *right)
704 union perf_mem_data_src data_src_l;
705 union perf_mem_data_src data_src_r;
708 data_src_l = left->mem_info->data_src;
710 data_src_l.mem_snoop = PERF_MEM_SNOOP_NA;
713 data_src_r = right->mem_info->data_src;
715 data_src_r.mem_snoop = PERF_MEM_SNOOP_NA;
717 return (int64_t)(data_src_r.mem_snoop - data_src_l.mem_snoop);
720 static const char * const snoop_access[] = {
727 #define NUM_SNOOP_ACCESS (sizeof(snoop_access)/sizeof(const char *))
729 static int hist_entry__snoop_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_SNOOP_NA;
740 m = he->mem_info->data_src.mem_snoop;
742 for (i = 0; m && i < NUM_SNOOP_ACCESS; i++, m >>= 1) {
749 strncat(out, snoop_access[i], sz - l);
750 l += strlen(snoop_access[i]);
756 return repsep_snprintf(bf, size, "%-*s", width, out);
759 struct sort_entry sort_mispredict = {
760 .se_header = "Branch Mispredicted",
761 .se_cmp = sort__mispredict_cmp,
762 .se_snprintf = hist_entry__mispredict_snprintf,
763 .se_width_idx = HISTC_MISPREDICT,
766 static u64 he_weight(struct hist_entry *he)
768 return he->stat.nr_events ? he->stat.weight / he->stat.nr_events : 0;
772 sort__local_weight_cmp(struct hist_entry *left, struct hist_entry *right)
774 return he_weight(left) - he_weight(right);
777 static int hist_entry__local_weight_snprintf(struct hist_entry *he, char *bf,
778 size_t size, unsigned int width)
780 return repsep_snprintf(bf, size, "%-*llu", width, he_weight(he));
783 struct sort_entry sort_local_weight = {
784 .se_header = "Local Weight",
785 .se_cmp = sort__local_weight_cmp,
786 .se_snprintf = hist_entry__local_weight_snprintf,
787 .se_width_idx = HISTC_LOCAL_WEIGHT,
791 sort__global_weight_cmp(struct hist_entry *left, struct hist_entry *right)
793 return left->stat.weight - right->stat.weight;
796 static int hist_entry__global_weight_snprintf(struct hist_entry *he, char *bf,
797 size_t size, unsigned int width)
799 return repsep_snprintf(bf, size, "%-*llu", width, he->stat.weight);
802 struct sort_entry sort_global_weight = {
803 .se_header = "Weight",
804 .se_cmp = sort__global_weight_cmp,
805 .se_snprintf = hist_entry__global_weight_snprintf,
806 .se_width_idx = HISTC_GLOBAL_WEIGHT,
809 struct sort_entry sort_mem_daddr_sym = {
810 .se_header = "Data Symbol",
811 .se_cmp = sort__daddr_cmp,
812 .se_snprintf = hist_entry__daddr_snprintf,
813 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,
816 struct sort_entry sort_mem_daddr_dso = {
817 .se_header = "Data Object",
818 .se_cmp = sort__dso_daddr_cmp,
819 .se_snprintf = hist_entry__dso_daddr_snprintf,
820 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,
823 struct sort_entry sort_mem_locked = {
824 .se_header = "Locked",
825 .se_cmp = sort__locked_cmp,
826 .se_snprintf = hist_entry__locked_snprintf,
827 .se_width_idx = HISTC_MEM_LOCKED,
830 struct sort_entry sort_mem_tlb = {
831 .se_header = "TLB access",
832 .se_cmp = sort__tlb_cmp,
833 .se_snprintf = hist_entry__tlb_snprintf,
834 .se_width_idx = HISTC_MEM_TLB,
837 struct sort_entry sort_mem_lvl = {
838 .se_header = "Memory access",
839 .se_cmp = sort__lvl_cmp,
840 .se_snprintf = hist_entry__lvl_snprintf,
841 .se_width_idx = HISTC_MEM_LVL,
844 struct sort_entry sort_mem_snoop = {
845 .se_header = "Snoop",
846 .se_cmp = sort__snoop_cmp,
847 .se_snprintf = hist_entry__snoop_snprintf,
848 .se_width_idx = HISTC_MEM_SNOOP,
852 sort__abort_cmp(struct hist_entry *left, struct hist_entry *right)
854 return left->branch_info->flags.abort !=
855 right->branch_info->flags.abort;
858 static int hist_entry__abort_snprintf(struct hist_entry *he, char *bf,
859 size_t size, unsigned int width)
861 static const char *out = ".";
863 if (he->branch_info->flags.abort)
865 return repsep_snprintf(bf, size, "%-*s", width, out);
868 struct sort_entry sort_abort = {
869 .se_header = "Transaction abort",
870 .se_cmp = sort__abort_cmp,
871 .se_snprintf = hist_entry__abort_snprintf,
872 .se_width_idx = HISTC_ABORT,
876 sort__in_tx_cmp(struct hist_entry *left, struct hist_entry *right)
878 return left->branch_info->flags.in_tx !=
879 right->branch_info->flags.in_tx;
882 static int hist_entry__in_tx_snprintf(struct hist_entry *he, char *bf,
883 size_t size, unsigned int width)
885 static const char *out = ".";
887 if (he->branch_info->flags.in_tx)
890 return repsep_snprintf(bf, size, "%-*s", width, out);
893 struct sort_entry sort_in_tx = {
894 .se_header = "Branch in transaction",
895 .se_cmp = sort__in_tx_cmp,
896 .se_snprintf = hist_entry__in_tx_snprintf,
897 .se_width_idx = HISTC_IN_TX,
901 sort__transaction_cmp(struct hist_entry *left, struct hist_entry *right)
903 return left->transaction - right->transaction;
906 static inline char *add_str(char *p, const char *str)
909 return p + strlen(str);
912 static struct txbit {
917 { PERF_TXN_ELISION, "EL ", 0 },
918 { PERF_TXN_TRANSACTION, "TX ", 1 },
919 { PERF_TXN_SYNC, "SYNC ", 1 },
920 { PERF_TXN_ASYNC, "ASYNC ", 0 },
921 { PERF_TXN_RETRY, "RETRY ", 0 },
922 { PERF_TXN_CONFLICT, "CON ", 0 },
923 { PERF_TXN_CAPACITY_WRITE, "CAP-WRITE ", 1 },
924 { PERF_TXN_CAPACITY_READ, "CAP-READ ", 0 },
928 int hist_entry__transaction_len(void)
933 for (i = 0; txbits[i].name; i++) {
934 if (!txbits[i].skip_for_len)
935 len += strlen(txbits[i].name);
937 len += 4; /* :XX<space> */
941 static int hist_entry__transaction_snprintf(struct hist_entry *he, char *bf,
942 size_t size, unsigned int width)
944 u64 t = he->transaction;
950 for (i = 0; txbits[i].name; i++)
951 if (txbits[i].flag & t)
952 p = add_str(p, txbits[i].name);
953 if (t && !(t & (PERF_TXN_SYNC|PERF_TXN_ASYNC)))
954 p = add_str(p, "NEITHER ");
955 if (t & PERF_TXN_ABORT_MASK) {
956 sprintf(p, ":%" PRIx64,
957 (t & PERF_TXN_ABORT_MASK) >>
958 PERF_TXN_ABORT_SHIFT);
962 return repsep_snprintf(bf, size, "%-*s", width, buf);
965 struct sort_entry sort_transaction = {
966 .se_header = "Transaction ",
967 .se_cmp = sort__transaction_cmp,
968 .se_snprintf = hist_entry__transaction_snprintf,
969 .se_width_idx = HISTC_TRANSACTION,
972 struct sort_dimension {
974 struct sort_entry *entry;
978 #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) }
980 static struct sort_dimension common_sort_dimensions[] = {
981 DIM(SORT_PID, "pid", sort_thread),
982 DIM(SORT_COMM, "comm", sort_comm),
983 DIM(SORT_DSO, "dso", sort_dso),
984 DIM(SORT_SYM, "symbol", sort_sym),
985 DIM(SORT_PARENT, "parent", sort_parent),
986 DIM(SORT_CPU, "cpu", sort_cpu),
987 DIM(SORT_SRCLINE, "srcline", sort_srcline),
988 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
989 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
990 DIM(SORT_TRANSACTION, "transaction", sort_transaction),
995 #define DIM(d, n, func) [d - __SORT_BRANCH_STACK] = { .name = n, .entry = &(func) }
997 static struct sort_dimension bstack_sort_dimensions[] = {
998 DIM(SORT_DSO_FROM, "dso_from", sort_dso_from),
999 DIM(SORT_DSO_TO, "dso_to", sort_dso_to),
1000 DIM(SORT_SYM_FROM, "symbol_from", sort_sym_from),
1001 DIM(SORT_SYM_TO, "symbol_to", sort_sym_to),
1002 DIM(SORT_MISPREDICT, "mispredict", sort_mispredict),
1003 DIM(SORT_IN_TX, "in_tx", sort_in_tx),
1004 DIM(SORT_ABORT, "abort", sort_abort),
1009 #define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) }
1011 static struct sort_dimension memory_sort_dimensions[] = {
1012 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),
1013 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),
1014 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),
1015 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),
1016 DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
1017 DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
1022 static void __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
1027 if (sd->entry->se_collapse)
1028 sort__need_collapse = 1;
1030 if (list_empty(&hist_entry__sort_list))
1031 sort__first_dimension = idx;
1033 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
1037 int sort_dimension__add(const char *tok)
1041 for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) {
1042 struct sort_dimension *sd = &common_sort_dimensions[i];
1044 if (strncasecmp(tok, sd->name, strlen(tok)))
1047 if (sd->entry == &sort_parent) {
1048 int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
1052 regerror(ret, &parent_regex, err, sizeof(err));
1053 pr_err("Invalid regex: %s\n%s", parent_pattern, err);
1056 sort__has_parent = 1;
1057 } else if (sd->entry == &sort_sym) {
1061 __sort_dimension__add(sd, i);
1065 for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) {
1066 struct sort_dimension *sd = &bstack_sort_dimensions[i];
1068 if (strncasecmp(tok, sd->name, strlen(tok)))
1071 if (sort__mode != SORT_MODE__BRANCH)
1074 if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to)
1077 __sort_dimension__add(sd, i + __SORT_BRANCH_STACK);
1081 for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) {
1082 struct sort_dimension *sd = &memory_sort_dimensions[i];
1084 if (strncasecmp(tok, sd->name, strlen(tok)))
1087 if (sort__mode != SORT_MODE__MEMORY)
1090 if (sd->entry == &sort_mem_daddr_sym)
1093 __sort_dimension__add(sd, i + __SORT_MEMORY_MODE);
1100 int setup_sorting(void)
1102 char *tmp, *tok, *str = strdup(sort_order);
1106 error("Not enough memory to setup sort keys");
1110 for (tok = strtok_r(str, ", ", &tmp);
1111 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1112 ret = sort_dimension__add(tok);
1113 if (ret == -EINVAL) {
1114 error("Invalid --sort key: `%s'", tok);
1116 } else if (ret == -ESRCH) {
1117 error("Unknown --sort key: `%s'", tok);
1126 static void sort_entry__setup_elide(struct sort_entry *se,
1127 struct strlist *list,
1128 const char *list_name, FILE *fp)
1130 if (list && strlist__nr_entries(list) == 1) {
1132 fprintf(fp, "# %s: %s\n", list_name,
1133 strlist__entry(list, 0)->s);
1138 void sort__setup_elide(FILE *output)
1140 struct sort_entry *se;
1142 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1144 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list,
1146 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list,
1149 if (sort__mode == SORT_MODE__BRANCH) {
1150 sort_entry__setup_elide(&sort_dso_from,
1151 symbol_conf.dso_from_list,
1152 "dso_from", output);
1153 sort_entry__setup_elide(&sort_dso_to,
1154 symbol_conf.dso_to_list,
1156 sort_entry__setup_elide(&sort_sym_from,
1157 symbol_conf.sym_from_list,
1158 "sym_from", output);
1159 sort_entry__setup_elide(&sort_sym_to,
1160 symbol_conf.sym_to_list,
1162 } else if (sort__mode == SORT_MODE__MEMORY) {
1163 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1164 "symbol_daddr", output);
1165 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1166 "dso_daddr", output);
1167 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1169 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1170 "local_weight", output);
1171 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1173 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1178 * It makes no sense to elide all of sort entries.
1179 * Just revert them to show up again.
1181 list_for_each_entry(se, &hist_entry__sort_list, list) {
1186 list_for_each_entry(se, &hist_entry__sort_list, list)