diff options
| -rw-r--r-- | tools/perf/ui/hist.c | 74 | ||||
| -rw-r--r-- | tools/perf/ui/stdio/hist.c | 3 |
2 files changed, 50 insertions, 27 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 8ccd1f2330d1..009adf206c81 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
| @@ -8,10 +8,9 @@ | |||
| 8 | /* hist period print (hpp) functions */ | 8 | /* hist period print (hpp) functions */ |
| 9 | static int hpp__header_overhead(struct perf_hpp *hpp) | 9 | static int hpp__header_overhead(struct perf_hpp *hpp) |
| 10 | { | 10 | { |
| 11 | if (hpp->ptr) | 11 | const char *fmt = hpp->ptr ? "Baseline" : "Overhead"; |
| 12 | return scnprintf(hpp->buf, hpp->size, "Baseline"); | 12 | |
| 13 | else | 13 | return scnprintf(hpp->buf, hpp->size, fmt); |
| 14 | return scnprintf(hpp->buf, hpp->size, "Overhead"); | ||
| 15 | } | 14 | } |
| 16 | 15 | ||
| 17 | static int hpp__width_overhead(struct perf_hpp *hpp __used) | 16 | static int hpp__width_overhead(struct perf_hpp *hpp __used) |
| @@ -40,6 +39,7 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 40 | static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) | 39 | static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) |
| 41 | { | 40 | { |
| 42 | double percent = 100.0 * he->period / hpp->total_period; | 41 | double percent = 100.0 * he->period / hpp->total_period; |
| 42 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%%"; | ||
| 43 | 43 | ||
| 44 | if (hpp->ptr) { | 44 | if (hpp->ptr) { |
| 45 | struct hists *old_hists = hpp->ptr; | 45 | struct hists *old_hists = hpp->ptr; |
| @@ -52,12 +52,14 @@ static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 52 | percent = 0.0; | 52 | percent = 0.0; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | return scnprintf(hpp->buf, hpp->size, " %5.2f%%", percent); | 55 | return scnprintf(hpp->buf, hpp->size, fmt, percent); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | static int hpp__header_overhead_sys(struct perf_hpp *hpp) | 58 | static int hpp__header_overhead_sys(struct perf_hpp *hpp) |
| 59 | { | 59 | { |
| 60 | return scnprintf(hpp->buf, hpp->size, " sys "); | 60 | const char *fmt = symbol_conf.field_sep ? "%s" : "%6s"; |
| 61 | |||
| 62 | return scnprintf(hpp->buf, hpp->size, fmt, "sys"); | ||
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | static int hpp__width_overhead_sys(struct perf_hpp *hpp __used) | 65 | static int hpp__width_overhead_sys(struct perf_hpp *hpp __used) |
| @@ -74,12 +76,16 @@ static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 74 | static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) | 76 | static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) |
| 75 | { | 77 | { |
| 76 | double percent = 100.0 * he->period_sys / hpp->total_period; | 78 | double percent = 100.0 * he->period_sys / hpp->total_period; |
| 77 | return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); | 79 | const char *fmt = symbol_conf.field_sep ? "%.2f" : "%5.2f%%"; |
| 80 | |||
| 81 | return scnprintf(hpp->buf, hpp->size, fmt, percent); | ||
| 78 | } | 82 | } |
| 79 | 83 | ||
| 80 | static int hpp__header_overhead_us(struct perf_hpp *hpp) | 84 | static int hpp__header_overhead_us(struct perf_hpp *hpp) |
| 81 | { | 85 | { |
| 82 | return scnprintf(hpp->buf, hpp->size, " user "); | 86 | const char *fmt = symbol_conf.field_sep ? "%s" : "%6s"; |
| 87 | |||
| 88 | return scnprintf(hpp->buf, hpp->size, fmt, "user"); | ||
| 83 | } | 89 | } |
| 84 | 90 | ||
| 85 | static int hpp__width_overhead_us(struct perf_hpp *hpp __used) | 91 | static int hpp__width_overhead_us(struct perf_hpp *hpp __used) |
| @@ -96,7 +102,9 @@ static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 96 | static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) | 102 | static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) |
| 97 | { | 103 | { |
| 98 | double percent = 100.0 * he->period_us / hpp->total_period; | 104 | double percent = 100.0 * he->period_us / hpp->total_period; |
| 99 | return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); | 105 | const char *fmt = symbol_conf.field_sep ? "%.2f" : "%5.2f%%"; |
| 106 | |||
| 107 | return scnprintf(hpp->buf, hpp->size, fmt, percent); | ||
| 100 | } | 108 | } |
| 101 | 109 | ||
| 102 | static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp) | 110 | static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp) |
| @@ -120,7 +128,9 @@ static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, | |||
| 120 | struct hist_entry *he) | 128 | struct hist_entry *he) |
| 121 | { | 129 | { |
| 122 | double percent = 100.0 * he->period_guest_sys / hpp->total_period; | 130 | double percent = 100.0 * he->period_guest_sys / hpp->total_period; |
| 123 | return scnprintf(hpp->buf, hpp->size, " %5.2f%% ", percent); | 131 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%% "; |
| 132 | |||
| 133 | return scnprintf(hpp->buf, hpp->size, fmt, percent); | ||
| 124 | } | 134 | } |
| 125 | 135 | ||
| 126 | static int hpp__header_overhead_guest_us(struct perf_hpp *hpp) | 136 | static int hpp__header_overhead_guest_us(struct perf_hpp *hpp) |
| @@ -144,12 +154,16 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, | |||
| 144 | struct hist_entry *he) | 154 | struct hist_entry *he) |
| 145 | { | 155 | { |
| 146 | double percent = 100.0 * he->period_guest_us / hpp->total_period; | 156 | double percent = 100.0 * he->period_guest_us / hpp->total_period; |
| 147 | return scnprintf(hpp->buf, hpp->size, " %5.2f%% ", percent); | 157 | const char *fmt = symbol_conf.field_sep ? "%.2f" : " %5.2f%% "; |
| 158 | |||
| 159 | return scnprintf(hpp->buf, hpp->size, fmt, percent); | ||
| 148 | } | 160 | } |
| 149 | 161 | ||
| 150 | static int hpp__header_samples(struct perf_hpp *hpp) | 162 | static int hpp__header_samples(struct perf_hpp *hpp) |
| 151 | { | 163 | { |
| 152 | return scnprintf(hpp->buf, hpp->size, " Samples "); | 164 | const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; |
| 165 | |||
| 166 | return scnprintf(hpp->buf, hpp->size, fmt, "Samples"); | ||
| 153 | } | 167 | } |
| 154 | 168 | ||
| 155 | static int hpp__width_samples(struct perf_hpp *hpp __used) | 169 | static int hpp__width_samples(struct perf_hpp *hpp __used) |
| @@ -159,12 +173,16 @@ static int hpp__width_samples(struct perf_hpp *hpp __used) | |||
| 159 | 173 | ||
| 160 | static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) | 174 | static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) |
| 161 | { | 175 | { |
| 162 | return scnprintf(hpp->buf, hpp->size, "%11" PRIu64, he->nr_events); | 176 | const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64; |
| 177 | |||
| 178 | return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events); | ||
| 163 | } | 179 | } |
| 164 | 180 | ||
| 165 | static int hpp__header_period(struct perf_hpp *hpp) | 181 | static int hpp__header_period(struct perf_hpp *hpp) |
| 166 | { | 182 | { |
| 167 | return scnprintf(hpp->buf, hpp->size, " Period "); | 183 | const char *fmt = symbol_conf.field_sep ? "%s" : "%12s"; |
| 184 | |||
| 185 | return scnprintf(hpp->buf, hpp->size, fmt, "Period"); | ||
| 168 | } | 186 | } |
| 169 | 187 | ||
| 170 | static int hpp__width_period(struct perf_hpp *hpp __used) | 188 | static int hpp__width_period(struct perf_hpp *hpp __used) |
| @@ -174,12 +192,16 @@ static int hpp__width_period(struct perf_hpp *hpp __used) | |||
| 174 | 192 | ||
| 175 | static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) | 193 | static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) |
| 176 | { | 194 | { |
| 177 | return scnprintf(hpp->buf, hpp->size, "%12" PRIu64, he->period); | 195 | const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; |
| 196 | |||
| 197 | return scnprintf(hpp->buf, hpp->size, fmt, he->period); | ||
| 178 | } | 198 | } |
| 179 | 199 | ||
| 180 | static int hpp__header_delta(struct perf_hpp *hpp) | 200 | static int hpp__header_delta(struct perf_hpp *hpp) |
| 181 | { | 201 | { |
| 182 | return scnprintf(hpp->buf, hpp->size, " Delta "); | 202 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7s"; |
| 203 | |||
| 204 | return scnprintf(hpp->buf, hpp->size, fmt, "Delta"); | ||
| 183 | } | 205 | } |
| 184 | 206 | ||
| 185 | static int hpp__width_delta(struct perf_hpp *hpp __used) | 207 | static int hpp__width_delta(struct perf_hpp *hpp __used) |
| @@ -193,7 +215,8 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 193 | u64 old_total, new_total; | 215 | u64 old_total, new_total; |
| 194 | double old_percent = 0, new_percent = 0; | 216 | double old_percent = 0, new_percent = 0; |
| 195 | double diff; | 217 | double diff; |
| 196 | char buf[32]; | 218 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; |
| 219 | char buf[32] = " "; | ||
| 197 | 220 | ||
| 198 | old_total = pair_hists->stats.total_period; | 221 | old_total = pair_hists->stats.total_period; |
| 199 | if (old_total > 0 && he->pair) | 222 | if (old_total > 0 && he->pair) |
| @@ -204,11 +227,10 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) | |||
| 204 | new_percent = 100.0 * he->period / new_total; | 227 | new_percent = 100.0 * he->period / new_total; |
| 205 | 228 | ||
| 206 | diff = new_percent - old_percent; | 229 | diff = new_percent - old_percent; |
| 207 | if (fabs(diff) < 0.01) | 230 | if (fabs(diff) >= 0.01) |
| 208 | return scnprintf(hpp->buf, hpp->size, " "); | 231 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); |
| 209 | 232 | ||
| 210 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); | 233 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
| 211 | return scnprintf(hpp->buf, hpp->size, "%7.7s", buf); | ||
| 212 | } | 234 | } |
| 213 | 235 | ||
| 214 | static int hpp__header_displ(struct perf_hpp *hpp) | 236 | static int hpp__header_displ(struct perf_hpp *hpp) |
| @@ -223,13 +245,13 @@ static int hpp__width_displ(struct perf_hpp *hpp __used) | |||
| 223 | 245 | ||
| 224 | static int hpp__entry_displ(struct perf_hpp *hpp, struct hist_entry *he __used) | 246 | static int hpp__entry_displ(struct perf_hpp *hpp, struct hist_entry *he __used) |
| 225 | { | 247 | { |
| 226 | char buf[32]; | 248 | const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s"; |
| 249 | char buf[32] = " "; | ||
| 227 | 250 | ||
| 228 | if (!hpp->displacement) | 251 | if (hpp->displacement) |
| 229 | return scnprintf(hpp->buf, hpp->size, " "); | 252 | scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement); |
| 230 | 253 | ||
| 231 | scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement); | 254 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
| 232 | return scnprintf(hpp->buf, hpp->size, "%6.6s", buf); | ||
| 233 | } | 255 | } |
| 234 | 256 | ||
| 235 | #define HPP__COLOR_PRINT_FNS(_name) \ | 257 | #define HPP__COLOR_PRINT_FNS(_name) \ |
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 4228b4c6b72d..882461a42830 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
| @@ -319,11 +319,12 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, | |||
| 319 | .displacement = displacement, | 319 | .displacement = displacement, |
| 320 | .ptr = pair_hists, | 320 | .ptr = pair_hists, |
| 321 | }; | 321 | }; |
| 322 | bool color = !symbol_conf.field_sep; | ||
| 322 | 323 | ||
| 323 | if (size == 0 || size > sizeof(bf)) | 324 | if (size == 0 || size > sizeof(bf)) |
| 324 | size = hpp.size = sizeof(bf); | 325 | size = hpp.size = sizeof(bf); |
| 325 | 326 | ||
| 326 | ret = hist_entry__period_snprintf(&hpp, he, true); | 327 | ret = hist_entry__period_snprintf(&hpp, he, color); |
| 327 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); | 328 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); |
| 328 | 329 | ||
| 329 | ret = fprintf(fp, "%s\n", bf); | 330 | ret = fprintf(fp, "%s\n", bf); |
