Commit 9754c4f9 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf hists: Add color overhead for stdio output buffer

Following commit tightened up the buffer size for output to strict width
of used format columns:

  99cf666c perf hists: Fix formatting of long symbol names

This works fine until you hit color overhead output which places extra
bytes into output buffer. We need to account for color overhead in the
output buffer. Adding maximum color byte size to the output buffer size.
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1382700293-1803-1-git-send-email-jolsa@redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d17cccbe
...@@ -315,8 +315,7 @@ static inline void advance_hpp(struct perf_hpp *hpp, int inc) ...@@ -315,8 +315,7 @@ static inline void advance_hpp(struct perf_hpp *hpp, int inc)
} }
static int hist_entry__period_snprintf(struct perf_hpp *hpp, static int hist_entry__period_snprintf(struct perf_hpp *hpp,
struct hist_entry *he, struct hist_entry *he)
bool color)
{ {
const char *sep = symbol_conf.field_sep; const char *sep = symbol_conf.field_sep;
struct perf_hpp_fmt *fmt; struct perf_hpp_fmt *fmt;
...@@ -338,7 +337,7 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp, ...@@ -338,7 +337,7 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp,
} else } else
first = false; first = false;
if (color && fmt->color) if (perf_hpp__use_color() && fmt->color)
ret = fmt->color(fmt, hpp, he); ret = fmt->color(fmt, hpp, he);
else else
ret = fmt->entry(fmt, hpp, he); ret = fmt->entry(fmt, hpp, he);
...@@ -358,12 +357,11 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ...@@ -358,12 +357,11 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
.buf = bf, .buf = bf,
.size = size, .size = size,
}; };
bool color = !symbol_conf.field_sep;
if (size == 0 || size > bfsz) if (size == 0 || size > bfsz)
size = hpp.size = bfsz; size = hpp.size = bfsz;
ret = hist_entry__period_snprintf(&hpp, he, color); ret = hist_entry__period_snprintf(&hpp, he);
hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
ret = fprintf(fp, "%s\n", bf); ret = fprintf(fp, "%s\n", bf);
...@@ -482,6 +480,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, ...@@ -482,6 +480,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
print_entries: print_entries:
linesz = hists__sort_list_width(hists) + 3 + 1; linesz = hists__sort_list_width(hists) + 3 + 1;
linesz += perf_hpp__color_overhead();
line = malloc(linesz); line = malloc(linesz);
if (line == NULL) { if (line == NULL) {
ret = -1; ret = -1;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <pthread.h> #include <pthread.h>
#include "callchain.h" #include "callchain.h"
#include "header.h" #include "header.h"
#include "color.h"
extern struct callchain_param callchain_param; extern struct callchain_param callchain_param;
...@@ -175,6 +176,18 @@ void perf_hpp__init(void); ...@@ -175,6 +176,18 @@ void perf_hpp__init(void);
void perf_hpp__column_register(struct perf_hpp_fmt *format); void perf_hpp__column_register(struct perf_hpp_fmt *format);
void perf_hpp__column_enable(unsigned col); void perf_hpp__column_enable(unsigned col);
static inline size_t perf_hpp__use_color(void)
{
return !symbol_conf.field_sep;
}
static inline size_t perf_hpp__color_overhead(void)
{
return perf_hpp__use_color() ?
(COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
: 0;
}
struct perf_evlist; struct perf_evlist;
struct hist_browser_timer { struct hist_browser_timer {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment