perf hists: Fix formatting of long symbol names

We had a hardcoded buffer for formatting histogram entries, truncating
long symbol names (C++ anyone?).

Fix it by using hists__sort_list_width() before formatting the first
histogram entry to calculate the max lenght needed by traversing the
overheads and columns lists (sort order).
Reported-by: NStephane Eranian <eranian@google.com>
Tested-by: NStephane Eranian <eranian@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-vdfkkyfdp8rboh7j9344o3ss@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 98be6966
...@@ -350,9 +350,9 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp, ...@@ -350,9 +350,9 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp,
} }
static int hist_entry__fprintf(struct hist_entry *he, size_t size, static int hist_entry__fprintf(struct hist_entry *he, size_t size,
struct hists *hists, FILE *fp) struct hists *hists,
char *bf, size_t bfsz, FILE *fp)
{ {
char bf[512];
int ret; int ret;
struct perf_hpp hpp = { struct perf_hpp hpp = {
.buf = bf, .buf = bf,
...@@ -360,8 +360,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ...@@ -360,8 +360,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
}; };
bool color = !symbol_conf.field_sep; bool color = !symbol_conf.field_sep;
if (size == 0 || size > sizeof(bf)) if (size == 0 || size > bfsz)
size = hpp.size = sizeof(bf); size = hpp.size = bfsz;
ret = hist_entry__period_snprintf(&hpp, he, color); ret = hist_entry__period_snprintf(&hpp, he, color);
hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
...@@ -392,6 +392,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, ...@@ -392,6 +392,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
.ptr = hists_to_evsel(hists), .ptr = hists_to_evsel(hists),
}; };
bool first = true; bool first = true;
size_t linesz;
char *line = NULL;
init_rem_hits(); init_rem_hits();
...@@ -479,6 +481,13 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, ...@@ -479,6 +481,13 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
goto out; goto out;
print_entries: print_entries:
linesz = hists__sort_list_width(hists) + 3 + 1;
line = malloc(linesz);
if (line == NULL) {
ret = -1;
goto out;
}
for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
float percent = h->stat.period * 100.0 / float percent = h->stat.period * 100.0 /
...@@ -490,10 +499,10 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, ...@@ -490,10 +499,10 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
if (percent < min_pcnt) if (percent < min_pcnt)
continue; continue;
ret += hist_entry__fprintf(h, max_cols, hists, fp); ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp);
if (max_rows && ++nr_rows >= max_rows) if (max_rows && ++nr_rows >= max_rows)
goto out; break;
if (h->ms.map == NULL && verbose > 1) { if (h->ms.map == NULL && verbose > 1) {
__map_groups__fprintf_maps(&h->thread->mg, __map_groups__fprintf_maps(&h->thread->mg,
...@@ -501,6 +510,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, ...@@ -501,6 +510,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
fprintf(fp, "%.10s end\n", graph_dotted_line); fprintf(fp, "%.10s end\n", graph_dotted_line);
} }
} }
free(line);
out: out:
free(rem_sq_bracket); free(rem_sq_bracket);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册