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 | 4a62109 | 2014-03-03 10:14:03 +0900 | [diff] [blame] | 18 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 19 | hpp_field_fn get_field, const char *fmt, |
| 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 | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 35 | ret = hpp__call_print_fn(hpp, print_fn, fmt, percent); |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 36 | } else |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 37 | ret = hpp__call_print_fn(hpp, print_fn, fmt, 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, |
| 63 | fmt, 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, |
| 66 | fmt, 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) { |
| 71 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
| 72 | 100.0 * period / total); |
| 73 | } else { |
| 74 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
| 75 | period); |
| 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, |
| 89 | fmt, 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, |
| 92 | fmt, 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 | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 107 | static int field_cmp(u64 field_a, u64 field_b) |
| 108 | { |
| 109 | if (field_a > field_b) |
| 110 | return 1; |
| 111 | if (field_a < field_b) |
| 112 | return -1; |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static int __hpp__sort(struct hist_entry *a, struct hist_entry *b, |
| 117 | hpp_field_fn get_field) |
| 118 | { |
| 119 | s64 ret; |
| 120 | int i, nr_members; |
| 121 | struct perf_evsel *evsel; |
| 122 | struct hist_entry *pair; |
| 123 | u64 *fields_a, *fields_b; |
| 124 | |
| 125 | ret = field_cmp(get_field(a), get_field(b)); |
| 126 | if (ret || !symbol_conf.event_group) |
| 127 | return ret; |
| 128 | |
| 129 | evsel = hists_to_evsel(a->hists); |
| 130 | if (!perf_evsel__is_group_event(evsel)) |
| 131 | return ret; |
| 132 | |
| 133 | nr_members = evsel->nr_members; |
| 134 | fields_a = calloc(sizeof(*fields_a), nr_members); |
| 135 | fields_b = calloc(sizeof(*fields_b), nr_members); |
| 136 | |
| 137 | if (!fields_a || !fields_b) |
| 138 | goto out; |
| 139 | |
| 140 | list_for_each_entry(pair, &a->pairs.head, pairs.node) { |
| 141 | evsel = hists_to_evsel(pair->hists); |
| 142 | fields_a[perf_evsel__group_idx(evsel)] = get_field(pair); |
| 143 | } |
| 144 | |
| 145 | list_for_each_entry(pair, &b->pairs.head, pairs.node) { |
| 146 | evsel = hists_to_evsel(pair->hists); |
| 147 | fields_b[perf_evsel__group_idx(evsel)] = get_field(pair); |
| 148 | } |
| 149 | |
| 150 | for (i = 1; i < nr_members; i++) { |
| 151 | ret = field_cmp(fields_a[i], fields_b[i]); |
| 152 | if (ret) |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | out: |
| 157 | free(fields_a); |
| 158 | free(fields_b); |
| 159 | |
| 160 | return ret; |
| 161 | } |
| 162 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 163 | #define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 164 | static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 165 | struct perf_hpp *hpp, \ |
| 166 | struct perf_evsel *evsel) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 167 | { \ |
| 168 | int len = _min_width; \ |
| 169 | \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 170 | if (symbol_conf.event_group) \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 171 | len = max(len, evsel->nr_members * _unit_width); \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 172 | \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 173 | return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 176 | #define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 177 | static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 178 | struct perf_hpp *hpp __maybe_unused, \ |
| 179 | struct perf_evsel *evsel) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 180 | { \ |
| 181 | int len = _min_width; \ |
| 182 | \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 183 | if (symbol_conf.event_group) \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 184 | len = max(len, evsel->nr_members * _unit_width); \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 185 | \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 186 | return len; \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 187 | } |
| 188 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 189 | static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 190 | { |
| 191 | va_list args; |
| 192 | ssize_t ssize = hpp->size; |
| 193 | double percent; |
| 194 | int ret; |
| 195 | |
| 196 | va_start(args, fmt); |
| 197 | percent = va_arg(args, double); |
| 198 | ret = value_color_snprintf(hpp->buf, hpp->size, fmt, percent); |
| 199 | va_end(args); |
| 200 | |
| 201 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 202 | } |
| 203 | |
| 204 | static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 205 | { |
| 206 | va_list args; |
| 207 | ssize_t ssize = hpp->size; |
| 208 | int ret; |
| 209 | |
| 210 | va_start(args, fmt); |
| 211 | ret = vsnprintf(hpp->buf, hpp->size, fmt, args); |
| 212 | va_end(args); |
| 213 | |
| 214 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 215 | } |
| 216 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 217 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 218 | static u64 he_get_##_field(struct hist_entry *he) \ |
| 219 | { \ |
| 220 | return he->stat._field; \ |
| 221 | } \ |
| 222 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 223 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
| 224 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 225 | { \ |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 226 | return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 227 | hpp_color_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 228 | } |
| 229 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 230 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 231 | static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ |
| 232 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 233 | { \ |
| 234 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 235 | return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 236 | hpp_entry_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 237 | } |
| 238 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 239 | #define __HPP_SORT_FN(_type, _field) \ |
| 240 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 241 | { \ |
Namhyung Kim | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 242 | return __hpp__sort(a, b, he_get_##_field); \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 243 | } |
| 244 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 245 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 246 | static u64 he_get_raw_##_field(struct hist_entry *he) \ |
| 247 | { \ |
| 248 | return he->stat._field; \ |
| 249 | } \ |
| 250 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 251 | static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ |
| 252 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 253 | { \ |
| 254 | const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ |
Namhyung Kim | fb821c9e | 2014-03-03 17:05:19 +0900 | [diff] [blame] | 255 | return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 256 | hpp_entry_scnprintf, false); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 257 | } |
| 258 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 259 | #define __HPP_SORT_RAW_FN(_type, _field) \ |
| 260 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 261 | { \ |
Namhyung Kim | f156d84 | 2014-03-03 14:14:03 +0900 | [diff] [blame] | 262 | return __hpp__sort(a, b, he_get_raw_##_field); \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 266 | #define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 267 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 268 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
| 269 | __HPP_COLOR_PERCENT_FN(_type, _field) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 270 | __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
| 271 | __HPP_SORT_FN(_type, _field) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 272 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 273 | #define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 274 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 275 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 276 | __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 277 | __HPP_SORT_RAW_FN(_type, _field) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 278 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 279 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 280 | HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) |
| 281 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) |
| 282 | HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) |
| 283 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) |
| 284 | HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8) |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 285 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 286 | HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) |
| 287 | HPP_RAW_FNS(period, "Period", period, 12, 12) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 288 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 289 | static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, |
| 290 | struct hist_entry *b __maybe_unused) |
| 291 | { |
| 292 | return 0; |
| 293 | } |
| 294 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 295 | #define HPP__COLOR_PRINT_FNS(_name) \ |
| 296 | { \ |
| 297 | .header = hpp__header_ ## _name, \ |
| 298 | .width = hpp__width_ ## _name, \ |
| 299 | .color = hpp__color_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 300 | .entry = hpp__entry_ ## _name, \ |
| 301 | .cmp = hpp__nop_cmp, \ |
| 302 | .collapse = hpp__nop_cmp, \ |
| 303 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 304 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 305 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 306 | #define HPP__PRINT_FNS(_name) \ |
| 307 | { \ |
| 308 | .header = hpp__header_ ## _name, \ |
| 309 | .width = hpp__width_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame] | 310 | .entry = hpp__entry_ ## _name, \ |
| 311 | .cmp = hpp__nop_cmp, \ |
| 312 | .collapse = hpp__nop_cmp, \ |
| 313 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 314 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 315 | |
| 316 | struct perf_hpp_fmt perf_hpp__format[] = { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 317 | HPP__COLOR_PRINT_FNS(overhead), |
| 318 | HPP__COLOR_PRINT_FNS(overhead_sys), |
| 319 | HPP__COLOR_PRINT_FNS(overhead_us), |
| 320 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), |
| 321 | HPP__COLOR_PRINT_FNS(overhead_guest_us), |
| 322 | HPP__PRINT_FNS(samples), |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 323 | HPP__PRINT_FNS(period) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 324 | }; |
| 325 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 326 | LIST_HEAD(perf_hpp__list); |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 327 | LIST_HEAD(perf_hpp__sort_list); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 328 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 329 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 330 | #undef HPP__COLOR_PRINT_FNS |
| 331 | #undef HPP__PRINT_FNS |
| 332 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 333 | #undef HPP_PERCENT_FNS |
| 334 | #undef HPP_RAW_FNS |
| 335 | |
| 336 | #undef __HPP_HEADER_FN |
| 337 | #undef __HPP_WIDTH_FN |
| 338 | #undef __HPP_COLOR_PERCENT_FN |
| 339 | #undef __HPP_ENTRY_PERCENT_FN |
| 340 | #undef __HPP_ENTRY_RAW_FN |
| 341 | |
| 342 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 343 | void perf_hpp__init(void) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 344 | { |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 345 | struct list_head *list; |
| 346 | int i; |
| 347 | |
| 348 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
Namhyung Kim | a2ce067 | 2014-03-04 09:06:42 +0900 | [diff] [blame] | 349 | struct perf_hpp_fmt *fmt = &perf_hpp__format[i]; |
| 350 | |
| 351 | INIT_LIST_HEAD(&fmt->list); |
| 352 | |
| 353 | /* sort_list may be linked by setup_sorting() */ |
| 354 | if (fmt->sort_list.next == NULL) |
| 355 | INIT_LIST_HEAD(&fmt->sort_list); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 356 | } |
| 357 | |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 358 | /* |
| 359 | * If user specified field order, no need to setup default fields. |
| 360 | */ |
| 361 | if (field_order) |
| 362 | return; |
| 363 | |
Jiri Olsa | 2b8bfa6 | 2013-01-31 23:34:25 +0100 | [diff] [blame] | 364 | perf_hpp__column_enable(PERF_HPP__OVERHEAD); |
| 365 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 366 | if (symbol_conf.show_cpu_utilization) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 367 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS); |
| 368 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 369 | |
| 370 | if (perf_guest) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 371 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS); |
| 372 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | if (symbol_conf.show_nr_samples) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 377 | perf_hpp__column_enable(PERF_HPP__SAMPLES); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 378 | |
| 379 | if (symbol_conf.show_total_period) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 380 | perf_hpp__column_enable(PERF_HPP__PERIOD); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 381 | |
| 382 | /* prepend overhead field for backward compatiblity. */ |
| 383 | list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list; |
| 384 | if (list_empty(list)) |
| 385 | list_add(list, &perf_hpp__sort_list); |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 386 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 387 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 388 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| 389 | { |
| 390 | list_add_tail(&format->list, &perf_hpp__list); |
| 391 | } |
| 392 | |
Namhyung Kim | 8b53699 | 2014-03-03 11:46:55 +0900 | [diff] [blame] | 393 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) |
| 394 | { |
| 395 | list_add_tail(&format->sort_list, &perf_hpp__sort_list); |
| 396 | } |
| 397 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 398 | void perf_hpp__column_enable(unsigned col) |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 399 | { |
| 400 | BUG_ON(col >= PERF_HPP__MAX_INDEX); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 401 | perf_hpp__column_register(&perf_hpp__format[col]); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 402 | } |
| 403 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 404 | void perf_hpp__setup_output_field(void) |
| 405 | { |
| 406 | struct perf_hpp_fmt *fmt; |
| 407 | |
| 408 | /* append sort keys to output field */ |
| 409 | perf_hpp__for_each_sort_list(fmt) { |
Namhyung Kim | a7d945b | 2014-03-04 10:46:34 +0900 | [diff] [blame] | 410 | if (!list_empty(&fmt->list)) |
| 411 | continue; |
| 412 | |
| 413 | /* |
| 414 | * sort entry fields are dynamically created, |
| 415 | * so they can share a same sort key even though |
| 416 | * the list is empty. |
| 417 | */ |
| 418 | if (perf_hpp__is_sort_entry(fmt)) { |
| 419 | struct perf_hpp_fmt *pos; |
| 420 | |
| 421 | perf_hpp__for_each_format(pos) { |
| 422 | if (perf_hpp__same_sort_entry(pos, fmt)) |
| 423 | goto next; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | perf_hpp__column_register(fmt); |
| 428 | next: |
| 429 | continue; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | void perf_hpp__append_sort_keys(void) |
| 434 | { |
| 435 | struct perf_hpp_fmt *fmt; |
| 436 | |
| 437 | /* append output fields to sort keys */ |
| 438 | perf_hpp__for_each_format(fmt) { |
| 439 | if (!list_empty(&fmt->sort_list)) |
| 440 | continue; |
| 441 | |
| 442 | /* |
| 443 | * sort entry fields are dynamically created, |
| 444 | * so they can share a same sort key even though |
| 445 | * the list is empty. |
| 446 | */ |
| 447 | if (perf_hpp__is_sort_entry(fmt)) { |
| 448 | struct perf_hpp_fmt *pos; |
| 449 | |
| 450 | perf_hpp__for_each_sort_list(pos) { |
| 451 | if (perf_hpp__same_sort_entry(pos, fmt)) |
| 452 | goto next; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | perf_hpp__register_sort_field(fmt); |
| 457 | next: |
| 458 | continue; |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Namhyung Kim | 1c89fe9 | 2014-05-07 18:42:24 +0900 | [diff] [blame^] | 462 | void perf_hpp__reset_output_field(void) |
| 463 | { |
| 464 | struct perf_hpp_fmt *fmt, *tmp; |
| 465 | |
| 466 | /* reset output fields */ |
| 467 | perf_hpp__for_each_format_safe(fmt, tmp) { |
| 468 | list_del_init(&fmt->list); |
| 469 | list_del_init(&fmt->sort_list); |
| 470 | } |
| 471 | |
| 472 | /* reset sort keys */ |
| 473 | perf_hpp__for_each_sort_list_safe(fmt, tmp) { |
| 474 | list_del_init(&fmt->list); |
| 475 | list_del_init(&fmt->sort_list); |
| 476 | } |
| 477 | } |
| 478 | |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 479 | /* |
| 480 | * See hists__fprintf to match the column widths |
| 481 | */ |
| 482 | unsigned int hists__sort_list_width(struct hists *hists) |
| 483 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 484 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 485 | int ret = 0; |
| 486 | bool first = true; |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 487 | struct perf_hpp dummy_hpp; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 488 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 489 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 490 | if (perf_hpp__should_skip(fmt)) |
| 491 | continue; |
| 492 | |
| 493 | if (first) |
| 494 | first = false; |
| 495 | else |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 496 | ret += 2; |
| 497 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 498 | ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 499 | } |
| 500 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 501 | if (verbose && sort__has_sym) /* Addr + origin */ |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 502 | ret += 3 + BITS_PER_LONG / 4; |
| 503 | |
| 504 | return ret; |
| 505 | } |