Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 1 | #include <math.h> |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 2 | #include <linux/compiler.h> |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 3 | |
| 4 | #include "../util/hist.h" |
| 5 | #include "../util/util.h" |
| 6 | #include "../util/sort.h" |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 7 | #include "../util/evsel.h" |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 8 | |
| 9 | /* hist period print (hpp) functions */ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 10 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 11 | #define hpp__call_print_fn(hpp, fn, fmt, ...) \ |
| 12 | ({ \ |
| 13 | int __ret = fn(hpp, fmt, ##__VA_ARGS__); \ |
| 14 | advance_hpp(hpp, __ret); \ |
| 15 | __ret; \ |
| 16 | }) |
| 17 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 18 | static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
| 19 | hpp_field_fn get_field, const char *fmt, int len, |
| 20 | hpp_snprint_fn print_fn, bool fmt_percent) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 21 | { |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 22 | int ret; |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 23 | struct hists *hists = he->hists; |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 24 | struct perf_evsel *evsel = hists_to_evsel(hists); |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 25 | char *buf = hpp->buf; |
| 26 | size_t size = hpp->size; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 27 | |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 28 | if (fmt_percent) { |
| 29 | double percent = 0.0; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 30 | u64 total = hists__total_period(hists); |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 31 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 32 | if (total) |
| 33 | percent = 100.0 * get_field(he) / total; |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 34 | |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 35 | ret = hpp__call_print_fn(hpp, print_fn, fmt, len, percent); |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 36 | } else |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 37 | ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he)); |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 38 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 39 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 40 | int prev_idx, idx_delta; |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 41 | struct hist_entry *pair; |
| 42 | int nr_members = evsel->nr_members; |
| 43 | |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 44 | prev_idx = perf_evsel__group_idx(evsel); |
| 45 | |
| 46 | list_for_each_entry(pair, &he->pairs.head, pairs.node) { |
| 47 | u64 period = get_field(pair); |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 48 | u64 total = hists__total_period(pair->hists); |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 49 | |
| 50 | if (!total) |
| 51 | continue; |
| 52 | |
| 53 | evsel = hists_to_evsel(pair->hists); |
| 54 | idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; |
| 55 | |
| 56 | while (idx_delta--) { |
| 57 | /* |
| 58 | * zero-fill group members in the middle which |
| 59 | * have no sample |
| 60 | */ |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 61 | if (fmt_percent) { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 62 | ret += hpp__call_print_fn(hpp, print_fn, |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 63 | fmt, len, 0.0); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 64 | } else { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 65 | ret += hpp__call_print_fn(hpp, print_fn, |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 66 | fmt, len, 0ULL); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 67 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 68 | } |
| 69 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 70 | if (fmt_percent) { |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 71 | ret += hpp__call_print_fn(hpp, print_fn, fmt, len, |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 72 | 100.0 * period / total); |
| 73 | } else { |
| 74 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 75 | len, period); |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 76 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 77 | |
| 78 | prev_idx = perf_evsel__group_idx(evsel); |
| 79 | } |
| 80 | |
| 81 | idx_delta = nr_members - prev_idx - 1; |
| 82 | |
| 83 | while (idx_delta--) { |
| 84 | /* |
| 85 | * zero-fill group members at last which have no sample |
| 86 | */ |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 87 | if (fmt_percent) { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 88 | ret += hpp__call_print_fn(hpp, print_fn, |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 89 | fmt, len, 0.0); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 90 | } else { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 91 | ret += hpp__call_print_fn(hpp, print_fn, |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 92 | fmt, len, 0ULL); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 93 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 94 | } |
| 95 | } |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * Restore original buf and size as it's where caller expects |
| 99 | * the result will be saved. |
| 100 | */ |
| 101 | hpp->buf = buf; |
| 102 | hpp->size = size; |
| 103 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 104 | return ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 105 | } |
| 106 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 107 | int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 108 | struct hist_entry *he, hpp_field_fn get_field, |
| 109 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent) |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 110 | { |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 111 | int len = fmt->user_len ?: fmt->len; |
| 112 | |
| 113 | if (symbol_conf.field_sep) { |
| 114 | return __hpp__fmt(hpp, he, get_field, fmtstr, 1, |
| 115 | print_fn, fmt_percent); |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 116 | } |
| 117 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 118 | if (fmt_percent) |
| 119 | len -= 2; /* 2 for a space and a % sign */ |
| 120 | else |
| 121 | len -= 1; |
| 122 | |
| 123 | return __hpp__fmt(hpp, he, get_field, fmtstr, len, print_fn, fmt_percent); |
| 124 | } |
| 125 | |
| 126 | int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 127 | struct hist_entry *he, hpp_field_fn get_field, |
| 128 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent) |
| 129 | { |
| 130 | if (!symbol_conf.cumulate_callchain) { |
| 131 | int len = fmt->user_len ?: fmt->len; |
| 132 | return snprintf(hpp->buf, hpp->size, " %*s", len - 1, "N/A"); |
| 133 | } |
| 134 | |
| 135 | return hpp__fmt(fmt, hpp, he, get_field, fmtstr, print_fn, fmt_percent); |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 136 | } |
| 137 | |
Namhyung Kim | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 138 | static int field_cmp(u64 field_a, u64 field_b) |
| 139 | { |
| 140 | if (field_a > field_b) |
| 141 | return 1; |
| 142 | if (field_a < field_b) |
| 143 | return -1; |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int __hpp__sort(struct hist_entry *a, struct hist_entry *b, |
| 148 | hpp_field_fn get_field) |
| 149 | { |
| 150 | s64 ret; |
| 151 | int i, nr_members; |
| 152 | struct perf_evsel *evsel; |
| 153 | struct hist_entry *pair; |
| 154 | u64 *fields_a, *fields_b; |
| 155 | |
| 156 | ret = field_cmp(get_field(a), get_field(b)); |
| 157 | if (ret || !symbol_conf.event_group) |
| 158 | return ret; |
| 159 | |
| 160 | evsel = hists_to_evsel(a->hists); |
| 161 | if (!perf_evsel__is_group_event(evsel)) |
| 162 | return ret; |
| 163 | |
| 164 | nr_members = evsel->nr_members; |
| 165 | fields_a = calloc(sizeof(*fields_a), nr_members); |
| 166 | fields_b = calloc(sizeof(*fields_b), nr_members); |
| 167 | |
| 168 | if (!fields_a || !fields_b) |
| 169 | goto out; |
| 170 | |
| 171 | list_for_each_entry(pair, &a->pairs.head, pairs.node) { |
| 172 | evsel = hists_to_evsel(pair->hists); |
| 173 | fields_a[perf_evsel__group_idx(evsel)] = get_field(pair); |
| 174 | } |
| 175 | |
| 176 | list_for_each_entry(pair, &b->pairs.head, pairs.node) { |
| 177 | evsel = hists_to_evsel(pair->hists); |
| 178 | fields_b[perf_evsel__group_idx(evsel)] = get_field(pair); |
| 179 | } |
| 180 | |
| 181 | for (i = 1; i < nr_members; i++) { |
| 182 | ret = field_cmp(fields_a[i], fields_b[i]); |
| 183 | if (ret) |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | out: |
| 188 | free(fields_a); |
| 189 | free(fields_b); |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 194 | static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b, |
| 195 | hpp_field_fn get_field) |
| 196 | { |
| 197 | s64 ret = 0; |
| 198 | |
| 199 | if (symbol_conf.cumulate_callchain) { |
| 200 | /* |
| 201 | * Put caller above callee when they have equal period. |
| 202 | */ |
| 203 | ret = field_cmp(get_field(a), get_field(b)); |
| 204 | if (ret) |
| 205 | return ret; |
| 206 | |
| 207 | ret = b->callchain->max_depth - a->callchain->max_depth; |
| 208 | } |
| 209 | return ret; |
| 210 | } |
| 211 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 212 | #define __HPP_WIDTH_FN(_type, _str) \ |
| 213 | static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 214 | struct perf_hpp *hpp __maybe_unused, \ |
| 215 | struct perf_evsel *evsel) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 216 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 217 | int len = fmt->user_len ?: fmt->len; \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 218 | \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 219 | if (symbol_conf.event_group) \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 220 | len = max(len, evsel->nr_members * fmt->len); \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 221 | \ |
| 222 | if (len < (int)strlen(_str)) \ |
| 223 | len = strlen(_str); \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 224 | \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 225 | return len; \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 226 | } |
| 227 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 228 | #define __HPP_HEADER_FN(_type, _str) \ |
| 229 | static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \ |
| 230 | struct perf_hpp *hpp, \ |
| 231 | struct perf_evsel *evsel) \ |
| 232 | { \ |
| 233 | int len = hpp__width_##_type(fmt, hpp, evsel); \ |
| 234 | return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \ |
| 235 | } |
| 236 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 237 | static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 238 | { |
| 239 | va_list args; |
| 240 | ssize_t ssize = hpp->size; |
| 241 | double percent; |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 242 | int ret, len; |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 243 | |
| 244 | va_start(args, fmt); |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 245 | len = va_arg(args, int); |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 246 | percent = va_arg(args, double); |
Namhyung Kim | d675107 | 2014-07-31 14:47:36 +0900 | [diff] [blame] | 247 | ret = percent_color_len_snprintf(hpp->buf, hpp->size, fmt, len, percent); |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 248 | va_end(args); |
| 249 | |
| 250 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 251 | } |
| 252 | |
| 253 | static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 254 | { |
| 255 | va_list args; |
| 256 | ssize_t ssize = hpp->size; |
| 257 | int ret; |
| 258 | |
| 259 | va_start(args, fmt); |
| 260 | ret = vsnprintf(hpp->buf, hpp->size, fmt, args); |
| 261 | va_end(args); |
| 262 | |
| 263 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 264 | } |
| 265 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 266 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 267 | static u64 he_get_##_field(struct hist_entry *he) \ |
| 268 | { \ |
| 269 | return he->stat._field; \ |
| 270 | } \ |
| 271 | \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 272 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 273 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 274 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 275 | return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
| 276 | hpp_color_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 279 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 280 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 281 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 282 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 283 | return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
| 284 | hpp_entry_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 285 | } |
| 286 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 287 | #define __HPP_SORT_FN(_type, _field) \ |
| 288 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 289 | { \ |
Namhyung Kim | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 290 | return __hpp__sort(a, b, he_get_##_field); \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 291 | } |
| 292 | |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 293 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
| 294 | static u64 he_get_acc_##_field(struct hist_entry *he) \ |
| 295 | { \ |
| 296 | return he->stat_acc->_field; \ |
| 297 | } \ |
| 298 | \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 299 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 300 | struct perf_hpp *hpp, struct hist_entry *he) \ |
| 301 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 302 | return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \ |
| 303 | hpp_color_scnprintf, true); \ |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | #define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 307 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 308 | struct perf_hpp *hpp, struct hist_entry *he) \ |
| 309 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 310 | return hpp__fmt_acc(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
| 311 | hpp_entry_scnprintf, true); \ |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | #define __HPP_SORT_ACC_FN(_type, _field) \ |
| 315 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 316 | { \ |
| 317 | return __hpp__sort_acc(a, b, he_get_acc_##_field); \ |
| 318 | } |
| 319 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 320 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 321 | static u64 he_get_raw_##_field(struct hist_entry *he) \ |
| 322 | { \ |
| 323 | return he->stat._field; \ |
| 324 | } \ |
| 325 | \ |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 326 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 327 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 328 | { \ |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 329 | return hpp__fmt(fmt, hpp, he, he_get_raw_##_field, " %*"PRIu64, \ |
| 330 | hpp_entry_scnprintf, false); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 331 | } |
| 332 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 333 | #define __HPP_SORT_RAW_FN(_type, _field) \ |
| 334 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 335 | { \ |
Namhyung Kim | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 336 | return __hpp__sort(a, b, he_get_raw_##_field); \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 340 | #define HPP_PERCENT_FNS(_type, _str, _field) \ |
| 341 | __HPP_WIDTH_FN(_type, _str) \ |
| 342 | __HPP_HEADER_FN(_type, _str) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 343 | __HPP_COLOR_PERCENT_FN(_type, _field) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 344 | __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
| 345 | __HPP_SORT_FN(_type, _field) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 346 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 347 | #define HPP_PERCENT_ACC_FNS(_type, _str, _field) \ |
| 348 | __HPP_WIDTH_FN(_type, _str) \ |
| 349 | __HPP_HEADER_FN(_type, _str) \ |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 350 | __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
| 351 | __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ |
| 352 | __HPP_SORT_ACC_FN(_type, _field) |
| 353 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 354 | #define HPP_RAW_FNS(_type, _str, _field) \ |
| 355 | __HPP_WIDTH_FN(_type, _str) \ |
| 356 | __HPP_HEADER_FN(_type, _str) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 357 | __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 358 | __HPP_SORT_RAW_FN(_type, _field) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 359 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 360 | __HPP_WIDTH_FN(overhead_self, "Self") |
| 361 | __HPP_HEADER_FN(overhead_self, "Self") |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 362 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 363 | HPP_PERCENT_FNS(overhead, "Overhead", period) |
| 364 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys) |
| 365 | HPP_PERCENT_FNS(overhead_us, "usr", period_us) |
| 366 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys) |
| 367 | HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us) |
| 368 | HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period) |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 369 | |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 370 | HPP_RAW_FNS(samples, "Samples", nr_events) |
| 371 | HPP_RAW_FNS(period, "Period", period) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 372 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 373 | static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, |
| 374 | struct hist_entry *b __maybe_unused) |
| 375 | { |
| 376 | return 0; |
| 377 | } |
| 378 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 379 | #define HPP__COLOR_PRINT_FNS(_name) \ |
| 380 | { \ |
| 381 | .header = hpp__header_ ## _name, \ |
| 382 | .width = hpp__width_ ## _name, \ |
| 383 | .color = hpp__color_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 384 | .entry = hpp__entry_ ## _name, \ |
| 385 | .cmp = hpp__nop_cmp, \ |
| 386 | .collapse = hpp__nop_cmp, \ |
| 387 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 388 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 389 | |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 390 | #define HPP__COLOR_ACC_PRINT_FNS(_name) \ |
| 391 | { \ |
| 392 | .header = hpp__header_ ## _name, \ |
| 393 | .width = hpp__width_ ## _name, \ |
| 394 | .color = hpp__color_ ## _name, \ |
| 395 | .entry = hpp__entry_ ## _name, \ |
| 396 | .cmp = hpp__nop_cmp, \ |
| 397 | .collapse = hpp__nop_cmp, \ |
| 398 | .sort = hpp__sort_ ## _name, \ |
| 399 | } |
| 400 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 401 | #define HPP__PRINT_FNS(_name) \ |
| 402 | { \ |
| 403 | .header = hpp__header_ ## _name, \ |
| 404 | .width = hpp__width_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 405 | .entry = hpp__entry_ ## _name, \ |
| 406 | .cmp = hpp__nop_cmp, \ |
| 407 | .collapse = hpp__nop_cmp, \ |
| 408 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 409 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 410 | |
| 411 | struct perf_hpp_fmt perf_hpp__format[] = { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 412 | HPP__COLOR_PRINT_FNS(overhead), |
| 413 | HPP__COLOR_PRINT_FNS(overhead_sys), |
| 414 | HPP__COLOR_PRINT_FNS(overhead_us), |
| 415 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), |
| 416 | HPP__COLOR_PRINT_FNS(overhead_guest_us), |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 417 | HPP__COLOR_ACC_PRINT_FNS(overhead_acc), |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 418 | HPP__PRINT_FNS(samples), |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 419 | HPP__PRINT_FNS(period) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 420 | }; |
| 421 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 422 | LIST_HEAD(perf_hpp__list); |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 423 | LIST_HEAD(perf_hpp__sort_list); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 424 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 425 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 426 | #undef HPP__COLOR_PRINT_FNS |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 427 | #undef HPP__COLOR_ACC_PRINT_FNS |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 428 | #undef HPP__PRINT_FNS |
| 429 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 430 | #undef HPP_PERCENT_FNS |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 431 | #undef HPP_PERCENT_ACC_FNS |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 432 | #undef HPP_RAW_FNS |
| 433 | |
| 434 | #undef __HPP_HEADER_FN |
| 435 | #undef __HPP_WIDTH_FN |
| 436 | #undef __HPP_COLOR_PERCENT_FN |
| 437 | #undef __HPP_ENTRY_PERCENT_FN |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 438 | #undef __HPP_COLOR_ACC_PERCENT_FN |
| 439 | #undef __HPP_ENTRY_ACC_PERCENT_FN |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 440 | #undef __HPP_ENTRY_RAW_FN |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 441 | #undef __HPP_SORT_FN |
| 442 | #undef __HPP_SORT_ACC_FN |
| 443 | #undef __HPP_SORT_RAW_FN |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 444 | |
| 445 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 446 | void perf_hpp__init(void) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 447 | { |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 448 | struct list_head *list; |
| 449 | int i; |
| 450 | |
| 451 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 452 | struct perf_hpp_fmt *fmt = &perf_hpp__format[i]; |
| 453 | |
| 454 | INIT_LIST_HEAD(&fmt->list); |
| 455 | |
| 456 | /* sort_list may be linked by setup_sorting() */ |
| 457 | if (fmt->sort_list.next == NULL) |
| 458 | INIT_LIST_HEAD(&fmt->sort_list); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 459 | } |
| 460 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 461 | /* |
| 462 | * If user specified field order, no need to setup default fields. |
| 463 | */ |
| 464 | if (field_order) |
| 465 | return; |
| 466 | |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 467 | if (symbol_conf.cumulate_callchain) { |
| 468 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC); |
| 469 | |
| 470 | perf_hpp__format[PERF_HPP__OVERHEAD].header = |
| 471 | hpp__header_overhead_self; |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 472 | perf_hpp__format[PERF_HPP__OVERHEAD].width = |
| 473 | hpp__width_overhead_self; |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 474 | } |
| 475 | |
Jiri Olsa | 2b8bfa6 | 2013-01-31 23:34:25 +0100 | [diff] [blame] | 476 | perf_hpp__column_enable(PERF_HPP__OVERHEAD); |
| 477 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 478 | if (symbol_conf.show_cpu_utilization) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 479 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS); |
| 480 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 481 | |
| 482 | if (perf_guest) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 483 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS); |
| 484 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | if (symbol_conf.show_nr_samples) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 489 | perf_hpp__column_enable(PERF_HPP__SAMPLES); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 490 | |
| 491 | if (symbol_conf.show_total_period) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 492 | perf_hpp__column_enable(PERF_HPP__PERIOD); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 493 | |
| 494 | /* prepend overhead field for backward compatiblity. */ |
| 495 | list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list; |
| 496 | if (list_empty(list)) |
| 497 | list_add(list, &perf_hpp__sort_list); |
Namhyung Kim | 594dcbf | 2013-10-30 16:06:59 +0900 | [diff] [blame] | 498 | |
| 499 | if (symbol_conf.cumulate_callchain) { |
| 500 | list = &perf_hpp__format[PERF_HPP__OVERHEAD_ACC].sort_list; |
| 501 | if (list_empty(list)) |
| 502 | list_add(list, &perf_hpp__sort_list); |
| 503 | } |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 504 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 505 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 506 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| 507 | { |
| 508 | list_add_tail(&format->list, &perf_hpp__list); |
| 509 | } |
| 510 | |
Namhyung Kim | 77284de | 2013-12-16 16:55:13 +0900 | [diff] [blame] | 511 | void perf_hpp__column_unregister(struct perf_hpp_fmt *format) |
| 512 | { |
| 513 | list_del(&format->list); |
| 514 | } |
| 515 | |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 516 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) |
| 517 | { |
| 518 | list_add_tail(&format->sort_list, &perf_hpp__sort_list); |
| 519 | } |
| 520 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 521 | void perf_hpp__column_enable(unsigned col) |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 522 | { |
| 523 | BUG_ON(col >= PERF_HPP__MAX_INDEX); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 524 | perf_hpp__column_register(&perf_hpp__format[col]); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 525 | } |
| 526 | |
Namhyung Kim | 77284de | 2013-12-16 16:55:13 +0900 | [diff] [blame] | 527 | void perf_hpp__column_disable(unsigned col) |
| 528 | { |
| 529 | BUG_ON(col >= PERF_HPP__MAX_INDEX); |
| 530 | perf_hpp__column_unregister(&perf_hpp__format[col]); |
| 531 | } |
| 532 | |
| 533 | void perf_hpp__cancel_cumulate(void) |
| 534 | { |
Namhyung Kim | 2bf1a12 | 2014-03-20 09:10:29 +0900 | [diff] [blame] | 535 | if (field_order) |
| 536 | return; |
| 537 | |
Namhyung Kim | 77284de | 2013-12-16 16:55:13 +0900 | [diff] [blame] | 538 | perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC); |
| 539 | perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead; |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 540 | perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead; |
Namhyung Kim | 77284de | 2013-12-16 16:55:13 +0900 | [diff] [blame] | 541 | } |
| 542 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 543 | void perf_hpp__setup_output_field(void) |
| 544 | { |
| 545 | struct perf_hpp_fmt *fmt; |
| 546 | |
| 547 | /* append sort keys to output field */ |
| 548 | perf_hpp__for_each_sort_list(fmt) { |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 549 | if (!list_empty(&fmt->list)) |
| 550 | continue; |
| 551 | |
| 552 | /* |
| 553 | * sort entry fields are dynamically created, |
| 554 | * so they can share a same sort key even though |
| 555 | * the list is empty. |
| 556 | */ |
| 557 | if (perf_hpp__is_sort_entry(fmt)) { |
| 558 | struct perf_hpp_fmt *pos; |
| 559 | |
| 560 | perf_hpp__for_each_format(pos) { |
| 561 | if (perf_hpp__same_sort_entry(pos, fmt)) |
| 562 | goto next; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | perf_hpp__column_register(fmt); |
| 567 | next: |
| 568 | continue; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | void perf_hpp__append_sort_keys(void) |
| 573 | { |
| 574 | struct perf_hpp_fmt *fmt; |
| 575 | |
| 576 | /* append output fields to sort keys */ |
| 577 | perf_hpp__for_each_format(fmt) { |
| 578 | if (!list_empty(&fmt->sort_list)) |
| 579 | continue; |
| 580 | |
| 581 | /* |
| 582 | * sort entry fields are dynamically created, |
| 583 | * so they can share a same sort key even though |
| 584 | * the list is empty. |
| 585 | */ |
| 586 | if (perf_hpp__is_sort_entry(fmt)) { |
| 587 | struct perf_hpp_fmt *pos; |
| 588 | |
| 589 | perf_hpp__for_each_sort_list(pos) { |
| 590 | if (perf_hpp__same_sort_entry(pos, fmt)) |
| 591 | goto next; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | perf_hpp__register_sort_field(fmt); |
| 596 | next: |
| 597 | continue; |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
Namhyung Kim | 1c89fe9 | 2014-05-07 18:42:24 +0900 | [diff] [blame] | 601 | void perf_hpp__reset_output_field(void) |
| 602 | { |
| 603 | struct perf_hpp_fmt *fmt, *tmp; |
| 604 | |
| 605 | /* reset output fields */ |
| 606 | perf_hpp__for_each_format_safe(fmt, tmp) { |
| 607 | list_del_init(&fmt->list); |
| 608 | list_del_init(&fmt->sort_list); |
| 609 | } |
| 610 | |
| 611 | /* reset sort keys */ |
| 612 | perf_hpp__for_each_sort_list_safe(fmt, tmp) { |
| 613 | list_del_init(&fmt->list); |
| 614 | list_del_init(&fmt->sort_list); |
| 615 | } |
| 616 | } |
| 617 | |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 618 | /* |
| 619 | * See hists__fprintf to match the column widths |
| 620 | */ |
| 621 | unsigned int hists__sort_list_width(struct hists *hists) |
| 622 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 623 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 624 | int ret = 0; |
| 625 | bool first = true; |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 626 | struct perf_hpp dummy_hpp; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 627 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 628 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 629 | if (perf_hpp__should_skip(fmt)) |
| 630 | continue; |
| 631 | |
| 632 | if (first) |
| 633 | first = false; |
| 634 | else |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 635 | ret += 2; |
| 636 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 637 | ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 638 | } |
| 639 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 640 | if (verbose && sort__has_sym) /* Addr + origin */ |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 641 | ret += 3 + BITS_PER_LONG / 4; |
| 642 | |
| 643 | return ret; |
| 644 | } |
Namhyung Kim | e0d66c7 | 2014-07-31 14:47:37 +0900 | [diff] [blame] | 645 | |
| 646 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists) |
| 647 | { |
| 648 | int idx; |
| 649 | |
| 650 | if (perf_hpp__is_sort_entry(fmt)) |
| 651 | return perf_hpp__reset_sort_width(fmt, hists); |
| 652 | |
| 653 | for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { |
| 654 | if (fmt == &perf_hpp__format[idx]) |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | if (idx == PERF_HPP__MAX_INDEX) |
| 659 | return; |
| 660 | |
| 661 | switch (idx) { |
| 662 | case PERF_HPP__OVERHEAD: |
| 663 | case PERF_HPP__OVERHEAD_SYS: |
| 664 | case PERF_HPP__OVERHEAD_US: |
| 665 | case PERF_HPP__OVERHEAD_ACC: |
| 666 | fmt->len = 8; |
| 667 | break; |
| 668 | |
| 669 | case PERF_HPP__OVERHEAD_GUEST_SYS: |
| 670 | case PERF_HPP__OVERHEAD_GUEST_US: |
| 671 | fmt->len = 9; |
| 672 | break; |
| 673 | |
| 674 | case PERF_HPP__SAMPLES: |
| 675 | case PERF_HPP__PERIOD: |
| 676 | fmt->len = 12; |
| 677 | break; |
| 678 | |
| 679 | default: |
| 680 | break; |
| 681 | } |
| 682 | } |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 683 | |
| 684 | void perf_hpp__set_user_width(const char *width_list_str) |
| 685 | { |
| 686 | struct perf_hpp_fmt *fmt; |
| 687 | const char *ptr = width_list_str; |
| 688 | |
| 689 | perf_hpp__for_each_format(fmt) { |
| 690 | char *p; |
| 691 | |
| 692 | int len = strtol(ptr, &p, 10); |
| 693 | fmt->user_len = len; |
| 694 | |
| 695 | if (*p == ',') |
| 696 | ptr = p + 1; |
| 697 | else |
| 698 | break; |
| 699 | } |
| 700 | } |