On Fri, Apr 29, 2016 at 5:45 PM, Rob Landley <[email protected]> wrote: > On 04/29/2016 04:06 PM, enh wrote: >> sorry, hadn't had time to look until now. notes: >> >> * the tid column seems very wrong. in particular, i see a lot of >> duplicate tids. ah, the pid/tid columns don't auto-expand and are >> truncating... >> >> GNU: 147139 130820 ? 00:00:00 default_ThreadM >> toybox: 14713 13082 ? 00:00:00 default_ThreadM > > Hmmm, this sounds like a problem for PIDs too.
(yeah, sorry --- you can see that in my example above but i forgot to actually call it out.) > Let's see... > > $ ps -o pid:3,user:3,cmd:3 > PID USER CMD > 18748 la+ bash > 19147 la+ ps -o pid:3,user:3,cmd:3 > > Ok, I need to mark some columns as "expand this regardless" and others > to indicate when they get truncated, and yet it truncates the cmdline at > the right edge of the screen without indicating truncation... > > Hmmm... It's not quite obvious to me what the correct behavior is. > (Numeric fields expand, command lines are silently truncated, > non-command string fields do the + thing...? Maybe?) > >> * your -T is (like the desktop) showing the process name for each >> thread. Android shows the thread name, which is probably what you want >> if you're asking to see the threads in the first place. > > There's a thread name? Ah, the stat[2] field gets rewritten. in the pthread implementation we read/write /proc/self/task/%d/comm. toolbox's ps shows the text between ()s in the stat file. since you have to read that anyway, that probably makes sense. > How about if I treat PID != TID the same as kernel threads? [stat2name] > in square brackets? i reserve the right to come back later with strong negative feedback from users, but that sounds good to me. it might actually be useful to have a visible "not the main thread" distinction that doesn't require skipping back to the pid/tid columns. >> * you say 0 for BIT when you don't know, rather than leaving it blank >> (like Android) or using '-' (like some other ps fields). i don't think >> this matters, but i've attached a patch anyway. > > Applied. > >> * there's a whitespace mixup in the help text for -O. patch attached. > > Applied. > >> * i need to send you the Android-specific cruft for scheduling policy. > > Woot. you say that because you haven't seen it yet :-) attached. i kept the #ifs in lib/portability.* because there was no obvious way to just say "this field isn't useful outside of Android". >> other than that, i went through my old notes and i think everything >> else is now done. i'll get AOSP synced this afternoon (must be friday >> again!) and send you a patch for the scheduling policy names. > > I'll try to figure out what to do about column expansion. (Mental note: > how does this impact top not wrapping lines and thus scrolling the > screen...) > > Rob -- Elliott Hughes - http://who/enh - http://jessies.org/~enh/ Android native code/tools questions? Mail me/drop by/add me as a reviewer.
From 2f3acae8c94a83719bb8d33c35105ef569794723 Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Fri, 29 Apr 2016 18:04:20 -0700 Subject: [PATCH] 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 78e500b..f4354a8 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 <cutils/sched_policy.h>. +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 fdee5fc..87258fa 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 <cutils/sched_policy.h> +#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 1edddde..c0d382f 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<buf) out = buf; - } else if (CFG_TOYBOX_DEBUG) error_exit("bad which %d", which); + } else if (which==PS_PCY) sprintf(out, "%.2s", get_sched_policy_name(ll)); + else if (CFG_TOYBOX_DEBUG) error_exit("bad which %d", which); return out; } @@ -674,6 +679,9 @@ static int get_ps(struct dirtree *new) } } + // Do we need Android scheduling policy? + if (TT.bits&_PS_PCY) get_sched_policy(*slot, (SchedPolicy *)&slot[SLOT_pcy]); + // Fetch string data while parentfd still available, appending to buf. // (There's well over 3k of toybuf left. We could dynamically malloc, but // it'd almost never get used, querying length of a proc file is awkward, -- 2.8.0.rc3.226.g39d4020
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
