ref: b9d3ca5753cc1922236fc733605bc8b3caabc8c1
parent: 19657859166321fc3e32d1ab7e652dcc4c767e19
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Oct 24 18:51:30 EDT 2025
tput: add 'windowed' flag so we only average over windows it's often useful to see the roughly-instantaneous througput of something is, rather than the cumulative throughput; add a flag that dumps the throughput for the last second and then resets the counter.
--- a/sys/src/cmd/tput.c
+++ b/sys/src/cmd/tput.c
@@ -3,7 +3,9 @@
int dopipe;
int buflen;
-uvlong bc, sec;
+int windowed;
+vlong sec;
+Avlong nbytes;
void
usage(void)
@@ -26,6 +28,9 @@
case 'p':
dopipe = 1;
break;
+ case 'w':
+ windowed = 1;
+ break;
default:
usage();
} ARGEND
@@ -33,8 +38,6 @@
if(argc != 0)
usage();
- bc = 0;
- sec = 0;
if(buflen <= 0){buflen = iounit(0);
if(buflen <= 0)
@@ -47,7 +50,10 @@
if(cpid == 0) { while(1) {sleep(1000);
- speed = bc / ++sec;
+ if(windowed)
+ speed = aswapv(&nbytes, 0);
+ else
+ speed = agetv(&nbytes) / ++sec;
if(speed >= 1073741824) fprint(2, "%.2f GB/s\n", speed / 1073741824);
else if(speed >= 1048576) fprint(2, "%.2f MB/s\n", speed / 1048576);
else if(speed >= 1024) fprint(2, "%.2f KB/s\n", speed / 1024);
@@ -58,7 +64,7 @@
rc = read(0, buf, buflen);
if(rc <= 0) break;
if(dopipe) write(1, buf, rc);
- bc += rc;
+ aincv(&nbytes, rc);
}
postnote(PNPROC, cpid, "kill");
if(rc < 0) sysfatal("%r");--
⑨