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