Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 1 | #include <sys/mman.h> |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 2 | #include "sort.h" |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 3 | #include "hist.h" |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 4 | #include "comm.h" |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 5 | #include "symbol.h" |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 6 | #include "evsel.h" |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 7 | |
| 8 | regex_t parent_regex; |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 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"; |
Andi Kleen | 40997d6 | 2015-07-18 08:24:53 -0700 | [diff] [blame] | 12 | const char default_branch_sort_order[] = "comm,dso_from,symbol_from,symbol_to,cycles"; |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 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; |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 17 | const char *field_order; |
Greg Price | b21484f | 2012-12-06 21:48:05 -0800 | [diff] [blame] | 18 | regex_t ignore_callees_regex; |
| 19 | int have_ignore_callees = 0; |
Frederic Weisbecker | af0a6fa | 2009-10-22 23:23:22 +0200 | [diff] [blame] | 20 | int sort__need_collapse = 0; |
| 21 | int sort__has_parent = 0; |
Namhyung Kim | 1af55640 | 2012-09-14 17:35:27 +0900 | [diff] [blame] | 22 | int sort__has_sym = 0; |
Namhyung Kim | 68f6d02 | 2013-12-18 14:21:10 +0900 | [diff] [blame] | 23 | int sort__has_dso = 0; |
Namhyung Kim | 55369fc | 2013-04-01 20:35:20 +0900 | [diff] [blame] | 24 | enum sort_mode sort__mode = SORT_MODE__NORMAL; |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 25 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 26 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 27 | static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 28 | { |
| 29 | int n; |
| 30 | va_list ap; |
| 31 | |
| 32 | va_start(ap, fmt); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 33 | n = vsnprintf(bf, size, fmt, ap); |
Jiri Olsa | 0ca0c13 | 2012-09-06 17:46:56 +0200 | [diff] [blame] | 34 | if (symbol_conf.field_sep && n > 0) { |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 35 | char *sep = bf; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 37 | while (1) { |
Jiri Olsa | 0ca0c13 | 2012-09-06 17:46:56 +0200 | [diff] [blame] | 38 | sep = strchr(sep, *symbol_conf.field_sep); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 39 | if (sep == NULL) |
| 40 | break; |
| 41 | *sep = '.'; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 42 | } |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 43 | } |
| 44 | va_end(ap); |
Anton Blanchard | b832796 | 2012-03-07 11:42:49 +1100 | [diff] [blame] | 45 | |
| 46 | if (n >= (int)size) |
| 47 | return size - 1; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 48 | return n; |
| 49 | } |
| 50 | |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 51 | static int64_t cmp_null(const void *l, const void *r) |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 52 | { |
| 53 | if (!l && !r) |
| 54 | return 0; |
| 55 | else if (!l) |
| 56 | return -1; |
| 57 | else |
| 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | /* --sort pid */ |
| 62 | |
| 63 | static int64_t |
| 64 | sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) |
| 65 | { |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 66 | return right->thread->tid - left->thread->tid; |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 69 | static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 70 | size_t size, unsigned int width) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 71 | { |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 72 | const char *comm = thread__comm_str(he->thread); |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 73 | |
| 74 | width = max(7U, width) - 6; |
| 75 | return repsep_snprintf(bf, size, "%5d:%-*.*s", he->thread->tid, |
| 76 | width, width, comm ?: ""); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 79 | struct sort_entry sort_thread = { |
Namhyung Kim | 8246de8 | 2014-07-31 14:47:35 +0900 | [diff] [blame] | 80 | .se_header = " Pid:Command", |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 81 | .se_cmp = sort__thread_cmp, |
| 82 | .se_snprintf = hist_entry__thread_snprintf, |
| 83 | .se_width_idx = HISTC_THREAD, |
| 84 | }; |
| 85 | |
| 86 | /* --sort comm */ |
| 87 | |
| 88 | static int64_t |
| 89 | sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) |
| 90 | { |
Frederic Weisbecker | fedd63d | 2013-09-11 17:18:09 +0200 | [diff] [blame] | 91 | /* Compare the addr that should be unique among comm */ |
Jiri Olsa | 2f15bd8 | 2015-05-15 17:54:28 +0200 | [diff] [blame] | 92 | return strcmp(comm__str(right->comm), comm__str(left->comm)); |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static int64_t |
| 96 | sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) |
| 97 | { |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 98 | /* Compare the addr that should be unique among comm */ |
Jiri Olsa | 2f15bd8 | 2015-05-15 17:54:28 +0200 | [diff] [blame] | 99 | return strcmp(comm__str(right->comm), comm__str(left->comm)); |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 102 | static int64_t |
| 103 | sort__comm_sort(struct hist_entry *left, struct hist_entry *right) |
| 104 | { |
| 105 | return strcmp(comm__str(right->comm), comm__str(left->comm)); |
| 106 | } |
| 107 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 108 | static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 109 | size_t size, unsigned int width) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 110 | { |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 111 | return repsep_snprintf(bf, size, "%-*.*s", width, width, comm__str(he->comm)); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 114 | struct sort_entry sort_comm = { |
| 115 | .se_header = "Command", |
| 116 | .se_cmp = sort__comm_cmp, |
| 117 | .se_collapse = sort__comm_collapse, |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 118 | .se_sort = sort__comm_sort, |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 119 | .se_snprintf = hist_entry__comm_snprintf, |
| 120 | .se_width_idx = HISTC_COMM, |
| 121 | }; |
| 122 | |
| 123 | /* --sort dso */ |
| 124 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 125 | static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 126 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 127 | struct dso *dso_l = map_l ? map_l->dso : NULL; |
| 128 | struct dso *dso_r = map_r ? map_r->dso : NULL; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 129 | const char *dso_name_l, *dso_name_r; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 130 | |
| 131 | if (!dso_l || !dso_r) |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 132 | return cmp_null(dso_r, dso_l); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 133 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 134 | if (verbose) { |
| 135 | dso_name_l = dso_l->long_name; |
| 136 | dso_name_r = dso_r->long_name; |
| 137 | } else { |
| 138 | dso_name_l = dso_l->short_name; |
| 139 | dso_name_r = dso_r->short_name; |
| 140 | } |
| 141 | |
| 142 | return strcmp(dso_name_l, dso_name_r); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 145 | static int64_t |
| 146 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 147 | { |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 148 | return _sort__dso_cmp(right->ms.map, left->ms.map); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 151 | static int _hist_entry__dso_snprintf(struct map *map, char *bf, |
| 152 | size_t size, unsigned int width) |
| 153 | { |
| 154 | if (map && map->dso) { |
| 155 | const char *dso_name = !verbose ? map->dso->short_name : |
| 156 | map->dso->long_name; |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 157 | return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 158 | } |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 159 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 160 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "[unknown]"); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 163 | static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 164 | size_t size, unsigned int width) |
| 165 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 166 | return _hist_entry__dso_snprintf(he->ms.map, bf, size, width); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 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, |
| 174 | }; |
| 175 | |
| 176 | /* --sort symbol */ |
| 177 | |
Namhyung Kim | 2037be5 | 2013-12-18 14:21:09 +0900 | [diff] [blame] | 178 | static int64_t _sort__addr_cmp(u64 left_ip, u64 right_ip) |
| 179 | { |
| 180 | return (int64_t)(right_ip - left_ip); |
| 181 | } |
| 182 | |
Namhyung Kim | 51f27d1 | 2013-02-06 14:57:15 +0900 | [diff] [blame] | 183 | static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r) |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 184 | { |
| 185 | if (!sym_l || !sym_r) |
| 186 | return cmp_null(sym_l, sym_r); |
| 187 | |
| 188 | if (sym_l == sym_r) |
| 189 | return 0; |
| 190 | |
Yannick Brosseau | c05676c | 2015-06-17 16:41:10 -0700 | [diff] [blame] | 191 | if (sym_l->start != sym_r->start) |
| 192 | return (int64_t)(sym_r->start - sym_l->start); |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 193 | |
Yannick Brosseau | c05676c | 2015-06-17 16:41:10 -0700 | [diff] [blame] | 194 | return (int64_t)(sym_r->end - sym_l->end); |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static int64_t |
| 198 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) |
| 199 | { |
Namhyung Kim | 09600e0 | 2013-10-15 11:01:56 +0900 | [diff] [blame] | 200 | int64_t ret; |
| 201 | |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 202 | if (!left->ms.sym && !right->ms.sym) |
Namhyung Kim | 2037be5 | 2013-12-18 14:21:09 +0900 | [diff] [blame] | 203 | return _sort__addr_cmp(left->ip, right->ip); |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 204 | |
Namhyung Kim | 09600e0 | 2013-10-15 11:01:56 +0900 | [diff] [blame] | 205 | /* |
| 206 | * comparing symbol address alone is not enough since it's a |
| 207 | * relative address within a dso. |
| 208 | */ |
Namhyung Kim | 68f6d02 | 2013-12-18 14:21:10 +0900 | [diff] [blame] | 209 | if (!sort__has_dso) { |
| 210 | ret = sort__dso_cmp(left, right); |
| 211 | if (ret != 0) |
| 212 | return ret; |
| 213 | } |
Namhyung Kim | 09600e0 | 2013-10-15 11:01:56 +0900 | [diff] [blame] | 214 | |
Namhyung Kim | 51f27d1 | 2013-02-06 14:57:15 +0900 | [diff] [blame] | 215 | return _sort__sym_cmp(left->ms.sym, right->ms.sym); |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 218 | static int64_t |
| 219 | sort__sym_sort(struct hist_entry *left, struct hist_entry *right) |
| 220 | { |
| 221 | if (!left->ms.sym || !right->ms.sym) |
| 222 | return cmp_null(left->ms.sym, right->ms.sym); |
| 223 | |
| 224 | return strcmp(right->ms.sym->name, left->ms.sym->name); |
| 225 | } |
| 226 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 227 | static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, |
| 228 | u64 ip, char level, char *bf, size_t size, |
Namhyung Kim | 4335552 | 2012-12-27 18:11:39 +0900 | [diff] [blame] | 229 | unsigned int width) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 230 | { |
| 231 | size_t ret = 0; |
| 232 | |
| 233 | if (verbose) { |
| 234 | char o = map ? dso__symtab_origin(map->dso) : '!'; |
| 235 | ret += repsep_snprintf(bf, size, "%-#*llx %c ", |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 236 | BITS_PER_LONG / 4 + 2, ip, o); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 240 | if (sym && map) { |
| 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", |
Namhyung Kim | 6266774 | 2013-01-24 16:10:42 +0100 | [diff] [blame] | 244 | ip - map->unmap_ip(map, sym->start)); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 245 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", |
| 246 | width - ret, ""); |
| 247 | } else { |
| 248 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", |
| 249 | width - ret, |
| 250 | sym->name); |
| 251 | } |
| 252 | } else { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 253 | size_t len = BITS_PER_LONG / 4; |
| 254 | ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", |
| 255 | len, ip); |
| 256 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", |
| 257 | width - ret, ""); |
| 258 | } |
| 259 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 260 | if (ret > width) |
| 261 | bf[width] = '\0'; |
| 262 | |
| 263 | return width; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 266 | static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, |
Namhyung Kim | 4335552 | 2012-12-27 18:11:39 +0900 | [diff] [blame] | 267 | size_t size, unsigned int width) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 268 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 269 | return _hist_entry__sym_snprintf(he->ms.map, he->ms.sym, he->ip, |
| 270 | he->level, bf, size, width); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 271 | } |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 272 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 273 | struct sort_entry sort_sym = { |
| 274 | .se_header = "Symbol", |
| 275 | .se_cmp = sort__sym_cmp, |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 276 | .se_sort = sort__sym_sort, |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 277 | .se_snprintf = hist_entry__sym_snprintf, |
| 278 | .se_width_idx = HISTC_SYMBOL, |
| 279 | }; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 280 | |
Arnaldo Carvalho de Melo | 409a8be | 2012-05-30 10:33:24 -0300 | [diff] [blame] | 281 | /* --sort srcline */ |
| 282 | |
| 283 | static int64_t |
| 284 | sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) |
| 285 | { |
Namhyung Kim | 4adcc43 | 2013-09-11 14:09:33 +0900 | [diff] [blame] | 286 | if (!left->srcline) { |
| 287 | if (!left->ms.map) |
| 288 | left->srcline = SRCLINE_UNKNOWN; |
| 289 | else { |
| 290 | struct map *map = left->ms.map; |
| 291 | left->srcline = get_srcline(map->dso, |
Andi Kleen | 85c116a | 2014-11-12 18:05:27 -0800 | [diff] [blame] | 292 | map__rip_2objdump(map, left->ip), |
| 293 | left->ms.sym, true); |
Namhyung Kim | 4adcc43 | 2013-09-11 14:09:33 +0900 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | if (!right->srcline) { |
| 297 | if (!right->ms.map) |
| 298 | right->srcline = SRCLINE_UNKNOWN; |
| 299 | else { |
| 300 | struct map *map = right->ms.map; |
| 301 | right->srcline = get_srcline(map->dso, |
Andi Kleen | 85c116a | 2014-11-12 18:05:27 -0800 | [diff] [blame] | 302 | map__rip_2objdump(map, right->ip), |
| 303 | right->ms.sym, true); |
Namhyung Kim | 4adcc43 | 2013-09-11 14:09:33 +0900 | [diff] [blame] | 304 | } |
| 305 | } |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 306 | return strcmp(right->srcline, left->srcline); |
Arnaldo Carvalho de Melo | 409a8be | 2012-05-30 10:33:24 -0300 | [diff] [blame] | 307 | } |
| 308 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 309 | static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 310 | size_t size, unsigned int width) |
Arnaldo Carvalho de Melo | 409a8be | 2012-05-30 10:33:24 -0300 | [diff] [blame] | 311 | { |
Arnaldo Carvalho de Melo | b2d5367 | 2014-11-18 18:02:51 -0300 | [diff] [blame] | 312 | return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcline); |
Arnaldo Carvalho de Melo | 409a8be | 2012-05-30 10:33:24 -0300 | [diff] [blame] | 313 | } |
| 314 | |
| 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, |
| 320 | }; |
| 321 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 322 | /* --sort parent */ |
| 323 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 324 | static int64_t |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 325 | sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) |
| 326 | { |
| 327 | struct symbol *sym_l = left->parent; |
| 328 | struct symbol *sym_r = right->parent; |
| 329 | |
| 330 | if (!sym_l || !sym_r) |
| 331 | return cmp_null(sym_l, sym_r); |
| 332 | |
Namhyung Kim | 202e7a6 | 2014-03-04 11:01:41 +0900 | [diff] [blame] | 333 | return strcmp(sym_r->name, sym_l->name); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 336 | static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 337 | size_t size, unsigned int width) |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 338 | { |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 339 | return repsep_snprintf(bf, size, "%-*.*s", width, width, |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 340 | he->parent ? he->parent->name : "[other]"); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 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, |
| 348 | }; |
| 349 | |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 350 | /* --sort cpu */ |
| 351 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 352 | static int64_t |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 353 | sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right) |
| 354 | { |
| 355 | return right->cpu - left->cpu; |
| 356 | } |
| 357 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 358 | static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf, |
| 359 | size_t size, unsigned int width) |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 360 | { |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 361 | return repsep_snprintf(bf, size, "%*.*d", width, width, he->cpu); |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 362 | } |
| 363 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 364 | struct sort_entry sort_cpu = { |
| 365 | .se_header = "CPU", |
| 366 | .se_cmp = sort__cpu_cmp, |
| 367 | .se_snprintf = hist_entry__cpu_snprintf, |
| 368 | .se_width_idx = HISTC_CPU, |
| 369 | }; |
| 370 | |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 371 | /* sort keys for branch stacks */ |
| 372 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 373 | static int64_t |
| 374 | sort__dso_from_cmp(struct hist_entry *left, struct hist_entry *right) |
| 375 | { |
Jiri Olsa | 288a4b9 | 2014-10-16 16:07:07 +0200 | [diff] [blame] | 376 | if (!left->branch_info || !right->branch_info) |
| 377 | return cmp_null(left->branch_info, right->branch_info); |
| 378 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 379 | return _sort__dso_cmp(left->branch_info->from.map, |
| 380 | right->branch_info->from.map); |
| 381 | } |
| 382 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 383 | static int hist_entry__dso_from_snprintf(struct hist_entry *he, char *bf, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 384 | size_t size, unsigned int width) |
| 385 | { |
Jiri Olsa | 288a4b9 | 2014-10-16 16:07:07 +0200 | [diff] [blame] | 386 | if (he->branch_info) |
| 387 | return _hist_entry__dso_snprintf(he->branch_info->from.map, |
| 388 | bf, size, width); |
| 389 | else |
| 390 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 393 | static int64_t |
| 394 | sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right) |
| 395 | { |
Jiri Olsa | 8b62fa5 | 2014-10-16 16:07:06 +0200 | [diff] [blame] | 396 | if (!left->branch_info || !right->branch_info) |
| 397 | return cmp_null(left->branch_info, right->branch_info); |
| 398 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 399 | return _sort__dso_cmp(left->branch_info->to.map, |
| 400 | right->branch_info->to.map); |
| 401 | } |
| 402 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 403 | static int hist_entry__dso_to_snprintf(struct hist_entry *he, char *bf, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 404 | size_t size, unsigned int width) |
| 405 | { |
Jiri Olsa | 8b62fa5 | 2014-10-16 16:07:06 +0200 | [diff] [blame] | 406 | if (he->branch_info) |
| 407 | return _hist_entry__dso_snprintf(he->branch_info->to.map, |
| 408 | bf, size, width); |
| 409 | else |
| 410 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static int64_t |
| 414 | sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right) |
| 415 | { |
| 416 | struct addr_map_symbol *from_l = &left->branch_info->from; |
| 417 | struct addr_map_symbol *from_r = &right->branch_info->from; |
| 418 | |
Jiri Olsa | 1b9e97a | 2014-10-16 16:07:05 +0200 | [diff] [blame] | 419 | if (!left->branch_info || !right->branch_info) |
| 420 | return cmp_null(left->branch_info, right->branch_info); |
| 421 | |
| 422 | from_l = &left->branch_info->from; |
| 423 | from_r = &right->branch_info->from; |
| 424 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 425 | if (!from_l->sym && !from_r->sym) |
Namhyung Kim | 2037be5 | 2013-12-18 14:21:09 +0900 | [diff] [blame] | 426 | return _sort__addr_cmp(from_l->addr, from_r->addr); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 427 | |
Namhyung Kim | 51f27d1 | 2013-02-06 14:57:15 +0900 | [diff] [blame] | 428 | return _sort__sym_cmp(from_l->sym, from_r->sym); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static int64_t |
| 432 | sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right) |
| 433 | { |
Jiri Olsa | 38cdbd3 | 2014-10-16 16:07:04 +0200 | [diff] [blame] | 434 | struct addr_map_symbol *to_l, *to_r; |
| 435 | |
| 436 | if (!left->branch_info || !right->branch_info) |
| 437 | return cmp_null(left->branch_info, right->branch_info); |
| 438 | |
| 439 | to_l = &left->branch_info->to; |
| 440 | to_r = &right->branch_info->to; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 441 | |
| 442 | if (!to_l->sym && !to_r->sym) |
Namhyung Kim | 2037be5 | 2013-12-18 14:21:09 +0900 | [diff] [blame] | 443 | return _sort__addr_cmp(to_l->addr, to_r->addr); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 444 | |
Namhyung Kim | 51f27d1 | 2013-02-06 14:57:15 +0900 | [diff] [blame] | 445 | return _sort__sym_cmp(to_l->sym, to_r->sym); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 448 | static int hist_entry__sym_from_snprintf(struct hist_entry *he, char *bf, |
Namhyung Kim | 4335552 | 2012-12-27 18:11:39 +0900 | [diff] [blame] | 449 | size_t size, unsigned int width) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 450 | { |
Jiri Olsa | 1b9e97a | 2014-10-16 16:07:05 +0200 | [diff] [blame] | 451 | if (he->branch_info) { |
| 452 | struct addr_map_symbol *from = &he->branch_info->from; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 453 | |
Jiri Olsa | 1b9e97a | 2014-10-16 16:07:05 +0200 | [diff] [blame] | 454 | return _hist_entry__sym_snprintf(from->map, from->sym, from->addr, |
| 455 | he->level, bf, size, width); |
| 456 | } |
| 457 | |
| 458 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 461 | static int hist_entry__sym_to_snprintf(struct hist_entry *he, char *bf, |
Namhyung Kim | 4335552 | 2012-12-27 18:11:39 +0900 | [diff] [blame] | 462 | size_t size, unsigned int width) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 463 | { |
Jiri Olsa | 38cdbd3 | 2014-10-16 16:07:04 +0200 | [diff] [blame] | 464 | if (he->branch_info) { |
| 465 | struct addr_map_symbol *to = &he->branch_info->to; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 466 | |
Jiri Olsa | 38cdbd3 | 2014-10-16 16:07:04 +0200 | [diff] [blame] | 467 | return _hist_entry__sym_snprintf(to->map, to->sym, to->addr, |
| 468 | he->level, bf, size, width); |
| 469 | } |
| 470 | |
| 471 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A"); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Namhyung Kim | 14d1ac7 | 2012-12-27 18:11:38 +0900 | [diff] [blame] | 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, |
| 479 | }; |
| 480 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 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, |
| 486 | }; |
| 487 | |
| 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, |
| 493 | }; |
| 494 | |
| 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, |
| 500 | }; |
| 501 | |
| 502 | static int64_t |
| 503 | sort__mispredict_cmp(struct hist_entry *left, struct hist_entry *right) |
| 504 | { |
Jiri Olsa | 428560e | 2014-10-16 16:07:03 +0200 | [diff] [blame] | 505 | unsigned char mp, p; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 506 | |
Jiri Olsa | 428560e | 2014-10-16 16:07:03 +0200 | [diff] [blame] | 507 | if (!left->branch_info || !right->branch_info) |
| 508 | return cmp_null(left->branch_info, right->branch_info); |
| 509 | |
| 510 | mp = left->branch_info->flags.mispred != right->branch_info->flags.mispred; |
| 511 | p = left->branch_info->flags.predicted != right->branch_info->flags.predicted; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 512 | return mp || p; |
| 513 | } |
| 514 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 515 | static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 516 | size_t size, unsigned int width){ |
| 517 | static const char *out = "N/A"; |
| 518 | |
Jiri Olsa | 428560e | 2014-10-16 16:07:03 +0200 | [diff] [blame] | 519 | if (he->branch_info) { |
| 520 | if (he->branch_info->flags.predicted) |
| 521 | out = "N"; |
| 522 | else if (he->branch_info->flags.mispred) |
| 523 | out = "Y"; |
| 524 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 525 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 526 | return repsep_snprintf(bf, size, "%-*.*s", width, width, out); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 527 | } |
| 528 | |
Andi Kleen | 0e332f0 | 2015-07-18 08:24:46 -0700 | [diff] [blame] | 529 | static int64_t |
| 530 | sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right) |
| 531 | { |
| 532 | return left->branch_info->flags.cycles - |
| 533 | right->branch_info->flags.cycles; |
| 534 | } |
| 535 | |
| 536 | static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf, |
| 537 | size_t size, unsigned int width) |
| 538 | { |
| 539 | if (he->branch_info->flags.cycles == 0) |
| 540 | return repsep_snprintf(bf, size, "%-*s", width, "-"); |
| 541 | return repsep_snprintf(bf, size, "%-*hd", width, |
| 542 | he->branch_info->flags.cycles); |
| 543 | } |
| 544 | |
| 545 | struct sort_entry sort_cycles = { |
| 546 | .se_header = "Basic Block Cycles", |
| 547 | .se_cmp = sort__cycles_cmp, |
| 548 | .se_snprintf = hist_entry__cycles_snprintf, |
| 549 | .se_width_idx = HISTC_CYCLES, |
| 550 | }; |
| 551 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 552 | /* --sort daddr_sym */ |
| 553 | static int64_t |
| 554 | sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right) |
| 555 | { |
| 556 | uint64_t l = 0, r = 0; |
| 557 | |
| 558 | if (left->mem_info) |
| 559 | l = left->mem_info->daddr.addr; |
| 560 | if (right->mem_info) |
| 561 | r = right->mem_info->daddr.addr; |
| 562 | |
| 563 | return (int64_t)(r - l); |
| 564 | } |
| 565 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 566 | static int hist_entry__daddr_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 567 | size_t size, unsigned int width) |
| 568 | { |
| 569 | uint64_t addr = 0; |
| 570 | struct map *map = NULL; |
| 571 | struct symbol *sym = NULL; |
| 572 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 573 | if (he->mem_info) { |
| 574 | addr = he->mem_info->daddr.addr; |
| 575 | map = he->mem_info->daddr.map; |
| 576 | sym = he->mem_info->daddr.sym; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 577 | } |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 578 | return _hist_entry__sym_snprintf(map, sym, addr, he->level, bf, size, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 579 | width); |
| 580 | } |
| 581 | |
| 582 | static int64_t |
| 583 | sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right) |
| 584 | { |
| 585 | struct map *map_l = NULL; |
| 586 | struct map *map_r = NULL; |
| 587 | |
| 588 | if (left->mem_info) |
| 589 | map_l = left->mem_info->daddr.map; |
| 590 | if (right->mem_info) |
| 591 | map_r = right->mem_info->daddr.map; |
| 592 | |
| 593 | return _sort__dso_cmp(map_l, map_r); |
| 594 | } |
| 595 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 596 | static int hist_entry__dso_daddr_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 597 | size_t size, unsigned int width) |
| 598 | { |
| 599 | struct map *map = NULL; |
| 600 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 601 | if (he->mem_info) |
| 602 | map = he->mem_info->daddr.map; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 603 | |
| 604 | return _hist_entry__dso_snprintf(map, bf, size, width); |
| 605 | } |
| 606 | |
| 607 | static int64_t |
| 608 | sort__locked_cmp(struct hist_entry *left, struct hist_entry *right) |
| 609 | { |
| 610 | union perf_mem_data_src data_src_l; |
| 611 | union perf_mem_data_src data_src_r; |
| 612 | |
| 613 | if (left->mem_info) |
| 614 | data_src_l = left->mem_info->data_src; |
| 615 | else |
| 616 | data_src_l.mem_lock = PERF_MEM_LOCK_NA; |
| 617 | |
| 618 | if (right->mem_info) |
| 619 | data_src_r = right->mem_info->data_src; |
| 620 | else |
| 621 | data_src_r.mem_lock = PERF_MEM_LOCK_NA; |
| 622 | |
| 623 | return (int64_t)(data_src_r.mem_lock - data_src_l.mem_lock); |
| 624 | } |
| 625 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 626 | static int hist_entry__locked_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 627 | size_t size, unsigned int width) |
| 628 | { |
| 629 | const char *out; |
| 630 | u64 mask = PERF_MEM_LOCK_NA; |
| 631 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 632 | if (he->mem_info) |
| 633 | mask = he->mem_info->data_src.mem_lock; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 634 | |
| 635 | if (mask & PERF_MEM_LOCK_NA) |
| 636 | out = "N/A"; |
| 637 | else if (mask & PERF_MEM_LOCK_LOCKED) |
| 638 | out = "Yes"; |
| 639 | else |
| 640 | out = "No"; |
| 641 | |
| 642 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 643 | } |
| 644 | |
| 645 | static int64_t |
| 646 | sort__tlb_cmp(struct hist_entry *left, struct hist_entry *right) |
| 647 | { |
| 648 | union perf_mem_data_src data_src_l; |
| 649 | union perf_mem_data_src data_src_r; |
| 650 | |
| 651 | if (left->mem_info) |
| 652 | data_src_l = left->mem_info->data_src; |
| 653 | else |
| 654 | data_src_l.mem_dtlb = PERF_MEM_TLB_NA; |
| 655 | |
| 656 | if (right->mem_info) |
| 657 | data_src_r = right->mem_info->data_src; |
| 658 | else |
| 659 | data_src_r.mem_dtlb = PERF_MEM_TLB_NA; |
| 660 | |
| 661 | return (int64_t)(data_src_r.mem_dtlb - data_src_l.mem_dtlb); |
| 662 | } |
| 663 | |
| 664 | static const char * const tlb_access[] = { |
| 665 | "N/A", |
| 666 | "HIT", |
| 667 | "MISS", |
| 668 | "L1", |
| 669 | "L2", |
| 670 | "Walker", |
| 671 | "Fault", |
| 672 | }; |
| 673 | #define NUM_TLB_ACCESS (sizeof(tlb_access)/sizeof(const char *)) |
| 674 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 675 | static int hist_entry__tlb_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 676 | size_t size, unsigned int width) |
| 677 | { |
| 678 | char out[64]; |
| 679 | size_t sz = sizeof(out) - 1; /* -1 for null termination */ |
| 680 | size_t l = 0, i; |
| 681 | u64 m = PERF_MEM_TLB_NA; |
| 682 | u64 hit, miss; |
| 683 | |
| 684 | out[0] = '\0'; |
| 685 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 686 | if (he->mem_info) |
| 687 | m = he->mem_info->data_src.mem_dtlb; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 688 | |
| 689 | hit = m & PERF_MEM_TLB_HIT; |
| 690 | miss = m & PERF_MEM_TLB_MISS; |
| 691 | |
| 692 | /* already taken care of */ |
| 693 | m &= ~(PERF_MEM_TLB_HIT|PERF_MEM_TLB_MISS); |
| 694 | |
| 695 | for (i = 0; m && i < NUM_TLB_ACCESS; i++, m >>= 1) { |
| 696 | if (!(m & 0x1)) |
| 697 | continue; |
| 698 | if (l) { |
| 699 | strcat(out, " or "); |
| 700 | l += 4; |
| 701 | } |
| 702 | strncat(out, tlb_access[i], sz - l); |
| 703 | l += strlen(tlb_access[i]); |
| 704 | } |
| 705 | if (*out == '\0') |
| 706 | strcpy(out, "N/A"); |
| 707 | if (hit) |
| 708 | strncat(out, " hit", sz - l); |
| 709 | if (miss) |
| 710 | strncat(out, " miss", sz - l); |
| 711 | |
| 712 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 713 | } |
| 714 | |
| 715 | static int64_t |
| 716 | sort__lvl_cmp(struct hist_entry *left, struct hist_entry *right) |
| 717 | { |
| 718 | union perf_mem_data_src data_src_l; |
| 719 | union perf_mem_data_src data_src_r; |
| 720 | |
| 721 | if (left->mem_info) |
| 722 | data_src_l = left->mem_info->data_src; |
| 723 | else |
| 724 | data_src_l.mem_lvl = PERF_MEM_LVL_NA; |
| 725 | |
| 726 | if (right->mem_info) |
| 727 | data_src_r = right->mem_info->data_src; |
| 728 | else |
| 729 | data_src_r.mem_lvl = PERF_MEM_LVL_NA; |
| 730 | |
| 731 | return (int64_t)(data_src_r.mem_lvl - data_src_l.mem_lvl); |
| 732 | } |
| 733 | |
| 734 | static const char * const mem_lvl[] = { |
| 735 | "N/A", |
| 736 | "HIT", |
| 737 | "MISS", |
| 738 | "L1", |
| 739 | "LFB", |
| 740 | "L2", |
| 741 | "L3", |
| 742 | "Local RAM", |
| 743 | "Remote RAM (1 hop)", |
| 744 | "Remote RAM (2 hops)", |
| 745 | "Remote Cache (1 hop)", |
| 746 | "Remote Cache (2 hops)", |
| 747 | "I/O", |
| 748 | "Uncached", |
| 749 | }; |
| 750 | #define NUM_MEM_LVL (sizeof(mem_lvl)/sizeof(const char *)) |
| 751 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 752 | static int hist_entry__lvl_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 753 | size_t size, unsigned int width) |
| 754 | { |
| 755 | char out[64]; |
| 756 | size_t sz = sizeof(out) - 1; /* -1 for null termination */ |
| 757 | size_t i, l = 0; |
| 758 | u64 m = PERF_MEM_LVL_NA; |
| 759 | u64 hit, miss; |
| 760 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 761 | if (he->mem_info) |
| 762 | m = he->mem_info->data_src.mem_lvl; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 763 | |
| 764 | out[0] = '\0'; |
| 765 | |
| 766 | hit = m & PERF_MEM_LVL_HIT; |
| 767 | miss = m & PERF_MEM_LVL_MISS; |
| 768 | |
| 769 | /* already taken care of */ |
| 770 | m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS); |
| 771 | |
| 772 | for (i = 0; m && i < NUM_MEM_LVL; i++, m >>= 1) { |
| 773 | if (!(m & 0x1)) |
| 774 | continue; |
| 775 | if (l) { |
| 776 | strcat(out, " or "); |
| 777 | l += 4; |
| 778 | } |
| 779 | strncat(out, mem_lvl[i], sz - l); |
| 780 | l += strlen(mem_lvl[i]); |
| 781 | } |
| 782 | if (*out == '\0') |
| 783 | strcpy(out, "N/A"); |
| 784 | if (hit) |
| 785 | strncat(out, " hit", sz - l); |
| 786 | if (miss) |
| 787 | strncat(out, " miss", sz - l); |
| 788 | |
| 789 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 790 | } |
| 791 | |
| 792 | static int64_t |
| 793 | sort__snoop_cmp(struct hist_entry *left, struct hist_entry *right) |
| 794 | { |
| 795 | union perf_mem_data_src data_src_l; |
| 796 | union perf_mem_data_src data_src_r; |
| 797 | |
| 798 | if (left->mem_info) |
| 799 | data_src_l = left->mem_info->data_src; |
| 800 | else |
| 801 | data_src_l.mem_snoop = PERF_MEM_SNOOP_NA; |
| 802 | |
| 803 | if (right->mem_info) |
| 804 | data_src_r = right->mem_info->data_src; |
| 805 | else |
| 806 | data_src_r.mem_snoop = PERF_MEM_SNOOP_NA; |
| 807 | |
| 808 | return (int64_t)(data_src_r.mem_snoop - data_src_l.mem_snoop); |
| 809 | } |
| 810 | |
| 811 | static const char * const snoop_access[] = { |
| 812 | "N/A", |
| 813 | "None", |
| 814 | "Miss", |
| 815 | "Hit", |
| 816 | "HitM", |
| 817 | }; |
| 818 | #define NUM_SNOOP_ACCESS (sizeof(snoop_access)/sizeof(const char *)) |
| 819 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 820 | static int hist_entry__snoop_snprintf(struct hist_entry *he, char *bf, |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 821 | size_t size, unsigned int width) |
| 822 | { |
| 823 | char out[64]; |
| 824 | size_t sz = sizeof(out) - 1; /* -1 for null termination */ |
| 825 | size_t i, l = 0; |
| 826 | u64 m = PERF_MEM_SNOOP_NA; |
| 827 | |
| 828 | out[0] = '\0'; |
| 829 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 830 | if (he->mem_info) |
| 831 | m = he->mem_info->data_src.mem_snoop; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 832 | |
| 833 | for (i = 0; m && i < NUM_SNOOP_ACCESS; i++, m >>= 1) { |
| 834 | if (!(m & 0x1)) |
| 835 | continue; |
| 836 | if (l) { |
| 837 | strcat(out, " or "); |
| 838 | l += 4; |
| 839 | } |
| 840 | strncat(out, snoop_access[i], sz - l); |
| 841 | l += strlen(snoop_access[i]); |
| 842 | } |
| 843 | |
| 844 | if (*out == '\0') |
| 845 | strcpy(out, "N/A"); |
| 846 | |
| 847 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 848 | } |
| 849 | |
Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 850 | static inline u64 cl_address(u64 address) |
| 851 | { |
| 852 | /* return the cacheline of the address */ |
| 853 | return (address & ~(cacheline_size - 1)); |
| 854 | } |
| 855 | |
| 856 | static int64_t |
| 857 | sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right) |
| 858 | { |
| 859 | u64 l, r; |
| 860 | struct map *l_map, *r_map; |
| 861 | |
| 862 | if (!left->mem_info) return -1; |
| 863 | if (!right->mem_info) return 1; |
| 864 | |
| 865 | /* group event types together */ |
| 866 | if (left->cpumode > right->cpumode) return -1; |
| 867 | if (left->cpumode < right->cpumode) return 1; |
| 868 | |
| 869 | l_map = left->mem_info->daddr.map; |
| 870 | r_map = right->mem_info->daddr.map; |
| 871 | |
| 872 | /* if both are NULL, jump to sort on al_addr instead */ |
| 873 | if (!l_map && !r_map) |
| 874 | goto addr; |
| 875 | |
| 876 | if (!l_map) return -1; |
| 877 | if (!r_map) return 1; |
| 878 | |
| 879 | if (l_map->maj > r_map->maj) return -1; |
| 880 | if (l_map->maj < r_map->maj) return 1; |
| 881 | |
| 882 | if (l_map->min > r_map->min) return -1; |
| 883 | if (l_map->min < r_map->min) return 1; |
| 884 | |
| 885 | if (l_map->ino > r_map->ino) return -1; |
| 886 | if (l_map->ino < r_map->ino) return 1; |
| 887 | |
| 888 | if (l_map->ino_generation > r_map->ino_generation) return -1; |
| 889 | if (l_map->ino_generation < r_map->ino_generation) return 1; |
| 890 | |
| 891 | /* |
| 892 | * Addresses with no major/minor numbers are assumed to be |
| 893 | * anonymous in userspace. Sort those on pid then address. |
| 894 | * |
| 895 | * The kernel and non-zero major/minor mapped areas are |
| 896 | * assumed to be unity mapped. Sort those on address. |
| 897 | */ |
| 898 | |
| 899 | if ((left->cpumode != PERF_RECORD_MISC_KERNEL) && |
| 900 | (!(l_map->flags & MAP_SHARED)) && |
| 901 | !l_map->maj && !l_map->min && !l_map->ino && |
| 902 | !l_map->ino_generation) { |
| 903 | /* userspace anonymous */ |
| 904 | |
| 905 | if (left->thread->pid_ > right->thread->pid_) return -1; |
| 906 | if (left->thread->pid_ < right->thread->pid_) return 1; |
| 907 | } |
| 908 | |
| 909 | addr: |
| 910 | /* al_addr does all the right addr - start + offset calculations */ |
| 911 | l = cl_address(left->mem_info->daddr.al_addr); |
| 912 | r = cl_address(right->mem_info->daddr.al_addr); |
| 913 | |
| 914 | if (l > r) return -1; |
| 915 | if (l < r) return 1; |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf, |
| 921 | size_t size, unsigned int width) |
| 922 | { |
| 923 | |
| 924 | uint64_t addr = 0; |
| 925 | struct map *map = NULL; |
| 926 | struct symbol *sym = NULL; |
| 927 | char level = he->level; |
| 928 | |
| 929 | if (he->mem_info) { |
| 930 | addr = cl_address(he->mem_info->daddr.al_addr); |
| 931 | map = he->mem_info->daddr.map; |
| 932 | sym = he->mem_info->daddr.sym; |
| 933 | |
| 934 | /* print [s] for shared data mmaps */ |
| 935 | if ((he->cpumode != PERF_RECORD_MISC_KERNEL) && |
| 936 | map && (map->type == MAP__VARIABLE) && |
| 937 | (map->flags & MAP_SHARED) && |
| 938 | (map->maj || map->min || map->ino || |
| 939 | map->ino_generation)) |
| 940 | level = 's'; |
| 941 | else if (!map) |
| 942 | level = 'X'; |
| 943 | } |
| 944 | return _hist_entry__sym_snprintf(map, sym, addr, level, bf, size, |
| 945 | width); |
| 946 | } |
| 947 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 948 | struct sort_entry sort_mispredict = { |
| 949 | .se_header = "Branch Mispredicted", |
| 950 | .se_cmp = sort__mispredict_cmp, |
| 951 | .se_snprintf = hist_entry__mispredict_snprintf, |
| 952 | .se_width_idx = HISTC_MISPREDICT, |
| 953 | }; |
| 954 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 955 | static u64 he_weight(struct hist_entry *he) |
| 956 | { |
| 957 | return he->stat.nr_events ? he->stat.weight / he->stat.nr_events : 0; |
| 958 | } |
| 959 | |
| 960 | static int64_t |
| 961 | sort__local_weight_cmp(struct hist_entry *left, struct hist_entry *right) |
| 962 | { |
| 963 | return he_weight(left) - he_weight(right); |
| 964 | } |
| 965 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 966 | static int hist_entry__local_weight_snprintf(struct hist_entry *he, char *bf, |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 967 | size_t size, unsigned int width) |
| 968 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 969 | return repsep_snprintf(bf, size, "%-*llu", width, he_weight(he)); |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | struct sort_entry sort_local_weight = { |
| 973 | .se_header = "Local Weight", |
| 974 | .se_cmp = sort__local_weight_cmp, |
| 975 | .se_snprintf = hist_entry__local_weight_snprintf, |
| 976 | .se_width_idx = HISTC_LOCAL_WEIGHT, |
| 977 | }; |
| 978 | |
| 979 | static int64_t |
| 980 | sort__global_weight_cmp(struct hist_entry *left, struct hist_entry *right) |
| 981 | { |
| 982 | return left->stat.weight - right->stat.weight; |
| 983 | } |
| 984 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 985 | static int hist_entry__global_weight_snprintf(struct hist_entry *he, char *bf, |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 986 | size_t size, unsigned int width) |
| 987 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 988 | return repsep_snprintf(bf, size, "%-*llu", width, he->stat.weight); |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | struct sort_entry sort_global_weight = { |
| 992 | .se_header = "Weight", |
| 993 | .se_cmp = sort__global_weight_cmp, |
| 994 | .se_snprintf = hist_entry__global_weight_snprintf, |
| 995 | .se_width_idx = HISTC_GLOBAL_WEIGHT, |
| 996 | }; |
| 997 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 998 | struct sort_entry sort_mem_daddr_sym = { |
| 999 | .se_header = "Data Symbol", |
| 1000 | .se_cmp = sort__daddr_cmp, |
| 1001 | .se_snprintf = hist_entry__daddr_snprintf, |
| 1002 | .se_width_idx = HISTC_MEM_DADDR_SYMBOL, |
| 1003 | }; |
| 1004 | |
| 1005 | struct sort_entry sort_mem_daddr_dso = { |
| 1006 | .se_header = "Data Object", |
| 1007 | .se_cmp = sort__dso_daddr_cmp, |
| 1008 | .se_snprintf = hist_entry__dso_daddr_snprintf, |
| 1009 | .se_width_idx = HISTC_MEM_DADDR_SYMBOL, |
| 1010 | }; |
| 1011 | |
| 1012 | struct sort_entry sort_mem_locked = { |
| 1013 | .se_header = "Locked", |
| 1014 | .se_cmp = sort__locked_cmp, |
| 1015 | .se_snprintf = hist_entry__locked_snprintf, |
| 1016 | .se_width_idx = HISTC_MEM_LOCKED, |
| 1017 | }; |
| 1018 | |
| 1019 | struct sort_entry sort_mem_tlb = { |
| 1020 | .se_header = "TLB access", |
| 1021 | .se_cmp = sort__tlb_cmp, |
| 1022 | .se_snprintf = hist_entry__tlb_snprintf, |
| 1023 | .se_width_idx = HISTC_MEM_TLB, |
| 1024 | }; |
| 1025 | |
| 1026 | struct sort_entry sort_mem_lvl = { |
| 1027 | .se_header = "Memory access", |
| 1028 | .se_cmp = sort__lvl_cmp, |
| 1029 | .se_snprintf = hist_entry__lvl_snprintf, |
| 1030 | .se_width_idx = HISTC_MEM_LVL, |
| 1031 | }; |
| 1032 | |
| 1033 | struct sort_entry sort_mem_snoop = { |
| 1034 | .se_header = "Snoop", |
| 1035 | .se_cmp = sort__snoop_cmp, |
| 1036 | .se_snprintf = hist_entry__snoop_snprintf, |
| 1037 | .se_width_idx = HISTC_MEM_SNOOP, |
| 1038 | }; |
| 1039 | |
Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 1040 | struct sort_entry sort_mem_dcacheline = { |
| 1041 | .se_header = "Data Cacheline", |
| 1042 | .se_cmp = sort__dcacheline_cmp, |
| 1043 | .se_snprintf = hist_entry__dcacheline_snprintf, |
| 1044 | .se_width_idx = HISTC_MEM_DCACHELINE, |
| 1045 | }; |
| 1046 | |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1047 | static int64_t |
| 1048 | sort__abort_cmp(struct hist_entry *left, struct hist_entry *right) |
| 1049 | { |
Jiri Olsa | 49f4744 | 2014-10-16 16:07:01 +0200 | [diff] [blame] | 1050 | if (!left->branch_info || !right->branch_info) |
| 1051 | return cmp_null(left->branch_info, right->branch_info); |
| 1052 | |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1053 | return left->branch_info->flags.abort != |
| 1054 | right->branch_info->flags.abort; |
| 1055 | } |
| 1056 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 1057 | static int hist_entry__abort_snprintf(struct hist_entry *he, char *bf, |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1058 | size_t size, unsigned int width) |
| 1059 | { |
Jiri Olsa | 49f4744 | 2014-10-16 16:07:01 +0200 | [diff] [blame] | 1060 | static const char *out = "N/A"; |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1061 | |
Jiri Olsa | 49f4744 | 2014-10-16 16:07:01 +0200 | [diff] [blame] | 1062 | if (he->branch_info) { |
| 1063 | if (he->branch_info->flags.abort) |
| 1064 | out = "A"; |
| 1065 | else |
| 1066 | out = "."; |
| 1067 | } |
| 1068 | |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1069 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 1070 | } |
| 1071 | |
| 1072 | struct sort_entry sort_abort = { |
| 1073 | .se_header = "Transaction abort", |
| 1074 | .se_cmp = sort__abort_cmp, |
| 1075 | .se_snprintf = hist_entry__abort_snprintf, |
| 1076 | .se_width_idx = HISTC_ABORT, |
| 1077 | }; |
| 1078 | |
| 1079 | static int64_t |
| 1080 | sort__in_tx_cmp(struct hist_entry *left, struct hist_entry *right) |
| 1081 | { |
Jiri Olsa | 0199d24 | 2014-10-16 16:07:02 +0200 | [diff] [blame] | 1082 | if (!left->branch_info || !right->branch_info) |
| 1083 | return cmp_null(left->branch_info, right->branch_info); |
| 1084 | |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1085 | return left->branch_info->flags.in_tx != |
| 1086 | right->branch_info->flags.in_tx; |
| 1087 | } |
| 1088 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 1089 | static int hist_entry__in_tx_snprintf(struct hist_entry *he, char *bf, |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1090 | size_t size, unsigned int width) |
| 1091 | { |
Jiri Olsa | 0199d24 | 2014-10-16 16:07:02 +0200 | [diff] [blame] | 1092 | static const char *out = "N/A"; |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1093 | |
Jiri Olsa | 0199d24 | 2014-10-16 16:07:02 +0200 | [diff] [blame] | 1094 | if (he->branch_info) { |
| 1095 | if (he->branch_info->flags.in_tx) |
| 1096 | out = "T"; |
| 1097 | else |
| 1098 | out = "."; |
| 1099 | } |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1100 | |
| 1101 | return repsep_snprintf(bf, size, "%-*s", width, out); |
| 1102 | } |
| 1103 | |
| 1104 | struct sort_entry sort_in_tx = { |
| 1105 | .se_header = "Branch in transaction", |
| 1106 | .se_cmp = sort__in_tx_cmp, |
| 1107 | .se_snprintf = hist_entry__in_tx_snprintf, |
| 1108 | .se_width_idx = HISTC_IN_TX, |
| 1109 | }; |
| 1110 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1111 | static int64_t |
| 1112 | sort__transaction_cmp(struct hist_entry *left, struct hist_entry *right) |
| 1113 | { |
| 1114 | return left->transaction - right->transaction; |
| 1115 | } |
| 1116 | |
| 1117 | static inline char *add_str(char *p, const char *str) |
| 1118 | { |
| 1119 | strcpy(p, str); |
| 1120 | return p + strlen(str); |
| 1121 | } |
| 1122 | |
| 1123 | static struct txbit { |
| 1124 | unsigned flag; |
| 1125 | const char *name; |
| 1126 | int skip_for_len; |
| 1127 | } txbits[] = { |
| 1128 | { PERF_TXN_ELISION, "EL ", 0 }, |
| 1129 | { PERF_TXN_TRANSACTION, "TX ", 1 }, |
| 1130 | { PERF_TXN_SYNC, "SYNC ", 1 }, |
| 1131 | { PERF_TXN_ASYNC, "ASYNC ", 0 }, |
| 1132 | { PERF_TXN_RETRY, "RETRY ", 0 }, |
| 1133 | { PERF_TXN_CONFLICT, "CON ", 0 }, |
| 1134 | { PERF_TXN_CAPACITY_WRITE, "CAP-WRITE ", 1 }, |
| 1135 | { PERF_TXN_CAPACITY_READ, "CAP-READ ", 0 }, |
| 1136 | { 0, NULL, 0 } |
| 1137 | }; |
| 1138 | |
| 1139 | int hist_entry__transaction_len(void) |
| 1140 | { |
| 1141 | int i; |
| 1142 | int len = 0; |
| 1143 | |
| 1144 | for (i = 0; txbits[i].name; i++) { |
| 1145 | if (!txbits[i].skip_for_len) |
| 1146 | len += strlen(txbits[i].name); |
| 1147 | } |
| 1148 | len += 4; /* :XX<space> */ |
| 1149 | return len; |
| 1150 | } |
| 1151 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 1152 | static int hist_entry__transaction_snprintf(struct hist_entry *he, char *bf, |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1153 | size_t size, unsigned int width) |
| 1154 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 1155 | u64 t = he->transaction; |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1156 | char buf[128]; |
| 1157 | char *p = buf; |
| 1158 | int i; |
| 1159 | |
| 1160 | buf[0] = 0; |
| 1161 | for (i = 0; txbits[i].name; i++) |
| 1162 | if (txbits[i].flag & t) |
| 1163 | p = add_str(p, txbits[i].name); |
| 1164 | if (t && !(t & (PERF_TXN_SYNC|PERF_TXN_ASYNC))) |
| 1165 | p = add_str(p, "NEITHER "); |
| 1166 | if (t & PERF_TXN_ABORT_MASK) { |
| 1167 | sprintf(p, ":%" PRIx64, |
| 1168 | (t & PERF_TXN_ABORT_MASK) >> |
| 1169 | PERF_TXN_ABORT_SHIFT); |
| 1170 | p += strlen(p); |
| 1171 | } |
| 1172 | |
| 1173 | return repsep_snprintf(bf, size, "%-*s", width, buf); |
| 1174 | } |
| 1175 | |
| 1176 | struct sort_entry sort_transaction = { |
| 1177 | .se_header = "Transaction ", |
| 1178 | .se_cmp = sort__transaction_cmp, |
| 1179 | .se_snprintf = hist_entry__transaction_snprintf, |
| 1180 | .se_width_idx = HISTC_TRANSACTION, |
| 1181 | }; |
| 1182 | |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 1183 | struct sort_dimension { |
| 1184 | const char *name; |
| 1185 | struct sort_entry *entry; |
| 1186 | int taken; |
| 1187 | }; |
| 1188 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1189 | #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) } |
| 1190 | |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1191 | static struct sort_dimension common_sort_dimensions[] = { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1192 | DIM(SORT_PID, "pid", sort_thread), |
| 1193 | DIM(SORT_COMM, "comm", sort_comm), |
| 1194 | DIM(SORT_DSO, "dso", sort_dso), |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1195 | DIM(SORT_SYM, "symbol", sort_sym), |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1196 | DIM(SORT_PARENT, "parent", sort_parent), |
| 1197 | DIM(SORT_CPU, "cpu", sort_cpu), |
Arnaldo Carvalho de Melo | 409a8be | 2012-05-30 10:33:24 -0300 | [diff] [blame] | 1198 | DIM(SORT_SRCLINE, "srcline", sort_srcline), |
Andi Kleen | f9ea55d | 2013-07-18 15:58:53 -0700 | [diff] [blame] | 1199 | DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight), |
| 1200 | DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1201 | DIM(SORT_TRANSACTION, "transaction", sort_transaction), |
Frederic Weisbecker | 872a878 | 2011-06-29 03:14:52 +0200 | [diff] [blame] | 1202 | }; |
| 1203 | |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1204 | #undef DIM |
| 1205 | |
| 1206 | #define DIM(d, n, func) [d - __SORT_BRANCH_STACK] = { .name = n, .entry = &(func) } |
| 1207 | |
| 1208 | static struct sort_dimension bstack_sort_dimensions[] = { |
| 1209 | DIM(SORT_DSO_FROM, "dso_from", sort_dso_from), |
| 1210 | DIM(SORT_DSO_TO, "dso_to", sort_dso_to), |
| 1211 | DIM(SORT_SYM_FROM, "symbol_from", sort_sym_from), |
| 1212 | DIM(SORT_SYM_TO, "symbol_to", sort_sym_to), |
| 1213 | DIM(SORT_MISPREDICT, "mispredict", sort_mispredict), |
Andi Kleen | f5d05bc | 2013-09-20 07:40:41 -0700 | [diff] [blame] | 1214 | DIM(SORT_IN_TX, "in_tx", sort_in_tx), |
| 1215 | DIM(SORT_ABORT, "abort", sort_abort), |
Andi Kleen | 0e332f0 | 2015-07-18 08:24:46 -0700 | [diff] [blame] | 1216 | DIM(SORT_CYCLES, "cycles", sort_cycles), |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | #undef DIM |
| 1220 | |
Namhyung Kim | afab87b | 2013-04-03 21:26:11 +0900 | [diff] [blame] | 1221 | #define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) } |
| 1222 | |
| 1223 | static struct sort_dimension memory_sort_dimensions[] = { |
Namhyung Kim | afab87b | 2013-04-03 21:26:11 +0900 | [diff] [blame] | 1224 | DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym), |
| 1225 | DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso), |
| 1226 | DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked), |
| 1227 | DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb), |
| 1228 | DIM(SORT_MEM_LVL, "mem", sort_mem_lvl), |
| 1229 | DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop), |
Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 1230 | DIM(SORT_MEM_DCACHELINE, "dcacheline", sort_mem_dcacheline), |
Namhyung Kim | afab87b | 2013-04-03 21:26:11 +0900 | [diff] [blame] | 1231 | }; |
| 1232 | |
| 1233 | #undef DIM |
| 1234 | |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 1235 | struct hpp_dimension { |
| 1236 | const char *name; |
| 1237 | struct perf_hpp_fmt *fmt; |
| 1238 | int taken; |
| 1239 | }; |
| 1240 | |
| 1241 | #define DIM(d, n) { .name = n, .fmt = &perf_hpp__format[d], } |
| 1242 | |
| 1243 | static struct hpp_dimension hpp_sort_dimensions[] = { |
| 1244 | DIM(PERF_HPP__OVERHEAD, "overhead"), |
| 1245 | DIM(PERF_HPP__OVERHEAD_SYS, "overhead_sys"), |
| 1246 | DIM(PERF_HPP__OVERHEAD_US, "overhead_us"), |
| 1247 | DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"), |
| 1248 | DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"), |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 1249 | DIM(PERF_HPP__OVERHEAD_ACC, "overhead_children"), |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 1250 | DIM(PERF_HPP__SAMPLES, "sample"), |
| 1251 | DIM(PERF_HPP__PERIOD, "period"), |
| 1252 | }; |
| 1253 | |
| 1254 | #undef DIM |
| 1255 | |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1256 | struct hpp_sort_entry { |
| 1257 | struct perf_hpp_fmt hpp; |
| 1258 | struct sort_entry *se; |
| 1259 | }; |
| 1260 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1261 | bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) |
| 1262 | { |
| 1263 | struct hpp_sort_entry *hse_a; |
| 1264 | struct hpp_sort_entry *hse_b; |
| 1265 | |
| 1266 | if (!perf_hpp__is_sort_entry(a) || !perf_hpp__is_sort_entry(b)) |
| 1267 | return false; |
| 1268 | |
| 1269 | hse_a = container_of(a, struct hpp_sort_entry, hpp); |
| 1270 | hse_b = container_of(b, struct hpp_sort_entry, hpp); |
| 1271 | |
| 1272 | return hse_a->se == hse_b->se; |
| 1273 | } |
| 1274 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 1275 | void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists) |
Namhyung Kim | 678a500 | 2014-03-20 11:18:54 +0900 | [diff] [blame] | 1276 | { |
| 1277 | struct hpp_sort_entry *hse; |
| 1278 | |
| 1279 | if (!perf_hpp__is_sort_entry(fmt)) |
| 1280 | return; |
| 1281 | |
| 1282 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
Namhyung Kim | 1ecd445 | 2014-07-31 14:47:40 +0900 | [diff] [blame] | 1283 | hists__new_col_len(hists, hse->se->se_width_idx, strlen(fmt->name)); |
Namhyung Kim | 678a500 | 2014-03-20 11:18:54 +0900 | [diff] [blame] | 1284 | } |
| 1285 | |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1286 | static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 1287 | struct perf_evsel *evsel) |
| 1288 | { |
| 1289 | struct hpp_sort_entry *hse; |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1290 | size_t len = fmt->user_len; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1291 | |
| 1292 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1293 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1294 | if (!len) |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1295 | len = hists__col_len(evsel__hists(evsel), hse->se->se_width_idx); |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1296 | |
Namhyung Kim | 1ecd445 | 2014-07-31 14:47:40 +0900 | [diff] [blame] | 1297 | return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, fmt->name); |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static int __sort__hpp_width(struct perf_hpp_fmt *fmt, |
| 1301 | struct perf_hpp *hpp __maybe_unused, |
| 1302 | struct perf_evsel *evsel) |
| 1303 | { |
| 1304 | struct hpp_sort_entry *hse; |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1305 | size_t len = fmt->user_len; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1306 | |
| 1307 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1308 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1309 | if (!len) |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 1310 | len = hists__col_len(evsel__hists(evsel), hse->se->se_width_idx); |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1311 | |
| 1312 | return len; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 1316 | struct hist_entry *he) |
| 1317 | { |
| 1318 | struct hpp_sort_entry *hse; |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1319 | size_t len = fmt->user_len; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1320 | |
| 1321 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1322 | |
| 1323 | if (!len) |
| 1324 | len = hists__col_len(he->hists, hse->se->se_width_idx); |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1325 | |
| 1326 | return hse->se->se_snprintf(he, hpp->buf, hpp->size, len); |
| 1327 | } |
| 1328 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1329 | static int64_t __sort__hpp_cmp(struct perf_hpp_fmt *fmt, |
| 1330 | struct hist_entry *a, struct hist_entry *b) |
| 1331 | { |
| 1332 | struct hpp_sort_entry *hse; |
| 1333 | |
| 1334 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1335 | return hse->se->se_cmp(a, b); |
| 1336 | } |
| 1337 | |
| 1338 | static int64_t __sort__hpp_collapse(struct perf_hpp_fmt *fmt, |
| 1339 | struct hist_entry *a, struct hist_entry *b) |
| 1340 | { |
| 1341 | struct hpp_sort_entry *hse; |
| 1342 | int64_t (*collapse_fn)(struct hist_entry *, struct hist_entry *); |
| 1343 | |
| 1344 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1345 | collapse_fn = hse->se->se_collapse ?: hse->se->se_cmp; |
| 1346 | return collapse_fn(a, b); |
| 1347 | } |
| 1348 | |
| 1349 | static int64_t __sort__hpp_sort(struct perf_hpp_fmt *fmt, |
| 1350 | struct hist_entry *a, struct hist_entry *b) |
| 1351 | { |
| 1352 | struct hpp_sort_entry *hse; |
| 1353 | int64_t (*sort_fn)(struct hist_entry *, struct hist_entry *); |
| 1354 | |
| 1355 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1356 | sort_fn = hse->se->se_sort ?: hse->se->se_cmp; |
| 1357 | return sort_fn(a, b); |
| 1358 | } |
| 1359 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1360 | static struct hpp_sort_entry * |
| 1361 | __sort_dimension__alloc_hpp(struct sort_dimension *sd) |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1362 | { |
| 1363 | struct hpp_sort_entry *hse; |
| 1364 | |
| 1365 | hse = malloc(sizeof(*hse)); |
| 1366 | if (hse == NULL) { |
| 1367 | pr_err("Memory allocation failed\n"); |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1368 | return NULL; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | hse->se = sd->entry; |
Namhyung Kim | 1ecd445 | 2014-07-31 14:47:40 +0900 | [diff] [blame] | 1372 | hse->hpp.name = sd->entry->se_header; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1373 | hse->hpp.header = __sort__hpp_header; |
| 1374 | hse->hpp.width = __sort__hpp_width; |
| 1375 | hse->hpp.entry = __sort__hpp_entry; |
| 1376 | hse->hpp.color = NULL; |
| 1377 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1378 | hse->hpp.cmp = __sort__hpp_cmp; |
| 1379 | hse->hpp.collapse = __sort__hpp_collapse; |
| 1380 | hse->hpp.sort = __sort__hpp_sort; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1381 | |
| 1382 | INIT_LIST_HEAD(&hse->hpp.list); |
| 1383 | INIT_LIST_HEAD(&hse->hpp.sort_list); |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1384 | hse->hpp.elide = false; |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 1385 | hse->hpp.len = 0; |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame] | 1386 | hse->hpp.user_len = 0; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1387 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1388 | return hse; |
| 1389 | } |
| 1390 | |
| 1391 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format) |
| 1392 | { |
| 1393 | return format->header == __sort__hpp_header; |
| 1394 | } |
| 1395 | |
| 1396 | static int __sort_dimension__add_hpp_sort(struct sort_dimension *sd) |
| 1397 | { |
| 1398 | struct hpp_sort_entry *hse = __sort_dimension__alloc_hpp(sd); |
| 1399 | |
| 1400 | if (hse == NULL) |
| 1401 | return -1; |
| 1402 | |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1403 | perf_hpp__register_sort_field(&hse->hpp); |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1407 | static int __sort_dimension__add_hpp_output(struct sort_dimension *sd) |
| 1408 | { |
| 1409 | struct hpp_sort_entry *hse = __sort_dimension__alloc_hpp(sd); |
| 1410 | |
| 1411 | if (hse == NULL) |
| 1412 | return -1; |
| 1413 | |
| 1414 | perf_hpp__column_register(&hse->hpp); |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1418 | static int __sort_dimension__add(struct sort_dimension *sd) |
Namhyung Kim | 2f532d09 | 2013-04-03 21:26:10 +0900 | [diff] [blame] | 1419 | { |
| 1420 | if (sd->taken) |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1421 | return 0; |
| 1422 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1423 | if (__sort_dimension__add_hpp_sort(sd) < 0) |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1424 | return -1; |
Namhyung Kim | 2f532d09 | 2013-04-03 21:26:10 +0900 | [diff] [blame] | 1425 | |
| 1426 | if (sd->entry->se_collapse) |
| 1427 | sort__need_collapse = 1; |
| 1428 | |
Namhyung Kim | 2f532d09 | 2013-04-03 21:26:10 +0900 | [diff] [blame] | 1429 | sd->taken = 1; |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 1430 | |
| 1431 | return 0; |
Namhyung Kim | 2f532d09 | 2013-04-03 21:26:10 +0900 | [diff] [blame] | 1432 | } |
| 1433 | |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 1434 | static int __hpp_dimension__add(struct hpp_dimension *hd) |
| 1435 | { |
| 1436 | if (!hd->taken) { |
| 1437 | hd->taken = 1; |
| 1438 | |
| 1439 | perf_hpp__register_sort_field(hd->fmt); |
| 1440 | } |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1444 | static int __sort_dimension__add_output(struct sort_dimension *sd) |
| 1445 | { |
| 1446 | if (sd->taken) |
| 1447 | return 0; |
| 1448 | |
| 1449 | if (__sort_dimension__add_hpp_output(sd) < 0) |
| 1450 | return -1; |
| 1451 | |
| 1452 | sd->taken = 1; |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | static int __hpp_dimension__add_output(struct hpp_dimension *hd) |
| 1457 | { |
| 1458 | if (!hd->taken) { |
| 1459 | hd->taken = 1; |
| 1460 | |
| 1461 | perf_hpp__column_register(hd->fmt); |
| 1462 | } |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1466 | int sort_dimension__add(const char *tok) |
| 1467 | { |
| 1468 | unsigned int i; |
| 1469 | |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1470 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) { |
| 1471 | struct sort_dimension *sd = &common_sort_dimensions[i]; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1472 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1473 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1474 | continue; |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1475 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1476 | if (sd->entry == &sort_parent) { |
| 1477 | int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED); |
| 1478 | if (ret) { |
| 1479 | char err[BUFSIZ]; |
| 1480 | |
| 1481 | regerror(ret, &parent_regex, err, sizeof(err)); |
Arnaldo Carvalho de Melo | 2aefa4f | 2010-04-02 12:30:57 -0300 | [diff] [blame] | 1482 | pr_err("Invalid regex: %s\n%s", parent_pattern, err); |
| 1483 | return -EINVAL; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1484 | } |
| 1485 | sort__has_parent = 1; |
Namhyung Kim | 930477b | 2013-04-05 10:26:36 +0900 | [diff] [blame] | 1486 | } else if (sd->entry == &sort_sym) { |
Namhyung Kim | 1af55640 | 2012-09-14 17:35:27 +0900 | [diff] [blame] | 1487 | sort__has_sym = 1; |
Kan Liang | 94ba462 | 2015-02-09 05:39:44 +0000 | [diff] [blame] | 1488 | /* |
| 1489 | * perf diff displays the performance difference amongst |
| 1490 | * two or more perf.data files. Those files could come |
| 1491 | * from different binaries. So we should not compare |
| 1492 | * their ips, but the name of symbol. |
| 1493 | */ |
| 1494 | if (sort__mode == SORT_MODE__DIFF) |
| 1495 | sd->entry->se_collapse = sort__sym_sort; |
| 1496 | |
Namhyung Kim | 68f6d02 | 2013-12-18 14:21:10 +0900 | [diff] [blame] | 1497 | } else if (sd->entry == &sort_dso) { |
| 1498 | sort__has_dso = 1; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1499 | } |
| 1500 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1501 | return __sort_dimension__add(sd); |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1502 | } |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1503 | |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 1504 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) { |
| 1505 | struct hpp_dimension *hd = &hpp_sort_dimensions[i]; |
| 1506 | |
| 1507 | if (strncasecmp(tok, hd->name, strlen(tok))) |
| 1508 | continue; |
| 1509 | |
| 1510 | return __hpp_dimension__add(hd); |
| 1511 | } |
| 1512 | |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1513 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) { |
| 1514 | struct sort_dimension *sd = &bstack_sort_dimensions[i]; |
| 1515 | |
| 1516 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1517 | continue; |
| 1518 | |
Namhyung Kim | 55369fc | 2013-04-01 20:35:20 +0900 | [diff] [blame] | 1519 | if (sort__mode != SORT_MODE__BRANCH) |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1520 | return -EINVAL; |
| 1521 | |
| 1522 | if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) |
| 1523 | sort__has_sym = 1; |
| 1524 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1525 | __sort_dimension__add(sd); |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1526 | return 0; |
| 1527 | } |
| 1528 | |
Namhyung Kim | afab87b | 2013-04-03 21:26:11 +0900 | [diff] [blame] | 1529 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) { |
| 1530 | struct sort_dimension *sd = &memory_sort_dimensions[i]; |
| 1531 | |
| 1532 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1533 | continue; |
| 1534 | |
| 1535 | if (sort__mode != SORT_MODE__MEMORY) |
| 1536 | return -EINVAL; |
| 1537 | |
| 1538 | if (sd->entry == &sort_mem_daddr_sym) |
| 1539 | sort__has_sym = 1; |
| 1540 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1541 | __sort_dimension__add(sd); |
Namhyung Kim | afab87b | 2013-04-03 21:26:11 +0900 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 1545 | return -ESRCH; |
| 1546 | } |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1547 | |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 1548 | static const char *get_default_sort_order(void) |
| 1549 | { |
| 1550 | const char *default_sort_orders[] = { |
| 1551 | default_sort_order, |
| 1552 | default_branch_sort_order, |
| 1553 | default_mem_sort_order, |
| 1554 | default_top_sort_order, |
| 1555 | default_diff_sort_order, |
| 1556 | }; |
| 1557 | |
| 1558 | BUG_ON(sort__mode >= ARRAY_SIZE(default_sort_orders)); |
| 1559 | |
| 1560 | return default_sort_orders[sort__mode]; |
| 1561 | } |
| 1562 | |
Jiri Olsa | 1a1c0ff | 2014-08-23 14:59:48 +0200 | [diff] [blame] | 1563 | static int setup_sort_order(void) |
| 1564 | { |
| 1565 | char *new_sort_order; |
| 1566 | |
| 1567 | /* |
| 1568 | * Append '+'-prefixed sort order to the default sort |
| 1569 | * order string. |
| 1570 | */ |
| 1571 | if (!sort_order || is_strict_order(sort_order)) |
| 1572 | return 0; |
| 1573 | |
| 1574 | if (sort_order[1] == '\0') { |
| 1575 | error("Invalid --sort key: `+'"); |
| 1576 | return -EINVAL; |
| 1577 | } |
| 1578 | |
| 1579 | /* |
| 1580 | * We allocate new sort_order string, but we never free it, |
| 1581 | * because it's checked over the rest of the code. |
| 1582 | */ |
| 1583 | if (asprintf(&new_sort_order, "%s,%s", |
| 1584 | get_default_sort_order(), sort_order + 1) < 0) { |
| 1585 | error("Not enough memory to set up --sort"); |
| 1586 | return -ENOMEM; |
| 1587 | } |
| 1588 | |
| 1589 | sort_order = new_sort_order; |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1593 | static int __setup_sorting(void) |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1594 | { |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 1595 | char *tmp, *tok, *str; |
Jiri Olsa | 1a1c0ff | 2014-08-23 14:59:48 +0200 | [diff] [blame] | 1596 | const char *sort_keys; |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1597 | int ret = 0; |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1598 | |
Jiri Olsa | 1a1c0ff | 2014-08-23 14:59:48 +0200 | [diff] [blame] | 1599 | ret = setup_sort_order(); |
| 1600 | if (ret) |
| 1601 | return ret; |
| 1602 | |
| 1603 | sort_keys = sort_order; |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1604 | if (sort_keys == NULL) { |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1605 | if (is_strict_order(field_order)) { |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1606 | /* |
| 1607 | * If user specified field order but no sort order, |
| 1608 | * we'll honor it and not add default sort orders. |
| 1609 | */ |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 1613 | sort_keys = get_default_sort_order(); |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1614 | } |
Namhyung Kim | 512ae1b | 2014-03-18 11:31:39 +0900 | [diff] [blame] | 1615 | |
| 1616 | str = strdup(sort_keys); |
Namhyung Kim | 5936f54 | 2013-02-06 14:57:17 +0900 | [diff] [blame] | 1617 | if (str == NULL) { |
| 1618 | error("Not enough memory to setup sort keys"); |
| 1619 | return -ENOMEM; |
| 1620 | } |
| 1621 | |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1622 | for (tok = strtok_r(str, ", ", &tmp); |
| 1623 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1624 | ret = sort_dimension__add(tok); |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1625 | if (ret == -EINVAL) { |
| 1626 | error("Invalid --sort key: `%s'", tok); |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1627 | break; |
Namhyung Kim | fc5871e | 2012-12-27 18:11:46 +0900 | [diff] [blame] | 1628 | } else if (ret == -ESRCH) { |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1629 | error("Unknown --sort key: `%s'", tok); |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1630 | break; |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | free(str); |
Namhyung Kim | 5530998 | 2013-02-06 14:57:16 +0900 | [diff] [blame] | 1635 | return ret; |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 1636 | } |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1637 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1638 | void perf_hpp__set_elide(int idx, bool elide) |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1639 | { |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1640 | struct perf_hpp_fmt *fmt; |
| 1641 | struct hpp_sort_entry *hse; |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1642 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1643 | perf_hpp__for_each_format(fmt) { |
| 1644 | if (!perf_hpp__is_sort_entry(fmt)) |
| 1645 | continue; |
| 1646 | |
| 1647 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1648 | if (hse->se->se_width_idx == idx) { |
| 1649 | fmt->elide = elide; |
| 1650 | break; |
| 1651 | } |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1652 | } |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1653 | } |
| 1654 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1655 | static bool __get_elide(struct strlist *list, const char *list_name, FILE *fp) |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1656 | { |
| 1657 | if (list && strlist__nr_entries(list) == 1) { |
| 1658 | if (fp != NULL) |
| 1659 | fprintf(fp, "# %s: %s\n", list_name, |
| 1660 | strlist__entry(list, 0)->s); |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1661 | return true; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1662 | } |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1663 | return false; |
| 1664 | } |
| 1665 | |
| 1666 | static bool get_elide(int idx, FILE *output) |
| 1667 | { |
| 1668 | switch (idx) { |
| 1669 | case HISTC_SYMBOL: |
| 1670 | return __get_elide(symbol_conf.sym_list, "symbol", output); |
| 1671 | case HISTC_DSO: |
| 1672 | return __get_elide(symbol_conf.dso_list, "dso", output); |
| 1673 | case HISTC_COMM: |
| 1674 | return __get_elide(symbol_conf.comm_list, "comm", output); |
| 1675 | default: |
| 1676 | break; |
| 1677 | } |
| 1678 | |
| 1679 | if (sort__mode != SORT_MODE__BRANCH) |
| 1680 | return false; |
| 1681 | |
| 1682 | switch (idx) { |
| 1683 | case HISTC_SYMBOL_FROM: |
| 1684 | return __get_elide(symbol_conf.sym_from_list, "sym_from", output); |
| 1685 | case HISTC_SYMBOL_TO: |
| 1686 | return __get_elide(symbol_conf.sym_to_list, "sym_to", output); |
| 1687 | case HISTC_DSO_FROM: |
| 1688 | return __get_elide(symbol_conf.dso_from_list, "dso_from", output); |
| 1689 | case HISTC_DSO_TO: |
| 1690 | return __get_elide(symbol_conf.dso_to_list, "dso_to", output); |
| 1691 | default: |
| 1692 | break; |
| 1693 | } |
| 1694 | |
| 1695 | return false; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1696 | } |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 1697 | |
| 1698 | void sort__setup_elide(FILE *output) |
| 1699 | { |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1700 | struct perf_hpp_fmt *fmt; |
| 1701 | struct hpp_sort_entry *hse; |
Namhyung Kim | 7524f63 | 2013-11-08 17:53:42 +0900 | [diff] [blame] | 1702 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1703 | perf_hpp__for_each_format(fmt) { |
| 1704 | if (!perf_hpp__is_sort_entry(fmt)) |
| 1705 | continue; |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 1706 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1707 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
| 1708 | fmt->elide = get_elide(hse->se->se_width_idx, output); |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 1709 | } |
| 1710 | |
Namhyung Kim | 7524f63 | 2013-11-08 17:53:42 +0900 | [diff] [blame] | 1711 | /* |
| 1712 | * It makes no sense to elide all of sort entries. |
| 1713 | * Just revert them to show up again. |
| 1714 | */ |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1715 | perf_hpp__for_each_format(fmt) { |
| 1716 | if (!perf_hpp__is_sort_entry(fmt)) |
| 1717 | continue; |
| 1718 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1719 | if (!fmt->elide) |
Namhyung Kim | 7524f63 | 2013-11-08 17:53:42 +0900 | [diff] [blame] | 1720 | return; |
| 1721 | } |
| 1722 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1723 | perf_hpp__for_each_format(fmt) { |
| 1724 | if (!perf_hpp__is_sort_entry(fmt)) |
| 1725 | continue; |
| 1726 | |
Jiri Olsa | f299842 | 2014-05-23 17:15:47 +0200 | [diff] [blame] | 1727 | fmt->elide = false; |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 1728 | } |
Namhyung Kim | 08e7154 | 2013-04-03 21:26:19 +0900 | [diff] [blame] | 1729 | } |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1730 | |
| 1731 | static int output_field_add(char *tok) |
| 1732 | { |
| 1733 | unsigned int i; |
| 1734 | |
| 1735 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) { |
| 1736 | struct sort_dimension *sd = &common_sort_dimensions[i]; |
| 1737 | |
| 1738 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1739 | continue; |
| 1740 | |
| 1741 | return __sort_dimension__add_output(sd); |
| 1742 | } |
| 1743 | |
| 1744 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) { |
| 1745 | struct hpp_dimension *hd = &hpp_sort_dimensions[i]; |
| 1746 | |
| 1747 | if (strncasecmp(tok, hd->name, strlen(tok))) |
| 1748 | continue; |
| 1749 | |
| 1750 | return __hpp_dimension__add_output(hd); |
| 1751 | } |
| 1752 | |
| 1753 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) { |
| 1754 | struct sort_dimension *sd = &bstack_sort_dimensions[i]; |
| 1755 | |
| 1756 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1757 | continue; |
| 1758 | |
| 1759 | return __sort_dimension__add_output(sd); |
| 1760 | } |
| 1761 | |
| 1762 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) { |
| 1763 | struct sort_dimension *sd = &memory_sort_dimensions[i]; |
| 1764 | |
| 1765 | if (strncasecmp(tok, sd->name, strlen(tok))) |
| 1766 | continue; |
| 1767 | |
| 1768 | return __sort_dimension__add_output(sd); |
| 1769 | } |
| 1770 | |
| 1771 | return -ESRCH; |
| 1772 | } |
| 1773 | |
| 1774 | static void reset_dimensions(void) |
| 1775 | { |
| 1776 | unsigned int i; |
| 1777 | |
| 1778 | for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) |
| 1779 | common_sort_dimensions[i].taken = 0; |
| 1780 | |
| 1781 | for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) |
| 1782 | hpp_sort_dimensions[i].taken = 0; |
| 1783 | |
| 1784 | for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) |
| 1785 | bstack_sort_dimensions[i].taken = 0; |
| 1786 | |
| 1787 | for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) |
| 1788 | memory_sort_dimensions[i].taken = 0; |
| 1789 | } |
| 1790 | |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1791 | bool is_strict_order(const char *order) |
| 1792 | { |
| 1793 | return order && (*order != '+'); |
| 1794 | } |
| 1795 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1796 | static int __setup_output_field(void) |
| 1797 | { |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1798 | char *tmp, *tok, *str, *strp; |
| 1799 | int ret = -EINVAL; |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1800 | |
| 1801 | if (field_order == NULL) |
| 1802 | return 0; |
| 1803 | |
| 1804 | reset_dimensions(); |
| 1805 | |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1806 | strp = str = strdup(field_order); |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1807 | if (str == NULL) { |
| 1808 | error("Not enough memory to setup output fields"); |
| 1809 | return -ENOMEM; |
| 1810 | } |
| 1811 | |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1812 | if (!is_strict_order(field_order)) |
| 1813 | strp++; |
| 1814 | |
| 1815 | if (!strlen(strp)) { |
| 1816 | error("Invalid --fields key: `+'"); |
| 1817 | goto out; |
| 1818 | } |
| 1819 | |
| 1820 | for (tok = strtok_r(strp, ", ", &tmp); |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1821 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 1822 | ret = output_field_add(tok); |
| 1823 | if (ret == -EINVAL) { |
| 1824 | error("Invalid --fields key: `%s'", tok); |
| 1825 | break; |
| 1826 | } else if (ret == -ESRCH) { |
| 1827 | error("Unknown --fields key: `%s'", tok); |
| 1828 | break; |
| 1829 | } |
| 1830 | } |
| 1831 | |
Jiri Olsa | 2f3f9bc | 2014-08-22 15:58:38 +0200 | [diff] [blame] | 1832 | out: |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 1833 | free(str); |
| 1834 | return ret; |
| 1835 | } |
| 1836 | |
| 1837 | int setup_sorting(void) |
| 1838 | { |
| 1839 | int err; |
| 1840 | |
| 1841 | err = __setup_sorting(); |
| 1842 | if (err < 0) |
| 1843 | return err; |
| 1844 | |
| 1845 | if (parent_pattern != default_parent_pattern) { |
| 1846 | err = sort_dimension__add("parent"); |
| 1847 | if (err < 0) |
| 1848 | return err; |
| 1849 | } |
| 1850 | |
| 1851 | reset_dimensions(); |
| 1852 | |
| 1853 | /* |
| 1854 | * perf diff doesn't use default hpp output fields. |
| 1855 | */ |
| 1856 | if (sort__mode != SORT_MODE__DIFF) |
| 1857 | perf_hpp__init(); |
| 1858 | |
| 1859 | err = __setup_output_field(); |
| 1860 | if (err < 0) |
| 1861 | return err; |
| 1862 | |
| 1863 | /* copy sort keys to output fields */ |
| 1864 | perf_hpp__setup_output_field(); |
| 1865 | /* and then copy output fields to sort keys */ |
| 1866 | perf_hpp__append_sort_keys(); |
| 1867 | |
| 1868 | return 0; |
| 1869 | } |
Namhyung Kim | 1c89fe9 | 2014-05-07 18:42:24 +0900 | [diff] [blame] | 1870 | |
| 1871 | void reset_output_field(void) |
| 1872 | { |
| 1873 | sort__need_collapse = 0; |
| 1874 | sort__has_parent = 0; |
| 1875 | sort__has_sym = 0; |
| 1876 | sort__has_dso = 0; |
| 1877 | |
Namhyung Kim | d69b296 | 2014-05-23 10:59:01 +0900 | [diff] [blame] | 1878 | field_order = NULL; |
| 1879 | sort_order = NULL; |
| 1880 | |
Namhyung Kim | 1c89fe9 | 2014-05-07 18:42:24 +0900 | [diff] [blame] | 1881 | reset_dimensions(); |
| 1882 | perf_hpp__reset_output_field(); |
| 1883 | } |