]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/tput.c
merge
[plan9front.git] / sys / src / cmd / tput.c
1 #include <u.h>
2 #include <libc.h>
3
4 enum {buflen = 4096};
5
6 void
7 main(int argc, char **argv)
8 {
9         int rc, cpid, fd, dopipe;
10         static char buf[buflen];
11         static uvlong bc, sec;
12         double speed;
13         
14         dopipe = 0;
15         ARGBEGIN {
16         case 'p': dopipe = 1;
17         } ARGEND
18         
19         bc = 0;
20         sec = 0;
21         cpid = rfork(RFPROC | RFMEM);
22         if(cpid == 0) {
23                 while(1) {
24                         sleep(1000);
25                         speed = bc / ++sec;
26                         if(speed >= 1073741824) fprint(2, "%.2f GB/s\n", speed / 1073741824);
27                         else if(speed >= 1048576) fprint(2, "%.2f MB/s\n", speed / 1048576);
28                         else if(speed >= 1024) fprint(2, "%.2f KB/s\n", speed / 1024);
29                         else fprint(2, "%.2f B/s\n", speed);
30                 }
31         }
32         while(1) {
33                 rc = read(0, buf, buflen);
34                 if(rc <= 0) break;
35                 if(dopipe) write(1, buf, rc);
36                 bc += rc;
37         }
38         sprint(buf, "/proc/%d/note", cpid);
39         fd = open(buf, OWRITE);
40         write(fd, "kill", 4);
41         if(rc < 0) sysfatal("%r");
42 }