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