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

perf tools: Query terminal width and use in perf list

Automatically adapt the now wider and word wrapped perf list output to
wider terminals. This requires querying the terminal before the auto
pager takes over, and exporting this information from the pager
subsystem.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1473978296-20712-8-git-send-email-sukadev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andi Kleen and committed by
Arnaldo Carvalho de Melo
61eb2eb4 08e60ed1

+19 -1
+16
tools/lib/subcmd/pager.c
··· 3 3 #include <stdio.h> 4 4 #include <string.h> 5 5 #include <signal.h> 6 + #include <sys/ioctl.h> 6 7 #include "pager.h" 7 8 #include "run-command.h" 8 9 #include "sigchain.h" ··· 15 14 */ 16 15 17 16 static int spawned_pager; 17 + static int pager_columns; 18 18 19 19 void pager_init(const char *pager_env) 20 20 { ··· 60 58 void setup_pager(void) 61 59 { 62 60 const char *pager = getenv(subcmd_config.pager_env); 61 + struct winsize sz; 63 62 64 63 if (!isatty(1)) 65 64 return; 65 + if (ioctl(1, TIOCGWINSZ, &sz) == 0) 66 + pager_columns = sz.ws_col; 66 67 if (!pager) 67 68 pager = getenv("PAGER"); 68 69 if (!(pager || access("/usr/bin/pager", X_OK))) ··· 102 97 int pager_in_use(void) 103 98 { 104 99 return spawned_pager; 100 + } 101 + 102 + int pager_get_columns(void) 103 + { 104 + char *s; 105 + 106 + s = getenv("COLUMNS"); 107 + if (s) 108 + return atoi(s); 109 + 110 + return (pager_columns ? pager_columns : 80) - 2; 105 111 }
+1
tools/lib/subcmd/pager.h
··· 5 5 6 6 extern void setup_pager(void); 7 7 extern int pager_in_use(void); 8 + extern int pager_get_columns(void); 8 9 9 10 #endif /* __SUBCMD_PAGER_H */
+2 -1
tools/perf/util/pmu.c
··· 14 14 #include "cpumap.h" 15 15 #include "header.h" 16 16 #include "pmu-events/pmu-events.h" 17 + #include "cache.h" 17 18 18 19 struct perf_pmu_format { 19 20 char *name; ··· 1093 1092 int len, j; 1094 1093 struct pair *aliases; 1095 1094 int numdesc = 0; 1096 - int columns = 78; 1095 + int columns = pager_get_columns(); 1097 1096 1098 1097 pmu = NULL; 1099 1098 len = 0;