summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-07-05 14:52:38 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2012-07-05 14:52:38 +0200
commit7c197c8e730a3040d9718f9d2c3ad5f44a988a57 (patch)
treec63e6e32d545e2c04a8b55f8842193c1888b26d6
parentacce478d8ee70ead531a0a49d69404b0652cccf6 (diff)
tput(1) manpage, add -b buflen option, exit status
-rw-r--r--sys/man/1/tput39
-rw-r--r--sys/src/cmd/tput.c35
2 files changed, 65 insertions, 9 deletions
diff --git a/sys/man/1/tput b/sys/man/1/tput
new file mode 100644
index 000000000..6828a56b6
--- /dev/null
+++ b/sys/man/1/tput
@@ -0,0 +1,39 @@
+.TH TPUT 1
+.SH NAME
+tput \- measure read throughput
+.SH SYNOPSIS
+.B tput
+[
+.B -b
+.I buflen
+] [
+.B -p
+]
+.SH DESCRIPTION
+.I Tput
+continuously reads standard input writing throughput statistics
+to standard error. The throughput value is calculated and written
+once per second and automatically scaled to kilo-, mega- or gigabytes.
+.PP
+When the
+.B -p
+flag is specified,
+.I tput
+will write the data read to standard output (the default is to
+discard the data).
+.PP
+A read blocksize (default is 8192) in bytes can be given with the
+.B -b
+.I buflen
+option.
+.SH EXAMPLE
+.EX
+tput </dev/zero
+.EE
+.SH SOURCE
+.B /sys/src/cmd/tput.c
+.SH SEE ALSO
+.IR iostats (4)
+.SH DIAGNOSTICS
+.I Tput
+sets error status on read error.
diff --git a/sys/src/cmd/tput.c b/sys/src/cmd/tput.c
index 47ef99b89..cd34c5871 100644
--- a/sys/src/cmd/tput.c
+++ b/sys/src/cmd/tput.c
@@ -1,23 +1,41 @@
#include <u.h>
#include <libc.h>
-enum {buflen = 4096};
+int dopipe;
+int buflen = 8192;
+uvlong bc, sec;
+
+void
+usage(void)
+{
+ fprint(2, "usage: %s [-b buflen] [-p]\n", argv0);
+ exits("usage");
+}
void
main(int argc, char **argv)
{
- int rc, cpid, fd, dopipe;
- static char buf[buflen];
- static uvlong bc, sec;
double speed;
+ int rc, cpid;
+ char *buf;
- dopipe = 0;
ARGBEGIN {
- case 'p': dopipe = 1;
+ case 'b':
+ buflen = atoi(EARGF(usage()));
+ break;
+ case 'p':
+ dopipe = 1;
+ break;
+ default:
+ usage();
} ARGEND
+
+ if(argc != 0)
+ usage();
bc = 0;
sec = 0;
+ buf = sbrk(buflen);
cpid = rfork(RFPROC | RFMEM);
if(cpid == 0) {
while(1) {
@@ -35,8 +53,7 @@ main(int argc, char **argv)
if(dopipe) write(1, buf, rc);
bc += rc;
}
- sprint(buf, "/proc/%d/note", cpid);
- fd = open(buf, OWRITE);
- write(fd, "kill", 4);
+ postnote(PNPROC, cpid, "kill");
if(rc < 0) sysfatal("%r");
+ exits(0);
}