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" |
| 6 | |
| 7 | |
| 8 | /* hist period print (hpp) functions */ |
| 9 | static int hpp__header_overhead(struct perf_hpp *hpp) |
| 10 | { |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 11 | return scnprintf(hpp->buf, hpp->size, "Overhead"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 12 | } |
| 13 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 14 | static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 15 | { |
| 16 | return 8; |
| 17 | } |
| 18 | |
| 19 | static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) |
| 20 | { |
| 21 | double percent = 100.0 * he->period / hpp->total_period; |
| 22 | |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 23 | return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) |
| 27 | { |
| 28 | double percent = 100.0 * he->period / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 29 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 30 | |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 31 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static int hpp__header_overhead_sys(struct perf_hpp *hpp) |
| 35 | { |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 36 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7s"; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 37 | |
| 38 | return scnprintf(hpp->buf, hpp->size, fmt, "sys"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 39 | } |
| 40 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 41 | static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 42 | { |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 43 | return 7; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) |
| 47 | { |
| 48 | double percent = 100.0 * he->period_sys / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 49 | return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) |
| 53 | { |
| 54 | double percent = 100.0 * he->period_sys / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 55 | const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 56 | |
| 57 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static int hpp__header_overhead_us(struct perf_hpp *hpp) |
| 61 | { |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 62 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7s"; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 63 | |
| 64 | return scnprintf(hpp->buf, hpp->size, fmt, "user"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 65 | } |
| 66 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 67 | static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 68 | { |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 69 | return 7; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) |
| 73 | { |
| 74 | double percent = 100.0 * he->period_us / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 75 | return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) |
| 79 | { |
| 80 | double percent = 100.0 * he->period_us / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 81 | const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 82 | |
| 83 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp) |
| 87 | { |
| 88 | return scnprintf(hpp->buf, hpp->size, "guest sys"); |
| 89 | } |
| 90 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 91 | static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 92 | { |
| 93 | return 9; |
| 94 | } |
| 95 | |
| 96 | static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, |
| 97 | struct hist_entry *he) |
| 98 | { |
| 99 | double percent = 100.0 * he->period_guest_sys / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 100 | return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, |
| 104 | struct hist_entry *he) |
| 105 | { |
| 106 | double percent = 100.0 * he->period_guest_sys / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 107 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 108 | |
| 109 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static int hpp__header_overhead_guest_us(struct perf_hpp *hpp) |
| 113 | { |
| 114 | return scnprintf(hpp->buf, hpp->size, "guest usr"); |
| 115 | } |
| 116 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 117 | static int hpp__width_overhead_guest_us(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 118 | { |
| 119 | return 9; |
| 120 | } |
| 121 | |
| 122 | static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, |
| 123 | struct hist_entry *he) |
| 124 | { |
| 125 | double percent = 100.0 * he->period_guest_us / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 126 | return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, |
| 130 | struct hist_entry *he) |
| 131 | { |
| 132 | double percent = 100.0 * he->period_guest_us / hpp->total_period; |
Namhyung Kim | 721b311 | 2012-09-12 15:35:05 +0900 | [diff] [blame] | 133 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 134 | |
| 135 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 136 | } |
| 137 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 138 | static int hpp__header_baseline(struct perf_hpp *hpp) |
| 139 | { |
| 140 | return scnprintf(hpp->buf, hpp->size, "Baseline"); |
| 141 | } |
| 142 | |
| 143 | static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused) |
| 144 | { |
| 145 | return 8; |
| 146 | } |
| 147 | |
| 148 | static double baseline_percent(struct hist_entry *he) |
| 149 | { |
| 150 | struct hist_entry *pair = he->pair; |
| 151 | struct hists *pair_hists = pair ? pair->hists : NULL; |
| 152 | double percent = 0.0; |
| 153 | |
| 154 | if (pair) { |
| 155 | u64 total_period = pair_hists->stats.total_period; |
| 156 | u64 base_period = pair->period; |
| 157 | |
| 158 | percent = 100.0 * base_period / total_period; |
| 159 | } |
| 160 | |
| 161 | return percent; |
| 162 | } |
| 163 | |
| 164 | static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he) |
| 165 | { |
| 166 | double percent = baseline_percent(he); |
| 167 | |
| 168 | return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); |
| 169 | } |
| 170 | |
| 171 | static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he) |
| 172 | { |
| 173 | double percent = baseline_percent(he); |
| 174 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; |
| 175 | |
| 176 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
| 177 | } |
| 178 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 179 | static int hpp__header_samples(struct perf_hpp *hpp) |
| 180 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 181 | const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; |
| 182 | |
| 183 | return scnprintf(hpp->buf, hpp->size, fmt, "Samples"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 186 | static int hpp__width_samples(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 187 | { |
| 188 | return 11; |
| 189 | } |
| 190 | |
| 191 | static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) |
| 192 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 193 | const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64; |
| 194 | |
| 195 | return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static int hpp__header_period(struct perf_hpp *hpp) |
| 199 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 200 | const char *fmt = symbol_conf.field_sep ? "%s" : "%12s"; |
| 201 | |
| 202 | return scnprintf(hpp->buf, hpp->size, fmt, "Period"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 203 | } |
| 204 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 205 | static int hpp__width_period(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 206 | { |
| 207 | return 12; |
| 208 | } |
| 209 | |
| 210 | static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) |
| 211 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 212 | const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; |
| 213 | |
| 214 | return scnprintf(hpp->buf, hpp->size, fmt, he->period); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static int hpp__header_delta(struct perf_hpp *hpp) |
| 218 | { |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 219 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7s"; |
| 220 | |
| 221 | return scnprintf(hpp->buf, hpp->size, fmt, "Delta"); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 222 | } |
| 223 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 224 | static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 225 | { |
| 226 | return 7; |
| 227 | } |
| 228 | |
| 229 | static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) |
| 230 | { |
Jiri Olsa | 41724e4 | 2012-10-04 21:49:38 +0900 | [diff] [blame^] | 231 | struct hist_entry *pair = he->pair; |
| 232 | struct hists *pair_hists = pair ? pair->hists : NULL; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 233 | u64 old_total, new_total; |
| 234 | double old_percent = 0, new_percent = 0; |
| 235 | double diff; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 236 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; |
| 237 | char buf[32] = " "; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 238 | |
Jiri Olsa | 41724e4 | 2012-10-04 21:49:38 +0900 | [diff] [blame^] | 239 | old_total = pair_hists ? pair_hists->stats.total_period : 0; |
| 240 | if (old_total > 0 && pair) |
| 241 | old_percent = 100.0 * pair->period / old_total; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 242 | |
| 243 | new_total = hpp->total_period; |
| 244 | if (new_total > 0) |
| 245 | new_percent = 100.0 * he->period / new_total; |
| 246 | |
| 247 | diff = new_percent - old_percent; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 248 | if (fabs(diff) >= 0.01) |
| 249 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 250 | |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 251 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static int hpp__header_displ(struct perf_hpp *hpp) |
| 255 | { |
| 256 | return scnprintf(hpp->buf, hpp->size, "Displ."); |
| 257 | } |
| 258 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 259 | static int hpp__width_displ(struct perf_hpp *hpp __maybe_unused) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 260 | { |
| 261 | return 6; |
| 262 | } |
| 263 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 264 | static int hpp__entry_displ(struct perf_hpp *hpp, |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 265 | struct hist_entry *he) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 266 | { |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 267 | struct hist_entry *pair = he->pair; |
| 268 | long displacement = pair ? pair->position - he->position : 0; |
Namhyung Kim | 9ffad98 | 2012-09-03 11:53:07 +0900 | [diff] [blame] | 269 | const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s"; |
| 270 | char buf[32] = " "; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 271 | |
Jiri Olsa | dd46434 | 2012-10-04 21:49:36 +0900 | [diff] [blame] | 272 | if (displacement) |
| 273 | scnprintf(buf, sizeof(buf), "%+4ld", displacement); |
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 | |
| 278 | #define HPP__COLOR_PRINT_FNS(_name) \ |
| 279 | .header = hpp__header_ ## _name, \ |
| 280 | .width = hpp__width_ ## _name, \ |
| 281 | .color = hpp__color_ ## _name, \ |
| 282 | .entry = hpp__entry_ ## _name |
| 283 | |
| 284 | #define HPP__PRINT_FNS(_name) \ |
| 285 | .header = hpp__header_ ## _name, \ |
| 286 | .width = hpp__width_ ## _name, \ |
| 287 | .entry = hpp__entry_ ## _name |
| 288 | |
| 289 | struct perf_hpp_fmt perf_hpp__format[] = { |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 290 | { .cond = false, HPP__COLOR_PRINT_FNS(baseline) }, |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 291 | { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, |
| 292 | { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, |
| 293 | { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, |
| 294 | { .cond = false, HPP__COLOR_PRINT_FNS(overhead_guest_sys) }, |
| 295 | { .cond = false, HPP__COLOR_PRINT_FNS(overhead_guest_us) }, |
| 296 | { .cond = false, HPP__PRINT_FNS(samples) }, |
| 297 | { .cond = false, HPP__PRINT_FNS(period) }, |
| 298 | { .cond = false, HPP__PRINT_FNS(delta) }, |
| 299 | { .cond = false, HPP__PRINT_FNS(displ) } |
| 300 | }; |
| 301 | |
| 302 | #undef HPP__COLOR_PRINT_FNS |
| 303 | #undef HPP__PRINT_FNS |
| 304 | |
| 305 | void perf_hpp__init(bool need_pair, bool show_displacement) |
| 306 | { |
| 307 | if (symbol_conf.show_cpu_utilization) { |
| 308 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].cond = true; |
| 309 | perf_hpp__format[PERF_HPP__OVERHEAD_US].cond = true; |
| 310 | |
| 311 | if (perf_guest) { |
| 312 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].cond = true; |
| 313 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].cond = true; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (symbol_conf.show_nr_samples) |
| 318 | perf_hpp__format[PERF_HPP__SAMPLES].cond = true; |
| 319 | |
| 320 | if (symbol_conf.show_total_period) |
| 321 | perf_hpp__format[PERF_HPP__PERIOD].cond = true; |
| 322 | |
| 323 | if (need_pair) { |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 324 | perf_hpp__format[PERF_HPP__OVERHEAD].cond = false; |
| 325 | perf_hpp__format[PERF_HPP__BASELINE].cond = true; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 326 | perf_hpp__format[PERF_HPP__DELTA].cond = true; |
| 327 | |
| 328 | if (show_displacement) |
| 329 | perf_hpp__format[PERF_HPP__DISPL].cond = true; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
| 334 | { |
| 335 | hpp->buf += inc; |
| 336 | hpp->size -= inc; |
| 337 | } |
| 338 | |
| 339 | int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, |
| 340 | bool color) |
| 341 | { |
| 342 | const char *sep = symbol_conf.field_sep; |
| 343 | char *start = hpp->buf; |
| 344 | int i, ret; |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 345 | bool first = true; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 346 | |
| 347 | if (symbol_conf.exclude_other && !he->parent) |
| 348 | return 0; |
| 349 | |
| 350 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 351 | if (!perf_hpp__format[i].cond) |
| 352 | continue; |
| 353 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 354 | if (!sep || !first) { |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 355 | ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); |
| 356 | advance_hpp(hpp, ret); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 357 | first = false; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | if (color && perf_hpp__format[i].color) |
| 361 | ret = perf_hpp__format[i].color(hpp, he); |
| 362 | else |
| 363 | ret = perf_hpp__format[i].entry(hpp, he); |
| 364 | |
| 365 | advance_hpp(hpp, ret); |
| 366 | } |
| 367 | |
| 368 | return hpp->buf - start; |
| 369 | } |
| 370 | |
| 371 | int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size, |
| 372 | struct hists *hists) |
| 373 | { |
| 374 | const char *sep = symbol_conf.field_sep; |
| 375 | struct sort_entry *se; |
| 376 | int ret = 0; |
| 377 | |
| 378 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 379 | if (se->elide) |
| 380 | continue; |
| 381 | |
| 382 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); |
| 383 | ret += se->se_snprintf(he, s + ret, size - ret, |
| 384 | hists__col_len(hists, se->se_width_idx)); |
| 385 | } |
| 386 | |
| 387 | return ret; |
| 388 | } |
Namhyung Kim | 7e62ef4 | 2012-09-03 11:53:08 +0900 | [diff] [blame] | 389 | |
| 390 | /* |
| 391 | * See hists__fprintf to match the column widths |
| 392 | */ |
| 393 | unsigned int hists__sort_list_width(struct hists *hists) |
| 394 | { |
| 395 | struct sort_entry *se; |
| 396 | int i, ret = 0; |
| 397 | |
| 398 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 399 | if (!perf_hpp__format[i].cond) |
| 400 | continue; |
| 401 | if (i) |
| 402 | ret += 2; |
| 403 | |
| 404 | ret += perf_hpp__format[i].width(NULL); |
| 405 | } |
| 406 | |
| 407 | list_for_each_entry(se, &hist_entry__sort_list, list) |
| 408 | if (!se->elide) |
| 409 | ret += 2 + hists__col_len(hists, se->se_width_idx); |
| 410 | |
| 411 | if (verbose) /* Addr + origin */ |
| 412 | ret += 3 + BITS_PER_LONG / 4; |
| 413 | |
| 414 | return ret; |
| 415 | } |