Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 1 | #include <math.h> |
| 2 | |
| 3 | #include "../util/hist.h" |
| 4 | #include "../util/util.h" |
| 5 | #include "../util/sort.h" |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 6 | #include "../util/evsel.h" |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 7 | |
| 8 | /* hist period print (hpp) functions */ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 9 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 10 | typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 11 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 12 | static int __hpp__percent_fmt(struct perf_hpp *hpp, struct hist_entry *he, |
| 13 | u64 (*get_field)(struct hist_entry *), |
| 14 | const char *fmt, hpp_snprint_fn print_fn) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 15 | { |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 16 | int ret; |
| 17 | double percent = 0.0; |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 18 | struct hists *hists = he->hists; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 19 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 20 | if (hists->stats.total_period) |
| 21 | percent = 100.0 * get_field(he) / hists->stats.total_period; |
| 22 | |
| 23 | ret = print_fn(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 24 | |
| 25 | if (symbol_conf.event_group) { |
| 26 | int prev_idx, idx_delta; |
| 27 | struct perf_evsel *evsel = hists_to_evsel(hists); |
| 28 | struct hist_entry *pair; |
| 29 | int nr_members = evsel->nr_members; |
| 30 | |
| 31 | if (nr_members <= 1) |
| 32 | return ret; |
| 33 | |
| 34 | prev_idx = perf_evsel__group_idx(evsel); |
| 35 | |
| 36 | list_for_each_entry(pair, &he->pairs.head, pairs.node) { |
| 37 | u64 period = get_field(pair); |
| 38 | u64 total = pair->hists->stats.total_period; |
| 39 | |
| 40 | if (!total) |
| 41 | continue; |
| 42 | |
| 43 | evsel = hists_to_evsel(pair->hists); |
| 44 | idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; |
| 45 | |
| 46 | while (idx_delta--) { |
| 47 | /* |
| 48 | * zero-fill group members in the middle which |
| 49 | * have no sample |
| 50 | */ |
| 51 | ret += print_fn(hpp->buf + ret, hpp->size - ret, |
| 52 | fmt, 0.0); |
| 53 | } |
| 54 | |
| 55 | ret += print_fn(hpp->buf + ret, hpp->size - ret, |
| 56 | fmt, 100.0 * period / total); |
| 57 | |
| 58 | prev_idx = perf_evsel__group_idx(evsel); |
| 59 | } |
| 60 | |
| 61 | idx_delta = nr_members - prev_idx - 1; |
| 62 | |
| 63 | while (idx_delta--) { |
| 64 | /* |
| 65 | * zero-fill group members at last which have no sample |
| 66 | */ |
| 67 | ret += print_fn(hpp->buf + ret, hpp->size - ret, |
| 68 | fmt, 0.0); |
| 69 | } |
| 70 | } |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 71 | return ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 72 | } |
| 73 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 74 | static int __hpp__raw_fmt(struct perf_hpp *hpp, struct hist_entry *he, |
| 75 | u64 (*get_field)(struct hist_entry *), |
| 76 | const char *fmt, hpp_snprint_fn print_fn) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 77 | { |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 78 | int ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 79 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 80 | ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he)); |
| 81 | return ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 82 | } |
| 83 | |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 84 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 85 | #define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 86 | static int hpp__header_##_type(struct perf_hpp *hpp) \ |
| 87 | { \ |
| 88 | int len = _min_width; \ |
| 89 | \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 90 | if (symbol_conf.event_group) { \ |
| 91 | struct perf_evsel *evsel = hpp->ptr; \ |
| 92 | \ |
| 93 | len = max(len, evsel->nr_members * _unit_width); \ |
| 94 | } \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 95 | return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 96 | } |
| 97 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 98 | #define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
| 99 | static int hpp__width_##_type(struct perf_hpp *hpp __maybe_unused) \ |
| 100 | { \ |
| 101 | int len = _min_width; \ |
| 102 | \ |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 103 | if (symbol_conf.event_group) { \ |
| 104 | struct perf_evsel *evsel = hpp->ptr; \ |
| 105 | \ |
| 106 | len = max(len, evsel->nr_members * _unit_width); \ |
| 107 | } \ |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 108 | return len; \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 111 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 112 | static u64 he_get_##_field(struct hist_entry *he) \ |
| 113 | { \ |
| 114 | return he->stat._field; \ |
| 115 | } \ |
| 116 | \ |
| 117 | static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ |
| 118 | { \ |
| 119 | return __hpp__percent_fmt(hpp, he, he_get_##_field, " %6.2f%%", \ |
| 120 | (hpp_snprint_fn)percent_color_snprintf); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 121 | } |
| 122 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 123 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
| 124 | static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ |
| 125 | { \ |
| 126 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ |
| 127 | return __hpp__percent_fmt(hpp, he, he_get_##_field, fmt, \ |
| 128 | scnprintf); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 129 | } |
| 130 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 131 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
| 132 | static u64 he_get_raw_##_field(struct hist_entry *he) \ |
| 133 | { \ |
| 134 | return he->stat._field; \ |
| 135 | } \ |
| 136 | \ |
| 137 | static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ |
| 138 | { \ |
| 139 | const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ |
| 140 | return __hpp__raw_fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf); \ |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 141 | } |
| 142 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 143 | #define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 144 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 145 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
| 146 | __HPP_COLOR_PERCENT_FN(_type, _field) \ |
| 147 | __HPP_ENTRY_PERCENT_FN(_type, _field) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 148 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 149 | #define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ |
| 150 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
| 151 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
| 152 | __HPP_ENTRY_RAW_FN(_type, _field) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 153 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 154 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 155 | HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) |
| 156 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) |
| 157 | HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) |
| 158 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) |
| 159 | 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] | 160 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 161 | HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) |
| 162 | HPP_RAW_FNS(period, "Period", period, 12, 12) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 163 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 164 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 165 | static int hpp__header_baseline(struct perf_hpp *hpp) |
| 166 | { |
| 167 | return scnprintf(hpp->buf, hpp->size, "Baseline"); |
| 168 | } |
| 169 | |
| 170 | static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused) |
| 171 | { |
| 172 | return 8; |
| 173 | } |
| 174 | |
| 175 | static double baseline_percent(struct hist_entry *he) |
| 176 | { |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 177 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 178 | struct hists *pair_hists = pair ? pair->hists : NULL; |
| 179 | double percent = 0.0; |
| 180 | |
| 181 | if (pair) { |
| 182 | u64 total_period = pair_hists->stats.total_period; |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 183 | u64 base_period = pair->stat.period; |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 184 | |
| 185 | percent = 100.0 * base_period / total_period; |
| 186 | } |
| 187 | |
| 188 | return percent; |
| 189 | } |
| 190 | |
| 191 | static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he) |
| 192 | { |
| 193 | double percent = baseline_percent(he); |
| 194 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 195 | if (hist_entry__has_pairs(he) || symbol_conf.field_sep) |
Jiri Olsa | 6e92349 | 2012-10-05 16:44:47 +0200 | [diff] [blame] | 196 | return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); |
| 197 | else |
| 198 | return scnprintf(hpp->buf, hpp->size, " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he) |
| 202 | { |
| 203 | double percent = baseline_percent(he); |
| 204 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; |
| 205 | |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 206 | if (hist_entry__has_pairs(he) || symbol_conf.field_sep) |
Jiri Olsa | 6e92349 | 2012-10-05 16:44:47 +0200 | [diff] [blame] | 207 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
| 208 | else |
| 209 | return scnprintf(hpp->buf, hpp->size, " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 210 | } |
| 211 | |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 212 | static int hpp__header_period_baseline(struct perf_hpp *hpp) |
| 213 | { |
| 214 | const char *fmt = symbol_conf.field_sep ? "%s" : "%12s"; |
| 215 | |
| 216 | return scnprintf(hpp->buf, hpp->size, fmt, "Period Base"); |
| 217 | } |
| 218 | |
| 219 | static int hpp__width_period_baseline(struct perf_hpp *hpp __maybe_unused) |
| 220 | { |
| 221 | return 12; |
| 222 | } |
| 223 | |
| 224 | static int hpp__entry_period_baseline(struct perf_hpp *hpp, struct hist_entry *he) |
| 225 | { |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 226 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | 61949b2 | 2012-10-05 16:44:44 +0200 | [diff] [blame] | 227 | u64 period = pair ? pair->stat.period : 0; |
| 228 | const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; |
| 229 | |
| 230 | return scnprintf(hpp->buf, hpp->size, fmt, period); |
| 231 | } |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 232 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 233 | static int hpp__header_delta(struct perf_hpp *hpp) |
| 234 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 235 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7s"; |
| 236 | |
| 237 | return scnprintf(hpp->buf, hpp->size, fmt, "Delta"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 238 | } |
| 239 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 240 | static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 241 | { |
| 242 | return 7; |
| 243 | } |
| 244 | |
| 245 | static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) |
| 246 | { |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 247 | struct hist_entry *pair = hist_entry__next_pair(he); |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 248 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; |
| 249 | char buf[32] = " "; |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 250 | double diff = 0.0; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 251 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 252 | if (pair) { |
| 253 | if (he->diff.computed) |
| 254 | diff = he->diff.period_ratio_delta; |
| 255 | else |
| 256 | diff = perf_diff__compute_delta(he, pair); |
| 257 | } else |
| 258 | diff = perf_diff__period_percent(he, he->stat.period); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 259 | |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 260 | if (fabs(diff) >= 0.01) |
| 261 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 262 | |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 263 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 264 | } |
| 265 | |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 266 | static int hpp__header_ratio(struct perf_hpp *hpp) |
| 267 | { |
| 268 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
| 269 | |
| 270 | return scnprintf(hpp->buf, hpp->size, fmt, "Ratio"); |
| 271 | } |
| 272 | |
| 273 | static int hpp__width_ratio(struct perf_hpp *hpp __maybe_unused) |
| 274 | { |
| 275 | return 14; |
| 276 | } |
| 277 | |
| 278 | static int hpp__entry_ratio(struct perf_hpp *hpp, struct hist_entry *he) |
| 279 | { |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 280 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 281 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
| 282 | char buf[32] = " "; |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 283 | double ratio = 0.0; |
Jiri Olsa | 96c47f1 | 2012-10-05 16:44:42 +0200 | [diff] [blame] | 284 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 285 | if (pair) { |
| 286 | if (he->diff.computed) |
| 287 | ratio = he->diff.period_ratio; |
| 288 | else |
| 289 | ratio = perf_diff__compute_ratio(he, pair); |
| 290 | } |
Jiri Olsa | 7aaf6b3 | 2012-10-05 16:44:41 +0200 | [diff] [blame] | 291 | |
| 292 | if (ratio > 0.0) |
| 293 | scnprintf(buf, sizeof(buf), "%+14.6F", ratio); |
| 294 | |
| 295 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
| 296 | } |
| 297 | |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 298 | static int hpp__header_wdiff(struct perf_hpp *hpp) |
| 299 | { |
| 300 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
| 301 | |
| 302 | return scnprintf(hpp->buf, hpp->size, fmt, "Weighted diff"); |
| 303 | } |
| 304 | |
| 305 | static int hpp__width_wdiff(struct perf_hpp *hpp __maybe_unused) |
| 306 | { |
| 307 | return 14; |
| 308 | } |
| 309 | |
| 310 | static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he) |
| 311 | { |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 312 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 313 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
| 314 | char buf[32] = " "; |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 315 | s64 wdiff = 0; |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 316 | |
Jiri Olsa | 05472da | 2012-11-28 14:52:40 +0100 | [diff] [blame] | 317 | if (pair) { |
| 318 | if (he->diff.computed) |
| 319 | wdiff = he->diff.wdiff; |
| 320 | else |
| 321 | wdiff = perf_diff__compute_wdiff(he, pair); |
| 322 | } |
Jiri Olsa | 81d5f95 | 2012-10-05 16:44:43 +0200 | [diff] [blame] | 323 | |
| 324 | if (wdiff != 0) |
| 325 | scnprintf(buf, sizeof(buf), "%14ld", wdiff); |
| 326 | |
| 327 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
| 328 | } |
| 329 | |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 330 | static int hpp__header_formula(struct perf_hpp *hpp) |
| 331 | { |
| 332 | const char *fmt = symbol_conf.field_sep ? "%s" : "%70s"; |
| 333 | |
| 334 | return scnprintf(hpp->buf, hpp->size, fmt, "Formula"); |
| 335 | } |
| 336 | |
| 337 | static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused) |
| 338 | { |
| 339 | return 70; |
| 340 | } |
| 341 | |
| 342 | static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he) |
| 343 | { |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 344 | struct hist_entry *pair = hist_entry__next_pair(he); |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 345 | const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s"; |
| 346 | char buf[96] = " "; |
| 347 | |
Jiri Olsa | f4c8bae | 2012-11-28 14:52:41 +0100 | [diff] [blame] | 348 | if (pair) |
| 349 | perf_diff__formula(he, pair, buf, sizeof(buf)); |
| 350 | |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 351 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
| 352 | } |
| 353 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 354 | #define HPP__COLOR_PRINT_FNS(_name) \ |
| 355 | { \ |
| 356 | .header = hpp__header_ ## _name, \ |
| 357 | .width = hpp__width_ ## _name, \ |
| 358 | .color = hpp__color_ ## _name, \ |
| 359 | .entry = hpp__entry_ ## _name \ |
| 360 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 361 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 362 | #define HPP__PRINT_FNS(_name) \ |
| 363 | { \ |
| 364 | .header = hpp__header_ ## _name, \ |
| 365 | .width = hpp__width_ ## _name, \ |
| 366 | .entry = hpp__entry_ ## _name \ |
| 367 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 368 | |
| 369 | struct perf_hpp_fmt perf_hpp__format[] = { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 370 | HPP__COLOR_PRINT_FNS(baseline), |
| 371 | HPP__COLOR_PRINT_FNS(overhead), |
| 372 | HPP__COLOR_PRINT_FNS(overhead_sys), |
| 373 | HPP__COLOR_PRINT_FNS(overhead_us), |
| 374 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), |
| 375 | HPP__COLOR_PRINT_FNS(overhead_guest_us), |
| 376 | HPP__PRINT_FNS(samples), |
| 377 | HPP__PRINT_FNS(period), |
| 378 | HPP__PRINT_FNS(period_baseline), |
| 379 | HPP__PRINT_FNS(delta), |
| 380 | HPP__PRINT_FNS(ratio), |
| 381 | HPP__PRINT_FNS(wdiff), |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 382 | HPP__PRINT_FNS(formula) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 383 | }; |
| 384 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 385 | LIST_HEAD(perf_hpp__list); |
| 386 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 387 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 388 | #undef HPP__COLOR_PRINT_FNS |
| 389 | #undef HPP__PRINT_FNS |
| 390 | |
Namhyung Kim | 4fb7107 | 2013-01-22 18:09:34 +0900 | [diff] [blame] | 391 | #undef HPP_PERCENT_FNS |
| 392 | #undef HPP_RAW_FNS |
| 393 | |
| 394 | #undef __HPP_HEADER_FN |
| 395 | #undef __HPP_WIDTH_FN |
| 396 | #undef __HPP_COLOR_PERCENT_FN |
| 397 | #undef __HPP_ENTRY_PERCENT_FN |
| 398 | #undef __HPP_ENTRY_RAW_FN |
| 399 | |
| 400 | |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 401 | void perf_hpp__init(void) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 402 | { |
| 403 | if (symbol_conf.show_cpu_utilization) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 404 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS); |
| 405 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 406 | |
| 407 | if (perf_guest) { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 408 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS); |
| 409 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | if (symbol_conf.show_nr_samples) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 414 | perf_hpp__column_enable(PERF_HPP__SAMPLES); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 415 | |
| 416 | if (symbol_conf.show_total_period) |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 417 | perf_hpp__column_enable(PERF_HPP__PERIOD); |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 418 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 419 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 420 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| 421 | { |
| 422 | list_add_tail(&format->list, &perf_hpp__list); |
| 423 | } |
| 424 | |
| 425 | void perf_hpp__column_enable(unsigned col) |
Jiri Olsa | 1d77822 | 2012-10-04 21:49:39 +0900 | [diff] [blame] | 426 | { |
| 427 | BUG_ON(col >= PERF_HPP__MAX_INDEX); |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 428 | perf_hpp__column_register(&perf_hpp__format[col]); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
| 432 | { |
| 433 | hpp->buf += inc; |
| 434 | hpp->size -= inc; |
| 435 | } |
| 436 | |
| 437 | int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, |
| 438 | bool color) |
| 439 | { |
| 440 | const char *sep = symbol_conf.field_sep; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 441 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 442 | char *start = hpp->buf; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 443 | int ret; |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 444 | bool first = true; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 445 | |
| 446 | if (symbol_conf.exclude_other && !he->parent) |
| 447 | return 0; |
| 448 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 449 | perf_hpp__for_each_format(fmt) { |
Jiri Olsa | c0d246b | 2012-10-20 22:14:10 +0200 | [diff] [blame] | 450 | /* |
| 451 | * If there's no field_sep, we still need |
| 452 | * to display initial ' '. |
| 453 | */ |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 454 | if (!sep || !first) { |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 455 | ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); |
| 456 | advance_hpp(hpp, ret); |
Jiri Olsa | c0d246b | 2012-10-20 22:14:10 +0200 | [diff] [blame] | 457 | } else |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 458 | first = false; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 459 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 460 | if (color && fmt->color) |
| 461 | ret = fmt->color(hpp, he); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 462 | else |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 463 | ret = fmt->entry(hpp, he); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 464 | |
| 465 | advance_hpp(hpp, ret); |
| 466 | } |
| 467 | |
| 468 | return hpp->buf - start; |
| 469 | } |
| 470 | |
| 471 | int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size, |
| 472 | struct hists *hists) |
| 473 | { |
| 474 | const char *sep = symbol_conf.field_sep; |
| 475 | struct sort_entry *se; |
| 476 | int ret = 0; |
| 477 | |
| 478 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 479 | if (se->elide) |
| 480 | continue; |
| 481 | |
| 482 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); |
| 483 | ret += se->se_snprintf(he, s + ret, size - ret, |
| 484 | hists__col_len(hists, se->se_width_idx)); |
| 485 | } |
| 486 | |
| 487 | return ret; |
| 488 | } |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 489 | |
| 490 | /* |
| 491 | * See hists__fprintf to match the column widths |
| 492 | */ |
| 493 | unsigned int hists__sort_list_width(struct hists *hists) |
| 494 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 495 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 496 | struct sort_entry *se; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 497 | int i = 0, ret = 0; |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 498 | struct perf_hpp dummy_hpp = { |
| 499 | .ptr = hists_to_evsel(hists), |
| 500 | }; |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 501 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 502 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 503 | if (i) |
| 504 | ret += 2; |
| 505 | |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 506 | ret += fmt->width(&dummy_hpp); |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | list_for_each_entry(se, &hist_entry__sort_list, list) |
| 510 | if (!se->elide) |
| 511 | ret += 2 + hists__col_len(hists, se->se_width_idx); |
| 512 | |
| 513 | if (verbose) /* Addr + origin */ |
| 514 | ret += 3 + BITS_PER_LONG / 4; |
| 515 | |
| 516 | return ret; |
| 517 | } |