perf tools: Honor column width setting (v2)
Namhyung Kim
maintainercover perf tools: Honor column width setting (v2)
Hello,
This patchset is to control perf report/top output column width by -w/--column-widths option so that it can fit into the terminal size. The -w option is there for perf report but it ignored by recent output field changed due to some reason. This patchset fixes it and supports perf top also.
This is sometimes useful if your terminal is small and there's some C++ applications which have amazingly long symbol names. Without this patchset user might not see those symbols on TUI, since it maps left/right arrow keys to other functions.
The -w option sets column width starting from the first column (overhead or optional overhead_children column unless -F option is given). It doesn't make sense to limit those overhead columns so it's not a hard-limit for them. But it *is* a hard-limit for other columns such as comm, dso, symbol, and so on. One can use 0 not to limit/force a width for those columns.
For example:
$ perf report --stdio -s comm,dso
...
# Overhead Command Shared Object
# ........ ............... .....................................................
#
71.08% gnome-shell perf-1497.map
9.23% gnome-shell swrast_dri.so
3.99% Xorg [unknown]
3.18% Xorg [kernel.kallsyms]
2.93% gnome-shell [kernel.kallsyms]
2.41% swapper [kernel.kallsyms]
1.55% synergys libpthread-2.15.so
1.08% synergys synergys
0.68% systemd-journal [kernel.kallsyms]
0.59% synergys libstdc++.so.6.0.17
0.58% gnome-shell libc-2.15.so
0.54% kworker/0:2 [kernel.kallsyms]
0.20% systemd-journal [unknown]
0.19% gnome-shell libclutter-1.0.so.0.1000.8.#prelink#.1kh1we (deleted)
0.18% firefox libxul.so (deleted)
0.17% gnome-shell libcogl.so.9.1.1.#prelink#.ZL3fn1 (deleted)
0.14% firefox [kernel.kallsyms]
0.14% gnome-shell libgobject-2.0.so.0.3200.4
0.13% gnome-shell libpthread-2.15.so
0.11% synergys [kernel.kallsyms]
0.10% perf [kernel.kallsyms] $ perf report --stdio -s comm,dso -w 0,10,20 # 0 means no limit
...
# Overhead Command Shared Object
# ........ .......... ....................
#
71.08% gnome-shel perf-1497.map
9.23% gnome-shel swrast_dri.so
3.99% Xorg [unknown]
3.18% Xorg [kernel.kallsyms]
2.93% gnome-shel [kernel.kallsyms]
2.41% swapper [kernel.kallsyms]
1.55% synergys libpthread-2.15.so
1.08% synergys synergys
0.68% systemd-jo [kernel.kallsyms]
0.59% synergys libstdc++.so.6.0.17
0.58% gnome-shel libc-2.15.so
0.54% kworker/0: [kernel.kallsyms]
0.20% systemd-jo [unknown]
0.19% gnome-shel libclutter-1.0.so.0.
0.18% firefox libxul.so (deleted)
0.17% gnome-shel libcogl.so.9.1.1.#pr
0.14% firefox [kernel.kallsyms]
0.14% gnome-shel libgobject-2.0.so.0.
0.13% gnome-shel libpthread-2.15.so
0.11% synergys [kernel.kallsyms]
0.10% perf [kernel.kallsyms] * changes in v2:
- fix TUI alignment when no header is shown (Jiri)
- change printing order of pid sort key (Jiri)
You can also get this from 'perf/width-v2' branch on my tree
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Thanks,
Namhyung
Namhyung Kim (7):
perf tools: Left-align output contents
perf tools: Make __hpp__fmt() receive an additional len argument perf tools: Save column length in perf_hpp_fmt
perf report: Honor column width setting
perf top: Add -w option for setting column width
perf tools: Add name field into perf_hpp_fmt
perf tools: Fix column alignment when headers aren't shown on TUI
tools/perf/Documentation/perf-report.txt | 2 +- tools/perf/Documentation/perf-top.txt | 6 + tools/perf/builtin-top.c | 3 + tools/perf/ui/browsers/hists.c | 36 ++-- tools/perf/ui/gtk/hists.c | 18 +- tools/perf/ui/hist.c | 275 +++++++++++++++++++------------ tools/perf/ui/stdio/hist.c | 4 +- tools/perf/util/color.c | 16 ++ tools/perf/util/color.h | 1 + tools/perf/util/hist.h | 17 +- tools/perf/util/sort.c | 55 ++++--- 11 files changed, 279 insertions(+), 154 deletions(-)
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 1/7 perf tools: Left-align output contents
Now perf left-aligns column headers but the contents does not. It should have same alignment. This requires a change in pid sort key - it consists of two part (pid and comm). As length of comm can be vary it'd be better to change the order of them.
Thanks to Jiri Olsa for pointing this out.
--- tools/perf/util/sort.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/sort.c +5 -5
@@ -70,12 +70,12 @@ static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) {const char *comm =thread__comm_str (he->thread); -return repsep_snprintf (bf, size,"%*s:%5d" , width -6 , - comm ?:"" , he->thread->tid); +return repsep_snprintf (bf, size,"%5d:%-*s" , he->thread->tid, + width -6 , comm ?:"" ); }struct sort_entry sort_thread = { - .se_header ="Command: Pid" , + .se_header =" Pid:Command" , .se_cmp = sort__thread_cmp, .se_snprintf = hist_entry__thread_snprintf, .se_width_idx =HISTC_THREAD ,
@@ -106,7 +106,7 @@ sort__comm_sort(struct hist_entry *left, struct hist_entry *right)static int hist_entry__comm_snprintf (struct hist_entry *he,char *bf,size_t size,unsigned int width) { -return repsep_snprintf (bf, size,"%*s" , width,comm__str (he->comm)); +return repsep_snprintf (bf, size,"%-*s" , width,comm__str (he->comm)); }struct sort_entry sort_comm = {
@@ -305,7 +305,7 @@ static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width __maybe_unused) { -return repsep_snprintf (bf, size,"%s" , he->srcline); +return repsep_snprintf (bf, size,"%-s" , he->srcline); }struct sort_entry sort_srcline = {
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 2/7 perf tools: Make __hpp__fmt() receive an additional len argument
In reply to Namhyung KimSo that it can properly handle alignment requirements later. To do that, add percent_color_len_snprintf() fucntion to help coloring of overhead columns.
--- tools/perf/ui/browsers/hists.c | 14 ++++++++------ tools/perf/ui/gtk/hists.c | 8 +++++--- tools/perf/ui/hist.c | 43 +++++++++++++++++++++--------------------- tools/perf/util/color.c | 16 ++++++++++++++++ tools/perf/util/color.h | 1 + tools/perf/util/hist.h | 4 ++-- 6 files changed, 54 insertions(+), 32 deletions(-)
tools/perf/ui/browsers/hists.c +8 -6
@@ -653,17 +653,18 @@ struct hpp_arg {static int __hpp__slsmg_color_printf (struct perf_hpp *hpp,const char *fmt, ...) {struct hpp_arg *arg = hpp->ptr; -int ret; +int ret, len;va_list args;double percent;va_start (args, fmt); + len =va_arg (args, int); percent =va_arg (args, double);va_end (args);ui_browser__set_percent_color (arg->b, percent, arg->current_entry); - ret =scnprintf (hpp->buf, hpp->size, fmt, percent); + ret =scnprintf (hpp->buf, hpp->size, fmt, len, percent);slsmg_printf ("%s" , hpp->buf);advance_hpp (hpp, ret);
@@ -681,7 +682,7 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - return __hpp__fmt(hpp, he, __hpp_get_##_field, " %6.2f%%", \ + return __hpp__fmt(hpp, he, __hpp_get_##_field, " %*.2f%%", 6, \__hpp__slsmg_color_printf ,true ); \ }
@@ -697,13 +698,14 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ struct hist_entry *he) \ { \if (!symbol_conf.cumulate_callchain) { \ -int ret =scnprintf (hpp->buf, hpp->size,"%8s" ,"N/A" ); \ +int ret =scnprintf (hpp->buf, hpp->size, \ +"%*s" ,8 ,"N/A" ); \slsmg_printf ("%s" , hpp->buf); \ \return ret; \ } \ - return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %6.2f%%", \ - __hpp__slsmg_color_printf, true); \ + return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %*.2f%%", \ +6 , __hpp__slsmg_color_printf, true); \ }__HPP_COLOR_PERCENT_FN (overhead, period)
tools/perf/ui/gtk/hists.c +5 -3
@@ -11,6 +11,7 @@static int __percent_color_snprintf (struct perf_hpp *hpp,const char *fmt, ...) {int ret =0 ; +int len;va_list args;double percent;const char *markup;
@@ -18,6 +19,7 @@ static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)size_t size = hpp->size;va_start (args, fmt); + len =va_arg (args, int); percent =va_arg (args, double);va_end (args);
@@ -25,7 +27,7 @@ static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)if (markup) ret +=scnprintf (buf, size, markup); - ret +=scnprintf (buf + ret, size - ret, fmt, percent); + ret +=scnprintf (buf + ret, size - ret, fmt, len, percent);if (markup) ret +=scnprintf (buf + ret, size - ret,"</span>" );
@@ -43,7 +45,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ + return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \__percent_color_snprintf ,true ); \ }
@@ -57,7 +59,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ + return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \__percent_color_snprintf ,true ); \ }
tools/perf/ui/hist.c +22 -21
130 lines not on this page · raw message
tools/perf/util/color.c +16 -0
@@ -335,3 +335,19 @@ int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...)va_end (args);return value_color_snprintf (bf, size, fmt, percent); } + +int percent_color_len_snprintf (char *bf,size_t size,const char *fmt, ...) +{ +va_list args; +int len; +double percent; +const char *color; + +va_start (args, fmt); + len =va_arg (args, int); + percent =va_arg (args, double); +va_end (args); + + color =get_percent_color (percent); +return color_snprintf (bf, size, color, fmt, len, percent); +}
tools/perf/util/color.h +1 -0
@@ -41,6 +41,7 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);int color_fwrite_lines (FILE *fp,const char *color,size_t count,const char *buf);int value_color_snprintf (char *bf,size_t size,const char *fmt,double value);int percent_color_snprintf (char *bf,size_t size,const char *fmt, ...); +int percent_color_len_snprintf (char *bf,size_t size,const char *fmt, ...);int percent_color_fprintf (FILE *fp,const char *fmt,double percent);const char *get_percent_color (double percent);
tools/perf/util/hist.h +2 -2
@@ -267,10 +267,10 @@ typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);typedef int (*hpp_snprint_fn )(struct perf_hpp *hpp,const char *fmt, ...);int __hpp__fmt (struct perf_hpp *hpp,struct hist_entry *he, -hpp_field_fn get_field,const char *fmt, +hpp_field_fn get_field,const char *fmt,int len,hpp_snprint_fn print_fn,bool fmt_percent);int __hpp__fmt_acc (struct perf_hpp *hpp,struct hist_entry *he, -hpp_field_fn get_field,const char *fmt, +hpp_field_fn get_field,const char *fmt,int len,hpp_snprint_fn print_fn,bool fmt_percent);static inline void advance_hpp (struct perf_hpp *hpp,int inc)
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 3/7 perf tools: Save column length in perf_hpp_fmt
In reply to Namhyung KimSave column length in the hpp format and pass it to print functions. This is a preparation for users to control column width in the output.
--- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/hist.c | 135 +++++++++++++++++++++++++++-------------- tools/perf/util/hist.h | 2 + tools/perf/util/sort.c | 3 +- 4 files changed, 94 insertions(+), 48 deletions(-)
tools/perf/ui/browsers/hists.c +1 -1
@@ -849,7 +849,7 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)if (perf_hpp__should_skip (fmt))continue ; -/* We need to add the length of the columns header. */ +/* We need to ensure length of the columns header. */ perf_hpp__reset_width (fmt, hists); ret = fmt->header (fmt, &dummy_hpp,hists_to_evsel (hists));
tools/perf/ui/hist.c +89 -46
226 lines not on this page · raw message
tools/perf/util/hist.h +2 -0
@@ -207,6 +207,7 @@ struct perf_hpp_fmt {struct list_head list;struct list_head sort_list;bool elide; +int len; };extern struct list_head perf_hpp__list;
@@ -261,6 +262,7 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format) }void perf_hpp__reset_width (struct perf_hpp_fmt *fmt,struct hists *hists); +void perf_hpp__reset_sort_width (struct perf_hpp_fmt *fmt,struct hists *hists);typedef u64 (*hpp_field_fn )(struct hist_entry *he);typedef int (*hpp_callback_fn )(struct perf_hpp *hpp,bool front);
tools/perf/util/sort.c +2 -1
@@ -1194,7 +1194,7 @@ bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)return hse_a->se == hse_b->se; } -void perf_hpp__reset_width (struct perf_hpp_fmt *fmt,struct hists *hists) +void perf_hpp__reset_sort_width (struct perf_hpp_fmt *fmt,struct hists *hists) {struct hpp_sort_entry *hse;
@@ -1265,6 +1265,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)INIT_LIST_HEAD (&hse->hpp.list);INIT_LIST_HEAD (&hse->hpp.sort_list); hse->hpp.elide = false; + hse->hpp.len =0 ;return hse; }
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 4/7 perf report: Honor column width setting
In reply to Namhyung KimSet column width and do not change it if user gives -w/--column-widths option. It'll truncate longer symbols than the width if exists.
--- tools/perf/ui/browsers/hists.c | 23 ++++++++---- tools/perf/ui/gtk/hists.c | 10 ++--- tools/perf/ui/hist.c | 84 +++++++++++++++++++++++++++++------------- tools/perf/ui/stdio/hist.c | 4 +- tools/perf/util/hist.h | 14 ++++--- tools/perf/util/sort.c | 46 ++++++++++++++--------- 6 files changed, 117 insertions(+), 64 deletions(-)
tools/perf/ui/browsers/hists.c +15 -8
@@ -678,12 +678,12 @@ static u64 __hpp_get_##_field(struct hist_entry *he) \ } \ \static int \ -hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ +hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \struct perf_hpp *hpp, \struct hist_entry *he) \ { \ - return __hpp__fmt(hpp, he, __hpp_get_##_field, " %*.2f%%", 6, \ - __hpp__slsmg_color_printf, true); \ + return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \ + __hpp__slsmg_color_printf, true); \ }#define __HPP_COLOR_ACC_PERCENT_FN (_type, _field) \
@@ -693,19 +693,20 @@ static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ } \ \static int \ -hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ +hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \struct perf_hpp *hpp, \struct hist_entry *he) \ { \if (!symbol_conf.cumulate_callchain) { \ +int len = fmt->user_len ?: fmt->len; \int ret =scnprintf (hpp->buf, hpp->size, \ -"%*s" ,8 ,"N/A" ); \ +"%*s" , len,"N/A" ); \slsmg_printf ("%s" , hpp->buf); \ \return ret; \ } \ - return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %*.2f%%", \ -6 , __hpp__slsmg_color_printf, true); \ + return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \ +" %*.2f%%" , __hpp__slsmg_color_printf, true); \ }__HPP_COLOR_PERCENT_FN (overhead, period)
@@ -797,8 +798,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,if (fmt->color) { width -= fmt->color (fmt, &hpp, entry); }else { - width -= fmt->entry (fmt, &hpp, entry); +int ret = fmt->entry (fmt, &hpp, entry); + s[ret] ='\0' ;slsmg_printf ("%s" , s); + + width -= ret; } }
@@ -1549,6 +1553,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,memset (options,0 ,sizeof (options)); +if (symbol_conf.col_width_list_str) +perf_hpp__set_user_width (symbol_conf.col_width_list_str); +while (1 ) {const struct thread *thread =NULL ;const struct dso *dso =NULL ;
tools/perf/ui/gtk/hists.c +5 -5
@@ -41,12 +41,12 @@ static u64 he_get_##_field(struct hist_entry *he) \return he->stat._field; \ } \ \ -static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ +static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt, \struct perf_hpp *hpp, \struct hist_entry *he) \ { \ - return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \ - __percent_color_snprintf, true); \ + return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ + __percent_color_snprintf, true); \ }#define __HPP_COLOR_ACC_PERCENT_FN (_type, _field) \
@@ -59,8 +59,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \ -__percent_color_snprintf ,true ); \ + return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \ +__percent_color_snprintf ,true ); \ }__HPP_COLOR_PERCENT_FN (overhead, period)
tools/perf/ui/hist.c +58 -26
141 lines not on this page · raw message
tools/perf/ui/stdio/hist.c +3 -1
@@ -395,10 +395,12 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,init_rem_hits (); -perf_hpp__for_each_format (fmt)perf_hpp__reset_width (fmt, hists); +if (symbol_conf.col_width_list_str) +perf_hpp__set_user_width (symbol_conf.col_width_list_str); +if (!show_header) goto print_entries;
tools/perf/util/hist.h +8 -6
@@ -208,6 +208,7 @@ struct perf_hpp_fmt {struct list_head sort_list;bool elide;int len; +int user_len; };extern struct list_head perf_hpp__list;
@@ -263,17 +264,18 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format)void perf_hpp__reset_width (struct perf_hpp_fmt *fmt,struct hists *hists);void perf_hpp__reset_sort_width (struct perf_hpp_fmt *fmt,struct hists *hists); +void perf_hpp__set_user_width (const char *width_list_str);typedef u64 (*hpp_field_fn )(struct hist_entry *he);typedef int (*hpp_callback_fn )(struct perf_hpp *hpp,bool front);typedef int (*hpp_snprint_fn )(struct perf_hpp *hpp,const char *fmt, ...); -int __hpp__fmt (struct perf_hpp *hpp,struct hist_entry *he, -hpp_field_fn get_field,const char *fmt,int len, -hpp_snprint_fn print_fn,bool fmt_percent); -int __hpp__fmt_acc (struct perf_hpp *hpp,struct hist_entry *he, -hpp_field_fn get_field,const char *fmt,int len, -hpp_snprint_fn print_fn,bool fmt_percent); +int hpp__fmt (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he,hpp_field_fn get_field, +const char *fmtstr,hpp_snprint_fn print_fn,bool fmt_percent); +int hpp__fmt_acc (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he,hpp_field_fn get_field, +const char *fmtstr,hpp_snprint_fn print_fn,bool fmt_percent);static inline void advance_hpp (struct perf_hpp *hpp,int inc) {
tools/perf/util/sort.c +28 -18
129 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [PATCH 4/7] perf report: Honor column width setting
Quoted 5 lines · Namhyung Kim
Set column width and do not change it if user gives -w/--column-widths option. It'll truncate longer symbols than the width if exists.
Signed-off-by Namhyung Kim <[email protected]>---
SNIP
tools/perf/ui/browsers/hists.c static int hist_browser__show_entry(struct hist_browser *browser, · line 803
Quoted 10 lines
__HPP_COLOR_PERCENT_FN(overhead, period)tools/perf/ui/browsers/hists.c +2
-1@@ -797,8 +798,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,if (fmt->color) { width -= fmt->color (fmt, &hpp, entry); }else { - width -= fmt->entry (fmt, &hpp, entry); +int ret = fmt->entry (fmt, &hpp, entry); + s[ret] ='\0' ;slsmg_printf ("%s" , s);
from quick check it seems like all entry callback functions use some sort of snprint which should already handle the string length properly.. if not, we should fix that instead, no?
jirka
Namhyung Kim
maintainerRe: [PATCH 4/7] perf report: Honor column width setting
Quoted 10 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim
Set column width and do not change it if user gives -w/--column-widths option. It'll truncate longer symbols than the width if exists.
Signed-off-by Namhyung Kim <[email protected]>---
SNIP
Quoted 1 line
Quoted 13 lines
tools/perf/ui/browsers/hists.c static int hist_browser__show_entry(struct hist_browser *browser, · line 803
Quoted 9 lines
__HPP_COLOR_PERCENT_FN(overhead, period)tools/perf/ui/browsers/hists.c +2
-1@@ -797,8 +798,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,if (fmt->color) { width -= fmt->color (fmt, &hpp, entry); }else { - width -= fmt->entry (fmt, &hpp, entry); +int ret = fmt->entry (fmt, &hpp, entry); + s[ret] ='\0' ;slsmg_printf ("%s" , s);from quick check it seems like all entry callback functions use some sort of snprint which should already handle the string length properly.. if not, we should fix that instead, no?
It was 'symbol' sort entry (_hist_entry__sym_snprintf) which has several snprint calls in it. So I changed here rather than adding complexity the print function. I can change it if you want. ;)
Thanks,
Namhyung
Re: [PATCH 4/7] perf report: Honor column width setting
Quoted 25 lines · Namhyung Kim
Quoted 10 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim
Set column width and do not change it if user gives -w/--column-widths option. It'll truncate longer symbols than the width if exists.
Signed-off-by Namhyung Kim <[email protected]>---
SNIP
Quoted 1 line
Quoted 13 lines
tools/perf/ui/browsers/hists.c static int hist_browser__show_entry(struct hist_browser *browser, · line 803
Quoted 9 lines
__HPP_COLOR_PERCENT_FN(overhead, period)tools/perf/ui/browsers/hists.c +2
-1@@ -797,8 +798,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,if (fmt->color) { width -= fmt->color (fmt, &hpp, entry); }else { - width -= fmt->entry (fmt, &hpp, entry); +int ret = fmt->entry (fmt, &hpp, entry); + s[ret] ='\0' ;slsmg_printf ("%s" , s);from quick check it seems like all entry callback functions use some sort of snprint which should already handle the string length properly.. if not, we should fix that instead, no?
Quoted 3 lines
It was 'symbol' sort entry (
_hist_entry__sym_snprintf) which has several snprint calls in it. So I changed here rather than adding complexity the print function. I can change it if you want. ;)
it'd seem more consistent to me.. Arnaldo? ;-)
jirka
Namhyung Kim
maintainerPATCH 5/7 perf top: Add -w option for setting column width
In reply to Namhyung KimAdd -w/--column-widths option like perf report does so that users are able to see symbols even with some very long C++ library/functions. It can be a list separated by comma for each column.
$ perf top -w 0,20,30
The value of 0 means there's no limit.
--- tools/perf/Documentation/perf-report.txt | 2 +- tools/perf/Documentation/perf-top.txt | 6 ++++++ tools/perf/builtin-top.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +1 -1
@@ -147,7 +147,7 @@ OPTIONS -w:: --column-widths=<width[,width...]>:: Force each column width to the provided list, for large terminal - readability. + readability. 0 means no limit (default behavior). -t:: --field-separator=::
tools/perf/Documentation/perf-top.txt +6 -0
@@ -193,6 +193,12 @@ Default is to monitor all CPUS. sum of shown entries will be always 100%. "absolute" means it retains the original value before and after the filter is applied. +-w:: +--column-widths=<width[,width...]>:: + Force each column width to the provided list, for large terminal + readability. 0 means no limit (default behavior). + + INTERACTIVE PROMPTING KEYS --------------------------
tools/perf/builtin-top.c +3 -0
@@ -1131,6 +1131,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) "Don't show entries under that percent", parse_percent_limit),OPT_CALLBACK (0 ,"percentage" ,NULL ,"relative|absolute" ,"How to display percentage of filtered entries" , parse_filter_percentage), +OPT_STRING ('w' ,"column-widths" , &symbol_conf.col_width_list_str, +"width[,width...]" , +"don't try to adjust column width, use these fixed values" ),OPT_END () }; const char * const top_usage[] = {
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 6/7 perf tools: Add name field into perf_hpp_fmt
In reply to Namhyung KimIt makes the code a bit simpler and easier to debug IMHO.
I guess it can also remove similar code in perf diff, but let's keep it for a future work. :)
--- tools/perf/ui/gtk/hists.c | 4 +- tools/perf/ui/hist.c | 109 ++++++++++++++++++++++------------------------ tools/perf/util/hist.h | 1 + tools/perf/util/sort.c | 6 +-- 4 files changed, 57 insertions(+), 63 deletions(-)
tools/perf/ui/gtk/hists.c +1 -3
@@ -207,10 +207,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,if (perf_hpp__is_sort_entry (fmt)) sym_col = col_idx; - fmt->header (fmt, &hpp,hists_to_evsel (hists)); -gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), --1 ,ltrim (s), +-1 , fmt->name, renderer,"markup" , col_idx++,NULL ); }
tools/perf/ui/hist.c +52 -57
182 lines not on this page · raw message
tools/perf/util/hist.h +1 -0
@@ -192,6 +192,7 @@ struct perf_hpp { };struct perf_hpp_fmt { +const char *name;int (*header)(struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct perf_evsel *evsel); int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
tools/perf/util/sort.c +3 -3
@@ -1203,8 +1203,7 @@ void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)return ; hse = container_of(fmt, struct hpp_sort_entry, hpp); -hists__new_col_len (hists, hse->se->se_width_idx, -strlen (hse->se->se_header)); +hists__new_col_len (hists, hse->se->se_width_idx,strlen (fmt->name)); } static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -1218,7 +1217,7 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,if (!len) len =hists__col_len (&evsel->hists, hse->se->se_width_idx); -return scnprintf (hpp->buf, hpp->size,"%-*.*s" , len, len, hse->se->se_header); +return scnprintf (hpp->buf, hpp->size,"%-*.*s" , len, len, fmt->name); } static int __sort__hpp_width(struct perf_hpp_fmt *fmt,
@@ -1262,6 +1261,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd) } hse->se = sd->entry; + hse->hpp.name = sd->entry->se_header; hse->hpp.header = __sort__hpp_header; hse->hpp.width = __sort__hpp_width; hse->hpp.entry = __sort__hpp_entry;
Signature · 1 line
2.0.0
Re: [PATCH 6/7] perf tools: Add name field into perf_hpp_fmt
On Fri, Jul 25, 2014 at 10:18:57AM +0900, Namhyung Kim wrote:
SNIP
Quoted 8 lines
}
tools/perf/ui/hist.c +1
-1-#define __HPP_WIDTH_FN (_type, _str) \ +#define __HPP_WIDTH_FN (_type) \ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ struct perf_hpp *hpp __maybe_unused, \ struct perf_evsel *evsel) \
tools/perf/ui/hist.c static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ · line 223
Quoted 7 lines
tools/perf/ui/hist.c +2
-2@@ -219,19 +219,19 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \if (symbol_conf.event_group) \ len =max (len, evsel->nr_members * fmt->len); \ \ -if (len < (int )strlen (_str)) \ - len =strlen (_str); \ +if (len < (int )strlen (fmt->name)) \ + len =strlen (fmt->name); \
hum, so with the '_str' string argument missing we dont need this function to be generated by macro, right? could be one single function called hpp__width_entry or something like that
Quoted 5 lines
tools/perf/ui/hist.c +0
-1\return len; \ } -#define __HPP_HEADER_FN (_type, _str) \
tools/perf/ui/hist.c static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ · line 236
Quoted 10 lines
tools/perf/ui/hist.c +2
-1+#define __HPP_HEADER_FN (_type) \ static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \ struct perf_hpp *hpp, \ struct perf_evsel *evsel) \ { \ int len = hpp__width_##_type(fmt, hpp, evsel); \ -return scnprintf (hpp->buf, hpp->size,"%*s" , len, _str); \ + return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name); \ }
same here ^^^ for hpp__header_##_type
jirka
Namhyung Kim
maintainerRe: [PATCH 6/7] perf tools: Add name field into perf_hpp_fmt
Hi Jiri,
Quoted 15 lines · Jiri Olsa
On Fri, Jul 25, 2014 at 10:18:57AM +0900, Namhyung Kim wrote:
SNIP
Quoted 11 lines
}
tools/perf/ui/hist.c +1
-1-#define __HPP_WIDTH_FN (_type, _str) \ +#define __HPP_WIDTH_FN (_type) \ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ struct perf_hpp *hpp __maybe_unused, \ struct perf_evsel *evsel) \@@ -219,19 +219,19 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \if (symbol_conf.event_group) \ len =max (len, evsel->nr_members * fmt->len); \ \
Quoted 8 lines
tools/perf/ui/hist.c static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ · line 223
Quoted 4 lines
tools/perf/ui/hist.c +2
-2-if (len < (int )strlen (_str)) \ - len =strlen (_str); \ +if (len < (int )strlen (fmt->name)) \ + len =strlen (fmt->name); \hum, so with the '
_str' string argument missing we dont need this function to be generated by macro, right? could be one single function calledhpp__width_entryor something like that
You're right. Will change both!
Thanks,
Namhyung
Quoted 21 lines
Quoted 6 lines
tools/perf/ui/hist.c +0
-1\return len; \ } -#define __HPP_HEADER_FN (_type, _str) \tools/perf/ui/hist.c static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ · line 236
Quoted 10 lines
tools/perf/ui/hist.c +2
-1+#define __HPP_HEADER_FN (_type) \ static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \ struct perf_hpp *hpp, \ struct perf_evsel *evsel) \ { \ int len = hpp__width_##_type(fmt, hpp, evsel); \ -return scnprintf (hpp->buf, hpp->size,"%*s" , len, _str); \ + return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name); \ }same here ^^^ for hpp__header_##_type
jirka
Namhyung Kim
maintainerPATCH 7/7 perf tools: Fix column alignment when headers aren't shown on TUI
In reply to Namhyung KimIf user sets ui.show-headers config option to false, it didn't calculate default column width so it broke the alignment. This is because it does the calculation just before showing headers.
Move it to the beginning of the hist browser so that it can be called regardless of the config option.
--- tools/perf/ui/browsers/hists.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +4 -3
@@ -853,9 +853,6 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)if (perf_hpp__should_skip (fmt))continue ; -/* We need to ensure length of the columns header. */ -perf_hpp__reset_width (fmt, hists); - ret = fmt->header (fmt, &dummy_hpp,hists_to_evsel (hists));if (advance_hpp_check (&dummy_hpp, ret))break ;
@@ -1504,6 +1501,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,char buf[64 ];char script_opt[64 ];int delay_secs = hbt ? hbt->refresh :0 ; +struct perf_hpp_fmt *fmt;#define HIST_BROWSER_HELP_COMMON \ "h/?/F1 Show this window\n" \
@@ -1553,6 +1551,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,memset (options,0 ,sizeof (options)); +perf_hpp__for_each_format (fmt) +perf_hpp__reset_width (fmt, hists); +if (symbol_conf.col_width_list_str)perf_hpp__set_user_width (symbol_conf.col_width_list_str);
Signature · 1 line
2.0.0