diff options
author | Kenny Root <kroot@google.com> | 2014-05-15 00:03:39 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-05-15 00:03:41 +0000 |
commit | d20ba7fca295453648bc9093db03c16efbc6df1b (patch) | |
tree | 59ea8beed2b9d6ffc93da67c4782dd140bdb900b /toolbox | |
parent | ed02fbf05c21442f40407bfaefcca35b985ad66a (diff) | |
parent | 8f197e65790265b362fc01c5f730365dc7dc1809 (diff) | |
download | system_core-d20ba7fca295453648bc9093db03c16efbc6df1b.zip system_core-d20ba7fca295453648bc9093db03c16efbc6df1b.tar.gz system_core-d20ba7fca295453648bc9093db03c16efbc6df1b.tar.bz2 |
Merge "ps: add flag to show ABI"
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/ps.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index 7c35ccb..e9fba0b 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -28,9 +28,12 @@ static char *nexttok(char **strp) #define SHOW_POLICY 4 #define SHOW_CPU 8 #define SHOW_MACLABEL 16 +#define SHOW_ABI 32 static int display_flags = 0; +static void print_exe_abi(int pid); + static int ps_line(int pid, int tid, char *namefilter) { char statline[1024]; @@ -170,7 +173,11 @@ static int ps_line(int pid, int tid, char *namefilter) else printf(" %.2s ", get_sched_policy_name(p)); } - printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); + printf(" %08x %08x %s ", wchan, eip, state); + if (display_flags & SHOW_ABI) { + print_exe_abi(pid); + } + printf("%s", cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) printf(" (u:%d, s:%d)", utime, stime); @@ -179,6 +186,39 @@ static int ps_line(int pid, int tid, char *namefilter) return 0; } +static void print_exe_abi(int pid) +{ + int fd, r; + char exeline[1024]; + + sprintf(exeline, "/proc/%d/exe", pid); + fd = open(exeline, O_RDONLY); + if(fd == 0) { + printf(" "); + return; + } + r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); + close(fd); + if(r < 0) { + printf(" "); + return; + } + if (memcmp("\177ELF", exeline, 4) != 0) { + printf("?? "); + return; + } + switch (exeline[4]) { + case 1: + printf("32 "); + return; + case 2: + printf("64 "); + return; + default: + printf("?? "); + return; + } +} void ps_threads(int pid, char *namefilter) { @@ -224,7 +264,9 @@ int ps_main(int argc, char **argv) display_flags |= SHOW_PRIO; } else if(!strcmp(argv[1],"-c")) { display_flags |= SHOW_CPU; - } else if(isdigit(argv[1][0])){ + } else if(!strcmp(argv[1],"--abi")) { + display_flags |= SHOW_ABI; + } else if(isdigit(argv[1][0])){ pidfilter = atoi(argv[1]); } else { namefilter = argv[1]; @@ -236,10 +278,11 @@ int ps_main(int argc, char **argv) if (display_flags & SHOW_MACLABEL) { printf("LABEL USER PID PPID NAME\n"); } else { - printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n", + printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n", (display_flags&SHOW_CPU)?"CPU ":"", (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"", - (display_flags&SHOW_POLICY)?"PCY " : ""); + (display_flags&SHOW_POLICY)?"PCY " : "", + (display_flags&SHOW_ABI)?"ABI " : ""); } while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ |