diff options
| -rw-r--r-- | tools/perf/ui/stdio/hist.c | 9 | ||||
| -rw-r--r-- | tools/perf/util/hist.h | 13 |
2 files changed, 17 insertions, 5 deletions
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 194e2f42ff5d..6c152686e837 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
| @@ -315,8 +315,7 @@ static inline void advance_hpp(struct perf_hpp *hpp, int inc) | |||
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | static int hist_entry__period_snprintf(struct perf_hpp *hpp, | 317 | static int hist_entry__period_snprintf(struct perf_hpp *hpp, |
| 318 | struct hist_entry *he, | 318 | struct hist_entry *he) |
| 319 | bool color) | ||
| 320 | { | 319 | { |
| 321 | const char *sep = symbol_conf.field_sep; | 320 | const char *sep = symbol_conf.field_sep; |
| 322 | struct perf_hpp_fmt *fmt; | 321 | struct perf_hpp_fmt *fmt; |
| @@ -338,7 +337,7 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp, | |||
| 338 | } else | 337 | } else |
| 339 | first = false; | 338 | first = false; |
| 340 | 339 | ||
| 341 | if (color && fmt->color) | 340 | if (perf_hpp__use_color() && fmt->color) |
| 342 | ret = fmt->color(fmt, hpp, he); | 341 | ret = fmt->color(fmt, hpp, he); |
| 343 | else | 342 | else |
| 344 | ret = fmt->entry(fmt, hpp, he); | 343 | ret = fmt->entry(fmt, hpp, he); |
| @@ -358,12 +357,11 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, | |||
| 358 | .buf = bf, | 357 | .buf = bf, |
| 359 | .size = size, | 358 | .size = size, |
| 360 | }; | 359 | }; |
| 361 | bool color = !symbol_conf.field_sep; | ||
| 362 | 360 | ||
| 363 | if (size == 0 || size > bfsz) | 361 | if (size == 0 || size > bfsz) |
| 364 | size = hpp.size = bfsz; | 362 | size = hpp.size = bfsz; |
| 365 | 363 | ||
| 366 | ret = hist_entry__period_snprintf(&hpp, he, color); | 364 | ret = hist_entry__period_snprintf(&hpp, he); |
| 367 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); | 365 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); |
| 368 | 366 | ||
| 369 | ret = fprintf(fp, "%s\n", bf); | 367 | ret = fprintf(fp, "%s\n", bf); |
| @@ -482,6 +480,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, | |||
| 482 | 480 | ||
| 483 | print_entries: | 481 | print_entries: |
| 484 | linesz = hists__sort_list_width(hists) + 3 + 1; | 482 | linesz = hists__sort_list_width(hists) + 3 + 1; |
| 483 | linesz += perf_hpp__color_overhead(); | ||
| 485 | line = malloc(linesz); | 484 | line = malloc(linesz); |
| 486 | if (line == NULL) { | 485 | if (line == NULL) { |
| 487 | ret = -1; | 486 | ret = -1; |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 1329b6b6ffe6..ce8dc61ce2c3 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <pthread.h> | 5 | #include <pthread.h> |
| 6 | #include "callchain.h" | 6 | #include "callchain.h" |
| 7 | #include "header.h" | 7 | #include "header.h" |
| 8 | #include "color.h" | ||
| 8 | 9 | ||
| 9 | extern struct callchain_param callchain_param; | 10 | extern struct callchain_param callchain_param; |
| 10 | 11 | ||
| @@ -175,6 +176,18 @@ void perf_hpp__init(void); | |||
| 175 | void perf_hpp__column_register(struct perf_hpp_fmt *format); | 176 | void perf_hpp__column_register(struct perf_hpp_fmt *format); |
| 176 | void perf_hpp__column_enable(unsigned col); | 177 | void perf_hpp__column_enable(unsigned col); |
| 177 | 178 | ||
| 179 | static inline size_t perf_hpp__use_color(void) | ||
| 180 | { | ||
| 181 | return !symbol_conf.field_sep; | ||
| 182 | } | ||
| 183 | |||
| 184 | static inline size_t perf_hpp__color_overhead(void) | ||
| 185 | { | ||
| 186 | return perf_hpp__use_color() ? | ||
| 187 | (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX | ||
| 188 | : 0; | ||
| 189 | } | ||
| 190 | |||
| 178 | struct perf_evlist; | 191 | struct perf_evlist; |
| 179 | 192 | ||
| 180 | struct hist_browser_timer { | 193 | struct hist_browser_timer { |
