am 020f81bf: am d20ba7fc: Merge "ps: add flag to show ABI"

* commit '020f81bf1270bfa72167e3c358abf33bb60778a5':
  ps: add flag to show ABI
This commit is contained in:
Kenny Root 2014-05-15 00:11:09 +00:00 committed by Android Git Automerger
commit 101e92acf1

View file

@ -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])){