From 8b2646e1c048163e01a8dd7349f1e23d21ad76b0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 27 Jan 2017 12:54:25 -0800 Subject: top -H is more useful if it shows thread names. I knew that just showing the process name was a divergence from traditional Android behavior, but I was curious to see whether anyone cared. Bug reports show that they do. I've not made this conditional on CFG_TOYBOX_ON_ANDROID on the assumption that this is more useful for everyone else too. (Why are you asking for per-thread information if you don't actually want to be able to identify individual threads?) Why not _just_ show the thread name? Because on Android at least, every process has lots of identically-named threads; everyone has GC threads, everyone has JIT threads, and so knowing _just_ the thread name is rarely useful. Why show thread name first? Because the kernel limits thread names to 15 bytes plus a NUL, so any left-over space should go to the process name, so that should come last. Why call the thread name THREAD? Because "CMD" isn't obviously "thread name" to folks who don't know how this is implemented behind the scenes. This change also removes an incorrect "usage:" comment. None of the other commands in this file duplicated their "usage:" lines, and this copy wasn't even close to being correct. Bug: http://b/34610082 --- toys/posix/ps.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 8404e793..35763509 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1598,10 +1598,9 @@ static void top_setup(char *defo, char *defk) void top_main(void) { - // usage: [-h HEADER] -o OUTPUT -k SORT - - sprintf(toybuf, "PID,USER,%s%%CPU,%%MEM,TIME+,ARGS", - TT.top.O ? "" : "PR,NI,VIRT,RES,SHR,S,"); + sprintf(toybuf, "PID,USER,%s%%CPU,%%MEM,TIME+,%s", + TT.top.O ? "" : "PR,NI,VIRT,RES,SHR,S,", + toys.optflags&FLAG_H ? "CMD:15=THREAD,NAME=PROCESS" : "ARGS"); if (!TT.top.s) TT.top.s = TT.top.O ? 3 : 9; top_setup(toybuf, "-%CPU,-ETIME,-PID"); if (TT.top.O) { -- cgit v1.2.3