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 | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 19 | hpp_field_fn get_field, hpp_callback_fn callback, |
Namhyung Kim | 4a62109 | 2014-03-03 10:14:03 +0900 | [diff] [blame] | 20 | const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 21 | { |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 22 | int ret = 0; |
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 | |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 28 | if (callback) { |
| 29 | ret = callback(hpp, true); |
| 30 | advance_hpp(hpp, ret); |
| 31 | } |
| 32 | |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 33 | if (fmt_percent) { |
| 34 | double percent = 0.0; |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 35 | u64 total = hists__total_period(hists); |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 36 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 37 | if (total) |
| 38 | percent = 100.0 * get_field(he) / total; |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 39 | |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 40 | ret += hpp__call_print_fn(hpp, print_fn, fmt, percent); |
Jiri Olsa | 0c5268b | 2013-02-04 13:32:55 +0100 | [diff] [blame] | 41 | } else |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 42 | ret += hpp__call_print_fn(hpp, print_fn, fmt, get_field(he)); |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 43 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 44 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 45 | int prev_idx, idx_delta; |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 46 | struct hist_entry *pair; |
| 47 | int nr_members = evsel->nr_members; |
| 48 | |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 49 | prev_idx = perf_evsel__group_idx(evsel); |
| 50 | |
| 51 | list_for_each_entry(pair, &he->pairs.head, pairs.node) { |
| 52 | u64 period = get_field(pair); |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 53 | u64 total = hists__total_period(pair->hists); |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 54 | |
| 55 | if (!total) |
| 56 | continue; |
| 57 | |
| 58 | evsel = hists_to_evsel(pair->hists); |
| 59 | idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; |
| 60 | |
| 61 | while (idx_delta--) { |
| 62 | /* |
| 63 | * zero-fill group members in the middle which |
| 64 | * have no sample |
| 65 | */ |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 66 | if (fmt_percent) { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 67 | ret += hpp__call_print_fn(hpp, print_fn, |
| 68 | fmt, 0.0); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 69 | } else { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 70 | ret += hpp__call_print_fn(hpp, print_fn, |
| 71 | fmt, 0ULL); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 72 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 73 | } |
| 74 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 75 | if (fmt_percent) { |
| 76 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
| 77 | 100.0 * period / total); |
| 78 | } else { |
| 79 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
| 80 | period); |
| 81 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 82 | |
| 83 | prev_idx = perf_evsel__group_idx(evsel); |
| 84 | } |
| 85 | |
| 86 | idx_delta = nr_members - prev_idx - 1; |
| 87 | |
| 88 | while (idx_delta--) { |
| 89 | /* |
| 90 | * zero-fill group members at last which have no sample |
| 91 | */ |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 92 | if (fmt_percent) { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 93 | ret += hpp__call_print_fn(hpp, print_fn, |
| 94 | fmt, 0.0); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 95 | } else { |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 96 | ret += hpp__call_print_fn(hpp, print_fn, |
| 97 | fmt, 0ULL); |
Namhyung Kim | 9b0d2fb | 2014-03-03 10:14:02 +0900 | [diff] [blame] | 98 | } |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 99 | } |
| 100 | } |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 101 | |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 102 | if (callback) { |
| 103 | int __ret = callback(hpp, false); |
| 104 | |
| 105 | advance_hpp(hpp, __ret); |
| 106 | ret += __ret; |
| 107 | } |
| 108 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 109 | /* |
| 110 | * Restore original buf and size as it's where caller expects |
| 111 | * the result will be saved. |
| 112 | */ |
| 113 | hpp->buf = buf; |
| 114 | hpp->size = size; |
| 115 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 116 | return ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 119 | #define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 120 | static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 121 | struct perf_hpp *hpp, \ |
| 122 | struct perf_evsel *evsel) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 123 | { \ |
| 124 | int len = _min_width; \ |
| 125 | \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 126 | if (symbol_conf.event_group) \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 127 | len = max(len, evsel->nr_members * _unit_width); \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 128 | \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 129 | return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 130 | } |
| 131 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 132 | #define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 133 | static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 134 | struct perf_hpp *hpp __maybe_unused, \ |
| 135 | struct perf_evsel *evsel) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 136 | { \ |
| 137 | int len = _min_width; \ |
| 138 | \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 139 | if (symbol_conf.event_group) \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 140 | len = max(len, evsel->nr_members * _unit_width); \ |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 141 | \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 142 | return len; \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 143 | } |
| 144 | |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 145 | static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 146 | { |
| 147 | va_list args; |
| 148 | ssize_t ssize = hpp->size; |
| 149 | double percent; |
| 150 | int ret; |
| 151 | |
| 152 | va_start(args, fmt); |
| 153 | percent = va_arg(args, double); |
| 154 | ret = value_color_snprintf(hpp->buf, hpp->size, fmt, percent); |
| 155 | va_end(args); |
| 156 | |
| 157 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 158 | } |
| 159 | |
| 160 | static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) |
| 161 | { |
| 162 | va_list args; |
| 163 | ssize_t ssize = hpp->size; |
| 164 | int ret; |
| 165 | |
| 166 | va_start(args, fmt); |
| 167 | ret = vsnprintf(hpp->buf, hpp->size, fmt, args); |
| 168 | va_end(args); |
| 169 | |
| 170 | return (ret >= ssize) ? (ssize - 1) : ret; |
| 171 | } |
| 172 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 173 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 174 | static u64 he_get_##_field(struct hist_entry *he) \ |
| 175 | { \ |
| 176 | return he->stat._field; \ |
| 177 | } \ |
| 178 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 179 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
| 180 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 181 | { \ |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 182 | return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 183 | hpp_color_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 186 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 187 | static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ |
| 188 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 189 | { \ |
| 190 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 191 | return __hpp__fmt(hpp, he, he_get_##_field, NULL, fmt, \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 192 | hpp_entry_scnprintf, true); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 193 | } |
| 194 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 195 | #define __HPP_SORT_FN(_type, _field) \ |
| 196 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 197 | { \ |
| 198 | s64 __a = he_get_##_field(a); \ |
| 199 | s64 __b = he_get_##_field(b); \ |
| 200 | return __a - __b; \ |
| 201 | } |
| 202 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 203 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 204 | static u64 he_get_raw_##_field(struct hist_entry *he) \ |
| 205 | { \ |
| 206 | return he->stat._field; \ |
| 207 | } \ |
| 208 | \ |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 209 | static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ |
| 210 | struct perf_hpp *hpp, struct hist_entry *he) \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 211 | { \ |
| 212 | const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ |
Namhyung Kim | 2f6d900 | 2014-03-03 10:14:05 +0900 | [diff] [blame] | 213 | return __hpp__fmt(hpp, he, he_get_raw_##_field, NULL, fmt, \ |
Namhyung Kim | a0088ad | 2014-03-03 10:14:04 +0900 | [diff] [blame] | 214 | hpp_entry_scnprintf, false); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 217 | #define __HPP_SORT_RAW_FN(_type, _field) \ |
| 218 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ |
| 219 | { \ |
| 220 | s64 __a = he_get_raw_##_field(a); \ |
| 221 | s64 __b = he_get_raw_##_field(b); \ |
| 222 | return __a - __b; \ |
| 223 | } |
| 224 | |
| 225 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 226 | #define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 227 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 228 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
| 229 | __HPP_COLOR_PERCENT_FN(_type, _field) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 230 | __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
| 231 | __HPP_SORT_FN(_type, _field) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 232 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 233 | #define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 234 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 235 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 236 | __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 237 | __HPP_SORT_RAW_FN(_type, _field) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 238 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 239 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 240 | HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) |
| 241 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) |
| 242 | HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) |
| 243 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) |
| 244 | 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] | 245 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 246 | HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) |
| 247 | HPP_RAW_FNS(period, "Period", period, 12, 12) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 248 | |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 249 | static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, |
| 250 | struct hist_entry *b __maybe_unused) |
| 251 | { |
| 252 | return 0; |
| 253 | } |
| 254 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 255 | #define HPP__COLOR_PRINT_FNS(_name) \ |
| 256 | { \ |
| 257 | .header = hpp__header_ ## _name, \ |
| 258 | .width = hpp__width_ ## _name, \ |
| 259 | .color = hpp__color_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 260 | .entry = hpp__entry_ ## _name, \ |
| 261 | .cmp = hpp__nop_cmp, \ |
| 262 | .collapse = hpp__nop_cmp, \ |
| 263 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 264 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 265 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 266 | #define HPP__PRINT_FNS(_name) \ |
| 267 | { \ |
| 268 | .header = hpp__header_ ## _name, \ |
| 269 | .width = hpp__width_ ## _name, \ |
Namhyung Kim | bc18b7f | 2014-03-03 10:59:57 +0900 | [diff] [blame^] | 270 | .entry = hpp__entry_ ## _name, \ |
| 271 | .cmp = hpp__nop_cmp, \ |
| 272 | .collapse = hpp__nop_cmp, \ |
| 273 | .sort = hpp__sort_ ## _name, \ |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 274 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 275 | |
| 276 | struct perf_hpp_fmt perf_hpp__format[] = { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 277 | HPP__COLOR_PRINT_FNS(overhead), |
| 278 | HPP__COLOR_PRINT_FNS(overhead_sys), |
| 279 | HPP__COLOR_PRINT_FNS(overhead_us), |
| 280 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), |
| 281 | HPP__COLOR_PRINT_FNS(overhead_guest_us), |
| 282 | HPP__PRINT_FNS(samples), |
Jiri Olsa | 345dc0b | 2013-02-03 20:08:34 +0100 | [diff] [blame] | 283 | HPP__PRINT_FNS(period) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 284 | }; |
| 285 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 286 | LIST_HEAD(perf_hpp__list); |
| 287 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 288 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 289 | #undef HPP__COLOR_PRINT_FNS |
| 290 | #undef HPP__PRINT_FNS |
| 291 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 292 | #undef HPP_PERCENT_FNS |
| 293 | #undef HPP_RAW_FNS |
| 294 | |
| 295 | #undef __HPP_HEADER_FN |
| 296 | #undef __HPP_WIDTH_FN |
| 297 | #undef __HPP_COLOR_PERCENT_FN |
| 298 | #undef __HPP_ENTRY_PERCENT_FN |
| 299 | #undef __HPP_ENTRY_RAW_FN |
| 300 | |
| 301 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 302 | void perf_hpp__init(void) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 303 | { |
Jiri Olsa | 2b8bfa6 | 2013-01-31 23:34:25 +0100 | [diff] [blame] | 304 | perf_hpp__column_enable(PERF_HPP__OVERHEAD); |
| 305 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 306 | if (symbol_conf.show_cpu_utilization) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 307 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS); |
| 308 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 309 | |
| 310 | if (perf_guest) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 311 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS); |
| 312 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
| 316 | if (symbol_conf.show_nr_samples) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 317 | perf_hpp__column_enable(PERF_HPP__SAMPLES); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 318 | |
| 319 | if (symbol_conf.show_total_period) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 320 | perf_hpp__column_enable(PERF_HPP__PERIOD); |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 321 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 322 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 323 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| 324 | { |
| 325 | list_add_tail(&format->list, &perf_hpp__list); |
| 326 | } |
| 327 | |
| 328 | void perf_hpp__column_enable(unsigned col) |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 329 | { |
| 330 | BUG_ON(col >= PERF_HPP__MAX_INDEX); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 331 | perf_hpp__column_register(&perf_hpp__format[col]); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 332 | } |
| 333 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 334 | int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size, |
| 335 | struct hists *hists) |
| 336 | { |
| 337 | const char *sep = symbol_conf.field_sep; |
| 338 | struct sort_entry *se; |
| 339 | int ret = 0; |
| 340 | |
| 341 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 342 | if (se->elide) |
| 343 | continue; |
| 344 | |
| 345 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); |
| 346 | ret += se->se_snprintf(he, s + ret, size - ret, |
| 347 | hists__col_len(hists, se->se_width_idx)); |
| 348 | } |
| 349 | |
| 350 | return ret; |
| 351 | } |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * See hists__fprintf to match the column widths |
| 355 | */ |
| 356 | unsigned int hists__sort_list_width(struct hists *hists) |
| 357 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 358 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 359 | struct sort_entry *se; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 360 | int i = 0, ret = 0; |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 361 | struct perf_hpp dummy_hpp; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 362 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 363 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 364 | if (i) |
| 365 | ret += 2; |
| 366 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 367 | ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | list_for_each_entry(se, &hist_entry__sort_list, list) |
| 371 | if (!se->elide) |
| 372 | ret += 2 + hists__col_len(hists, se->se_width_idx); |
| 373 | |
| 374 | if (verbose) /* Addr + origin */ |
| 375 | ret += 3 + BITS_PER_LONG / 4; |
| 376 | |
| 377 | return ret; |
| 378 | } |