From e0dbc6beaf376f1a84464e103661840178576b84 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 29 Apr 2016 18:04:20 -0700 Subject: Add a ps "PCY" field for Android scheduling policy. --- lib/portability.c | 6 ++++++ lib/portability.h | 7 +++++++ toys/posix/ps.c | 22 +++++++++++++++------- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/portability.c b/lib/portability.c index 78e500b1..f4354a86 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -92,3 +92,9 @@ int clearenv(void) return 0; } #endif + +#if !defined(__ANDROID__) +// No-op implementations of . +int get_sched_policy(int tid, SchedPolicy *policy) { return 0; } +const char *get_sched_policy_name(SchedPolicy policy) { return "unknown"; } +#endif diff --git a/lib/portability.h b/lib/portability.h index fdee5fcf..87258fa9 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -270,3 +270,10 @@ pid_t xfork(void); //#define strncpy(...) @@strncpyisbadmmkay@@ //#define strncat(...) @@strncatisbadmmkay@@ +#ifdef __ANDROID__ +#include +#else +typedef int SchedPolicy; +int get_sched_policy(int tid, SchedPolicy *policy); +const char *get_sched_policy_name(SchedPolicy policy); +#endif diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 1eddddeb..c0d382f6 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -100,7 +100,8 @@ config PS GROUP Group name LABEL Security label MAJFL Major page faults MINFL Minor page faults NAME Command name (argv[0]) NI Niceness (lower is faster) - PCPU Percentage of CPU time used PGID Process Group ID + PCPU Percentage of CPU time used PCY Android scheduling policy + PGID Process Group ID PID Process ID PPID Parent Process ID PRI Priority (higher is faster) PSR Processor last executed on RGID Real (before sgid) group ID RGROUP Real (before sgid) group name @@ -304,15 +305,18 @@ enum { SLOT_rchar, /*All bytes read*/ SLOT_wchar, // All bytes written SLOT_rbytes, /*Disk bytes read*/ SLOT_wbytes, // Disk bytes written SLOT_swap, /*Swap pages used*/ SLOT_bits, // 32 or 64 - SLOT_tid, /*Thread ID*/ SLOT_tcount // Thread count + SLOT_tid, /*Thread ID*/ SLOT_tcount, // Thread count + SLOT_pcy, /*Android sched policy*/ + + SLOT_count }; // Data layout in toybuf struct carveup { - long long slot[58]; // data from /proc - unsigned short offset[5]; // offset of fields in str[] (skip name, always 0) + long long slot[SLOT_count]; // data (see enum above) + unsigned short offset[5]; // offset of fields in str[] (skip name, always 0) char state; - char str[]; // name, tty, command, wchan, attr, cmdline + char str[]; // name, tty, command, wchan, attr, cmdline }; // TODO: Android uses -30 for LABEL, but ideally it would auto-size. @@ -356,7 +360,7 @@ struct typography { // Misc {"STIME", 5, SLOT_starttime}, {"F", 1, 64|SLOT_flags}, {"S", -1, 64}, - {"STAT", -5, 64}, + {"STAT", -5, 64}, {"PCY", 3, 64|SLOT_pcy}, ); // Return 0 to discard, nonzero to keep @@ -518,7 +522,8 @@ static char *string_field(struct carveup *tb, struct strawberry *field) out = out+strlen(out)-3-abs(field->len); if (out