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

perf list: Allow wordwrap to wrap on commas

A raw event encoding may be a block with terms separated by commas. If
wrapping such a string it would be useful to break at the commas, so
add this ability to wordwrap.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20240308001915.4060155-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
aa1f4ad2 39aa4ff6

+17 -4
+17 -4
tools/perf/builtin-list.c
··· 22 22 #include <subcmd/pager.h> 23 23 #include <subcmd/parse-options.h> 24 24 #include <linux/zalloc.h> 25 + #include <ctype.h> 25 26 #include <stdarg.h> 26 27 #include <stdio.h> 27 28 ··· 77 76 78 77 static void default_print_end(void *print_state __maybe_unused) {} 79 78 79 + static const char *skip_spaces_or_commas(const char *str) 80 + { 81 + while (isspace(*str) || *str == ',') 82 + ++str; 83 + return str; 84 + } 85 + 80 86 static void wordwrap(FILE *fp, const char *s, int start, int max, int corr) 81 87 { 82 88 int column = start; 83 89 int n; 84 90 bool saw_newline = false; 91 + bool comma = false; 85 92 86 93 while (*s) { 87 - int wlen = strcspn(s, " \t\n"); 94 + int wlen = strcspn(s, " ,\t\n"); 95 + const char *sep = comma ? "," : " "; 88 96 89 97 if ((column + wlen >= max && column > start) || saw_newline) { 90 - fprintf(fp, "\n%*s", start, ""); 98 + fprintf(fp, comma ? ",\n%*s" : "\n%*s", start, ""); 91 99 column = start + corr; 92 100 } 93 - n = fprintf(fp, "%s%.*s", column > start ? " " : "", wlen, s); 101 + if (column <= start) 102 + sep = ""; 103 + n = fprintf(fp, "%s%.*s", sep, wlen, s); 94 104 if (n <= 0) 95 105 break; 96 106 saw_newline = s[wlen] == '\n'; 97 107 s += wlen; 108 + comma = s[0] == ','; 98 109 column += n; 99 - s = skip_spaces(s); 110 + s = skip_spaces_or_commas(s); 100 111 } 101 112 } 102 113