commit f10f52f1d5dfa787bd6b1ef53b857fdf57987119
parent 3f0a47dcd15e1c7f761a5fb713a5171d9df04814
Author: rpa <rpa@laika>
Date: Sun, 18 Dec 2022 21:01:58 +0000
src/bps: a primitive pipe speed monitor
Diffstat:
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/bps/bps.c b/src/bps/bps.c
@@ -0,0 +1,27 @@
+/*
+ bps - bytes per second
+*/
+#include <u.h>
+#include <libc.h>
+
+#define BSize 8192
+
+void
+main(void)
+{
+ char *buf = malloc(BSize);
+ long n;
+ vlong start = nsec(), cur, bytes = 0;;
+ for (;;) {
+ n = read(0, buf, BSize);
+ bytes += n;
+ write(1, buf, n);
+ if (n <= 0) return;
+ cur = nsec();
+ if (cur - start > 1000000000) {
+ fprint(2, "%lld\n", bytes);
+ start = cur;
+ bytes = 0;
+ }
+ }
+}
diff --git a/src/bps/mkfile b/src/bps/mkfile
@@ -0,0 +1,5 @@
+</$objtype/mkfile
+TARG=bps
+OFILES=bps.$O
+BIN=/$objtype/bin
+</sys/src/cmd/mkone