am 39274417: toolbox: Add scheduling policy display to top/ps
Merge commit '392744175c4de67dc98e72da6745e6351118c985' into eclair-mr2 * commit '392744175c4de67dc98e72da6745e6351118c985': toolbox: Add scheduling policy display to top/ps
This commit is contained in:
commit
0d6f587f92
2 changed files with 51 additions and 9 deletions
26
toolbox/ps.c
26
toolbox/ps.c
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
|
#include <cutils/sched_policy.h>
|
||||||
|
|
||||||
|
|
||||||
static char *nexttoksep(char **strp, char *sep)
|
static char *nexttoksep(char **strp, char *sep)
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +26,7 @@ static char *nexttok(char **strp)
|
||||||
|
|
||||||
#define SHOW_PRIO 1
|
#define SHOW_PRIO 1
|
||||||
#define SHOW_TIME 2
|
#define SHOW_TIME 2
|
||||||
|
#define SHOW_POLICY 4
|
||||||
|
|
||||||
static int display_flags = 0;
|
static int display_flags = 0;
|
||||||
|
|
||||||
|
|
@ -138,12 +141,26 @@ static int ps_line(int pid, int tid, char *namefilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
|
if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
|
||||||
printf("%-8s %-5d %-5d %-5d %-5d", user, pid, ppid, vss / 1024, rss * 4);
|
printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
|
||||||
if(display_flags&SHOW_PRIO)
|
if(display_flags&SHOW_PRIO)
|
||||||
printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
|
printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
|
||||||
|
if (display_flags & SHOW_POLICY) {
|
||||||
|
SchedPolicy p;
|
||||||
|
if (get_sched_policy(pid, &p) < 0)
|
||||||
|
printf(" un ");
|
||||||
|
else {
|
||||||
|
if (p == SP_BACKGROUND)
|
||||||
|
printf(" bg ");
|
||||||
|
else if (p == SP_FOREGROUND)
|
||||||
|
printf(" fg ");
|
||||||
|
else
|
||||||
|
printf(" er ");
|
||||||
|
}
|
||||||
|
}
|
||||||
printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);
|
printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);
|
||||||
if(display_flags&SHOW_TIME)
|
if(display_flags&SHOW_TIME)
|
||||||
printf(" (u:%d, s:%d)", utime, stime);
|
printf(" (u:%d, s:%d)", utime, stime);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -186,6 +203,8 @@ int ps_main(int argc, char **argv)
|
||||||
threads = 1;
|
threads = 1;
|
||||||
} else if(!strcmp(argv[1],"-x")) {
|
} else if(!strcmp(argv[1],"-x")) {
|
||||||
display_flags |= SHOW_TIME;
|
display_flags |= SHOW_TIME;
|
||||||
|
} else if(!strcmp(argv[1],"-P")) {
|
||||||
|
display_flags |= SHOW_POLICY;
|
||||||
} else if(!strcmp(argv[1],"-p")) {
|
} else if(!strcmp(argv[1],"-p")) {
|
||||||
display_flags |= SHOW_PRIO;
|
display_flags |= SHOW_PRIO;
|
||||||
} else if(isdigit(argv[1][0])){
|
} else if(isdigit(argv[1][0])){
|
||||||
|
|
@ -197,8 +216,9 @@ int ps_main(int argc, char **argv)
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("USER PID PPID VSIZE RSS %sWCHAN PC NAME\n",
|
printf("USER PID PPID VSIZE RSS %s %s WCHAN PC NAME\n",
|
||||||
(display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"");
|
(display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
|
||||||
|
(display_flags&SHOW_POLICY)?"PCY " : "");
|
||||||
while((de = readdir(d)) != 0){
|
while((de = readdir(d)) != 0){
|
||||||
if(isdigit(de->d_name[0])){
|
if(isdigit(de->d_name[0])){
|
||||||
int pid = atoi(de->d_name);
|
int pid = atoi(de->d_name);
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <cutils/sched_policy.h>
|
||||||
|
|
||||||
struct cpu_info {
|
struct cpu_info {
|
||||||
long unsigned utime, ntime, stime, itime;
|
long unsigned utime, ntime, stime, itime;
|
||||||
long unsigned iowtime, irqtime, sirqtime;
|
long unsigned iowtime, irqtime, sirqtime;
|
||||||
|
|
@ -64,6 +66,7 @@ struct proc_info {
|
||||||
long vss;
|
long vss;
|
||||||
long rss;
|
long rss;
|
||||||
int num_threads;
|
int num_threads;
|
||||||
|
char policy[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct proc_list {
|
struct proc_list {
|
||||||
|
|
@ -88,6 +91,7 @@ static struct proc_info *alloc_proc(void);
|
||||||
static void free_proc(struct proc_info *proc);
|
static void free_proc(struct proc_info *proc);
|
||||||
static void read_procs(void);
|
static void read_procs(void);
|
||||||
static int read_stat(char *filename, struct proc_info *proc);
|
static int read_stat(char *filename, struct proc_info *proc);
|
||||||
|
static void read_policy(int pid, struct proc_info *proc);
|
||||||
static void add_proc(int proc_num, struct proc_info *proc);
|
static void add_proc(int proc_num, struct proc_info *proc);
|
||||||
static int read_cmdline(char *filename, struct proc_info *proc);
|
static int read_cmdline(char *filename, struct proc_info *proc);
|
||||||
static int read_status(char *filename, struct proc_info *proc);
|
static int read_status(char *filename, struct proc_info *proc);
|
||||||
|
|
@ -260,6 +264,8 @@ static void read_procs(void) {
|
||||||
sprintf(filename, "/proc/%d/status", pid);
|
sprintf(filename, "/proc/%d/status", pid);
|
||||||
read_status(filename, proc);
|
read_status(filename, proc);
|
||||||
|
|
||||||
|
read_policy(pid, proc);
|
||||||
|
|
||||||
proc->num_threads = 0;
|
proc->num_threads = 0;
|
||||||
} else {
|
} else {
|
||||||
sprintf(filename, "/proc/%d/cmdline", pid);
|
sprintf(filename, "/proc/%d/cmdline", pid);
|
||||||
|
|
@ -289,6 +295,8 @@ static void read_procs(void) {
|
||||||
sprintf(filename, "/proc/%d/task/%d/stat", pid, tid);
|
sprintf(filename, "/proc/%d/task/%d/stat", pid, tid);
|
||||||
read_stat(filename, proc);
|
read_stat(filename, proc);
|
||||||
|
|
||||||
|
read_policy(tid, proc);
|
||||||
|
|
||||||
strcpy(proc->name, cur_proc.name);
|
strcpy(proc->name, cur_proc.name);
|
||||||
proc->uid = cur_proc.uid;
|
proc->uid = cur_proc.uid;
|
||||||
proc->gid = cur_proc.gid;
|
proc->gid = cur_proc.gid;
|
||||||
|
|
@ -368,6 +376,20 @@ static int read_cmdline(char *filename, struct proc_info *proc) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void read_policy(int pid, struct proc_info *proc) {
|
||||||
|
SchedPolicy p;
|
||||||
|
if (get_sched_policy(pid, &p) < 0)
|
||||||
|
strcpy(proc->policy, "unk");
|
||||||
|
else {
|
||||||
|
if (p == SP_BACKGROUND)
|
||||||
|
strcpy(proc->policy, "bg");
|
||||||
|
else if (p == SP_FOREGROUND)
|
||||||
|
strcpy(proc->policy, "fg");
|
||||||
|
else
|
||||||
|
strcpy(proc->policy, "er");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int read_status(char *filename, struct proc_info *proc) {
|
static int read_status(char *filename, struct proc_info *proc) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[MAX_LINE];
|
char line[MAX_LINE];
|
||||||
|
|
@ -432,9 +454,9 @@ static void print_procs(void) {
|
||||||
total_delta_time);
|
total_delta_time);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (!threads)
|
if (!threads)
|
||||||
printf("%5s %4s %1s %5s %7s %7s %-8s %s\n", "PID", "CPU%", "S", "#THR", "VSS", "RSS", "UID", "Name");
|
printf("%5s %4s %1s %5s %7s %7s %3s %-8s %s\n", "PID", "CPU%", "S", "#THR", "VSS", "RSS", "PCY", "UID", "Name");
|
||||||
else
|
else
|
||||||
printf("%5s %5s %4s %1s %7s %7s %-8s %-15s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "UID", "Thread", "Proc");
|
printf("%5s %5s %4s %1s %7s %7s %3s %-8s %-15s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "PCY", "UID", "Thread", "Proc");
|
||||||
|
|
||||||
for (i = 0; i < num_new_procs; i++) {
|
for (i = 0; i < num_new_procs; i++) {
|
||||||
proc = new_procs[i];
|
proc = new_procs[i];
|
||||||
|
|
@ -456,11 +478,11 @@ static void print_procs(void) {
|
||||||
group_str = group_buf;
|
group_str = group_buf;
|
||||||
}
|
}
|
||||||
if (!threads)
|
if (!threads)
|
||||||
printf("%5d %3ld%% %c %5d %6ldK %6ldK %-8.8s %s\n", proc->pid, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
|
printf("%5d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
|
||||||
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
|
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
|
||||||
else
|
else
|
||||||
printf("%5d %5d %3ld%% %c %6ldK %6ldK %-8.8s %-15s %s\n", proc->pid, proc->tid, proc->delta_time * 100 / total_delta_time, proc->state,
|
printf("%5d %5d %3ld%% %c %6ldK %6ldK %3s %-8.8s %-15s %s\n", proc->pid, proc->tid, proc->delta_time * 100 / total_delta_time, proc->state,
|
||||||
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->tname, proc->name);
|
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->tname, proc->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue