summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSan Mehat2009-10-27 13:53:22 -0500
committerSan Mehat2009-10-27 14:27:47 -0500
commit392744175c4de67dc98e72da6745e6351118c985 (patch)
tree60573427d30ce72b300fbe4e814162e91e5819f6
parentc0dfca7ae1f6016461235552091c2cacacca82a2 (diff)
downloadplatform-system-core-392744175c4de67dc98e72da6745e6351118c985.tar.gz
platform-system-core-392744175c4de67dc98e72da6745e6351118c985.tar.xz
platform-system-core-392744175c4de67dc98e72da6745e6351118c985.zip
toolbox: Add scheduling policy display to top/ps
Signed-off-by: San Mehat <san@google.com>
-rw-r--r--toolbox/ps.c26
-rw-r--r--toolbox/top.c34
2 files changed, 51 insertions, 9 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 3b86fa252..bc50cfa97 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -11,6 +11,8 @@
11 11
12#include <pwd.h> 12#include <pwd.h>
13 13
14#include <cutils/sched_policy.h>
15
14 16
15static char *nexttoksep(char **strp, char *sep) 17static char *nexttoksep(char **strp, char *sep)
16{ 18{
@@ -24,6 +26,7 @@ static char *nexttok(char **strp)
24 26
25#define SHOW_PRIO 1 27#define SHOW_PRIO 1
26#define SHOW_TIME 2 28#define SHOW_TIME 2
29#define SHOW_POLICY 4
27 30
28static int display_flags = 0; 31static int display_flags = 0;
29 32
@@ -138,12 +141,26 @@ static int ps_line(int pid, int tid, char *namefilter)
138 } 141 }
139 142
140 if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) { 143 if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
141 printf("%-8s %-5d %-5d %-5d %-5d", user, pid, ppid, vss / 1024, rss * 4); 144 printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
142 if(display_flags&SHOW_PRIO) 145 if(display_flags&SHOW_PRIO)
143 printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched); 146 printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
147 if (display_flags & SHOW_POLICY) {
148 SchedPolicy p;
149 if (get_sched_policy(pid, &p) < 0)
150 printf(" un ");
151 else {
152 if (p == SP_BACKGROUND)
153 printf(" bg ");
154 else if (p == SP_FOREGROUND)
155 printf(" fg ");
156 else
157 printf(" er ");
158 }
159 }
144 printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); 160 printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);
145 if(display_flags&SHOW_TIME) 161 if(display_flags&SHOW_TIME)
146 printf(" (u:%d, s:%d)", utime, stime); 162 printf(" (u:%d, s:%d)", utime, stime);
163
147 printf("\n"); 164 printf("\n");
148 } 165 }
149 return 0; 166 return 0;
@@ -186,6 +203,8 @@ int ps_main(int argc, char **argv)
186 threads = 1; 203 threads = 1;
187 } else if(!strcmp(argv[1],"-x")) { 204 } else if(!strcmp(argv[1],"-x")) {
188 display_flags |= SHOW_TIME; 205 display_flags |= SHOW_TIME;
206 } else if(!strcmp(argv[1],"-P")) {
207 display_flags |= SHOW_POLICY;
189 } else if(!strcmp(argv[1],"-p")) { 208 } else if(!strcmp(argv[1],"-p")) {
190 display_flags |= SHOW_PRIO; 209 display_flags |= SHOW_PRIO;
191 } else if(isdigit(argv[1][0])){ 210 } else if(isdigit(argv[1][0])){
@@ -197,8 +216,9 @@ int ps_main(int argc, char **argv)
197 argv++; 216 argv++;
198 } 217 }
199 218
200 printf("USER PID PPID VSIZE RSS %sWCHAN PC NAME\n", 219 printf("USER PID PPID VSIZE RSS %s %s WCHAN PC NAME\n",
201 (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":""); 220 (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
221 (display_flags&SHOW_POLICY)?"PCY " : "");
202 while((de = readdir(d)) != 0){ 222 while((de = readdir(d)) != 0){
203 if(isdigit(de->d_name[0])){ 223 if(isdigit(de->d_name[0])){
204 int pid = atoi(de->d_name); 224 int pid = atoi(de->d_name);
diff --git a/toolbox/top.c b/toolbox/top.c
index dcc084344..daade6d64 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -39,6 +39,8 @@
39#include <sys/types.h> 39#include <sys/types.h>
40#include <unistd.h> 40#include <unistd.h>
41 41
42#include <cutils/sched_policy.h>
43
42struct cpu_info { 44struct cpu_info {
43 long unsigned utime, ntime, stime, itime; 45 long unsigned utime, ntime, stime, itime;
44 long unsigned iowtime, irqtime, sirqtime; 46 long unsigned iowtime, irqtime, sirqtime;
@@ -64,6 +66,7 @@ struct proc_info {
64 long vss; 66 long vss;
65 long rss; 67 long rss;
66 int num_threads; 68 int num_threads;
69 char policy[32];
67}; 70};
68 71
69struct proc_list { 72struct proc_list {
@@ -88,6 +91,7 @@ static struct proc_info *alloc_proc(void);
88static void free_proc(struct proc_info *proc); 91static void free_proc(struct proc_info *proc);
89static void read_procs(void); 92static void read_procs(void);
90static int read_stat(char *filename, struct proc_info *proc); 93static int read_stat(char *filename, struct proc_info *proc);
94static void read_policy(int pid, struct proc_info *proc);
91static void add_proc(int proc_num, struct proc_info *proc); 95static void add_proc(int proc_num, struct proc_info *proc);
92static int read_cmdline(char *filename, struct proc_info *proc); 96static int read_cmdline(char *filename, struct proc_info *proc);
93static int read_status(char *filename, struct proc_info *proc); 97static int read_status(char *filename, struct proc_info *proc);
@@ -260,6 +264,8 @@ static void read_procs(void) {
260 sprintf(filename, "/proc/%d/status", pid); 264 sprintf(filename, "/proc/%d/status", pid);
261 read_status(filename, proc); 265 read_status(filename, proc);
262 266
267 read_policy(pid, proc);
268
263 proc->num_threads = 0; 269 proc->num_threads = 0;
264 } else { 270 } else {
265 sprintf(filename, "/proc/%d/cmdline", pid); 271 sprintf(filename, "/proc/%d/cmdline", pid);
@@ -289,6 +295,8 @@ static void read_procs(void) {
289 sprintf(filename, "/proc/%d/task/%d/stat", pid, tid); 295 sprintf(filename, "/proc/%d/task/%d/stat", pid, tid);
290 read_stat(filename, proc); 296 read_stat(filename, proc);
291 297
298 read_policy(tid, proc);
299
292 strcpy(proc->name, cur_proc.name); 300 strcpy(proc->name, cur_proc.name);
293 proc->uid = cur_proc.uid; 301 proc->uid = cur_proc.uid;
294 proc->gid = cur_proc.gid; 302 proc->gid = cur_proc.gid;
@@ -368,6 +376,20 @@ static int read_cmdline(char *filename, struct proc_info *proc) {
368 return 0; 376 return 0;
369} 377}
370 378
379static void read_policy(int pid, struct proc_info *proc) {
380 SchedPolicy p;
381 if (get_sched_policy(pid, &p) < 0)
382 strcpy(proc->policy, "unk");
383 else {
384 if (p == SP_BACKGROUND)
385 strcpy(proc->policy, "bg");
386 else if (p == SP_FOREGROUND)
387 strcpy(proc->policy, "fg");
388 else
389 strcpy(proc->policy, "er");
390 }
391}
392
371static int read_status(char *filename, struct proc_info *proc) { 393static int read_status(char *filename, struct proc_info *proc) {
372 FILE *file; 394 FILE *file;
373 char line[MAX_LINE]; 395 char line[MAX_LINE];
@@ -432,9 +454,9 @@ static void print_procs(void) {
432 total_delta_time); 454 total_delta_time);
433 printf("\n"); 455 printf("\n");
434 if (!threads) 456 if (!threads)
435 printf("%5s %4s %1s %5s %7s %7s %-8s %s\n", "PID", "CPU%", "S", "#THR", "VSS", "RSS", "UID", "Name"); 457 printf("%5s %4s %1s %5s %7s %7s %3s %-8s %s\n", "PID", "CPU%", "S", "#THR", "VSS", "RSS", "PCY", "UID", "Name");
436 else 458 else
437 printf("%5s %5s %4s %1s %7s %7s %-8s %-15s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "UID", "Thread", "Proc"); 459 printf("%5s %5s %4s %1s %7s %7s %3s %-8s %-15s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "PCY", "UID", "Thread", "Proc");
438 460
439 for (i = 0; i < num_new_procs; i++) { 461 for (i = 0; i < num_new_procs; i++) {
440 proc = new_procs[i]; 462 proc = new_procs[i];
@@ -456,11 +478,11 @@ static void print_procs(void) {
456 group_str = group_buf; 478 group_str = group_buf;
457 } 479 }
458 if (!threads) 480 if (!threads)
459 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, 481 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,
460 proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->name[0] != 0 ? proc->name : proc->tname); 482 proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
461 else 483 else
462 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, 484 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,
463 proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->tname, proc->name); 485 proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->tname, proc->name);
464 } 486 }
465} 487}
466 488