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