aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-05-03 15:09:14 -0700
committerRob Landley <rob@landley.net>2018-05-06 10:23:22 -0500
commiteee28e7b5851a6eb16f7969393d8c6292b1f8754 (patch)
treec740f8f098623e245fd00e689894b944fc2687f8 /toys
parent828fc9c8be7e68a901e4fe79504a67cb6c9c33e8 (diff)
downloadtoybox-eee28e7b5851a6eb16f7969393d8c6292b1f8754.tar.gz
Support fractional seconds (and other time units) in `top -d`.
LTP uses `top -d 0.1`, which isn't convincingly useful, but general support for other time units might be useful, and switching to xparsetime addresses both at once. Also fix 3169d948c049664bcf7216d4c4ae751881099d3e where I mistakenly treated `rev` and `toys.optflags&FLAG_b` as interchangeable. (Without this second fix, `top -b` looks fine but `top` is broken!) Also fix xparsetime to reject input such as "monkey" or "1monkey".
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/ps.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index c5c0f790..c5d487f5 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -48,8 +48,8 @@ USE_PS(NEWTOY(ps, "k(sort)*P(ppid)*aAdeflMno*O*p(pid)*s*t*Tu*U*g*G*wZ[!ol][+Ae][
// stayroot because iotop needs root to read other process' proc/$$/io
// TOP and IOTOP have a large common option block used for common processing,
// the default values are different but the flags are in the same order.
-USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d#=3<1m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
-USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d#=3<1m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
+USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d:m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d:m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PKILL(NEWTOY(pkill, "?Vu*U*t*s*P*g*G*fnovxl:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
@@ -249,13 +249,15 @@ GLOBALS(
struct {
long n;
long m;
- long d;
+ char *d;
long s;
struct arg_list *u;
struct arg_list *p;
struct arg_list *o;
struct arg_list *k;
struct arg_list *O;
+
+ long d_ms;
} top;
struct {
char *L;
@@ -1359,9 +1361,9 @@ static int header_line(int line, int rev)
if (toys.optflags&FLAG_b) rev = 0;
- printf("%s%*.*s%s\n", rev ? "\033[7m" : "",
+ printf("%s%*.*s%s%s\n", rev ? "\033[7m" : "",
(toys.optflags&FLAG_b) ? 0 : -TT.width, TT.width, toybuf,
- rev ? "\033[0m\r" : "");
+ rev ? "\033[0m" : "", (toys.optflags&FLAG_b) ? "" : "\r");
return line-1;
}
@@ -1566,8 +1568,8 @@ static void top_common(
}
now = millitime();
- if (timeout<=now) timeout = new.whence+TT.top.d;
- if (timeout<=now || timeout>now+TT.top.d) timeout = now+TT.top.d;
+ if (timeout<=now) timeout = new.whence+TT.top.d_ms;
+ if (timeout<=now || timeout>now+TT.top.d_ms) timeout = now+TT.top.d_ms;
// In batch mode, we ignore the keyboard.
if (toys.optflags&FLAG_b) {
@@ -1621,7 +1623,12 @@ static void top_common(
static void top_setup(char *defo, char *defk)
{
- TT.top.d *= 1000;
+ if (TT.top.d) {
+ long frac;
+
+ TT.top.d_ms = xparsetime(TT.top.d, 1000, &frac) * 1000;
+ TT.top.d_ms += frac;
+ } else TT.top.d_ms = 3000;
TT.ticks = sysconf(_SC_CLK_TCK); // units for starttime/uptime
TT.tty = tty_fd() != -1;