From 60da2d0b043a23303f052038ea83a933c2f80eb5 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 4 May 2016 18:25:41 -0700 Subject: "top -b -n1" should end with a newline. The use of TT.time to determine whether to use \r or \n is a little odd, but let's stick with that for now. Correct the spelling of millitime and add a test. --- toys/posix/ps.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'toys') diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 3a39353a..6b89c5ff 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1228,13 +1228,11 @@ static int header_line(int line, int rev) return line-1; } -// Get current time in miliseconds -static long long militime(void) +static long long millitime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec*1000+ts.tv_nsec/1000000; } @@ -1264,7 +1262,7 @@ static void top_common( plold = plist+(tock++&1); plnew = plist+(tock&1); - plnew->whence = militime(); + plnew->whence = millitime(); dt = dirtree_read("/proc", get_ps); plnew->tb = collate(plnew->count = TT.kcount, dt); TT.kcount = 0; @@ -1421,7 +1419,7 @@ static void top_common( recalc = 1; for (i = 0; inow+TT.top.d) timeout = now+TT.top.d; @@ -1439,7 +1436,7 @@ static void top_common( if (toys.optflags&FLAG_b) { msleep(timeout-now); // Make an obvious gap between datasets. - xputs("\n\n\n"); + xputs("\n\n"); continue; } @@ -1488,10 +1485,10 @@ static void top_setup(char *defo, char *defk) { int len; - TT.time = militime(); TT.top.d *= 1000; if (toys.optflags&FLAG_b) TT.width = TT.height = 99999; else { + TT.time = millitime(); set_terminal(0, 1, 0); sigatexit(tty_sigreset); xsignal(SIGWINCH, generic_signal); @@ -1532,7 +1529,7 @@ void top_main(void) static int iotop_filter(long long *oslot, long long *nslot, int milis) { if (!(toys.optflags&FLAG_a)) merge_deltas(oslot, nslot, milis); - else oslot[SLOT_upticks] = ((militime()-TT.time)*TT.ticks)/1000; + else oslot[SLOT_upticks] = ((millitime()-TT.time)*TT.ticks)/1000; return !(toys.optflags&FLAG_o)||oslot[SLOT_iobytes+!(toys.optflags&FLAG_A)]; } -- cgit v1.2.3