aboutsummaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2012-03-05 16:14:39 -0800
committerGlenn Kasten <gkasten@google.com>2012-03-15 15:10:45 -0700
commit86c7cc81891a69ace7044de667b0624c284ee82b (patch)
tree6fff9f3e763724ee70181b6559e0a76b1ec21a03 /toolbox
parent019524a60e979053b8b8ffef61eae162de522257 (diff)
downloadsystem_core-86c7cc81891a69ace7044de667b0624c284ee82b.zip
system_core-86c7cc81891a69ace7044de667b0624c284ee82b.tar.gz
system_core-86c7cc81891a69ace7044de667b0624c284ee82b.tar.bz2
Add get_sched_policy_name() and use in ps and top
This will make it easier to add additional policies (cgroups) if needed. Also added comments to the sched_policy APIs. Change-Id: I33ce1cc4deae10983241f7391294b7a512d2c47c
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/ps.c10
-rw-r--r--toolbox/top.c13
2 files changed, 7 insertions, 16 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 7c3de4a..7c35ccb 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -167,14 +167,8 @@ static int ps_line(int pid, int tid, char *namefilter)
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 ");
- }
+ else
+ printf(" %.2s ", get_sched_policy_name(p));
}
printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);
if(display_flags&SHOW_TIME)
diff --git a/toolbox/top.c b/toolbox/top.c
index 999c8e1..7642522 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -48,6 +48,7 @@ struct cpu_info {
#define PROC_NAME_LEN 64
#define THREAD_NAME_LEN 32
+#define POLICY_NAME_LEN 4
struct proc_info {
struct proc_info *next;
@@ -67,7 +68,7 @@ struct proc_info {
long rss;
int prs;
int num_threads;
- char policy[32];
+ char policy[POLICY_NAME_LEN];
};
struct proc_list {
@@ -381,14 +382,10 @@ static int read_cmdline(char *filename, struct proc_info *proc) {
static void read_policy(int pid, struct proc_info *proc) {
SchedPolicy p;
if (get_sched_policy(pid, &p) < 0)
- strcpy(proc->policy, "unk");
+ strlcpy(proc->policy, "unk", POLICY_NAME_LEN);
else {
- if (p == SP_BACKGROUND)
- strcpy(proc->policy, "bg");
- else if (p == SP_FOREGROUND)
- strcpy(proc->policy, "fg");
- else
- strcpy(proc->policy, "er");
+ strlcpy(proc->policy, get_sched_policy_name(p), POLICY_NAME_LEN);
+ proc->policy[2] = '\0';
}
}