Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf list: Support newlines in wordwrap

Rather than a newline starting from column 0, record a newline was
seen and then add the newline and space before the next word.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221118024607.409083-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
1a9c20b4 6f520ce1

+7 -4
+7 -4
tools/perf/builtin-list.c
··· 74 74 { 75 75 int column = start; 76 76 int n; 77 + bool saw_newline = false; 77 78 78 79 while (*s) { 79 - int wlen = strcspn(s, " \t"); 80 + int wlen = strcspn(s, " \t\n"); 80 81 81 - if (column + wlen >= max && column > start) { 82 + if ((column + wlen >= max && column > start) || saw_newline) { 82 83 printf("\n%*s", start, ""); 83 84 column = start + corr; 84 85 } 85 86 n = printf("%s%.*s", column > start ? " " : "", wlen, s); 86 87 if (n <= 0) 87 88 break; 89 + saw_newline = s[wlen] == '\n'; 88 90 s += wlen; 89 91 column += n; 90 92 s = skip_spaces(s); ··· 148 146 wordwrap(desc, 8, pager_get_columns(), 0); 149 147 printf("]\n"); 150 148 } 151 - 149 + long_desc = long_desc ?: desc; 152 150 if (long_desc && print_state->long_desc) { 153 151 printf("%*s", 8, "["); 154 152 wordwrap(long_desc, 8, pager_get_columns(), 0); ··· 156 154 } 157 155 158 156 if (print_state->detailed && encoding_desc) { 159 - printf("%*s%s", 8, "", encoding_desc); 157 + printf("%*s", 8, ""); 158 + wordwrap(encoding_desc, 8, pager_get_columns(), 0); 160 159 if (metric_name) 161 160 printf(" MetricName: %s", metric_name); 162 161 if (metric_expr)