Skip to content

Commit 678a500

Browse files
namhyungolsajiri
authored andcommitted
perf hists: Reset width of output fields with header length
Some fields missed to set default column length so it broke align in --stdio output. Add perf_hpp__reset_width() to set it to a sane default value. Note that this change will ignore -w/--column-widths option for now. Before: $ perf report -F cpu,comm,overhead --stdio ... # CPU Command Overhead # ............... ........ # 0 firefox 2.65% 0 kworker/0:0 1.45% 0 swapper 5.52% 0 synergys 0.92% 1 firefox 4.54% After: # CPU Command Overhead # ... ............... ........ # 0 firefox 2.65% 0 kworker/0:0 1.45% 0 swapper 5.52% 0 synergys 0.92% 1 firefox 4.54% Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/1400480762-22852-17-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent e67d49a commit 678a500

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

‎tools/perf/ui/stdio/hist.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,10 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
369369
int max_cols, float min_pcnt, FILE *fp)
370370
{
371371
struct perf_hpp_fmt *fmt;
372-
struct sort_entry *se;
373372
struct rb_node *nd;
374373
size_t ret = 0;
375374
unsigned int width;
376375
const char *sep = symbol_conf.field_sep;
377-
const char *col_width = symbol_conf.col_width_list_str;
378376
int nr_rows = 0;
379377
char bf[96];
380378
struct perf_hpp dummy_hpp = {
@@ -387,22 +385,9 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
387385

388386
init_rem_hits();
389387

390-
list_for_each_entry(se, &hist_entry__sort_list, list) {
391-
if (se->elide)
392-
continue;
393-
width = strlen(se->se_header);
394-
if (symbol_conf.col_width_list_str) {
395-
if (col_width) {
396-
hists__set_col_len(hists, se->se_width_idx,
397-
atoi(col_width));
398-
col_width = strchr(col_width, ',');
399-
if (col_width)
400-
++col_width;
401-
}
402-
}
403-
if (!hists__new_col_len(hists, se->se_width_idx, width))
404-
width = hists__col_len(hists, se->se_width_idx);
405-
}
388+
389+
perf_hpp__for_each_format(fmt)
390+
perf_hpp__reset_width(fmt, hists);
406391

407392
if (!show_header)
408393
goto print_entries;

‎tools/perf/util/hist.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void perf_hpp__append_sort_keys(void);
202202
bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
203203
bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
204204
bool perf_hpp__should_skip(struct perf_hpp_fmt *format);
205+
void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
205206

206207
typedef u64 (*hpp_field_fn)(struct hist_entry *he);
207208
typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);

‎tools/perf/util/sort.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,18 @@ bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
10891089
return hse_a->se == hse_b->se;
10901090
}
10911091

1092+
void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
1093+
{
1094+
struct hpp_sort_entry *hse;
1095+
1096+
if (!perf_hpp__is_sort_entry(fmt))
1097+
return;
1098+
1099+
hse = container_of(fmt, struct hpp_sort_entry, hpp);
1100+
hists__new_col_len(hists, hse->se->se_width_idx,
1101+
strlen(hse->se->se_header));
1102+
}
1103+
10921104
static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
10931105
struct perf_evsel *evsel)
10941106
{

0 commit comments

Comments
 (0)