diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-09-05 14:39:12 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-09-05 15:18:28 -0400 |
| commit | 99cf666c5c0cd4f4c3e4155e7b01cf593d71d60e (patch) | |
| tree | 5a0d8e427ba37dfb438062c2fa748bb5abad258d /tools/perf/ui/stdio | |
| parent | 98be6966ed7ed977881305aff5a1bfb305090f43 (diff) | |
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: Stephane Eranian <eranian@google.com>
Tested-by: Stephane 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/stdio')
| -rw-r--r-- | tools/perf/ui/stdio/hist.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 5b4fb330f656..194e2f42ff5d 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
| @@ -350,9 +350,9 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp, | |||
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, | 352 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, |
| 353 | struct hists *hists, FILE *fp) | 353 | struct hists *hists, |
| 354 | char *bf, size_t bfsz, FILE *fp) | ||
| 354 | { | 355 | { |
| 355 | char bf[512]; | ||
| 356 | int ret; | 356 | int ret; |
| 357 | struct perf_hpp hpp = { | 357 | struct perf_hpp hpp = { |
| 358 | .buf = bf, | 358 | .buf = bf, |
| @@ -360,8 +360,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, | |||
| 360 | }; | 360 | }; |
| 361 | bool color = !symbol_conf.field_sep; | 361 | bool color = !symbol_conf.field_sep; |
| 362 | 362 | ||
| 363 | if (size == 0 || size > sizeof(bf)) | 363 | if (size == 0 || size > bfsz) |
| 364 | size = hpp.size = sizeof(bf); | 364 | size = hpp.size = bfsz; |
| 365 | 365 | ||
| 366 | ret = hist_entry__period_snprintf(&hpp, he, color); | 366 | ret = hist_entry__period_snprintf(&hpp, he, color); |
| 367 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); | 367 | 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 | .ptr = hists_to_evsel(hists), | 392 | .ptr = hists_to_evsel(hists), |
| 393 | }; | 393 | }; |
| 394 | bool first = true; | 394 | bool first = true; |
| 395 | size_t linesz; | ||
| 396 | char *line = NULL; | ||
| 395 | 397 | ||
| 396 | init_rem_hits(); | 398 | init_rem_hits(); |
| 397 | 399 | ||
| @@ -479,6 +481,13 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, | |||
| 479 | goto out; | 481 | goto out; |
| 480 | 482 | ||
| 481 | print_entries: | 483 | print_entries: |
| 484 | linesz = hists__sort_list_width(hists) + 3 + 1; | ||
| 485 | line = malloc(linesz); | ||
| 486 | if (line == NULL) { | ||
| 487 | ret = -1; | ||
| 488 | goto out; | ||
| 489 | } | ||
| 490 | |||
| 482 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | 491 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 483 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 492 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 484 | float percent = h->stat.period * 100.0 / | 493 | float percent = h->stat.period * 100.0 / |
| @@ -490,10 +499,10 @@ print_entries: | |||
| 490 | if (percent < min_pcnt) | 499 | if (percent < min_pcnt) |
| 491 | continue; | 500 | continue; |
| 492 | 501 | ||
| 493 | ret += hist_entry__fprintf(h, max_cols, hists, fp); | 502 | ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp); |
| 494 | 503 | ||
| 495 | if (max_rows && ++nr_rows >= max_rows) | 504 | if (max_rows && ++nr_rows >= max_rows) |
| 496 | goto out; | 505 | break; |
| 497 | 506 | ||
| 498 | if (h->ms.map == NULL && verbose > 1) { | 507 | if (h->ms.map == NULL && verbose > 1) { |
| 499 | __map_groups__fprintf_maps(&h->thread->mg, | 508 | __map_groups__fprintf_maps(&h->thread->mg, |
| @@ -501,6 +510,8 @@ print_entries: | |||
| 501 | fprintf(fp, "%.10s end\n", graph_dotted_line); | 510 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 502 | } | 511 | } |
| 503 | } | 512 | } |
| 513 | |||
| 514 | free(line); | ||
| 504 | out: | 515 | out: |
| 505 | free(rem_sq_bracket); | 516 | free(rem_sq_bracket); |
| 506 | 517 | ||
